Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations filters UI #2743

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["extend"]
"ignoreAtRules": ["extend", "for"]
}
],
"selector-type-no-unknown": [
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CVAT-3D: Load all frames corresponding to the job instance
(<https://github.com/openvinotoolkit/cvat/pull/2645>)
- Intelligent scissors with OpenCV javascript (<https://github.com/openvinotoolkit/cvat/pull/2689>)
- Annotations Filters UI (<https://github.com/openvinotoolkit/cvat/issues/1418>)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2020 Intel Corporation
// Copyright (C) 2021 Intel Corporation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 2019-2021

//
// SPDX-License-Identifier: MIT

Expand Down
61 changes: 57 additions & 4 deletions cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
Expand Down Expand Up @@ -58,6 +59,7 @@
"@types/react-router-dom": "^5.1.7",
"@types/react-share": "^3.0.3",
"@types/redux-logger": "^3.0.8",
"@types/uuid": "8.3.0",
"antd": "^4.10.2",
"copy-to-clipboard": "^3.3.1",
"cvat-canvas3d": "file:../cvat-canvas3d",
Expand All @@ -81,6 +83,7 @@
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"uuid": "8.3.1"
}
}
5 changes: 1 addition & 4 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,10 +1362,7 @@ export function pasteShapeAsync(): ThunkAction {
};
}

export function interactWithCanvas(
activeInteractor: Model | OpenCVTool,
activeLabelID: number,
): AnyAction {
export function interactWithCanvas(activeInteractor: Model | OpenCVTool, activeLabelID: number): AnyAction {
return {
type: AnnotationActionTypes.INTERACT_WITH_CANVAS,
payload: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

import { Tag } from 'antd';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the same import policy, now project uses modular import: import Tag from /antd/lib/Tag
For information: https://nsisodiya.medium.com/reduce-size-in-ant-design-bundle-size-c35dad9ce3a8

import PropTypes from 'prop-types';
import React, { ReactElement, useEffect, useReducer } from 'react';

interface State {
id: string;
concatenator: string;
filterBy: string;
operator: string;
value: string;
attribute: string;
attributeOperator: string;
attributeValue: string;
anotherAttributeLabel: string;
anotherAttributeValue: string;
left: string[];
right: string[];
}

interface Props {
item: State;
onEdit: Function;
onDelete: Function;
onGrouping: Function;
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use precise type? Function is too abstract

}

enum ActionType {
addLeft,
addRight,
removeLeft,
removeRight,
}

const reducer = (state: State, action: { type: ActionType; payload?: any }): State => {
switch (action.type) {
case ActionType.addLeft:
return { ...state, left: [...state.left, '('] };
case ActionType.addRight:
return { ...state, right: [...state.right, ')'] };
case ActionType.removeLeft:
state.left.pop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state.right property before reducing is equal to state.right property after.
It is better to use something destructive like that:
return { ...state, left: state.left.slice(0, -1) };

return { ...state };
case ActionType.removeRight:
state.right.pop();
return { ...state };
Comment on lines +48 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

default:
return state;
}
};
function AnnotationFilterItem({
item, onEdit, onDelete, onGrouping,
}: Props): ReactElement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReactElement > JSX.Element

const [state, dispatch] = useReducer(reducer, item);

useEffect(() => {
onGrouping(state);
}, [state]);

return (
<>
{state.concatenator && ` ${state.concatenator} `}
<span className='group'>{state.left?.map((leftItem: string) => leftItem)}</span>
<Tag
style={{ cursor: 'context-menu' }}
onClick={(e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
e.stopPropagation();
if (e.shiftKey) {
dispatch({ type: ActionType.addLeft });
} else if (e.altKey) {
dispatch({ type: ActionType.removeLeft });
} else {
onEdit(state);
}
}}
onContextMenu={(e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
e.preventDefault();
if (e.shiftKey || e.altKey) e.stopPropagation();
if (e.shiftKey) {
dispatch({ type: ActionType.addRight });
} else if (e.altKey) {
dispatch({ type: ActionType.removeRight });
}
}}
onClose={(e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
e.preventDefault();
onDelete(state);
}}
closable
>
{!state.attribute && `${state.filterBy}${state.operator}"${state.value}"`}

{state.attribute &&
!state.anotherAttributeLabel &&
`attr["${state.attribute}"]${state.attributeOperator}"${state.attributeValue}"`}

{state.anotherAttributeLabel &&
`attr["${state.attribute}"]${state.attributeOperator}attr["${state.anotherAttributeValue}"]`}
</Tag>
<span className='group'>{state.right?.map((rightItem: string) => rightItem)}</span>
</>
);
}

AnnotationFilterItem.propTypes = {
item: PropTypes.objectOf(PropTypes.any),
onEdit: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
onGrouping: PropTypes.func,
};

export default AnnotationFilterItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

@import '../../../../base.scss';

.annotation-filters-pane {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
min-height: $grid-unit-size * 5;
max-height: $grid-unit-size * 15;
padding: $grid-unit-size/2;
background-color: #fff;
border: 1px solid #ccc;
border-radius: $grid-unit-size/2;
user-select: none;
overflow: auto;

& > *:not(.group) {
margin: $grid-unit-size/2;
}

&.invalid {
border-color: #f00;
}

.add-more {
cursor: pointer;
}

.no-filters {
color: #999;

.no-filters-icon {
margin-right: $grid-unit-size/2;
}
}

.pop-confirm-wrapper {
position: absolute;
top: 0;
left: 45%;
}
}
Loading