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

React UI: Filters history #1225

Merged
merged 3 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ export class CanvasViewImpl implements CanvasView, Listener {
if (![Mode.ZOOM_CANVAS, Mode.GROUP].includes(this.mode) || event.which === 2) {
self.controller.enableDrag(event.clientX, event.clientY);
}
event.preventDefault();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface Props {
statesCollapsed: boolean;
statesOrdering: StatesOrdering;
annotationsFilters: string[];
annotationsFiltersHistory: string[];
changeStatesOrdering(value: StatesOrdering): void;
changeAnnotationsFilters(value: SelectValue): void;
lockAllStates(): void;
Expand All @@ -76,6 +77,7 @@ interface Props {
function ObjectListHeader(props: Props): JSX.Element {
const {
annotationsFilters,
annotationsFiltersHistory,
statesHidden,
statesLocked,
statesCollapsed,
Expand Down Expand Up @@ -105,9 +107,12 @@ function ObjectListHeader(props: Props): JSX.Element {
<span style={{ marginLeft: 5 }}>Annotations filter</span>
</>
)}
dropdownStyle={{ display: 'none' }}
onChange={changeAnnotationsFilters}
/>
>
{annotationsFiltersHistory.map((element: string): JSX.Element => (
<Select.Option key={element} value={element}>{element}</Select.Option>
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 add comment here.
Something like: it is guaranteed, that each filter is unique
because keys must be unique

))}
</Select>
</Col>
</Row>
<Row type='flex' justify='space-between' align='middle'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
statesOrdering: StatesOrdering;
sortedStatesID: number[];
annotationsFilters: string[];
annotationsFiltersHistory: string[];
changeStatesOrdering(value: StatesOrdering): void;
changeAnnotationsFilters(value: SelectValue): void;
lockAllStates(): void;
Expand All @@ -37,6 +38,7 @@ function ObjectListComponent(props: Props): JSX.Element {
statesOrdering,
sortedStatesID,
annotationsFilters,
annotationsFiltersHistory,
changeStatesOrdering,
changeAnnotationsFilters,
lockAllStates,
Expand All @@ -63,6 +65,7 @@ function ObjectListComponent(props: Props): JSX.Element {
expandAllStates={expandAllStates}
hideAllStates={hideAllStates}
showAllStates={showAllStates}
annotationsFiltersHistory={annotationsFiltersHistory}
/>
<div className='cvat-objects-sidebar-states-list'>
{ sortedStatesID.map((id: number): JSX.Element => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface StateToProps {
statesCollapsed: boolean;
objectStates: any[];
annotationsFilters: string[];
annotationsFiltersHistory: string[];
}

interface DispatchToProps {
Expand All @@ -43,6 +44,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
annotations: {
states: objectStates,
filters: annotationsFilters,
filtersHistory: annotationsFiltersHistory,
collapsed,
},
job: {
Expand Down Expand Up @@ -78,6 +80,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
frameNumber,
jobInstance,
annotationsFilters,
annotationsFiltersHistory,
};
}

Expand Down Expand Up @@ -221,7 +224,10 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
}

public render(): JSX.Element {
const { annotationsFilters } = this.props;
const {
annotationsFilters,
annotationsFiltersHistory,
} = this.props;
const {
sortedStatesID,
statesOrdering,
Expand All @@ -233,6 +239,7 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
statesOrdering={statesOrdering}
sortedStatesID={sortedStatesID}
annotationsFilters={annotationsFilters}
annotationsFiltersHistory={annotationsFiltersHistory}
changeStatesOrdering={this.onChangeStatesOrdering}
changeAnnotationsFilters={this.onChangeAnnotationsFilters}
lockAllStates={this.onLockAllStates}
Expand Down
10 changes: 10 additions & 0 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const defaultState: AnnotationState = {
collapsed: {},
states: [],
filters: [],
filtersHistory: [],
Copy link
Member

Choose a reason for hiding this comment

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

In old UI we use local storage to save filters between sessions.
Let's do the same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bsekachev, maybe it can be useful to have one storage for user data like settings, history etc, can it?

Copy link
Member

Choose a reason for hiding this comment

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

@ActiveChooN

Don't think about settings storage now. It was not a feature before and we should not hasten about it. Need to discuss it IRL before implementation

history: {
undo: [],
redo: [],
Expand Down Expand Up @@ -947,10 +948,19 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
}
case AnnotationActionTypes.CHANGE_ANNOTATIONS_FILTERS: {
const { filters } = action.payload;
const { filtersHistory, filters: oldFilters } = state.annotations;
bsekachev marked this conversation as resolved.
Show resolved Hide resolved

filters.forEach((element: string) => {
if (!(filtersHistory.includes(element) || oldFilters.includes(element))) {
filtersHistory.push(element);
}
});

return {
...state,
annotations: {
...state.annotations,
filtersHistory: filtersHistory.slice(-10),
filters,
},
};
Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export interface AnnotationState {
collapsed: Record<number, boolean>;
states: any[];
filters: string[];
filtersHistory: string[];
history: {
undo: string[];
redo: string[];
Expand Down