B: Fix renaming validation
This commit is contained in:
parent
05ef45fac8
commit
8035a604bd
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user