-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vijayan Balasubramanian <[email protected]>
- Loading branch information
Showing
8 changed files
with
259 additions
and
1 deletion.
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
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