From 4b35038a76820f9b55067ea046167729e7692309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 28 Nov 2024 10:47:20 +0100 Subject: [PATCH 1/3] disallow empty annotation layer names and names starting with a '.' --- .../oxalis/view/components/editable_text_label.tsx | 6 ++++++ .../view/left-border-tabs/layer_settings_tab.tsx | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/frontend/javascripts/oxalis/view/components/editable_text_label.tsx b/frontend/javascripts/oxalis/view/components/editable_text_label.tsx index 6b514d5bc2d..3e27aa02ce0 100644 --- a/frontend/javascripts/oxalis/view/components/editable_text_label.tsx +++ b/frontend/javascripts/oxalis/view/components/editable_text_label.tsx @@ -10,6 +10,7 @@ import FastTooltip from "components/fast_tooltip"; type Rule = { message?: string; type?: string; + min?: number; validator?: (arg0: string) => ValidationResult; }; export type EditableTextLabelProp = { @@ -118,6 +119,11 @@ class EditableTextLabel extends React.PureComponent { }); }} rules={[ + layerNameRules[0] as { min: number }, // Ensuring minimum length { validator: (newReadableLayerName) => validateReadableLayerName( @@ -756,6 +758,14 @@ 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" /> From 0504908d22903d4b6031f7575852f95e626fcccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 28 Nov 2024 11:00:43 +0100 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 72a07b2592b..a8f6f2b1e43 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -24,6 +24,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released ### Fixed - Fix performance bottleneck when deleting a lot of trees at once. [#8176](https://github.com/scalableminds/webknossos/pull/8176) - Fix a bug where changing the color of a segment via the menu in the segments tab would update the segment color of the previous segment, on which the context menu was opened. [#8225](https://github.com/scalableminds/webknossos/pull/8225) +- Fix that the frontend did not ensure a minium length for annotation layer names. Moreover, names starting with a `.` are also disallowed now. [#8244](https://github.com/scalableminds/webknossos/pull/8244) - Fix a bug when importing an NML with groups when only groups but no trees exist in an annotation. [#8176](https://github.com/scalableminds/webknossos/pull/8176) - Fix a bug where trying to delete a non-existing node (via the API, for example) would delete the whole active tree. [#8176](https://github.com/scalableminds/webknossos/pull/8176) - Fix a bug where dataset uploads would fail if the organization directory on disk is missing. [#8230](https://github.com/scalableminds/webknossos/pull/8230) 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 3/3] 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 4a1a0ae2288..066a5bbea49 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 f0371c45d1b..9caf578d5cd 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 565b8ace677..db38870be03 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.