From 898cb345ec462f2b322a96b3cf5cbc830e4cc079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B8=D0=BC=D0=B8=D0=BD?= Date: Thu, 14 May 2026 12:33:43 +0000 Subject: [PATCH] fix(ui): DictionaryEditorDialog disables Save when draft workflow needed --- .../schema/DictionaryEditorDialog.tsx | 31 +++++++++++- .../service/DictionaryDefinitionService.java | 21 ++++++-- .../reference/CascadeCloseService.java | 50 ++++++++++++++++++- 3 files changed, 95 insertions(+), 7 deletions(-) diff --git a/ordinis-admin-ui/src/components/schema/DictionaryEditorDialog.tsx b/ordinis-admin-ui/src/components/schema/DictionaryEditorDialog.tsx index f58a0d3..79d09d5 100644 --- a/ordinis-admin-ui/src/components/schema/DictionaryEditorDialog.tsx +++ b/ordinis-admin-ui/src/components/schema/DictionaryEditorDialog.tsx @@ -138,6 +138,24 @@ export const DictionaryEditorDialog = ({ open, mode, onClose, onSuccess }: Props [isEdit, initial, changes, schemaVersion], ) + // Approval-aware Save: when editing an approval-required dict, any schema + // change OR toggling approvalRequired off OR changing approvalMinRole has + // to route through the schema-draft workflow. The backend will reject with + // 422 approval_required, but it's much better UX to disable Save up front + // and tell the user to open a draft instead. Mirror the three backend + // gate clauses exactly so the UX matches the server contract. + const wasApprovalRequired = + Boolean((initial as { approvalRequired?: boolean } | null)?.approvalRequired) + const initialMinRole = + ((initial as { approvalMinRole?: string } | null)?.approvalMinRole ?? '') || null + const currentMinRole = approvalMinRole.trim() === '' ? null : approvalMinRole.trim() + const schemaChangedFromInitial = isEdit && changes.length > 0 + const approvalToggledOff = isEdit && wasApprovalRequired && !approvalRequired + const minRoleChanged = isEdit && wasApprovalRequired && initialMinRole !== currentMinRole + const requiresDraftFlow = + isEdit && wasApprovalRequired + && (schemaChangedFromInitial || approvalToggledOff || minRoleChanged) + const activeMutation = isEdit ? updateMut : createMut const serverError = serverErrorMessage(activeMutation.error) @@ -412,6 +430,17 @@ export const DictionaryEditorDialog = ({ open, mode, onClose, onSuccess }: Props {serverError && {serverError}} + {requiresDraftFlow && ( + + {t('schema.approvalRequired.editorBlock', { + defaultValue: + 'Этот словарь требует ревью изменений. Закройте редактор и нажмите ' + + '«Создать черновик схемы» на странице справочника — там вы сможете ' + + 'отправить эти изменения на согласование.', + })} + + )} +