Skip to content

Commit 1bbaa00

Browse files
committed
Add query preset dropdown to panel
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 3fb2ace commit 1bbaa00

File tree

1 file changed

+62
-12
lines changed
  • public/pages/workflow_detail/tools/query

1 file changed

+62
-12
lines changed

public/pages/workflow_detail/tools/query/query.tsx

+62-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ import { useFormikContext } from 'formik';
1010
import {
1111
EuiCodeEditor,
1212
EuiComboBox,
13+
EuiContextMenu,
1314
EuiEmptyPrompt,
1415
EuiFlexGroup,
1516
EuiFlexItem,
17+
EuiPopover,
1618
EuiSmallButton,
1719
EuiSmallButtonEmpty,
1820
EuiText,
1921
} from '@elastic/eui';
2022
import {
2123
CONFIG_STEP,
2224
customStringify,
25+
QUERY_PRESETS,
2326
QueryParam,
27+
QueryPreset,
2428
SearchResponse,
2529
SearchResponseVerbose,
2630
WorkflowFormValues,
@@ -74,6 +78,9 @@ export function Query(props: QueryProps) {
7478
const { loading } = useSelector((state: AppState) => state.opensearch);
7579
const { values } = useFormikContext<WorkflowFormValues>();
7680

81+
// popover state
82+
const [popoverOpen, setPopoverOpen] = useState<boolean>(false);
83+
7784
// state for if to execute search w/ or w/o any configured search pipeline.
7885
// default based on if there is an available search pipeline or not.
7986
const [includePipeline, setIncludePipeline] = useState<boolean>(false);
@@ -231,20 +238,63 @@ export function Query(props: QueryProps) {
231238
<EuiFlexItem grow={false}>
232239
<EuiText size="s">Query</EuiText>
233240
</EuiFlexItem>
234-
{props.selectedStep === CONFIG_STEP.SEARCH &&
235-
!isEmpty(values?.search?.request) &&
236-
values?.search?.request !== props.queryRequest && (
237-
<EuiFlexItem grow={false} style={{ marginBottom: '0px' }}>
238-
<EuiSmallButtonEmpty
239-
disabled={false}
240-
onClick={() => {
241-
props.setQueryRequest(values?.search?.request);
242-
}}
241+
<EuiFlexItem grow={false}>
242+
<EuiFlexGroup direction="row" gutterSize="s">
243+
{props.selectedStep === CONFIG_STEP.SEARCH &&
244+
!isEmpty(values?.search?.request) &&
245+
values?.search?.request !== props.queryRequest && (
246+
<EuiFlexItem
247+
grow={false}
248+
style={{ marginBottom: '0px' }}
249+
>
250+
<EuiSmallButtonEmpty
251+
disabled={false}
252+
onClick={() => {
253+
props.setQueryRequest(values?.search?.request);
254+
}}
255+
>
256+
Revert to original query
257+
</EuiSmallButtonEmpty>
258+
</EuiFlexItem>
259+
)}
260+
<EuiFlexItem grow={false}>
261+
<EuiPopover
262+
button={
263+
<EuiSmallButton
264+
onClick={() => setPopoverOpen(!popoverOpen)}
265+
data-testid="inspectorQueryPresetButton"
266+
iconSide="right"
267+
iconType="arrowDown"
268+
>
269+
Query samples
270+
</EuiSmallButton>
271+
}
272+
isOpen={popoverOpen}
273+
closePopover={() => setPopoverOpen(false)}
274+
anchorPosition="downLeft"
243275
>
244-
Revert to original query
245-
</EuiSmallButtonEmpty>
276+
<EuiContextMenu
277+
size="s"
278+
initialPanelId={0}
279+
panels={[
280+
{
281+
id: 0,
282+
items: QUERY_PRESETS.map(
283+
(preset: QueryPreset) => ({
284+
name: preset.name,
285+
onClick: () => {
286+
props.setQueryRequest(preset.query);
287+
setPopoverOpen(false);
288+
},
289+
})
290+
),
291+
},
292+
]}
293+
/>
294+
</EuiPopover>
246295
</EuiFlexItem>
247-
)}
296+
</EuiFlexGroup>
297+
</EuiFlexItem>
248298
</EuiFlexGroup>
249299
</EuiFlexItem>
250300
<EuiFlexItem grow={true}>

0 commit comments

Comments
 (0)