From 8ba23ba5160492a85dacd4ecbc223d77db06067b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 28 Nov 2024 11:58:46 +0100 Subject: [PATCH] move new annotation layer validation rules to validateReadableLayerName --- frontend/javascripts/messages.tsx | 2 ++ .../view/left-border-tabs/layer_settings_tab.tsx | 10 ---------- .../modals/add_volume_layer_modal.tsx | 13 +++++++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/javascripts/messages.tsx b/frontend/javascripts/messages.tsx index 4a1a0ae228..066a5bbea4 100644 --- a/frontend/javascripts/messages.tsx +++ b/frontend/javascripts/messages.tsx @@ -212,6 +212,8 @@ instead. Only enable this option if you understand its effect. All layers will n } "${disallowedCharacters}". Please remove ${ disallowedCharacters.length > 1 ? "them" : "it" } to set the layer name.`, + "tracing.volume_layer_name_too_short": "The layer name must be at least one character long.", + "tracing.volume_layer_name_starts_with_dot": "The layer name must not start with a dot.", "tracing.delete_initial_node": "Do you really want to delete the initial node?", "tracing.delete_tree": "Do you really want to delete the whole tree?", "tracing.delete_tree_with_initial_node": diff --git a/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx b/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx index f0371c45d1..9caf578d5c 100644 --- a/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx +++ b/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx @@ -131,7 +131,6 @@ import { getDefaultLayerViewConfiguration, } from "types/schemas/dataset_view_configuration.schema"; import defaultState from "oxalis/default_state"; -import { layerNameRules } from "admin/dataset/dataset_components"; type DatasetSettingsProps = { userConfiguration: UserConfiguration; @@ -749,7 +748,6 @@ class DatasetSettings extends React.PureComponent { }); }} rules={[ - layerNameRules[0] as { min: number }, // Ensuring minimum length { validator: (newReadableLayerName) => validateReadableLayerName( @@ -758,14 +756,6 @@ class DatasetSettings extends React.PureComponent { readableName, ), }, - { - validator: (newReadableLayerName) => { - const startsWithADot = newReadableLayerName.startsWith("."); - return startsWithADot - ? { isValid: false, message: "The name must not start with a dot." } - : { isValid: true, message: "" }; - }, - }, ]} label="Volume Layer Name" /> diff --git a/frontend/javascripts/oxalis/view/left-border-tabs/modals/add_volume_layer_modal.tsx b/frontend/javascripts/oxalis/view/left-border-tabs/modals/add_volume_layer_modal.tsx index 565b8ace67..db38870be0 100644 --- a/frontend/javascripts/oxalis/view/left-border-tabs/modals/add_volume_layer_modal.tsx +++ b/frontend/javascripts/oxalis/view/left-border-tabs/modals/add_volume_layer_modal.tsx @@ -41,6 +41,13 @@ export function checkForLayerNameDuplication( } export function checkLayerNameForInvalidCharacters(readableLayerName: string): ValidationResult { + // A layer name is not allowed to start with a dot. + if (readableLayerName.startsWith(".")) { + return { + isValid: false, + message: messages["tracing.volume_layer_name_starts_with_dot"], + }; + } const uriSafeCharactersRegex = /[0-9a-zA-Z-._]+/g; // Removing all URISaveCharacters from readableLayerName. The leftover chars are all invalid. const allInvalidChars = readableLayerName.replace(uriSafeCharactersRegex, ""); @@ -62,6 +69,12 @@ export function validateReadableLayerName( allReadableLayerNames: string[], nameNotToCount?: string, ): ValidationResult { + if (readableLayerName.length < 1) { + return { + isValid: false, + message: messages["tracing.volume_layer_name_too_short"], + }; + } if (nameNotToCount) { // nameNotToCount needs to be removed once if it is included in allReadableLayerNames. // This is needed in case of saving an existing volume layer's name when the name was not modified.