-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Annotations filters UI #2743
Changes from all commits
0f79d3a
6bf4f59
050eb94
79feb87
a70e607
f4f3e79
4817065
93407c8
16a828f
73785ce
3eb8af8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. state.right property before reducing is equal to state.right property after. |
||
return { ...state }; | ||
case ActionType.removeRight: | ||
state.right.pop(); | ||
return { ...state }; | ||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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%; | ||
} | ||
} |
There was a problem hiding this comment.
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