mirror of
https://github.com/apache/superset.git
synced 2026-06-01 21:59:26 +00:00
fix: Prevents last temporal filter removal (#22982)
This commit is contained in:
committed by
GitHub
parent
32d497785a
commit
b63ea6386f
@@ -59,7 +59,7 @@ import AdhocFilterControl from '../FilterControl/AdhocFilterControl';
|
||||
import DndAdhocFilterOption from './DndAdhocFilterOption';
|
||||
import { useDefaultTimeFilter } from '../DateFilterControl/utils';
|
||||
|
||||
const { confirm } = Modal;
|
||||
const { warning } = Modal;
|
||||
|
||||
const EMPTY_OBJECT = {};
|
||||
const DND_ACCEPTED_TYPES = [
|
||||
@@ -78,14 +78,10 @@ export interface DndFilterSelectProps
|
||||
savedMetrics: Metric[];
|
||||
selectedMetrics: QueryFormMetric[];
|
||||
datasource: Datasource;
|
||||
confirmDeletion?: {
|
||||
triggerCondition: (
|
||||
valueToBeDeleted: OptionValueType,
|
||||
values: OptionValueType[],
|
||||
) => boolean;
|
||||
confirmationTitle: string;
|
||||
confirmationText: string;
|
||||
};
|
||||
canDelete?: (
|
||||
valueToBeDeleted: OptionValueType,
|
||||
values: OptionValueType[],
|
||||
) => true | string;
|
||||
}
|
||||
|
||||
const DndFilterSelect = (props: DndFilterSelectProps) => {
|
||||
@@ -93,7 +89,7 @@ const DndFilterSelect = (props: DndFilterSelectProps) => {
|
||||
datasource,
|
||||
onChange = () => {},
|
||||
name: controlName,
|
||||
confirmDeletion,
|
||||
canDelete,
|
||||
} = props;
|
||||
|
||||
const propsValues = Array.from(props.value ?? []);
|
||||
@@ -217,23 +213,14 @@ const DndFilterSelect = (props: DndFilterSelectProps) => {
|
||||
|
||||
const onClickClose = useCallback(
|
||||
(index: number) => {
|
||||
if (confirmDeletion) {
|
||||
const { confirmationText, confirmationTitle, triggerCondition } =
|
||||
confirmDeletion;
|
||||
if (triggerCondition(values[index], values)) {
|
||||
confirm({
|
||||
title: confirmationTitle,
|
||||
content: confirmationText,
|
||||
onOk() {
|
||||
removeValue(index);
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = canDelete?.(values[index], values);
|
||||
if (typeof result === 'string') {
|
||||
warning({ title: t('Warning'), content: result });
|
||||
return;
|
||||
}
|
||||
removeValue(index);
|
||||
},
|
||||
[confirmDeletion, removeValue, values],
|
||||
[canDelete, removeValue, values],
|
||||
);
|
||||
|
||||
const onShiftOptions = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user