diff --git a/package.json b/package.json index a061255..001652d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@thoughtspot/ts-chart-sdk", "private": false, - "version": "2.6.0", + "version": "2.6.1", "module": "lib/index", "main": "lib/index", "types": "lib/index", diff --git a/src/main/custom-chart-context.spec.ts b/src/main/custom-chart-context.spec.ts index e7f47bf..d1b44a6 100644 --- a/src/main/custom-chart-context.spec.ts +++ b/src/main/custom-chart-context.spec.ts @@ -1788,6 +1788,7 @@ describe('CustomChartContext', () => { }); expect(response).toEqual({ + isDownloadHandled: true, fileName: '', error: '', message: 'Download Excel not implemented.', @@ -1796,6 +1797,7 @@ describe('CustomChartContext', () => { test('should use custom handler when provided', async () => { const mockDownloadHandler = jest.fn().mockReturnValue({ + isDownloadHandled: true, fileName: 'custom-report.xlsx', error: '', message: 'Success', @@ -1825,6 +1827,7 @@ describe('CustomChartContext', () => { expect(mockDownloadHandler).toHaveBeenCalledWith(testPayload); expect(response).toEqual({ + isDownloadHandled: true, fileName: 'custom-report.xlsx', error: '', message: 'Success', @@ -1833,6 +1836,7 @@ describe('CustomChartContext', () => { test('should handle errors in custom handler', async () => { const mockDownloadHandler = jest.fn().mockReturnValue({ + isDownloadHandled: true, fileName: '', error: 'Failed to generate excel', message: 'Error occurred', @@ -1858,6 +1862,7 @@ describe('CustomChartContext', () => { expect(mockDownloadHandler).toHaveBeenCalled(); expect(response).toEqual({ + isDownloadHandled: true, fileName: '', error: 'Failed to generate excel', message: 'Error occurred', @@ -1866,6 +1871,7 @@ describe('CustomChartContext', () => { test('should pass through payload to custom handler', async () => { const mockDownloadHandler = jest.fn().mockReturnValue({ + isDownloadHandled: true, fileName: 'test.xlsx', error: '', message: 'Success', @@ -1912,6 +1918,7 @@ describe('CustomChartContext', () => { return response; } return { + isDownloadHandled: true, fileName: 'first.xlsx', error: '', message: 'First handler response', @@ -1921,6 +1928,7 @@ describe('CustomChartContext', () => { ); const secondHandler = jest.fn().mockReturnValue({ + isDownloadHandled: true, fileName: 'second.xlsx', error: '', message: 'Second handler response', @@ -1958,6 +1966,7 @@ describe('CustomChartContext', () => { // Verify handlers were called in correct order expect(secondHandler).toHaveBeenCalledWith(testPayload, undefined); expect(firstHandler).toHaveBeenCalledWith(testPayload, { + isDownloadHandled: true, fileName: 'second.xlsx', error: '', message: 'Second handler response', @@ -1967,6 +1976,7 @@ describe('CustomChartContext', () => { // Verify final result comes from first handler's return value // (last custom handler to execute) expect(result).toEqual({ + isDownloadHandled: true, fileName: 'second.xlsx', error: '', message: 'Second handler response', diff --git a/src/main/custom-chart-context.ts b/src/main/custom-chart-context.ts index be63666..684b41b 100644 --- a/src/main/custom-chart-context.ts +++ b/src/main/custom-chart-context.ts @@ -1186,6 +1186,7 @@ export class CustomChartContext { return response; } return Promise.resolve({ + isDownloadHandled: true, fileName: '', error: '', message: 'Download Excel not implemented.', diff --git a/src/react/use-custom-chart-context.spec.tsx b/src/react/use-custom-chart-context.spec.tsx index e98bc6e..555572f 100644 --- a/src/react/use-custom-chart-context.spec.tsx +++ b/src/react/use-custom-chart-context.spec.tsx @@ -629,6 +629,7 @@ describe('useChartContext DownloadExcelTrigger event handler', () => { await waitFor(() => { expect(response).toEqual({ + isDownloadHandled: true, fileName: '', error: '', message: 'Download Excel not implemented.', diff --git a/src/react/use-custom-chart-context.tsx b/src/react/use-custom-chart-context.tsx index 84ac347..a3432ae 100644 --- a/src/react/use-custom-chart-context.tsx +++ b/src/react/use-custom-chart-context.tsx @@ -113,6 +113,7 @@ export const useChartContext = ( ) => { setChartModel(context.getChartModel()); return Promise.resolve({ + isDownloadHandled: true, fileName: '', error: '', message: 'Download Excel not implemented.', diff --git a/src/types/ts-to-chart-event.types.ts b/src/types/ts-to-chart-event.types.ts index e8dedd3..37900a9 100644 --- a/src/types/ts-to-chart-event.types.ts +++ b/src/types/ts-to-chart-event.types.ts @@ -93,6 +93,15 @@ export interface DownloadExcelTriggerPayload { answerTitle: string; } export interface DownloadExcelTriggerResponse { + // This `isDownloadHandled` flag indicates whether the custom chart has + // handled the XLSX download. If true, the custom chart managed the + // download. If false, the ThoughtSpot default XLSX downloader will be used + // instead. For example, in Muze Studio, only pivot tables support XLSX + // export. For other chart types like bar or line charts, this flag should + // be set to false to signal that the download could not be processed by the + // custom chart, allowing the default ThoughtSpot downloader to handle the + // export. + isDownloadHandled: boolean; fileName: string; error: string; message: string;