Skip to content

Commit

Permalink
feat(selection): clear when switching datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Oct 9, 2023
1 parent c74c571 commit 01e2547
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 53 deletions.
53 changes: 2 additions & 51 deletions src/components/MeasurementsToolList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ const tools = computed(() => {
const selectionStore = useToolSelectionStore();
const {
selectAll,
deselectAll,
selected,
selectionState: visibleSelectionState,
} = useMultipleToolSelection(tools);
const { selectAll, deselectAll, selected, selectionState } =
useMultipleToolSelection(tools);
const toggleSelectAll = (shouldSelectAll: boolean) => {
if (shouldSelectAll) {
Expand Down Expand Up @@ -121,30 +117,6 @@ function toggleGlobalHidden() {
tool.updateTool({ hidden });
});
}
// info about selection that spans multiple images
const selectedIDsFromOtherImages = computed(() => {
const visibleSelection = new Set(tools.value.map((tool) => tool.id));
return selectionStore.selection
.filter((sel) => !visibleSelection.has(sel.id))
.map((sel) => sel.id);
});
function deselectAllFromOtherImages() {
selectedIDsFromOtherImages.value.forEach((id) => {
selectionStore.removeSelection(id);
});
}
// augments the visible selection with the selection from other images
const selectionState = computed(() => {
const sizeOfOtherSelection = selectedIDsFromOtherImages.value.length;
if (visibleSelectionState.value !== MultipleSelectionState.None)
return visibleSelectionState.value;
return sizeOfOtherSelection
? MultipleSelectionState.Some
: MultipleSelectionState.None;
});
</script>

<template>
Expand Down Expand Up @@ -197,27 +169,6 @@ const selectionState = computed(() => {
</v-col>
</v-row>

<v-list-item v-if="selectedIDsFromOtherImages.length">
<v-container>
<v-row class="d-flex align-center main-row">
<v-checkbox
class="no-grow mr-4"
density="compact"
hide-details
:model-value="true"
@click.stop="deselectAllFromOtherImages"
/>
<v-list-item-title class="d-flex align-center">
<v-icon size="small" color="warning" class="mr-2">
mdi-alert-circle-outline
</v-icon>
{{ selectedIDsFromOtherImages.length }}
selected annotation(s) on other images
</v-list-item-title>
</v-row></v-container
>
</v-list-item>

<v-list-item v-for="tool in tools" :key="tool.id">
<v-container>
<v-row class="d-flex align-center main-row">
Expand Down
11 changes: 9 additions & 2 deletions src/store/tools/toolSelection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AnnotationToolType } from '@/src/store/tools/types';
import { ToolID } from '@/src/types/annotation-tool';
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { defineStore, storeToRefs } from 'pinia';
import { computed, ref, watch } from 'vue';
import { useDatasetStore } from '@/src/store/datasets';

export interface ToolSelection {
id: ToolID;
Expand Down Expand Up @@ -44,6 +45,12 @@ export const useToolSelectionStore = defineStore('tool-selection', () => {
}));
});

const { primarySelection } = storeToRefs(useDatasetStore());

watch(primarySelection, () => {
clearSelection();
});

return {
addSelection,
clearSelection,
Expand Down

0 comments on commit 01e2547

Please sign in to comment.