React UI: Filters history (#1225)

* Added filters history

* Fixed unclosed dropdown

* Added saving filters to localStrorage
main
Dmitry Kalinin 6 years ago committed by GitHub
parent 6a59e7cff8
commit 401d66dcd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -629,7 +629,6 @@ export class CanvasViewImpl implements CanvasView, Listener {
if (![Mode.ZOOM_CANVAS, Mode.GROUP].includes(this.mode) || event.which === 2) { if (![Mode.ZOOM_CANVAS, Mode.GROUP].includes(this.mode) || event.which === 2) {
self.controller.enableDrag(event.clientX, event.clientY); self.controller.enableDrag(event.clientX, event.clientY);
} }
event.preventDefault();
} }
}); });

@ -179,10 +179,22 @@ ThunkAction<Promise<void>, {}, {}, AnyAction> {
} }
export function changeAnnotationsFilters(filters: string[]): AnyAction { export function changeAnnotationsFilters(filters: string[]): AnyAction {
const state: CombinedState = getStore().getState();
const { filtersHistory, filters: oldFilters } = state.annotation.annotations;
filters.forEach((element: string) => {
if (!(filtersHistory.includes(element) || oldFilters.includes(element))) {
filtersHistory.push(element);
}
});
window.localStorage.setItem('filtersHistory', JSON.stringify(filtersHistory.slice(-10)));
return { return {
type: AnnotationActionTypes.CHANGE_ANNOTATIONS_FILTERS, type: AnnotationActionTypes.CHANGE_ANNOTATIONS_FILTERS,
payload: { payload: {
filters, filters,
filtersHistory: filtersHistory.slice(-10),
}, },
}; };
} }

