Skip to content

Commit

Permalink
Merge pull request #5986 from gooddata/SHA_master
Browse files Browse the repository at this point in the history
fix: ui for new exports
  • Loading branch information
hackerstanislav authored Feb 28, 2025
2 parents 93f2b75 + d343ca2 commit 6d76b3b
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 39 deletions.
5 changes: 4 additions & 1 deletion libs/sdk-backend-base/api/sdk-backend-base.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ export abstract class DecoratedWorkspaceDashboardsService implements IWorkspaceD
// (undocumented)
exportDashboardToPdf(ref: ObjRef, filters?: FilterContextItem[]): Promise<IExportResult>;
// (undocumented)
exportDashboardToPresentation(ref: ObjRef, format: "PPTX" | "PDF", filters?: FilterContextItem[]): Promise<IExportResult>;
exportDashboardToPresentation(ref: ObjRef, format: "PPTX" | "PDF", filters?: FilterContextItem[], options?: {
widgetIds?: ObjRef[];
filename?: string;
}): Promise<IExportResult>;
// (undocumented)
exportDashboardToTabular(ref: ObjRef): Promise<IExportResult>;
// (undocumented)
Expand Down
6 changes: 5 additions & 1 deletion libs/sdk-backend-base/src/decoratedBackend/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ export abstract class DecoratedWorkspaceDashboardsService implements IWorkspaceD
ref: ObjRef,
format: "PPTX" | "PDF",
filters?: FilterContextItem[],
options?: {
widgetIds?: ObjRef[];
filename?: string;
},
): Promise<IExportResult> {
return this.decorated.exportDashboardToPresentation(ref, format, filters);
return this.decorated.exportDashboardToPresentation(ref, format, filters, options);
}

