From 55952a845f9fae2e66d09f58c4a1507999213a4c Mon Sep 17 00:00:00 2001 From: Psami-wondah Date: Tue, 1 Oct 2024 06:44:28 +0100 Subject: [PATCH 1/2] fix: Duplicating an asset in detail page leads to undefined route --- .../chart-module/components/chartSubheaderToolbar/index.tsx | 2 +- .../dataset-module/component/datasetSubHeaderToolbar.tsx | 2 +- .../report-module/components/reportSubHeaderToolbar/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/modules/chart-module/components/chartSubheaderToolbar/index.tsx b/src/app/modules/chart-module/components/chartSubheaderToolbar/index.tsx index 8b578b244..a36f4fc90 100644 --- a/src/app/modules/chart-module/components/chartSubheaderToolbar/index.tsx +++ b/src/app/modules/chart-module/components/chartSubheaderToolbar/index.tsx @@ -252,7 +252,7 @@ export function ChartSubheaderToolbar( storeInCrudData: true, filterString: "filter[order]=updatedDate desc", }); - setDuplicatedChartId(response.data.id); + setDuplicatedChartId(response.data?.data?.id); setSnackbarState({ ...snackbarState, open: true, diff --git a/src/app/modules/dataset-module/component/datasetSubHeaderToolbar.tsx b/src/app/modules/dataset-module/component/datasetSubHeaderToolbar.tsx index 6ad638dcf..9d406388c 100644 --- a/src/app/modules/dataset-module/component/datasetSubHeaderToolbar.tsx +++ b/src/app/modules/dataset-module/component/datasetSubHeaderToolbar.tsx @@ -110,7 +110,7 @@ export default function DatasetSubHeaderToolbar( onTryAgain: () => {}, }); } - setDuplicatedDatasetId(response.data.id); + setDuplicatedDatasetId(response.data?.data?.id); setSnackbarState({ ...snackbarState, open: true, diff --git a/src/app/modules/report-module/components/reportSubHeaderToolbar/index.tsx b/src/app/modules/report-module/components/reportSubHeaderToolbar/index.tsx index 76acdbd84..8ce6f7e47 100644 --- a/src/app/modules/report-module/components/reportSubHeaderToolbar/index.tsx +++ b/src/app/modules/report-module/components/reportSubHeaderToolbar/index.tsx @@ -230,7 +230,7 @@ export function ReportSubheaderToolbar( storeInCrudData: true, filterString: "filter[order]=updatedDate desc", }); - setDuplicatedReportId(response.data.id); + setDuplicatedReportId(response.data?.data?.id); setSnackbarState({ ...snackbarState, open: true, From 9ee1a5f27f04db082cea00df40e0fb88da72b39a Mon Sep 17 00:00:00 2001 From: Psami-wondah Date: Tue, 1 Oct 2024 07:06:47 +0100 Subject: [PATCH 2/2] test: update jest test --- .../chart-module/__test__/chartSubheaderToolbar.test.tsx | 2 +- .../report-module/__test__/reportSubheaderToolbar.test.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/modules/chart-module/__test__/chartSubheaderToolbar.test.tsx b/src/app/modules/chart-module/__test__/chartSubheaderToolbar.test.tsx index 126446bcc..49a60d8f1 100644 --- a/src/app/modules/chart-module/__test__/chartSubheaderToolbar.test.tsx +++ b/src/app/modules/chart-module/__test__/chartSubheaderToolbar.test.tsx @@ -581,7 +581,7 @@ test("clicking duplicate button should duplicate chart", async () => { const mockedAxios = axios.get as jest.Mock; mockedAxios .mockResolvedValueOnce({ - data: { id: "chart-id" }, + data: { data: { id: "chart-id" } }, } as AxiosResponse) .mockResolvedValueOnce({ data: mockChartList }); jest diff --git a/src/app/modules/report-module/__test__/reportSubheaderToolbar.test.tsx b/src/app/modules/report-module/__test__/reportSubheaderToolbar.test.tsx index ab1733f65..4874a179c 100644 --- a/src/app/modules/report-module/__test__/reportSubheaderToolbar.test.tsx +++ b/src/app/modules/report-module/__test__/reportSubheaderToolbar.test.tsx @@ -414,8 +414,10 @@ describe("Tests for tablet and desktop view", () => { const axiosMock = axios.get as jest.Mock; axiosMock - .mockResolvedValueOnce({ data: { id: "12345" } } as AxiosResponse) - .mockResolvedValueOnce({ data: [] }); + .mockResolvedValueOnce({ + data: { data: { id: "12345" } }, + } as AxiosResponse) + .mockResolvedValueOnce({ data: { data: [] } }); jest .spyOn(Router, "useParams") .mockReturnValue({ page: "12345", view: undefined });