Skip to content
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

feat(native-filters): allow cascading from time and numeric filters #23319

Merged
merged 6 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { useToasts } from 'src/components/MessageToasts/withToasts';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { cacheWrapper } from 'src/utils/cacheWrapper';
import { NativeFiltersForm } from '../types';
import { doesColumnMatchFilterType } from './utils';

interface ColumnSelectProps {
allowClear?: boolean;
Expand Down Expand Up @@ -84,10 +83,7 @@ export function ColumnSelect({
);

useEffect(() => {
if (
currentColumn &&
!doesColumnMatchFilterType(currentFilterType, currentColumn)
) {
if (currentColumn && !filterValues(currentColumn)) {
Comment on lines -87 to +86
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing the time column select to fail on numerical range filter, as it validated that the selected column was numerical (obviously not the case).

resetColumnField();
}
}, [currentColumn, currentFilterType, resetColumnField]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface DependencyListProps {
dependencies: string[];
onDependenciesChange: (dependencies: string[]) => void;
getDependencySuggestion: () => string;
children?: JSX.Element;
}

const MainPanel = styled.div`
Expand Down Expand Up @@ -176,6 +177,7 @@ const DependencyList = ({
dependencies = [],
onDependenciesChange,
getDependencySuggestion,
children,
}: DependencyListProps) => {
const hasAvailableFilters = availableFilters.length > 0;
const hasDependencies = dependencies.length > 0;
Expand Down Expand Up @@ -205,6 +207,7 @@ const DependencyList = ({
onDependenciesChange={onDependenciesChange}
getDependencySuggestion={getDependencySuggestion}
/>
{children}
</CollapsibleControl>
</MainPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ const FiltersConfigForm = (
const hasTimeRange =
formFilter?.time_range && formFilter.time_range !== 'No filter';

const hasTimeDependency = dependencies
?.map(filterId => form.getFieldValue('filters')?.[filterId]?.filterType)
.some(filterType => filterType === 'filter_time');

const hasAdhoc = formFilter?.adhoc_filters?.length > 0;

const defaultToFirstItem = formFilter?.controlValues?.defaultToFirstItem;
Expand Down Expand Up @@ -736,6 +740,42 @@ const FiltersConfigForm = (
return <RemovedFilter onClick={() => restoreFilter(filterId)} />;
}

const timeColumn = (
<StyledRowFormItem
name={['filters', filterId, 'granularity_sqla']}
label={
<>
<StyledLabel>{t('Time column')}</StyledLabel>&nbsp;
<InfoTooltipWithTrigger
placement="top"
tooltip={
hasTimeDependency
? t('Time column to apply dependent temporal filter to')
: t('Time column to apply time range to')
}
/>
</>
}
initialValue={filterToEdit?.granularity_sqla}
>
<ColumnSelect
allowClear
form={form}
formField="granularity_sqla"
filterId={filterId}
filterValues={(column: Column) => !!column.is_dttm}
datasetId={datasetId}
onChange={column => {
// We need reset default value when when column changed
setNativeFilterFieldValues(form, filterId, {
granularity_sqla: column,
});
forceUpdate();
}}
/>
</StyledRowFormItem>
);

return (
<StyledTabs
activeKey={activeTabKey}
Expand Down Expand Up @@ -892,7 +932,9 @@ const FiltersConfigForm = (
getDependencySuggestion={() =>
getDependencySuggestion(filterId)
}
/>
>
{hasTimeDependency ? timeColumn : undefined}
</DependencyList>
</StyledRowFormItem>
)}
{hasDataset && hasAdditionalFilters && (
Expand Down Expand Up @@ -966,39 +1008,9 @@ const FiltersConfigForm = (
/>
</StyledRowFormItem>
)}
{hasTimeRange && (
<StyledRowFormItem
name={['filters', filterId, 'granularity_sqla']}
label={
<>
<StyledLabel>{t('Time column')}</StyledLabel>&nbsp;
<InfoTooltipWithTrigger
placement="top"
tooltip={t(
'Optional time column if time range should apply to another column than the default time column',
)}
/>
</>
}
initialValue={filterToEdit?.granularity_sqla}
>
<ColumnSelect
allowClear
form={form}
formField="granularity_sqla"
filterId={filterId}
filterValues={(column: Column) => !!column.is_dttm}
datasetId={datasetId}
onChange={column => {
// We need reset default value when when column changed
setNativeFilterFieldValues(form, filterId, {
granularity_sqla: column,
});
forceUpdate();
}}
/>
</StyledRowFormItem>
)}
{hasTimeRange && !hasTimeDependency
? timeColumn
: undefined}
</CollapsibleControl>
</CleanFormItem>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export interface FiltersConfigModalProps {
onSave: (filterConfig: FilterConfiguration) => Promise<void>;
onCancel: () => void;
}
export const ALLOW_DEPENDENCIES = ['filter_select'];
export const ALLOW_DEPENDENCIES = [
'filter_range',
'filter_select',
'filter_time',
];

const DEFAULT_EMPTY_FILTERS: string[] = [];
const DEFAULT_REMOVED_FILTERS: Record<string, FilterRemoval> = {};
Expand Down