@ -63,6 +63,7 @@ interface Props {
statesCollapsed: boolean; statesCollapsed: boolean;
statesOrdering: StatesOrdering; statesOrdering: StatesOrdering;
annotationsFilters: string[]; annotationsFilters: string[];
annotationsFiltersHistory: string[];
changeStatesOrdering(value: StatesOrdering): void; changeStatesOrdering(value: StatesOrdering): void;
changeAnnotationsFilters(value: SelectValue): void; changeAnnotationsFilters(value: SelectValue): void;
lockAllStates(): void; lockAllStates(): void;
@ -76,6 +77,7 @@ interface Props {
function ObjectListHeader(props: Props): JSX.Element { function ObjectListHeader(props: Props): JSX.Element {
const { const {
annotationsFilters, annotationsFilters,
annotationsFiltersHistory,
statesHidden, statesHidden,
statesLocked, statesLocked,
statesCollapsed, statesCollapsed,
@ -105,9 +107,12 @@ function ObjectListHeader(props: Props): JSX.Element {
<span style={{ marginLeft: 5 }}>Annotations filter</span> <span style={{ marginLeft: 5 }}>Annotations filter</span>
</> </>
)} )}
dropdownStyle={{ display: 'none' }}
onChange={changeAnnotationsFilters} onChange={changeAnnotationsFilters}
/> >
{annotationsFiltersHistory.map((element: string): JSX.Element => (
<Select.Option key={element} value={element}>{element}</Select.Option>
))}
</Select>
</Col> </Col>
</Row> </Row>
<Row type='flex' justify='space-between' align='middle'> <Row type='flex' justify='space-between' align='middle'>

@ -18,6 +18,7 @@ interface Props {
statesOrdering: StatesOrdering; statesOrdering: StatesOrdering;
sortedStatesID: number[]; sortedStatesID: number[];
annotationsFilters: string[]; annotationsFilters: string[];
annotationsFiltersHistory: string[];
changeStatesOrdering(value: StatesOrdering): void; changeStatesOrdering(value: StatesOrdering): void;
changeAnnotationsFilters(value: SelectValue): void; changeAnnotationsFilters(value: SelectValue): void;
lockAllStates(): void; lockAllStates(): void;
@ -37,6 +38,7 @@ function ObjectListComponent(props: Props): JSX.Element {
statesOrdering, statesOrdering,
sortedStatesID, sortedStatesID,
annotationsFilters, annotationsFilters,
annotationsFiltersHistory,
changeStatesOrdering, changeStatesOrdering,
changeAnnotationsFilters, changeAnnotationsFilters,
lockAllStates, lockAllStates,
@ -63,6 +65,7 @@ function ObjectListComponent(props: Props): JSX.Element {
expandAllStates={expandAllStates} expandAllStates={expandAllStates}
hideAllStates={hideAllStates} hideAllStates={hideAllStates}
showAllStates={showAllStates} showAllStates={showAllStates}
annotationsFiltersHistory={annotationsFiltersHistory}
/> />
<div className='cvat-objects-sidebar-states-list'> <div className='cvat-objects-sidebar-states-list'>
{ sortedStatesID.map((id: number): JSX.Element => ( { sortedStatesID.map((id: number): JSX.Element => (

@ -29,6 +29,7 @@ interface StateToProps {
statesCollapsed: boolean; statesCollapsed: boolean;
objectStates: any[]; objectStates: any[];
annotationsFilters: string[]; annotationsFilters: string[];
annotationsFiltersHistory: string[];
} }
interface DispatchToProps { interface DispatchToProps {
@ -43,6 +44,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
annotations: { annotations: {
states: objectStates, states: objectStates,
filters: annotationsFilters, filters: annotationsFilters,
filtersHistory: annotationsFiltersHistory,
collapsed, collapsed,
}, },
job: { job: {
@ -78,6 +80,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
frameNumber, frameNumber,
jobInstance, jobInstance,
annotationsFilters, annotationsFilters,
annotationsFiltersHistory,
}; };
} }
@ -221,7 +224,10 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
} }
public render(): JSX.Element { public render(): JSX.Element {
const { annotationsFilters } = this.props; const {
annotationsFilters,
annotationsFiltersHistory,
} = this.props;
const { const {
sortedStatesID, sortedStatesID,
statesOrdering, statesOrdering,
@ -233,6 +239,7 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
statesOrdering={statesOrdering} statesOrdering={statesOrdering}
sortedStatesID={sortedStatesID} sortedStatesID={sortedStatesID}
annotationsFilters={annotationsFilters} annotationsFilters={annotationsFilters}
annotationsFiltersHistory={annotationsFiltersHistory}
changeStatesOrdering={this.onChangeStatesOrdering} changeStatesOrdering={this.onChangeStatesOrdering}
changeAnnotationsFilters={this.onChangeAnnotationsFilters} changeAnnotationsFilters={this.onChangeAnnotationsFilters}
lockAllStates={this.onLockAllStates} lockAllStates={this.onLockAllStates}

@ -61,6 +61,7 @@ const defaultState: AnnotationState = {
collapsed: {}, collapsed: {},
states: [], states: [],
filters: [], filters: [],
filtersHistory: JSON.parse(window.localStorage.getItem('filtersHistory') as string) || [],
history: { history: {
undo: [], undo: [],
redo: [], redo: [],
@ -954,11 +955,13 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
}; };
} }
case AnnotationActionTypes.CHANGE_ANNOTATIONS_FILTERS: { case AnnotationActionTypes.CHANGE_ANNOTATIONS_FILTERS: {
const { filters } = action.payload; const { filters, filtersHistory } = action.payload;
return { return {
...state, ...state,
annotations: { annotations: {
...state.annotations, ...state.annotations,
filtersHistory,
filters, filters,
}, },
}; };

@ -328,6 +328,7 @@ export interface AnnotationState {
collapsed: Record<number, boolean>; collapsed: Record<number, boolean>;
states: any[]; states: any[];
filters: string[]; filters: string[];
filtersHistory: string[];
history: { history: {
undo: string[]; undo: string[];
redo: string[]; redo: string[];

Loading…
Cancel
Save