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: allow to disable local saving and reset filter #5048

Merged
merged 1 commit into from
Jun 26, 2024
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
8 changes: 8 additions & 0 deletions libs/sdk-ui-dashboard/api/sdk-ui-dashboard.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,9 @@ export interface DashboardConfig {
allowUnfinishedFeatures?: boolean;
colorPalette?: IColorPalette;
dateFilterConfig?: IDateFilterConfig;
disableCrossFiltering?: boolean;
disableDefaultDrills?: boolean;
disableUserFilterReset?: boolean;
enableFilterValuesResolutionInDrillEvents?: boolean;
// @internal
exportId?: string;
Expand Down Expand Up @@ -6993,6 +6995,12 @@ export const selectIsDeleteDialogOpen: DashboardSelector<boolean>;
// @internal
export const selectIsDeleteFilterButtonEnabled: DashboardSelector<boolean>;

// @internal
export const selectIsDisabledCrossFiltering: DashboardSelector<boolean>;

// @internal
export const selectIsDisableUserFilterReset: DashboardSelector<boolean>;

// @internal (undocumented)
export const selectIsDraggingWidget: DashboardSelector<boolean>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021-2023 GoodData Corporation
// (C) 2021-2024 GoodData Corporation
import { SagaIterator } from "redux-saga";
import { all, call, put } from "redux-saga/effects";
import { IDateFilterConfigsQueryResult, IUserWorkspaceSettings } from "@gooddata/sdk-backend-spi";
Expand Down Expand Up @@ -187,6 +187,8 @@ function applyConfigDefaults<T extends DashboardConfig>(config: T) {
initialRenderMode: config.initialRenderMode ?? "view",
hideSaveAsNewButton: config.hideSaveAsNewButton ?? false,
hideShareButton: config.hideShareButton ?? false,
disableCrossFiltering: config.disableCrossFiltering ?? false,
disableUserFilterReset: config.disableUserFilterReset ?? false,
widgetsOverlay: config.widgetsOverlay ?? {},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ exports[`initialize dashboard handler > for any dashboard > should resolve confi
],
"selectedOption": "THIS_MONTH",
},
"disableCrossFiltering": false,
"disableDefaultDrills": false,
"disableUserFilterReset": false,
"enableFilterValuesResolutionInDrillEvents": false,
"hideSaveAsNewButton": false,
"hideShareButton": false,
Expand Down
24 changes: 24 additions & 0 deletions libs/sdk-ui-dashboard/src/model/store/config/configSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,30 @@ export const selectIsShareButtonHidden: DashboardSelector<boolean> = createSelec
return state.hideShareButton ?? false;
});

/**
* Returns whether cross filtering is disabled by config
*
* @internal
*/
export const selectIsDisabledCrossFiltering: DashboardSelector<boolean> = createSelector(
selectConfig,
(state) => {
return state.disableCrossFiltering ?? false;
},
);

/**
* Returns whether user filter reset is disabled by config
*
* @internal
*/
export const selectIsDisableUserFilterReset: DashboardSelector<boolean> = createSelector(
selectConfig,
(state) => {
return state.disableUserFilterReset ?? false;
},
);

/**
* Returns whether drill down is enabled.
*
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-ui-dashboard/src/model/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export {
selectEnableKDAttributeFilterDatesValidation,
selectEnableDuplicatedLabelValuesInAttributeFilter,
selectEnableRichTextDescriptions,
selectIsDisabledCrossFiltering,
selectIsDisableUserFilterReset,
} from "./config/configSelectors.js";
export { EntitlementsState } from "./entitlements/entitlementsState.js";
export { selectEntitlementExportPdf } from "./entitlements/entitlementsSelectors.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
selectHideKpiDrillInEmbedded,
selectIsEmbedded,
selectEnableKDCrossFiltering,
selectIsDisabledCrossFiltering,
} from "../config/configSelectors.js";
import flatMap from "lodash/flatMap.js";
import { selectAccessibleDashboardsMap } from "../accessibleDashboards/accessibleDashboardsSelectors.js";
Expand Down Expand Up @@ -345,18 +346,21 @@ const selectCrossFilteringByWidgetRef: (
selectSupportsCrossFiltering,
selectDrillTargetsByWidgetRef(ref),
selectDisableDashboardCrossFiltering,
selectIsDisabledCrossFiltering,
selectDrillableItems,
(
isCrossFilteringEnabled,
isCrossFilteringSupported,
availableDrillTargets,
disableCrossFiltering,
disableCrossFilteringByConfig,
drillableItems,
) => {
if (
!isCrossFilteringEnabled ||
!isCrossFilteringSupported ||
disableCrossFiltering ||
disableCrossFilteringByConfig ||
// When some drillable items are present, we need to disable
// cross filtering so that drill events are still possible to do.
drillableItems.length > 0
Expand Down Expand Up @@ -474,6 +478,7 @@ export const selectConfiguredDrillsByWidgetRef: (
selectHideKpiDrillInEmbedded,
selectIsEmbedded,
selectDisableDashboardCrossFiltering,
selectIsDisabledCrossFiltering,
(
drills = [],
disableDefaultDrills,
Expand All @@ -485,6 +490,7 @@ export const selectConfiguredDrillsByWidgetRef: (
hideKpiDrillInEmbedded,
isEmbedded,
disableCrossFiltering,
disableCrossFilteringByConfig,
) => {
if (disableDefaultDrills) {
return [];
Expand All @@ -509,7 +515,9 @@ export const selectConfiguredDrillsByWidgetRef: (
return !(isEmbedded && hideKpiDrillInEmbedded);
}
case "crossFiltering": {
return enableKDCrossFiltering && !disableCrossFiltering;
return (
enableKDCrossFiltering && !disableCrossFiltering && !disableCrossFilteringByConfig
);
}
default: {
const unhandledType: never = drillType;
Expand Down
20 changes: 19 additions & 1 deletion libs/sdk-ui-dashboard/src/model/types/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021-2023 GoodData Corporation
// (C) 2021-2024 GoodData Corporation
import { IAnalyticalBackend } from "@gooddata/sdk-backend-spi";
import {
IColorPalette,
Expand Down Expand Up @@ -212,6 +212,24 @@ export interface DashboardConfig {
* priority over other stored or supplied filter context.
*/
exportId?: string;

/**
* Disable cross filtering
*
* @remarks
* If set to true, cross filtering will be forced disabled even if the dashboard is configured to support it.
* If set to false or not set, cross filtering will be enabled if the dashboard is configured to support it.
*/
disableCrossFiltering?: boolean;

/**
* Disable user filter reset
*
* @remarks
* If set to true, user filter reset will be disabled even if the dashboard is configured to support it.
* If set to false or not set, user filter reset will be enabled if the dashboard is configured to support it.
*/
disableUserFilterReset?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
useDashboardUserInteraction,
selectDisableDashboardCrossFiltering,
selectDisableDashboardUserFilterReset,
selectIsDisabledCrossFiltering,
selectIsDisableUserFilterReset,
} from "../../../../model/index.js";

/**
Expand All @@ -44,7 +46,9 @@ export const useResetFiltersButton = (): {
const currentFilters = useDashboardSelector(selectFilterContextFilters);
const enableKDCrossFiltering = useDashboardSelector(selectEnableKDCrossFiltering);
const supportsCrossFiltering = useDashboardSelector(selectSupportsCrossFiltering);
const disableCrossFilteringByConfig = useDashboardSelector(selectIsDisabledCrossFiltering);
const disableCrossFiltering = useDashboardSelector(selectDisableDashboardCrossFiltering);
const disableUserFilterResetByConfig = useDashboardSelector(selectIsDisableUserFilterReset);
const disableUserFilterReset = useDashboardSelector(selectDisableDashboardUserFilterReset);

const dispatch = useDashboardDispatch();
Expand All @@ -65,13 +69,15 @@ export const useResetFiltersButton = (): {
!isEditMode &&
!isEqual(currentFilters, originalFilters) &&
// If the cross filter add some filters, we should allow the reset
(!disableUserFilterReset || newlyAddedFiltersLocalIds.length > 0)
((!disableUserFilterReset && !disableUserFilterResetByConfig) ||
newlyAddedFiltersLocalIds.length > 0)
);
}, [
isEditMode,
currentFilters,
originalFilters,
disableUserFilterReset,
disableUserFilterResetByConfig,
newlyAddedFiltersLocalIds.length,
]);

Expand All @@ -98,7 +104,12 @@ export const useResetFiltersButton = (): {
}

// If cross filtering is enabled, we need to remove all attribute filters that were added by cross filtering
if (enableKDCrossFiltering && supportsCrossFiltering && !disableCrossFiltering) {
if (
enableKDCrossFiltering &&
supportsCrossFiltering &&
!disableCrossFiltering &&
!disableCrossFilteringByConfig
) {
dispatch(removeAttributeFilters(newlyAddedFiltersLocalIds));
dispatch(drillActions.resetCrossFiltering());
}
Expand Down