Skip to content

Commit

Permalink
comments and linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-RyanK committed Jun 4, 2024
1 parent 34e28bb commit ca6bc99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type DataMaskAction =
filterState: {
label?: string;
filters?: AdhocFilter[];
value: AdhocFilter[];
value?: AdhocFilter[] | null;
};
};

Expand Down Expand Up @@ -95,7 +95,7 @@ export default function PluginFilterAdhoc(props: PluginFilterAdhocProps) {
unsetFocusedFilter,
appSection,
} = props;
const { enableEmptyFilter, inverseSelection, defaultToFirstItem } = formData;
const { enableEmptyFilter } = formData;
const datasetId = useMemo(
() => formData.datasource.split('_')[0],
[formData.datasource],
Expand Down Expand Up @@ -152,55 +152,39 @@ export default function PluginFilterAdhoc(props: PluginFilterAdhocProps) {
const { error, message } = await getClientErrorObject(badResponse);
let errorText = message || error || t('An error has occurred');
if (message === 'Forbidden') {
errorText = t('You do not have permission to edit this dashboard');
errorText = t('You do not have permission to access this dataset');
}
addDangerToast(errorText);
},
);
}
});

const labelString: (props: AdhocFilter) => string = (props: AdhocFilter) => {
if (ensureIsArray(props.comparator).length >= 2) {
return `${props.subject} ${props.operator} (${props.comparator.join(
', ',
)})`;
}
return `${props.subject} ${props.operator} ${props.comparator}`;
};

const updateDataMask = useCallback(
(adhoc_filters: AdhocFilter[]) => {
const emptyFilter =
enableEmptyFilter && !inverseSelection && !adhoc_filters?.length;
const emptyFilter = enableEmptyFilter && !adhoc_filters?.length;

dispatchDataMask({
type: 'filterState',
__cache: filterState,
extraFormData: getAdhocExtraFormData(
adhoc_filters,
emptyFilter,
inverseSelection,
),
extraFormData: getAdhocExtraFormData(adhoc_filters, emptyFilter),
filterState: {
...filterState,
label: (adhoc_filters || [])
.map(f =>
f.sqlExpression ? String(f.sqlExpression) : labelString(f),
f.sqlExpression ? String(f.sqlExpression) : f.getDefaultLabel(),
)
.join(', '),
value: adhoc_filters,
value: adhoc_filters?.length ? adhoc_filters : null,
filters: adhoc_filters,
},
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
appSection,
defaultToFirstItem,
dispatchDataMask,
enableEmptyFilter,
inverseSelection,
JSON.stringify(filterState),
labelFormatter,
],
Expand Down Expand Up @@ -245,7 +229,7 @@ export default function PluginFilterAdhoc(props: PluginFilterAdhocProps) {
updateDataMask(filters);
}}
label={' '}
value={filterState.filters || []}
value={filterState.filters || null}
/>
</ControlContainer>
</StyledFormItem>
Expand Down
1 change: 0 additions & 1 deletion superset-frontend/src/filters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
export const getAdhocExtraFormData = (
adhoc_filters: AdhocFilter[] = [],
emptyFilter = false,
inverseSelection = false,
): ExtraFormData => {
const extra: ExtraFormData = {};
if (emptyFilter) {
Expand Down
7 changes: 5 additions & 2 deletions superset-frontend/src/visualizations/presets/MainPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ export default class MainPreset extends Preset {
new HandlebarsChartPlugin().configure({ key: 'handlebars' }),
new EchartsBubbleChartPlugin().configure({ key: 'bubble_v2' }),
...experimentalPlugins,
].concat(isFeatureEnabled(FeatureFlag.AdhocDashboardNativeFilters) ?
[new AdhocFilterPlugin().configure({ key: 'filter_adhoc' })] : []),
].concat(
isFeatureEnabled(FeatureFlag.ADHOC_DASHBOARD_NATIVE_FILTERS)
? [new AdhocFilterPlugin().configure({ key: 'filter_adhoc' })]
: [],
),
});
}
}

0 comments on commit ca6bc99

Please sign in to comment.