-
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 support to draw rectangle shape to filter documents #348
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 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
113 changes: 113 additions & 0 deletions
113
public/components/toolbar/spatial_filter/__snapshots__/filter_by_rectangle.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 rectangle button 1`] = ` | ||
<EuiPopover | ||
anchorPosition="leftUp" | ||
button={ | ||
<EuiPanel | ||
className="spatialFilterToolbar__shape" | ||
paddingSize="none" | ||
> | ||
<EuiButtonIcon | ||
aria-label="draw_filter_rectangle" | ||
color="text" | ||
iconType={Object {}} | ||
isDisabled={false} | ||
onClick={[Function]} | ||
size="s" | ||
title="Draw Rectangle" | ||
/> | ||
</EuiPanel> | ||
} | ||
closePopover={[Function]} | ||
data-test-subj="drawRectanglePopOver" | ||
display="inlineBlock" | ||
hasArrow={true} | ||
id="drawRectangleId" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu | ||
initialPanelId={0} | ||
panels={ | ||
Array [ | ||
Object { | ||
"content": <FilterInputPanel | ||
defaultFilterLabel="rectangle" | ||
drawLabel="Draw Rectangle" | ||
mode="rectangle" | ||
onSubmit={[Function]} | ||
relations={ | ||
Array [ | ||
"intersects", | ||
"disjoint", | ||
"within", | ||
] | ||
} | ||
/>, | ||
"id": 0, | ||
"title": "DRAW SHAPE", | ||
}, | ||
] | ||
} | ||
size="m" | ||
/> | ||
</EuiPopover> | ||
`; | ||
|
||
exports[`renders filter by rectangle in middle of drawing 1`] = ` | ||
<EuiPopover | ||
anchorPosition="leftUp" | ||
button={ | ||
<EuiPanel | ||
className="spatialFilterToolbar__shape" | ||
paddingSize="none" | ||
> | ||
<EuiButtonIcon | ||
aria-label="draw_filter_rectangle" | ||
color="text" | ||
iconType={Object {}} | ||
isDisabled={true} | ||
onClick={[Function]} | ||
size="s" | ||
title="Draw Rectangle" | ||
/> | ||
</EuiPanel> | ||
} | ||
closePopover={[Function]} | ||
data-test-subj="drawRectanglePopOver" | ||
display="inlineBlock" | ||
hasArrow={true} | ||
id="drawRectangleId" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu | ||
initialPanelId={0} | ||
panels={ | ||
Array [ | ||
Object { | ||
"content": <FilterInputPanel | ||
defaultFilterLabel="rectangle" | ||
drawLabel="Draw Rectangle" | ||
mode="rectangle" | ||
onSubmit={[Function]} | ||
relations={ | ||
Array [ | ||
"intersects", | ||
"disjoint", | ||
"within", | ||
] | ||
} | ||
/>, | ||
"id": 0, | ||
"title": "DRAW SHAPE", | ||
}, | ||
] | ||
} | ||
size="m" | ||
/> | ||
</EuiPopover> | ||
`; |
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
23 changes: 23 additions & 0 deletions
23
public/components/toolbar/spatial_filter/filter_by_rectangle.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 { FilterByRectangle } from './filter_by_rectangle'; | ||
|
||
it('renders filter by rectangle button', () => { | ||
const mockCallback = jest.fn(); | ||
const component = shallow( | ||
<FilterByRectangle setDrawFilterProperties={mockCallback} isDrawActive={false} /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders filter by rectangle in middle of drawing', () => { | ||
const mockCallback = jest.fn(); | ||
const component = shallow( | ||
<FilterByRectangle setDrawFilterProperties={mockCallback} isDrawActive={true} /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); |
90 changes: 90 additions & 0 deletions
90
public/components/toolbar/spatial_filter/filter_by_rectangle.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,90 @@ | ||
/* | ||
* 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'; | ||
// TODO: replace with rectangle image file once available | ||
import rectangle from '../../../images/polygon.svg'; | ||
import { | ||
DrawFilterProperties, | ||
DRAW_FILTER_SPATIAL_RELATIONS, | ||
DRAW_FILTER_SHAPE_TITLE, | ||
DRAW_FILTER_RECTANGLE, | ||
DRAW_FILTER_RECTANGLE_DEFAULT_LABEL, | ||
} from '../../../../common'; | ||
import { FILTER_DRAW_MODE } from '../../../../common'; | ||
|
||
interface FilterByRectangleProps { | ||
setDrawFilterProperties: (properties: DrawFilterProperties) => void; | ||
isDrawActive: boolean; | ||
} | ||
|
||
export const FilterByRectangle = ({ | ||
setDrawFilterProperties, | ||
isDrawActive, | ||
}: FilterByRectangleProps) => { | ||
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_RECTANGLE} | ||
defaultFilterLabel={DRAW_FILTER_RECTANGLE_DEFAULT_LABEL} | ||
relations={DRAW_FILTER_SPATIAL_RELATIONS} | ||
onSubmit={onSubmit} | ||
mode={FILTER_DRAW_MODE.RECTANGLE} | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
const drawRectangleButton = ( | ||
<EuiPanel paddingSize="none" className="spatialFilterToolbar__shape"> | ||
<EuiButtonIcon | ||
color="text" | ||
size={'s'} | ||
iconType={rectangle} | ||
onClick={onClick} | ||
aria-label={'draw_filter_rectangle'} | ||
title={DRAW_FILTER_RECTANGLE} | ||
isDisabled={isDrawActive} | ||
/> | ||
</EuiPanel> | ||
); | ||
return ( | ||
<EuiPopover | ||
id="drawRectangleId" | ||
button={drawRectangleButton} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
anchorPosition="leftUp" | ||
data-test-subj="drawRectanglePopOver" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
}; |
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
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 use switch here?
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.
Ack