From 3e4935467c6982adbf553018d5f5c894086a8222 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Sun, 31 Dec 2023 09:42:45 -0500 Subject: [PATCH] feat(labels + segments): disable Done if duplicate name --- src/components/LabelControls.vue | 18 +++++++++++++++--- src/components/LabelEditor.vue | 10 ++++++---- src/components/SegmentEditor.vue | 22 +++++++++++++++++++--- src/components/SegmentList.vue | 7 +++++++ src/components/ToolLabelEditor.vue | 20 ++++++++------------ 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/components/LabelControls.vue b/src/components/LabelControls.vue index c5e671ee2..7feec20fd 100644 --- a/src/components/LabelControls.vue +++ b/src/components/LabelControls.vue @@ -6,6 +6,7 @@ import type { AnnotationTool } from '@/src/types/annotation-tool'; import { Maybe } from '@/src/types'; import ToolLabelEditor from '@/src/components/ToolLabelEditor.vue'; import IsolatedDialog from '@/src/components/IsolatedDialog.vue'; +import { nonNullable } from '@/src/utils'; const props = defineProps<{ labelsStore: LabelsStore>; @@ -42,6 +43,17 @@ const editingLabel = computed(() => { return props.labelsStore.labels[editingLabelID.value]; }); +const invalidNames = computed(() => { + const names = new Set( + Object.values(props.labelsStore.labels) + .map(({ labelName }) => labelName) + .filter(nonNullable) + ) + const currentName = editingLabel.value?.labelName; + if(currentName) names.delete(currentName); // allow current name + return names; +}); + const makeUniqueName = (name: string) => { const existingNames = new Set( Object.values(props.labelsStore.labels).map((label) => label.labelName) @@ -99,7 +111,7 @@ function deleteEditingLabel() { @create="createLabel" > diff --git a/src/components/LabelEditor.vue b/src/components/LabelEditor.vue index 45ae4f0fe..b2535f29d 100644 --- a/src/components/LabelEditor.vue +++ b/src/components/LabelEditor.vue @@ -1,11 +1,12 @@ diff --git a/src/components/SegmentList.vue b/src/components/SegmentList.vue index b3a945a2b..175fe81b8 100644 --- a/src/components/SegmentList.vue +++ b/src/components/SegmentList.vue @@ -70,6 +70,12 @@ const editingSegment = computed(() => { if (editingSegmentValue.value == null) return null; return segmentGroupStore.getSegment(groupId.value, editingSegmentValue.value); }); +const invalidNames = computed(() => { + const names = new Set(segments.value.map((seg) => seg.name)); + const currentName = editingSegment.value?.name; + if(currentName) names.delete(currentName); // allow current name + return names; +}); function startEditing(value: number) { editDialog.value = true; @@ -145,6 +151,7 @@ function deleteEditingSegment() { @delete="deleteEditingSegment" @cancel="stopEditing(false)" @done="stopEditing(true)" + :invalidNames="invalidNames" /> diff --git a/src/components/ToolLabelEditor.vue b/src/components/ToolLabelEditor.vue index c1e72c307..cfa1ebb71 100644 --- a/src/components/ToolLabelEditor.vue +++ b/src/components/ToolLabelEditor.vue @@ -1,8 +1,6 @@