Skip to content

Commit 2b70b39

Browse files
authored
Remove 'background' label from labels page (#1057)
1 parent 20214ab commit 2b70b39

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

web_ui/src/core/labels/utils.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {
1414
getNonEmptyLabelsFromProject,
1515
getNotEmptyLabelsFromOneTask,
1616
isAnomalous,
17+
isEmptyOrBackgroundLabel,
1718
isExclusive,
1819
isGlobal,
1920
isLocal,
21+
isNonEmptyOrBackgroundLabel,
2022
} from './utils';
2123

2224
it.each([
@@ -263,3 +265,47 @@ describe('filter out exclusive labels', () => {
263265
expect(filterOutExclusiveLabel(labels)).toHaveLength(0);
264266
});
265267
});
268+
269+
describe('isEmptyOrBackgroundLabel', () => {
270+
it('returns true for a label that is empty', () => {
271+
const label = { isEmpty: true, behaviour: LABEL_BEHAVIOUR.LOCAL };
272+
expect(isEmptyOrBackgroundLabel(label)).toBe(true);
273+
});
274+
275+
it('returns true for a label that is background', () => {
276+
const label = { isEmpty: false, behaviour: LABEL_BEHAVIOUR.BACKGROUND };
277+
expect(isEmptyOrBackgroundLabel(label)).toBe(true);
278+
});
279+
280+
it('returns true for a label that is both empty and background', () => {
281+
const label = { isEmpty: true, behaviour: LABEL_BEHAVIOUR.BACKGROUND };
282+
expect(isEmptyOrBackgroundLabel(label)).toBe(true);
283+
});
284+
285+
it('returns false for a label that is neither empty nor background', () => {
286+
const label = { isEmpty: false, behaviour: LABEL_BEHAVIOUR.LOCAL };
287+
expect(isEmptyOrBackgroundLabel(label)).toBe(false);
288+
});
289+
});
290+
291+
describe('isNonEmptyOrBackgroundLabel', () => {
292+
it('returns false for a label that is empty', () => {
293+
const label = { isEmpty: true, behaviour: LABEL_BEHAVIOUR.LOCAL };
294+
expect(isNonEmptyOrBackgroundLabel(label)).toBe(false);
295+
});
296+
297+
it('returns false for a label that is background', () => {
298+
const label = { isEmpty: false, behaviour: LABEL_BEHAVIOUR.BACKGROUND };
299+
expect(isNonEmptyOrBackgroundLabel(label)).toBe(false);
300+
});
301+
302+
it('returns false for a label that is both empty and background', () => {
303+
const label = { isEmpty: true, behaviour: LABEL_BEHAVIOUR.BACKGROUND };
304+
expect(isNonEmptyOrBackgroundLabel(label)).toBe(false);
305+
});
306+
307+
it('returns true for a label that is neither empty nor background', () => {
308+
const label = { isEmpty: false, behaviour: LABEL_BEHAVIOUR.LOCAL };
309+
expect(isNonEmptyOrBackgroundLabel(label)).toBe(true);
310+
});
311+
});

web_ui/src/core/labels/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const isBackgroundLabel = <T extends EmptyOrBackground>(label: T): boolea
8080
export const isNonBackgroundLabel = negate(isBackgroundLabel);
8181

8282
export const isEmptyOrBackgroundLabel = overSome([isEmptyLabel, isBackgroundLabel]);
83+
export const isNonEmptyOrBackgroundLabel = negate(isEmptyOrBackgroundLabel);
8384

8485
export const filterOutEmptyLabel = (labels: readonly Label[]): readonly Label[] => labels.filter(isNonEmptyLabel);
8586

@@ -200,3 +201,7 @@ export const getNonEmptyLabelsFromProject = (tasks: Task[]): Label[] => {
200201
export const getNotEmptyLabelsFromOneTask = (task: Task): readonly Label[] => {
201202
return filterOutEmptyLabel(task.labels);
202203
};
204+
205+
export const filterNonEmptyOrBackgroundLabels = (task: Task) => {
206+
return task.labels.filter((label) => isNonEmptyOrBackgroundLabel(label));
207+
};

web_ui/src/pages/project-details/components/project-labels/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
LabelTreeLabelProps,
99
} from '../../../../core/labels/label-tree-view.interface';
1010
import { Label, LabelsRelationType } from '../../../../core/labels/label.interface';
11-
import { getNotEmptyLabelsFromOneTask } from '../../../../core/labels/utils';
11+
import { filterNonEmptyOrBackgroundLabels } from '../../../../core/labels/utils';
1212
import { DOMAIN } from '../../../../core/projects/core.interface';
1313
import { Task, TaskMetadata } from '../../../../core/projects/task.interface';
1414
import { isNotCropTask } from '../../../../shared/utils';
@@ -64,7 +64,7 @@ export const getTasksMetadata = (tasks: Task[], keepNoObjectLabels = false): Tas
6464
const filteredTasks = tasks.filter(isNotCropTask);
6565

6666
return filteredTasks.map((task, index) => {
67-
const taskLabels = keepNoObjectLabels ? task.labels : [...getNotEmptyLabelsFromOneTask(task)];
67+
const taskLabels = keepNoObjectLabels ? task.labels : filterNonEmptyOrBackgroundLabels(task);
6868
const parent = !!index ? filteredTasks[index - 1].labels[0] : undefined;
6969
const parentId = parent ? parent.id : null;
7070
const parentGroup = parent ? parent.group : null;

0 commit comments

Comments
 (0)