From 8035a604bddb877ca4148d92ba34eb9e65c4bcc5 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:24:57 +0300 Subject: [PATCH] B: Fix renaming validation --- rsconcept/frontend/src/dialogs/DlgRenameCst.tsx | 4 +++- rsconcept/frontend/src/models/rsformAPI.ts | 15 ++++++++++++++- .../src/pages/RSFormPage/RSEditContext.tsx | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rsconcept/frontend/src/dialogs/DlgRenameCst.tsx b/rsconcept/frontend/src/dialogs/DlgRenameCst.tsx index 2c7985c9..c1dbef15 100644 --- a/rsconcept/frontend/src/dialogs/DlgRenameCst.tsx +++ b/rsconcept/frontend/src/dialogs/DlgRenameCst.tsx @@ -18,10 +18,11 @@ import { SelectorCstType } from '@/utils/selectors'; interface DlgRenameCstProps extends Pick { initial: ICstRenameData; + allowChangeType: boolean; onRename: (data: ICstRenameData) => void; } -function DlgRenameCst({ hideWindow, initial, onRename }: DlgRenameCstProps) { +function DlgRenameCst({ hideWindow, initial, allowChangeType, onRename }: DlgRenameCstProps) { const { schema } = useRSForm(); const [validated, setValidated] = useState(false); const [cstData, updateData] = usePartialUpdate(initial); @@ -52,6 +53,7 @@ function DlgRenameCst({ hideWindow, initial, onRename }: DlgRenameCstProps) { id='dlg_cst_type' placeholder='Выберите тип' className='min-w-[16rem] self-center' + isDisabled={!allowChangeType} options={SelectorCstType} value={{ value: cstData.cst_type, diff --git a/rsconcept/frontend/src/models/rsformAPI.ts b/rsconcept/frontend/src/models/rsformAPI.ts index d3f2c058..f87ec487 100644 --- a/rsconcept/frontend/src/models/rsformAPI.ts +++ b/rsconcept/frontend/src/models/rsformAPI.ts @@ -255,7 +255,20 @@ export function isFunctional(type: CstType): boolean { * Validate new alias against {@link CstType} and {@link IRSForm}. */ export function validateNewAlias(alias: string, type: CstType, schema: IRSForm): boolean { - return alias.length >= 2 && alias.startsWith(getCstTypePrefix(type)) && !schema.cstByAlias.has(alias); + if (alias.length < 2) { + return false; + } + const prefix = getCstTypePrefix(type); + if (!alias.startsWith(prefix)) { + return false; + } + if (schema.cstByAlias.has(alias)) { + return false; + } + if (!/^\d+$/.exec(alias.substring(prefix.length))) { + return false; + } + return true; } /** diff --git a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx index 3ba8367f..ea874aa8 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx @@ -689,10 +689,11 @@ export const RSEditState = ({ initial={createInitialData} /> ) : null} - {showRenameCst && renameInitialData ? ( + {activeCst && showRenameCst && renameInitialData ? ( setShowRenameCst(false)} onRename={handleRenameCst} + allowChangeType={!activeCst.is_inherited} initial={renameInitialData} /> ) : null}