-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add shape filter UI button #329
Merged
VijayanB
merged 2 commits into
opensearch-project:main
from
VijayanB:add-shape-filter-ui-button
Mar 8, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
public/components/toolbar/spatial_filter/__snapshots__/filter_by_polygon.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders filter by polygon button 1`] = ` | ||
<EuiPopover | ||
anchorPosition="leftUp" | ||
button={ | ||
<EuiPanel | ||
className="spatialFilterToolbar__shape" | ||
paddingSize="none" | ||
> | ||
<EuiButtonIcon | ||
aria-label="draw_filter_polygon" | ||
color="text" | ||
iconType={Object {}} | ||
isDisabled={false} | ||
onClick={[Function]} | ||
size="s" | ||
title="Draw Polygon" | ||
/> | ||
</EuiPanel> | ||
} | ||
closePopover={[Function]} | ||
data-test-subj="drawPolygonPopOver" | ||
display="inlineBlock" | ||
hasArrow={true} | ||
id="drawPolygonId" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu | ||
initialPanelId={0} | ||
panels={ | ||
Array [ | ||
Object { | ||
"content": <FilterInputPanel | ||
defaultFilterLabel="polygon" | ||
drawLabel="Draw Polygon" | ||
mode="polygon" | ||
onSubmit={[Function]} | ||
relations={ | ||
Array [ | ||
"intersects", | ||
"disjoint", | ||
"within", | ||
] | ||
} | ||
/>, | ||
"id": 0, | ||
"title": "DRAW SHAPE", | ||
}, | ||
] | ||
} | ||
size="m" | ||
/> | ||
</EuiPopover> | ||
`; | ||
|
||
exports[`renders filter by polygon in middle of drawing 1`] = ` | ||
<EuiPopover | ||
anchorPosition="leftUp" | ||
button={ | ||
<EuiPanel | ||
className="spatialFilterToolbar__shape" | ||
paddingSize="none" | ||
> | ||
<EuiButtonIcon | ||
aria-label="draw_filter_polygon" | ||
color="text" | ||
iconType={Object {}} | ||
isDisabled={true} | ||
onClick={[Function]} | ||
size="s" | ||
title="Draw Polygon" | ||
/> | ||
</EuiPanel> | ||
} | ||
closePopover={[Function]} | ||
data-test-subj="drawPolygonPopOver" | ||
display="inlineBlock" | ||
hasArrow={true} | ||
id="drawPolygonId" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu | ||
initialPanelId={0} | ||
panels={ | ||
Array [ | ||
Object { | ||
"content": <FilterInputPanel | ||
defaultFilterLabel="polygon" | ||
drawLabel="Draw Polygon" | ||
mode="polygon" | ||
onSubmit={[Function]} | ||
relations={ | ||
Array [ | ||
"intersects", | ||
"disjoint", | ||
"within", | ||
] | ||
} | ||
/>, | ||
"id": 0, | ||
"title": "DRAW SHAPE", | ||
}, | ||
] | ||
} | ||
size="m" | ||
/> | ||
</EuiPopover> | ||
`; |
41 changes: 41 additions & 0 deletions
41
public/components/toolbar/spatial_filter/__snapshots__/filter_toolbar.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders spatial filter before drawing 1`] = ` | ||
<EuiFlexGroup | ||
alignItems="flexStart" | ||
direction="column" | ||
gutterSize="s" | ||
responsive={false} | ||
> | ||
<EuiFlexItem> | ||
<FilterByPolygon | ||
isDrawActive={false} | ||
setDrawFilterProperties={[MockFunction]} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
`; | ||
|
||
exports[`renders spatial filter while drawing 1`] = ` | ||
<EuiFlexGroup | ||
gutterSize="s" | ||
> | ||
<EuiFlexItem | ||
grow={false} | ||
> | ||
<EuiButton | ||
fill={true} | ||
onClick={[Function]} | ||
size="s" | ||
> | ||
Cancel | ||
</EuiButton> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<FilterByPolygon | ||
isDrawActive={true} | ||
setDrawFilterProperties={[MockFunction]} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
`; |
23 changes: 23 additions & 0 deletions
23
public/components/toolbar/spatial_filter/filter_by_polygon.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import { FilterByPolygon } from './filter_by_polygon'; | ||
|
||
it('renders filter by polygon button', () => { | ||
const mockCallback = jest.fn(); | ||
const polygonComponent = shallow( | ||
<FilterByPolygon setDrawFilterProperties={mockCallback} isDrawActive={false} /> | ||
); | ||
expect(polygonComponent).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders filter by polygon in middle of drawing', () => { | ||
const mockCallback = jest.fn(); | ||
const polygonComponent = shallow( | ||
<FilterByPolygon setDrawFilterProperties={mockCallback} isDrawActive={true} /> | ||
); | ||
expect(polygonComponent).toMatchSnapshot(); | ||
}); |
89 changes: 89 additions & 0 deletions
89
public/components/toolbar/spatial_filter/filter_by_polygon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { EuiPopover, EuiContextMenu, EuiPanel, EuiButtonIcon } from '@elastic/eui'; | ||
import { FilterInputPanel } from './filter_input_panel'; | ||
import polygon from '../../../images/polygon.svg'; | ||
import { | ||
DrawFilterProperties, | ||
DRAW_FILTER_POLYGON, | ||
DRAW_FILTER_POLYGON_DEFAULT_LABEL, | ||
DRAW_FILTER_POLYGON_RELATIONS, | ||
DRAW_FILTER_SHAPE_TITLE, | ||
} from '../../../../common'; | ||
import { FILTER_DRAW_MODE } from '../../../../common'; | ||
|
||
interface FilterByPolygonProps { | ||
setDrawFilterProperties: (properties: DrawFilterProperties) => void; | ||
isDrawActive: boolean; | ||
} | ||
|
||
export const FilterByPolygon = ({ | ||
setDrawFilterProperties, | ||
isDrawActive, | ||
}: FilterByPolygonProps) => { | ||
const [isPopoverOpen, setPopover] = useState(false); | ||
|
||
const onClick = () => { | ||
setPopover(!isPopoverOpen); | ||
}; | ||
|
||
const closePopover = () => { | ||
setPopover(false); | ||
}; | ||
|
||
const onSubmit = (input: { relation: string; label: string; mode: FILTER_DRAW_MODE }) => { | ||
setDrawFilterProperties({ | ||
mode: input.mode, | ||
relation: input.relation, | ||
filterLabel: input.label, | ||
}); | ||
closePopover(); | ||
}; | ||
|
||
const panels = [ | ||
{ | ||
id: 0, | ||
title: DRAW_FILTER_SHAPE_TITLE, | ||
content: ( | ||
<FilterInputPanel | ||
drawLabel={DRAW_FILTER_POLYGON} | ||
defaultFilterLabel={DRAW_FILTER_POLYGON_DEFAULT_LABEL} | ||
relations={DRAW_FILTER_POLYGON_RELATIONS} | ||
onSubmit={onSubmit} | ||
mode={FILTER_DRAW_MODE.POLYGON} | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
const drawPolygonButton = ( | ||
<EuiPanel paddingSize="none" className="spatialFilterToolbar__shape"> | ||
<EuiButtonIcon | ||
color="text" | ||
size={'s'} | ||
iconType={polygon} | ||
onClick={onClick} | ||
aria-label={'draw_filter_polygon'} | ||
title={DRAW_FILTER_POLYGON} | ||
isDisabled={isDrawActive} | ||
/> | ||
</EuiPanel> | ||
); | ||
return ( | ||
<EuiPopover | ||
id="drawPolygonId" | ||
button={drawPolygonButton} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
anchorPosition="leftUp" | ||
data-test-subj="drawPolygonPopOver" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How about introduce a prop
isDrawActive
, the mode only contains different type of draw.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.
Good suggestion. Then we have to maintain two variable for 1 behavior. For ex: if draw is false, then i have to reset mode to null, similarly if we want to enable draw behavior, we have to set to true and set mode accordingly.