Skip to content

Commit

Permalink
disallow empty annotation layer names and names starting with a '.'
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 7206862 commit 4b35038
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -118,6 +119,11 @@ class EditableTextLabel extends React.PureComponent<EditableTextLabelProp, State
Toast.error(validationResult.message);
return false;
}
} else if (rule.min != null) {
if (this.state.value.length < rule.min) {
Toast.error(`Length must at least be ${rule.min}.`);
return false;
}
}
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ 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 @@ -748,6 +749,7 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
});
}}
rules={[
layerNameRules[0] as { min: number }, // Ensuring minimum length
{
validator: (newReadableLayerName) =>
validateReadableLayerName(
Expand All @@ -756,6 +758,14 @@ 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

0 comments on commit 4b35038

Please sign in to comment.