grafana/e2e/test-plugins/grafana-extensionstest-app/components/QueryModal/QueryModal.tsx
Erik Sundell 1373b37166
Plugin Extensions: E2E test addLink and legacy APIs (#92394)
* cleanup tests

* more cleanup

* added links

* test legacy hooks

* test legacy hooks

* update codeowners

* revert package changes

* add project specfic example script

* remove console log

* Update .github/CODEOWNERS

Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>

* Update CODEOWNERS

* use correct file names

* cleanup tests

---------

Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
2024-08-26 16:01:32 +02:00

46 lines
1.3 KiB
TypeScript

import { DataQuery } from '@grafana/data';
import { Button, FilterPill, Modal, Stack } from '@grafana/ui';
import { testIds } from '../../testIds';
import { ReactElement, useState } from 'react';
import { selectQuery } from '../../utils/utils';
type Props = {
targets: DataQuery[] | undefined;
onDismiss?: () => void;
};
export function QueryModal(props: Props): ReactElement {
const { targets = [], onDismiss } = props;
const [selected, setSelected] = useState(targets[0]);
return (
<div data-testid={testIds.modal.container}>
<p>Please select the query you would like to use to create &quot;something&quot; in the plugin.</p>
<Stack>
{targets.map((query) => (
<FilterPill
key={query.refId}
label={query.refId}
selected={query.refId === selected?.refId}
onClick={() => setSelected(query)}
/>
))}
</Stack>
<Modal.ButtonRow>
<Button variant="secondary" fill="outline" onClick={onDismiss}>
Cancel
</Button>
<Button
disabled={!Boolean(selected)}
onClick={() => {
onDismiss?.();
selectQuery(selected);
}}
>
OK
</Button>
</Modal.ButtonRow>
</div>
);
}