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'> {
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,

View File

@ -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;
}
/**

View File

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