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

fix(dashboard): Cross filters badge for cols with verbose names #23576

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 9 additions & 18 deletions superset-frontend/src/dashboard/components/FiltersBadge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import cx from 'classnames';
import {
DataMaskStateWithId,
Filters,
JsonObject,
styled,
usePrevious,
} from '@superset-ui/core';
Expand All @@ -36,12 +37,7 @@ import {
selectIndicatorsForChart,
selectNativeIndicatorsForChart,
} from '../nativeFilters/selectors';
import {
ChartsState,
DashboardInfo,
DashboardLayout,
RootState,
} from '../../types';
import { Chart, DashboardLayout, RootState } from '../../types';

export interface FiltersBadgeProps {
chartId: number;
Expand Down Expand Up @@ -113,10 +109,10 @@ export const FiltersBadge = ({ chartId }: FiltersBadgeProps) => {
const nativeFilters = useSelector<RootState, Filters>(
state => state.nativeFilters?.filters,
);
const dashboardInfo = useSelector<RootState, DashboardInfo>(
state => state.dashboardInfo,
const chartConfiguration = useSelector<RootState, JsonObject>(
state => state.dashboardInfo.metadata?.chart_configuration,
);
const charts = useSelector<RootState, ChartsState>(state => state.charts);
const chart = useSelector<RootState, Chart>(state => state.charts[chartId]);
const present = useSelector<RootState, DashboardLayout>(
state => state.dashboardLayout.present,
);
Expand All @@ -138,7 +134,6 @@ export const FiltersBadge = ({ chartId }: FiltersBadgeProps) => {
[dispatch],
);

const chart = charts[chartId];
const prevChart = usePrevious(chart);
const prevChartStatus = prevChart?.chartStatus;
const prevDashboardFilters = usePrevious(dashboardFilters);
Expand Down Expand Up @@ -184,9 +179,7 @@ export const FiltersBadge = ({ chartId }: FiltersBadgeProps) => {
const prevNativeFilters = usePrevious(nativeFilters);
const prevDashboardLayout = usePrevious(present);
const prevDataMask = usePrevious(dataMask);
const prevChartConfig = usePrevious(
dashboardInfo.metadata?.chart_configuration,
);
const prevChartConfig = usePrevious(chartConfiguration);
useEffect(() => {
if (!showIndicators && nativeIndicators.length > 0) {
setNativeIndicators(indicatorsInitialState);
Expand All @@ -199,7 +192,7 @@ export const FiltersBadge = ({ chartId }: FiltersBadgeProps) => {
nativeFilters !== prevNativeFilters ||
present !== prevDashboardLayout ||
dataMask !== prevDataMask ||
prevChartConfig !== dashboardInfo.metadata?.chart_configuration
prevChartConfig !== chartConfiguration
) {
setNativeIndicators(
selectNativeIndicatorsForChart(
Expand All @@ -208,19 +201,17 @@ export const FiltersBadge = ({ chartId }: FiltersBadgeProps) => {
chartId,
chart,
present,
dashboardInfo.metadata?.chart_configuration,
datasources[chart.form_data.datasource] ?? {},
chartConfiguration,
),
);
}
}
}, [
chart,
chartId,
dashboardInfo.metadata?.chart_configuration,
chartConfiguration,
dataMask,
nativeFilters,
datasources,
nativeIndicators.length,
present,
prevChart?.queriesResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/

import { DataMaskStateWithId, isDefined, JsonObject } from '@superset-ui/core';
import {
DataMaskStateWithId,
getColumnLabel,
isDefined,
JsonObject,
} from '@superset-ui/core';
import { DashboardLayout } from 'src/dashboard/types';
import { CrossFilterIndicator, getCrossFilterIndicator } from '../../selectors';

Expand All @@ -37,13 +42,15 @@ export const crossFiltersSelector = (props: {
id,
dataMask[id],
dashboardLayout,
verboseMaps[id],
);
if (
isDefined(filterIndicator.column) &&
isDefined(filterIndicator.value)
) {
return { ...filterIndicator, emitterId: id };
const verboseColName =
verboseMaps[id]?.[getColumnLabel(filterIndicator.column)] ||
filterIndicator.column;
return { ...filterIndicator, column: verboseColName, emitterId: id };
}
return null;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export const getCrossFilterIndicator = (
chartId: number,
dataMask: DataMask,
dashboardLayout: DashboardLayout,
verboseMap: Record<string, string> = {},
) => {
const filterState = dataMask?.filterState;
const filters = dataMask?.extraFormData?.filters;
Expand All @@ -181,7 +180,7 @@ export const getCrossFilterIndicator = (
layoutItem => layoutItem?.meta?.chartId === chartId,
);
const filterObject: Indicator = {
column: verboseMap[column] || column,
column,
name:
dashboardLayoutItem?.meta?.sliceNameOverride ||
dashboardLayoutItem?.meta?.sliceName ||
Expand Down Expand Up @@ -290,7 +289,6 @@ export const selectChartCrossFilters = (
chartConfiguration: ChartConfiguration = defaultChartConfig,
appliedColumns: Set<string>,
rejectedColumns: Set<string>,
verboseMap?: Record<string, string>,
filterEmitter = false,
): Indicator[] | CrossFilterIndicator[] => {
let crossFilterIndicators: any = [];
Expand All @@ -312,7 +310,6 @@ export const selectChartCrossFilters = (
chartConfig.id,
dataMask[chartConfig.id],
dashboardLayout,
verboseMap,
);
const filterStatus = getStatus({
label: filterIndicator.value,
Expand Down Expand Up @@ -341,7 +338,6 @@ export const selectNativeIndicatorsForChart = (
chart: any,
dashboardLayout: Layout,
chartConfiguration: ChartConfiguration = defaultChartConfig,
datasource: Datasource,
): Indicator[] => {
const appliedColumns = getAppliedColumns(chart);
const rejectedColumns = getRejectedColumns(chart);
Expand Down Expand Up @@ -397,7 +393,6 @@ export const selectNativeIndicatorsForChart = (
chartConfiguration,
appliedColumns,
rejectedColumns,
datasource.verbose_map,
);
}
const indicators = crossFilterIndicators.concat(nativeFilterIndicators);
Expand Down