Skip to content

Commit

Permalink
move new annotation layer validation rules to validateReadableLayerName
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Büßemeyer authored and Michael Büßemeyer committed Nov 28, 2024
1 parent 0504908 commit 8ba23ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions frontend/javascripts/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -749,7 +748,6 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
});
}}
rules={[
layerNameRules[0] as { min: number }, // Ensuring minimum length
{
validator: (newReadableLayerName) =>
validateReadableLayerName(
Expand All @@ -758,14 +756,6 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
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"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand All @@ -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.
Expand Down

0 comments on commit 8ba23ba

Please sign in to comment.