Files
NODEDC_MISSION_CORE/plugins/xgrids-k1/frontend/src/projectName.ts
T
DCCONSTRUCTIONS 0ca7316a24 wip(k1): checkpoint connection recovery rewrite
Capture the current unreleased K1 connection, recovery, lifecycle, viewer, and test work as a single known-bad baseline for subsequent fixes.
2026-08-14 14:57:50 +03:00

54 lines
1.5 KiB
TypeScript

export const K1_PROJECT_NAME_MAX_LENGTH = 96;
export interface ProjectNameValidation {
value: string;
error: string | null;
}
const CONTROL_CHARACTER_OR_SURROGATE = /[\p{Cc}\p{Cs}]/u;
export function normalizeProjectName(input: string): string {
return input.normalize("NFKC").trim();
}
export function validateProjectName(input: string): ProjectNameValidation {
const value = normalizeProjectName(input);
if (!value) {
return { value, error: "Введите название проекта." };
}
if (CONTROL_CHARACTER_OR_SURROGATE.test(value)) {
return {
value,
error: "Название проекта не должно содержать управляющие символы.",
};
}
if (Array.from(value).length > K1_PROJECT_NAME_MAX_LENGTH) {
return {
value,
error: `Название проекта должно быть не длиннее ${K1_PROJECT_NAME_MAX_LENGTH} символов.`,
};
}
return { value, error: null };
}
export function projectNameAfterConnectionModeSelection(
preparedProjectName: string | null | undefined,
): string {
return preparedProjectName ?? "";
}
export function shouldHydratePreparedProject({
acquisitionId,
hydratedAcquisitionId,
modeSwitchRequired,
}: {
acquisitionId: string | null;
hydratedAcquisitionId: string | null;
modeSwitchRequired: boolean;
}): boolean {
return Boolean(
acquisitionId
&& !(hydratedAcquisitionId === acquisitionId && modeSwitchRequired),
);
}