Repository navigation
feat: Add UI for configuring adhoc dashboard filters #3341
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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,6 @@ | ||
| --- | ||
| '@hyperdx/common-utils': patch | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| feat: Add UI for configuring adhoc dashboard filters |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
146 changes: 146 additions & 0 deletions
146
packages/app/src/components/DashboardFiltersModal/AdhocFilterEditForm.tsx
This file contains hidden or 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,146 @@ | ||
| import { Controller, UseFormSetValue, useWatch } from 'react-hook-form'; | ||
| import { getAdhocFilterSourceKinds } from '@hyperdx/common-utils/dist/filters'; | ||
| import { | ||
| AdhocFilterSourceType, | ||
| DashboardFilter, | ||
| SourceKind, | ||
| } from '@hyperdx/common-utils/dist/types'; | ||
| import { Box, Divider, SegmentedControl } from '@mantine/core'; | ||
|
|
||
| import { CheckBoxControlled } from '@/components/InputControlled'; | ||
| import { SourceMultiSelectControlled } from '@/components/SourceMultiSelect'; | ||
| import { IS_PROMQL_ENABLED } from '@/config'; | ||
| import { useSources } from '@/source'; | ||
|
|
||
| import { CustomInputWrapper } from './CustomInputWrapper'; | ||
| import { FilterFormControl, FilterFormValues } from './filterFormState'; | ||
| import { VariableNameInput } from './VariableNameInput'; | ||
|
|
||
| const SOURCE_TYPE_OPTIONS: { value: AdhocFilterSourceType; label: string }[] = [ | ||
| { value: 'sql', label: 'ClickHouse' }, | ||
| { value: 'promql', label: 'Prometheus' }, | ||
| ]; | ||
|
|
||
| interface AdhocFilterEditFormProps { | ||
| control: FilterFormControl; | ||
| setValue: UseFormSetValue<FilterFormValues>; | ||
| /** Filters other than the one being edited, used to keep variable names unique. */ | ||
| otherFilters: DashboardFilter[]; | ||
| } | ||
|
|
||
| /** Form describing an ad hoc dashboard filter */ | ||
| export const AdhocFilterEditForm = ({ | ||
| control, | ||
| setValue, | ||
| otherFilters, | ||
| }: AdhocFilterEditFormProps) => { | ||
| const { data: allSources } = useSources(); | ||
| const [sourceType, isBroadcastEnabled] = useWatch({ | ||
| control, | ||
| name: ['sourceType', 'isBroadcastEnabled'], | ||
| }); | ||
| const allowedSourceKinds = getAdhocFilterSourceKinds(sourceType); | ||
| // Kept visible for a saved PromQL filter so its source type can be changed | ||
| const showSourceType = | ||
| sourceType === 'promql' || | ||
| (IS_PROMQL_ENABLED && | ||
| !!allSources?.some(s => s.kind === SourceKind.Promql)); | ||
|
|
||
| // The multi-selects hide sources of other kinds, which the form can still | ||
| // hold after switching from another filter type. | ||
| const validateSourceKinds = (ids: string[] | undefined) => { | ||
|
pulpdrew marked this conversation as resolved.
Resolved
|
||
| const hasOtherKind = ids?.some(id => { | ||
| const source = allSources?.find(s => s.id === id); | ||
| return source && !allowedSourceKinds.includes(source.kind); | ||
| }); | ||
| return ( | ||
| !hasOtherKind || | ||
| (sourceType === 'promql' | ||
| ? 'Select only PromQL sources' | ||
| : 'Select only log, trace, or session sources') | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| {showSourceType && ( | ||
| <CustomInputWrapper | ||
| label="Source type" | ||
| tooltipText="Keys come from the columns and map keys of SQL sources, or from the labels of PromQL sources" | ||
| > | ||
| <Controller | ||
| control={control} | ||
| name="sourceType" | ||
| render={({ field: { value, onChange } }) => ( | ||
| <SegmentedControl | ||
| size="xs" | ||
| value={value} | ||
| onChange={next => { | ||
| onChange(next); | ||
| // Sources of the previous type can't be kept | ||
| setValue('sources', [], { shouldDirty: true }); | ||
| setValue('appliesToSourceIds', [], { shouldDirty: true }); | ||
| }} | ||
| data={SOURCE_TYPE_OPTIONS} | ||
| data-testid="adhoc-filter-source-type" | ||
| /> | ||
| )} | ||
| /> | ||
| </CustomInputWrapper> | ||
| )} | ||
| <CustomInputWrapper | ||
| label="Data sources" | ||
| tooltipText="The sources whose keys and values the filter offers" | ||
| > | ||
| <SourceMultiSelectControlled | ||
| control={control} | ||
| name="sources" | ||
| data-testid="adhoc-filter-sources" | ||
| comboboxProps={{ withinPortal: true }} | ||
| placeholder="Select sources" | ||
| allowedSourceKinds={allowedSourceKinds} | ||
| rules={{ | ||
| validate: (value: string[] | undefined) => | ||
| !value?.length | ||
| ? 'Select at least one source' | ||
| : validateSourceKinds(value), | ||
| }} | ||
| /> | ||
| </CustomInputWrapper> | ||
|
|
||
| <Divider /> | ||
| <CheckBoxControlled | ||
| control={control} | ||
| name="isBroadcastEnabled" | ||
| size="xs" | ||
| label="Broadcast filter conditions" | ||
| description={ | ||
| sourceType === 'promql' | ||
| ? 'Automatically add the selected conditions as label matchers to every selector in PromQL tiles. Optionally, specify which sources to broadcast to.' | ||
| : 'Automatically apply the selected conditions to every tile based on the selected data sources. Optionally, specify which sources to broadcast to.' | ||
| } | ||
| data-testid="filter-broadcast-checkbox" | ||
| /> | ||
| {isBroadcastEnabled && ( | ||
| <Box ml="xl"> | ||
|
pulpdrew marked this conversation as resolved.
Resolved
|
||
| <CustomInputWrapper | ||
| label="Applies to sources" | ||
| tooltipText="Which tiles the broadcast reaches. Leave empty to broadcast to all tiles using the filter's data sources." | ||
| > | ||
| <SourceMultiSelectControlled | ||
| control={control} | ||
| name="appliesToSourceIds" | ||
| data-testid="applies-to-source-selector" | ||
| comboboxProps={{ withinPortal: true }} | ||
| placeholder="Same as data sources" | ||
| allowedSourceKinds={allowedSourceKinds} | ||
| rules={{ validate: validateSourceKinds }} | ||
| /> | ||
| </CustomInputWrapper> | ||
| </Box> | ||
| )} | ||
| <Divider /> | ||
| <VariableNameInput control={control} otherFilters={otherFilters} /> | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.