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: defer catalog loading until dashboard is fully executed #5486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2022 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import {
IElementsQueryFactory,
IWorkspaceAttributesService,
Expand Down Expand Up @@ -28,7 +28,6 @@ import {
AfmValidObjectsQuery,
AttributeItem,
} from "@gooddata/api-client-tiger";
import flatMap from "lodash/flatMap.js";
import { invariant } from "ts-invariant";

import {
Expand Down Expand Up @@ -61,12 +60,37 @@ export class TigerWorkspaceAttributes implements IWorkspaceAttributesService {
};

public getAttributeDisplayForms(refs: ObjRef[]): Promise<IAttributeDisplayFormMetadataObject[]> {
return this.authCall(async (client) => {
const allAttributes = await loadAttributes(client, this.workspace);
if (refs.length === 0) {
return Promise.resolve([]);
}

return flatMap(allAttributes, (attr) => attr.displayForms).filter((df) =>
refs.find((ref) => areObjRefsEqual(ref, df.ref)),
);
return this.authCall(async (client) => {
const filter = refs.map((ref: any) => `id==${ref.identifier}`).join(",");
const allDisplayForms = await client.entities.getAllEntitiesLabels({
include: ["attribute"],
workspaceId: this.workspace,
origin: "ALL",
filter,
});
const result = allDisplayForms?.data?.data;

return result?.map((item) => ({
attribute: {
identifier: item.relationships?.attribute?.data?.id || "",
type: item.relationships?.attribute?.data?.type || "attribute",
},
ref: { identifier: item.id, type: "displayForm" },
title: item?.attributes?.title || "",
description: item?.attributes?.description || "",
tags: item?.attributes?.tags,
primary: item?.attributes?.primary,
deprecated: false,
uri: item.id,
type: "displayForm", // item.type is "label"
production: true,
unlisted: false,
id: item.id,
}));
});
}

Expand Down
3 changes: 3 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 @@ -7185,6 +7185,9 @@ export const selectCatalogDateDatasets: DashboardSelector<ICatalogDateDataset[]>
// @public (undocumented)
export const selectCatalogFacts: DashboardSelector<ICatalogFact[]>;

// @alpha (undocumented)
export const selectCatalogIsLoaded: DashboardSelector<boolean>;

// @public (undocumented)
export const selectCatalogMeasures: DashboardSelector<ICatalogMeasure[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { dateFilterConfigActions } from "../../../store/dateFilterConfig/index.j
import { DateFilterMergeResult, mergeDateFilterConfigWithOverrides } from "./mergeDateFilterConfigs.js";
import { resolvePermissions } from "./resolvePermissions.js";
import { permissionsActions } from "../../../store/permissions/index.js";
import { loadCatalog } from "./loadCatalog.js";
import { loadDashboardAlerts } from "./loadDashboardAlerts.js";
import { catalogActions } from "../../../store/catalog/index.js";
import { alertsActions } from "../../../store/alerts/index.js";
Expand All @@ -41,7 +40,7 @@ import {
actionsToInitializeNewDashboard,
} from "../common/stateInitializers.js";
import { executionResultsActions } from "../../../store/executionResults/index.js";
import { createDisplayFormMapFromCatalog } from "../../../../_staging/catalog/displayFormMap.js";
import { createDisplayFormMap } from "../../../../_staging/catalog/displayFormMap.js";
import { getPrivateContext } from "../../../store/_infra/contexts.js";
import { accessibleDashboardsActions } from "../../../store/accessibleDashboards/index.js";
import { loadAccessibleDashboardList } from "./loadAccessibleDashboardList.js";
Expand Down Expand Up @@ -163,7 +162,6 @@ function* loadExistingDashboard(
call(resolveDashboardConfig, ctx, cmd),
call(resolvePermissions, ctx, cmd),
call(resolveEntitlements, ctx),
call(loadCatalog, ctx, cmd),
call(loadDashboardAlerts, ctx),
call(loadUser, ctx),
call(loadDashboardList, ctx),
Expand All @@ -182,7 +180,6 @@ function* loadExistingDashboard(
config,
permissions,
entitlements,
catalog,
alerts,
user,
listedDashboards,
Expand All @@ -196,7 +193,6 @@ function* loadExistingDashboard(
SagaReturnType<typeof resolveDashboardConfig>,
SagaReturnType<typeof resolvePermissions>,
PromiseFnReturnType<typeof resolveEntitlements>,
PromiseFnReturnType<typeof loadCatalog>,
PromiseFnReturnType<typeof loadDashboardAlerts>,
PromiseFnReturnType<typeof loadUser>,
PromiseFnReturnType<typeof loadDashboardList>,
Expand Down Expand Up @@ -229,8 +225,8 @@ function* loadExistingDashboard(
insights,
config.settings,
effectiveDateFilterConfig.config,
catalog.dateDatasets(),
createDisplayFormMapFromCatalog(catalog),
[],
createDisplayFormMap([], []),
cmd.payload.persistedDashboard,
);

Expand All @@ -253,11 +249,6 @@ function* loadExistingDashboard(
userActions.setUser(user),
permissionsActions.setPermissions(permissions),
catalogActions.setCatalogItems({
attributes: catalog.attributes(),
dateDatasets: catalog.dateDatasets(),
facts: catalog.facts(),
measures: catalog.measures(),
attributeHierarchies: catalog.attributeHierarchies(),
dateHierarchyTemplates: dateHierarchyTemplates,
}),
...initActions,
Expand Down Expand Up @@ -306,32 +297,26 @@ function* initializeNewDashboard(
config,
permissions,
entitlements,
catalog,
user,
listedDashboards,
accessibleDashboards,
legacyDashboards,
dateHierarchyTemplates,
]: [
SagaReturnType<typeof resolveDashboardConfig>,
SagaReturnType<typeof resolvePermissions>,
PromiseFnReturnType<typeof resolveEntitlements>,
PromiseFnReturnType<typeof loadCatalog>,
PromiseFnReturnType<typeof loadUser>,
PromiseFnReturnType<typeof loadDashboardList>,
PromiseFnReturnType<typeof loadAccessibleDashboardList>,
PromiseFnReturnType<typeof loadLegacyDashboards>,
PromiseFnReturnType<typeof loadDateHierarchyTemplates>,
] = yield all([
call(resolveDashboardConfig, ctx, cmd),
call(resolvePermissions, ctx, cmd),
call(resolveEntitlements, ctx),
call(loadCatalog, ctx, cmd),
call(loadUser, ctx),
call(loadDashboardList, ctx),
call(loadAccessibleDashboardList, ctx),
call(loadLegacyDashboards, ctx),
call(loadDateHierarchyTemplates, ctx),
call(loadFilterViews, ctx),
]);

Expand All @@ -353,14 +338,6 @@ function* initializeNewDashboard(
entitlementsActions.setEntitlements(entitlements),
userActions.setUser(user),
permissionsActions.setPermissions(permissions),
catalogActions.setCatalogItems({
attributes: catalog.attributes(),
dateDatasets: catalog.dateDatasets(),
facts: catalog.facts(),
measures: catalog.measures(),
attributeHierarchies: catalog.attributeHierarchies(),
dateHierarchyTemplates: dateHierarchyTemplates,
}),
listedDashboardsActions.setListedDashboards(listedDashboards),
accessibleDashboardsActions.setAccessibleDashboards(accessibleDashboards),
legacyDashboardsActions.setLegacyDashboards(legacyDashboards),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { DashboardContext } from "../../types/commonTypes.js";
import { newDashboardEventPredicate } from "../../events/index.js";
import { renderRequested, renderResolved } from "../../events/render.js";
import { executedActions } from "../../store/executed/index.js";
import { loadCatalog } from "../dashboard/initializeDashboardHandler/loadCatalog.js";
import { loadDateHierarchyTemplates } from "../dashboard/initializeDashboardHandler/loadDateHierarchyTemplates.js";
import { catalogActions } from "../../store/catalog/index.js";

function* wait(ms: number): SagaIterator<true> {
yield delay(ms);
Expand Down Expand Up @@ -103,6 +106,20 @@ export function newRenderingWorker(renderingWorkerConfig: Partial<RenderingWorke

// Notify that the dashboard is fully rendered.
yield put(renderResolved(ctx, correlationId));

// TODO: load catalog here
const catalog = yield call(loadCatalog, ctx, { payload: { config: {} } } as any);
const dateHierarchyTemplates = yield call(loadDateHierarchyTemplates, ctx);
yield put(
catalogActions.setCatalogItems({
attributes: catalog.attributes(),
dateDatasets: catalog.dateDatasets(),
facts: catalog.facts(),
measures: catalog.measures(),
attributeHierarchies: catalog.attributeHierarchies(),
dateHierarchyTemplates: dateHierarchyTemplates,
}),
);
} catch (err) {
console.error("Rendering worker failed", err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
uriRef,
isDashboardAttributeFilterReference,
IKpiWidget,
ICatalogDateDataset,
//ICatalogDateDataset,
IAttributeDisplayFormMetadataObject,
IMetadataObject,
isInsightWidget,
Expand All @@ -38,7 +38,7 @@ import { selectAllFiltersForWidgetByRef, selectWidgetByRef } from "../store/layo
import { selectInsightByRef } from "../store/insights/insightsSelectors.js";
import { invalidQueryArguments } from "../events/general.js";
import compact from "lodash/compact.js";
import { selectAllCatalogDateDatasetsMap } from "../store/catalog/catalogSelectors.js";
//import { selectAllCatalogDateDatasetsMap } from "../store/catalog/catalogSelectors.js";
import { DashboardState } from "../store/types.js";
import { resolveDisplayFormMetadata } from "../utils/displayFormResolver.js";
import { invariant } from "ts-invariant";
Expand All @@ -64,7 +64,7 @@ interface IFilterDisplayFormPair {

interface IFilterDateDatasetPair {
filter: IDateFilter;
dateDataset: ICatalogDateDataset | undefined;
dateDataset: ObjRef | undefined; //ICatalogDateDataset | undefined;
}

function* loadDisplayFormsForAttributeFilters(
Expand All @@ -91,16 +91,16 @@ function* loadDisplayFormsForAttributeFilters(
}

function selectDateDatasetsForDateFilters(
state: DashboardState,
_state: DashboardState,
filters: IDateFilter[],
): IFilterDateDatasetPair[] {
const fromCatalog = selectAllCatalogDateDatasetsMap(state);
// const fromCatalog = selectAllCatalogDateDatasetsMap(state);

return filters.map((filter): IFilterDateDatasetPair => {
const dateDataset = fromCatalog.get(filterObjRef(filter));
// const dateDataset = fromCatalog.get(filterObjRef(filter));

return {
dateDataset,
dateDataset: filterObjRef(filter),
filter,
};
});
Expand Down Expand Up @@ -218,9 +218,8 @@ function resolveWidgetDateFilterIgnore(
const nonIgnoredCommonDateFilterDateDatasetPairs = commonDateFilterDateDatasetPairs.filter(
({ dateDataset }) => {
return (
!!widget.dateDataSet &&
dateDataset &&
refMatchesMdObject(widget.dateDataSet, dateDataset.dataSet, "dataSet")
!!widget.dateDataSet && dateDataset && areObjRefsEqual(widget.dateDataSet, dateDataset)
// refMatchesMdObject(widget.dateDataSet, dateDataset.dataSet, "dataSet")
);
},
);
Expand All @@ -230,7 +229,8 @@ function resolveWidgetDateFilterIgnore(
dateDataset &&
widget.ignoreDashboardFilters
?.filter(isDashboardDateFilterReference)
.some((ignored) => refMatchesMdObject(ignored.dataSet, dateDataset.dataSet, "dataSet"));
//.some((ignored) => refMatchesMdObject(ignored.dataSet, dateDataset.dataSet, "dataSet"));
.some((ignored) => areObjRefsEqual(ignored.dataSet, dateDataset));

return !matches;
},
Expand Down Expand Up @@ -268,7 +268,8 @@ function resolveDateFilters(
.filter((item) => !!item.dateDataset)
.reduceRight((acc: IDateFilter[], curr) => {
const alreadyPresent = acc.some((item) =>
refMatchesMdObject(filterObjRef(item), curr.dateDataset!.dataSet, "dataSet"),
//refMatchesMdObject(filterObjRef(item), curr.dateDataset!.dataSet, "dataSet"),
areObjRefsEqual(filterObjRef(item), curr.dateDataset),
);

if (!alreadyPresent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { CatalogState } from "./catalogState.js";
type CatalogReducer<A extends Action> = CaseReducer<CatalogState, A>;

export interface SetCatalogItemsPayload {
attributes: ICatalogAttribute[];
measures: ICatalogMeasure[];
facts: ICatalogFact[];
dateDatasets: ICatalogDateDataset[];
attributeHierarchies: ICatalogAttributeHierarchy[];
dateHierarchyTemplates: IDateHierarchyTemplate[];
attributes?: ICatalogAttribute[];
measures?: ICatalogMeasure[];
facts?: ICatalogFact[];
dateDatasets?: ICatalogDateDataset[];
attributeHierarchies?: ICatalogAttributeHierarchy[];
dateHierarchyTemplates?: IDateHierarchyTemplate[];
}

const setCatalogItems: CatalogReducer<PayloadAction<SetCatalogItemsPayload>> = (state, action) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ export const selectHasCatalogDateDatasets: DashboardSelector<boolean> = createSe
negate(isEmpty),
);

/**
* @alpha
*/
export const selectCatalogIsLoaded: DashboardSelector<boolean> = createSelector(selectSelf, (state) => {
return state.attributes !== undefined;
});

/**
* @public
*/
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-ui-dashboard/src/model/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export {
} from "./insights/insightsSelectors.js";
export type { CatalogState } from "./catalog/catalogState.js";
export {
selectCatalogIsLoaded,
selectAttributesWithDrillDown,
selectCatalogAttributes,
selectCatalogAttributeDisplayForms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
} from "../backendCapabilities/backendCapabilitiesSelectors.js";
import { existBlacklistHierarchyPredicate } from "../../utils/attributeHierarchyUtils.js";
import { selectDisableDashboardCrossFiltering } from "../meta/metaSelectors.js";
import { selectCatalogIsLoaded } from "../catalog/catalogSelectors.js";

/**
* @internal
Expand Down Expand Up @@ -628,17 +629,27 @@ export const selectConfiguredAndImplicitDrillsByWidgetRef: (
ref: ObjRef,
) => DashboardSelector<IImplicitDrillWithPredicates[]> = createMemoizedSelector((ref: ObjRef) =>
createSelector(
selectCatalogIsLoaded,
selectValidConfiguredDrillsByWidgetRef(ref),
selectImplicitDrillsDownByWidgetRef(ref),
selectImplicitDrillsToUrlByWidgetRef(ref),
selectCrossFilteringByWidgetRef(ref),
(configuredDrills, implicitDrillDownDrills, implicitDrillToUrlDrills, crossFiltering) => {
return compact([
...configuredDrills,
...implicitDrillDownDrills,
...implicitDrillToUrlDrills,
crossFiltering,
]);
(
catalogIsLoaded,
configuredDrills,
implicitDrillDownDrills,
implicitDrillToUrlDrills,
crossFiltering,
) => {
// disable drilling until catalog is fully loaded
return catalogIsLoaded
? compact([
...configuredDrills,
...implicitDrillDownDrills,
...implicitDrillToUrlDrills,
crossFiltering,
])
: [];
},
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021-2022 GoodData Corporation
// (C) 2021-2024 GoodData Corporation
import { ObjRef, IAttributeDisplayFormMetadataObject } from "@gooddata/sdk-model";
import { SagaIterator } from "redux-saga";
import { selectAllCatalogDisplayFormsMap } from "../store/catalog/catalogSelectors.js";
Expand Down
Loading
Loading