Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 511a0e8

Browse files
Travis1282hlomzik
andauthored
fix: LSDV-5164: Unselect labels with tools (#1460)
* create a method for unselecting ajacent labels with tools and fire on toolswitch * move to actions, double on checks * unselect all exists already * check if tool is segmentation tool and only unselect on segmentation tools * filter segmentation tools with lables before unselect all * Fix visual discrepancy with multi labels in Info tab * Fix Label unselection with broken results When we have broken region with incompatible labels assigned, we should be able to unassign wrong ones (like with wrong tool). --------- Co-authored-by: hlomzik <[email protected]> Co-authored-by: hlomzik <[email protected]>
1 parent cf56017 commit 511a0e8

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Diff for: src/components/SidePanels/DetailsPanel/RegionLabels.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { FC } from 'react';
2+
import { observer } from 'mobx-react';
23

34
import { Block } from '../../../utils/bem';
45

5-
export const RegionLabels: FC<{region: LSFRegion}> = ({ region }) => {
6+
export const RegionLabels: FC<{region: LSFRegion}> = observer(({ region }) => {
67
const labelsInResults = region.results
78
.filter(result => result.type.endsWith('labels'))
89
.map((result: any) => result.selectedLabels || []);
@@ -24,4 +25,4 @@ export const RegionLabels: FC<{region: LSFRegion}> = ({ region }) => {
2425
})}
2526
</Block>
2627
);
27-
};
28+
});

Diff for: src/tags/control/Label.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,22 @@ const Model = types.model({
154154
// is changing the label we need to make sure that region is
155155
// not going to end up without labels at all
156156
const applicableRegions = affectedRegions.filter(region => {
157+
// if that's the only selected label, the only labelset assigned to region,
158+
// and we are trying to unselect it, then don't allow that
159+
// (except for rare labelsets that allow empty labels)
157160
if (
158161
labels.selectedLabels.length === 1 &&
159162
self.selected &&
160163
region.labelings.length === 1 &&
161-
(!self.parent?.allowempty || self.isEmpty)
164+
(!labels?.allowempty || self.isEmpty)
162165
)
163166
return false;
164-
if (self.parent?.type !== 'labels' && !self.parent?.type.includes(region.results[0].type)) return false;
167+
// @todo rewrite this check and add more named vars
168+
// @todo select only related specific labels
169+
// @todo unselect any label, but only if that won't leave region without specific labels!
170+
// @todo but check for regions created by tools
171+
// @todo lot of tests!
172+
if (!self.selected && labels.type !== 'labels' && !labels.type.includes(region.type.replace(/region$/, ''))) return false;
165173
return true;
166174
});
167175

Diff for: src/tools/Manager.js

+18
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ class ToolsManager {
100100

101101
selectTool(tool, selected) {
102102
const currentTool = this.findSelectedTool();
103+
const newSelection = tool?.group;
104+
105+
// if there are no tools selected, there are no specific labels to unselect
106+
// also this will skip annotation init
107+
if (currentTool && newSelection === 'segmentation') {
108+
const toolType = tool.control.type.replace(/labels$/, '');
109+
const currentLabels = tool.obj.activeStates();
110+
// labels of different types; we can't create regions with different tools simultaneously, so we have to unselect them
111+
const unrelatedLabels = currentLabels.filter(tag => {
112+
const type = tag.type.replace(/labels$/, '');
113+
114+
if (tag.type === 'labels') return false;
115+
if (type === toolType) return false;
116+
return true;
117+
});
118+
119+
unrelatedLabels.forEach(tag => tag.unselectAll());
120+
}
103121

104122
if (currentTool && currentTool.handleToolSwitch) {
105123
currentTool.handleToolSwitch(tool);

0 commit comments

Comments
 (0)