Skip to content

Commit

Permalink
refactor(native-filters): allow cascading only for filter_select (apa…
Browse files Browse the repository at this point in the history
…che#14441)

* fix:fix get permission function

* refactor: allow cascading only for filter_select
  • Loading branch information
simcha90 authored May 2, 2021
1 parent 1f8de1d commit abbf4bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ import ControlItems from './ControlItems';
import FilterScope from './FilterScope/FilterScope';
import RemovedFilter from './RemovedFilter';
import DefaultValue from './DefaultValue';
import { getFiltersConfigModalTestId } from '../FiltersConfigModal';
import {
CASCADING_FILTERS,
getFiltersConfigModalTestId,
} from '../FiltersConfigModal';
// TODO: move styles from AdhocFilterControl to emotion and delete this ./main.less
import './main.less';

Expand Down Expand Up @@ -174,6 +177,8 @@ export const FiltersConfigForm: React.FC<FiltersConfigFormProps> = ({
formFilter?.filterType,
);

const isCascadingFilter = CASCADING_FILTERS.includes(formFilter?.filterType);

const isDataDirty = formFilter?.isDataDirty ?? true;

useBackendFormUpdate(form, filterId);
Expand Down Expand Up @@ -405,20 +410,22 @@ export const FiltersConfigForm: React.FC<FiltersConfigFormProps> = ({
hidden
initialValue={null}
/>
<StyledFormItem
name={['filters', filterId, 'parentFilter']}
label={<StyledLabel>{t('Parent filter')}</StyledLabel>}
initialValue={parentFilterOptions.find(
({ value }) => value === filterToEdit?.cascadeParentIds[0],
)}
data-test="parent-filter-input"
>
<Select
placeholder={t('None')}
options={parentFilterOptions}
isClearable
/>
</StyledFormItem>
{isCascadingFilter && (
<StyledFormItem
name={['filters', filterId, 'parentFilter']}
label={<StyledLabel>{t('Parent filter')}</StyledLabel>}
initialValue={parentFilterOptions.find(
({ value }) => value === filterToEdit?.cascadeParentIds[0],
)}
data-test="parent-filter-input"
>
<Select
placeholder={t('None')}
options={parentFilterOptions}
isClearable
/>
</StyledFormItem>
)}
<StyledContainer>
<StyledFormItem className="bottom" label={<StyledLabel />}>
{hasDataset && hasFilledDataset && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface FiltersConfigModalProps {
onSave: (filterConfig: FilterConfiguration) => Promise<void>;
onCancel: () => void;
}
export const CASCADING_FILTERS = ['filter_select'];

/**
* This is the modal to configure all the dashboard-native filters.
Expand Down Expand Up @@ -170,6 +171,9 @@ export function FiltersConfigModal({
const getParentFilters = (id: string) =>
filterIds
.filter(filterId => filterId !== id && !removedFilters[filterId])
.filter(filterId =>
CASCADING_FILTERS.includes(formValues.filters[filterId]?.filterType),
)
.map(id => ({
id,
title: getFilterTitle(id),
Expand Down

0 comments on commit abbf4bf

Please sign in to comment.