exportDashboardToTabular(ref: ObjRef): Promise<IExportResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ export class RecordedDashboards implements IWorkspaceDashboardsService {
_ref: ObjRef,
_format: string,
_filters?: FilterContextItem[],
_options?: {
widgetIds?: ObjRef[];
filename?: string;
},
): Promise<IExportResult> {
throw new NotSupported("recorded backend does not support this call");
}
Expand Down
5 changes: 4 additions & 1 deletion libs/sdk-backend-spi/api/sdk-backend-spi.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,10 @@ export interface IWorkspaceDashboardsService {
deleteWidgetAlert(ref: ObjRef): Promise<void>;
deleteWidgetAlerts(refs: ObjRef[]): Promise<void>;
exportDashboardToPdf(ref: ObjRef, filters?: FilterContextItem[]): Promise<IExportResult>;
exportDashboardToPresentation(ref: ObjRef, format: "PDF" | "PPTX", filters?: FilterContextItem[]): Promise<IExportResult>;
exportDashboardToPresentation(ref: ObjRef, format: "PDF" | "PPTX", filters?: FilterContextItem[], options?: {
widgetIds?: ObjRef[];
filename?: string;
}): Promise<IExportResult>;
exportDashboardToTabular(ref: ObjRef): Promise<IExportResult>;
getAllWidgetAlertsForCurrentUser(): Promise<IWidgetAlert[]>;
getDashboard(ref: ObjRef, filterContextRef?: ObjRef, options?: IGetDashboardOptions): Promise<IDashboard>;
Expand Down
5 changes: 5 additions & 0 deletions libs/sdk-backend-spi/src/workspace/dashboards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,17 @@ export interface IWorkspaceDashboardsService {
* @param ref - dashboard reference
* @param format - export format
* @param filters - Override stored dashboard filters with custom filters
* @param options - additional options
* @returns promise with object URL pointing to a Blob data of downloaded exported dashboard
*/
exportDashboardToPresentation(
ref: ObjRef,
format: "PDF" | "PPTX",
filters?: FilterContextItem[],
options?: {
widgetIds?: ObjRef[];
filename?: string;
},
): Promise<IExportResult>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ export class TigerWorkspaceDashboards implements IWorkspaceDashboardsService {
dashboardRef: ObjRef,
format: "PDF" | "PPTX",
filters?: FilterContextItem[],
options?: {
widgetIds?: ObjRef[];
filename?: string;
},
): Promise<IExportResult> => {
const dashboardId = await objRefToIdentifier(dashboardRef, this.authCall);

Expand All @@ -451,9 +455,10 @@ export class TigerWorkspaceDashboards implements IWorkspaceDashboardsService {

const { title } = convertDashboard(dashboardResponse.data);
const slidesExportRequest = {
fileName: title,
format,
dashboardId,
fileName: options?.filename ?? title,
widgetIds: options?.widgetIds?.map((widgetId) => objRefToString(widgetId)),
metadata: convertToBackendExportMetadata({ filters: withoutAllTime }),
};
const slideshowExport = await client.export.createSlidesExport({
Expand Down
23 changes: 21 additions & 2 deletions libs/sdk-ui-dashboard/api/sdk-ui-dashboard.api.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions libs/sdk-ui-dashboard/src/model/commandHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import { exportRawInsightWidgetHandler } from "./widgets/exportRawInsightWidgetH
import { exportDashboardToExcelHandler } from "./dashboard/exportDashboardToExcelHandler.js";
import { exportDashboardToPdfPresentationHandler } from "./dashboard/exportDashboardToPdfPresentationHandler.js";
import { exportDashboardToPptPresentationHandler } from "./dashboard/exportDashboardToPptPresentationHandler.js";
import { exportSlidesInsightWidgetHandler } from "./widgets/exportSlidesInsightWidgetHandler.js";

function* notImplementedCommand(ctx: DashboardContext, cmd: IDashboardCommand): SagaIterator<void> {
yield dispatchDashboardEvent(commandRejected(ctx, cmd.correlationId));
Expand Down Expand Up @@ -172,6 +173,7 @@ export const DefaultCommandHandlers: {
"GDC.DASH/CMD.KPI_WIDGET.SET_DRILL": setDrillForKpiWidgetHandler,
"GDC.DASH/CMD.KPI_WIDGET.REFRESH": notImplementedCommand,
"GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_RAW": exportRawInsightWidgetHandler,
"GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_SLIDES": exportSlidesInsightWidgetHandler,
"GDC.DASH/CMD.KPI_WIDGET.CHANGE_DESCRIPTION": changeKpiWidgetDescriptionHandler,
"GDC.DASH/CMD.KPI_WIDGET.CHANGE_CONFIGURATION": changeKpiWidgetConfigurationHandler,
"GDC.DASH/CMD.INSIGHT_WIDGET.CHANGE_HEADER": changeInsightWidgetHeaderHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// (C) 2024-2025 GoodData Corporation
import { SagaIterator } from "redux-saga";
import { call, select } from "redux-saga/effects";
import { IExportResult } from "@gooddata/sdk-backend-spi";
import { DashboardInsightWidgetExportResolved, insightWidgetExportResolved } from "../../events/insight.js";
import { DashboardContext } from "../../types/commonTypes.js";
import { PromiseFnReturnType } from "../../types/sagas.js";
import { invalidArgumentsProvided } from "../../events/general.js";
import { selectFilterContextFilters } from "../../store/filterContext/filterContextSelectors.js";
import { selectDashboardRef } from "../../store/meta/metaSelectors.js";
import { ensureAllTimeFilterForExport } from "../../../_staging/exportUtils/filterUtils.js";
import { ExportSlidesInsightWidget } from "../../commands/insight.js";

export function* exportSlidesInsightWidgetHandler(
ctx: DashboardContext,
cmd: ExportSlidesInsightWidget,
): SagaIterator<DashboardInsightWidgetExportResolved> {
const { ref, filename, exportType } = cmd.payload;
const { workspace, backend } = ctx;

const dashboardRef = yield select(selectDashboardRef);
if (!dashboardRef) {
throw invalidArgumentsProvided(ctx, cmd, "Dashboard to export to EXCEL must have an ObjRef.");
}
const filterContextFilters = yield select(selectFilterContextFilters);
const effectiveFilters = ensureAllTimeFilterForExport(filterContextFilters);

const exportDashboardToPresentation = backend
.workspace(workspace)
.dashboards().exportDashboardToPresentation;
const result: PromiseFnReturnType<typeof exportDashboardToPresentation> = yield call(
exportDashboardToPresentation,
dashboardRef,
exportType === "pptx" ? "PPTX" : "PDF",
effectiveFilters,
{
widgetIds: [ref],
filename,
},
);
// prepend hostname if provided so that the results are downloaded from there, not from where the app is hosted
const fullUri = ctx.backend.config.hostname
? new URL(result.uri, ctx.backend.config.hostname).href
: result.uri;
const sanitizedResult: IExportResult = {
...result,
uri: fullUri,
};
return insightWidgetExportResolved(ctx, sanitizedResult, cmd.correlationId);
}
3 changes: 2 additions & 1 deletion libs/sdk-ui-dashboard/src/model/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export type DashboardCommandType =
| "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.RELOAD"
// @internal
| "GDC.DASH/CMD.USERS.LOAD_ALL"
| "GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_RAW";
| "GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_RAW"
| "GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_SLIDES";

/**
* @public
Expand Down
7 changes: 6 additions & 1 deletion libs/sdk-ui-dashboard/src/model/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
ModifyDrillDownForInsightWidget,
AttributeHierarchyModified,
ChangeInsightWidgetIgnoreCrossFiltering,
ExportSlidesInsightWidget,
} from "./insight.js";
import {
ChangeKpiWidgetComparison,
Expand Down Expand Up @@ -441,6 +442,8 @@ export type {
AttributeHierarchyModified,
ExportRawInsightWidget,
ExportRawInsightWidgetPayload,
ExportSlidesInsightWidget,
ExportSlidesInsightWidgetPayload,
} from "./insight.js";
export {
changeInsightWidgetHeader,
Expand All @@ -465,6 +468,7 @@ export {
refreshInsightWidget,
exportInsightWidget,
exportRawInsightWidget,
exportSlidesInsightWidget,
attributeHierarchyModified,
} from "./insight.js";
export { loadAllWorkspaceUsers } from "./users.js";
Expand Down Expand Up @@ -613,4 +617,5 @@ export type DashboardCommands =
//internal
| SetScreenSize
| LoadAllWorkspaceUsers
| ExportRawInsightWidget;
| ExportRawInsightWidget
| ExportSlidesInsightWidget;
60 changes: 59 additions & 1 deletion libs/sdk-ui-dashboard/src/model/commands/insight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ export interface ExportRawInsightWidgetPayload {
*/
readonly filename: string;
}

/**
* @alpha
*/
Expand All @@ -984,7 +985,8 @@ export interface ExportRawInsightWidget extends IDashboardCommand {
/**
* Creates the ExportRawInsightWidget command. Dispatching this command will result in exporting of the widget to a CSV.
*
* @param ref - reference to the Insight widget to refresh
* @param insight - insight to export
* @param filename - filename of the exported file
* @param correlationId - specify correlation id to use for this command. this will be included in all
* events that will be emitted during the command processing
*
Expand All @@ -1005,6 +1007,62 @@ export function exportRawInsightWidget(
};
}

/**
* Payload of the {@link ExportRawInsightWidget} command.
* @alpha
*/
export interface ExportSlidesInsightWidgetPayload {
/**
* Reference to Insight to export.
*/
readonly ref: ObjRef;

/**
* Reference to Insight title to export.
*/
readonly filename: string;

/**
* Type of export to perform.
*/
readonly exportType: "pdf" | "pptx";
}

/**
* @alpha
*/
export interface ExportSlidesInsightWidget extends IDashboardCommand {
readonly type: "GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_SLIDES";
readonly payload: ExportSlidesInsightWidgetPayload;
}
/**
* Creates the ExportSlidesInsightWidget command. Dispatching this command will result in exporting of the widget to a slides type (pdf, pptx).
*
* @param ref - reference to the Insight to export
* @param filename - filename of the exported file
* @param exportType - type of export to perform
* @param correlationId - specify correlation id to use for this command. this will be included in all
* events that will be emitted during the command processing
*
* @alpha
*/
export function exportSlidesInsightWidget(
ref: ObjRef,
filename: string,
exportType: "pdf" | "pptx",
correlationId?: string,
): ExportSlidesInsightWidget {
return {
type: "GDC.DASH/CMD.INSIGHT_WIDGET.EXPORT_SLIDES",
correlationId,
payload: {
ref,
filename,
exportType,
},
};
}

//
//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
"comment": "Export submenu",
"limit": 0
},
"options.menu.export.header.presentation": {
"value": "Presentation",
"comment": "Export submenu for presentation",
"options.menu.export.header.data": {
"value": "Data",
"comment": "Export submenu for data",
"limit": 0
},
"options.menu.export_to_pdf": {
Expand All @@ -133,17 +133,22 @@
"limit": 0
},
"options.menu.export.PDF": {
"value": "PDF",
"value": "Snapshot (PDF)",
"comment": "Export whole KPI dashboard to PDF",
"limit": 0
},
"options.menu.export.EXCEL": {
"value": "Excel",
"value": "Data (XLSX)",
"comment": "Export whole KPI dashboard to EXCEL",
"limit": 0
},
"options.menu.export.PPTX": {
"value": "PowerPoint",
"options.menu.export.presentation.PPTX": {
"value": "Slide Deck (PPTX)",
"comment": "Export whole KPI dashboard to PowerPoint",
"limit": 0
},
"options.menu.export.presentation.PDF": {
"value": "Slide Deck (PDF)",
"comment": "Export whole KPI dashboard to PowerPoint",
"limit": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,10 @@ export function useDefaultMenuItems(): IMenuButtonItem[] {
disabled: isInProgress,
icon: "gd-icon-download",
},
{
type: "button",
itemId: "excel-export-item", // careful, this is also used as a selector in tests, do not change
itemName: intl.formatMessage({ id: "options.menu.export.EXCEL" }),
onClick: defaultOnExportToExcel,
visible:
(menuButtonItemsVisibility.excelExportButton ?? true) &&
isEnableDashboardTabularExport &&
isEnableOrchestratedTabularExports,
disabled: isInProgress,
icon: "gd-icon-download",
},
{
type: "header",
itemId: "export-header-presentation",
itemName: intl.formatMessage({ id: "options.menu.export.header.presentation" }),
},
{
type: "button",
itemId: "pdf-presentation-export-item", // careful, this is also used as a selector in tests, do not change
itemName: intl.formatMessage({ id: "options.menu.export.PDF" }),
itemName: intl.formatMessage({ id: "options.menu.export.presentation.PDF" }),
onClick: defaultOnExportToPdfPresentation,
visible: menuButtonItemsVisibility.pdfExportButton ?? true,
disabled: isInProgress,
Expand All @@ -302,12 +285,24 @@ export function useDefaultMenuItems(): IMenuButtonItem[] {
{
type: "button",
itemId: "pptx-presentation-export-item", // careful, this is also used as a selector in tests, do not change
itemName: intl.formatMessage({ id: "options.menu.export.PPTX" }),
itemName: intl.formatMessage({ id: "options.menu.export.presentation.PPTX" }),
onClick: defaultOnExportToPowerPointPresentation,
visible: menuButtonItemsVisibility.powerPointExportButton ?? true,
disabled: isInProgress,
icon: "gd-icon-download",
},
{
type: "button",
itemId: "excel-export-item", // careful, this is also used as a selector in tests, do not change
itemName: intl.formatMessage({ id: "options.menu.export.EXCEL" }),
onClick: defaultOnExportToExcel,
visible:
(menuButtonItemsVisibility.excelExportButton ?? true) &&
isEnableDashboardTabularExport &&
isEnableOrchestratedTabularExports,
disabled: isInProgress,
icon: "gd-icon-download",
},
],
},
],
Expand Down
Loading

0 comments on commit 6d76b3b

Please sign in to comment.