B: Fix renaming validation
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run

This commit is contained in:
Ivan 2024-09-05 21:25:09 +03:00
parent 38766f3588
commit 95f833d97d
3 changed files with 19 additions and 3 deletions

View File

@ -18,10 +18,11 @@ import { SelectorCstType } from '@/utils/selectors';
interface DlgRenameCstProps extends Pick<ModalProps, 'hideWindow'> { interface DlgRenameCstProps extends Pick<ModalProps, 'hideWindow'> {
initial: ICstRenameData; initial: ICstRenameData;
allowChangeType: boolean;
onRename: (data: ICstRenameData) => void; onRename: (data: ICstRenameData) => void;
} }
function DlgRenameCst({ hideWindow, initial, onRename }: DlgRenameCstProps) { function DlgRenameCst({ hideWindow, initial, allowChangeType, onRename }: DlgRenameCstProps) {
const { schema } = useRSForm(); const { schema } = useRSForm();
const [validated, setValidated] = useState(false); const [validated, setValidated] = useState(false);
const [cstData, updateData] = usePartialUpdate(initial); const [cstData, updateData] = usePartialUpdate(initial);
@ -52,6 +53,7 @@ function DlgRenameCst({ hideWindow, initial, onRename }: DlgRenameCstProps) {
id='dlg_cst_type' id='dlg_cst_type'
placeholder='Выберите тип' placeholder='Выберите тип'
className='min-w-[16rem] self-center' className='min-w-[16rem] self-center'
isDisabled={!allowChangeType}
options={SelectorCstType} options={SelectorCstType}
value={{ value={{
value: cstData.cst_type, value: cstData.cst_type,

View File

@ -255,7 +255,20 @@ export function isFunctional(type: CstType): boolean {
* Validate new alias against {@link CstType} and {@link IRSForm}. * Validate new alias against {@link CstType} and {@link IRSForm}.
*/ */
export function validateNewAlias(alias: string, type: CstType, schema: IRSForm): boolean { 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;
} }
/** /**

View File

@ -689,10 +689,11 @@ export const RSEditState = ({
initial={createInitialData} initial={createInitialData}
/> />
) : null} ) : null}
{showRenameCst && renameInitialData ? ( {activeCst && showRenameCst && renameInitialData ? (
<DlgRenameCst <DlgRenameCst
hideWindow={() => setShowRenameCst(false)} hideWindow={() => setShowRenameCst(false)}
onRename={handleRenameCst} onRename={handleRenameCst}
allowChangeType={!activeCst.is_inherited}
initial={renameInitialData} initial={renameInitialData}
/> />
) : null} ) : null}