From dd08284b668b855a8809af477620defce7f65f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Tue, 30 Jan 2024 13:23:04 +0100 Subject: [PATCH] fix: export modal loading child with keys issues https://github.com/gisce/webclient/issues/827 --- .../other/ExportModal/ExportModal.stories.tsx | 69 ++++++++++--------- .../other/ExportModal/ExportModal.tsx | 5 +- src/context/LocaleContext.tsx | 2 +- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/components/other/ExportModal/ExportModal.stories.tsx b/src/components/other/ExportModal/ExportModal.stories.tsx index a90fadc..95fdf59 100644 --- a/src/components/other/ExportModal/ExportModal.stories.tsx +++ b/src/components/other/ExportModal/ExportModal.stories.tsx @@ -298,39 +298,44 @@ export const Default: ComponentStory = () => { ]; }} onGetPredefinedExports={async () => { + console.log("onGetPredefinedExports"); await new Promise((resolve) => setTimeout(resolve, 1000)); - return [ - { - id: 3, - name: "Exportación de prueba 3", - fields: [ - { - key: "active/contador", - }, - { - key: "parent1/parent2/test", - }, - ], - }, - { - id: 1, - name: "Exportación de prueba", - fields: [ - { - key: "active", - }, - ], - }, - { - id: 2, - name: "Exportación de prueba 2", - fields: [ - { - key: "city", - }, - ], - }, - ]; + console.log("onGetPredefinedExports 2"); + return { + predefinedExports: [ + { + id: 3, + name: "Exportación de prueba 3", + fields: [ + { + key: "active/contador", + }, + { + key: "parent1/parent2/test", + }, + ], + }, + { + id: 1, + name: "Exportación de prueba", + fields: [ + { + key: "active", + }, + ], + }, + { + id: 2, + name: "Exportación de prueba 2", + fields: [ + { + key: "city", + }, + ], + }, + ], + keysWithChilds: [], + }; }} onSavePredefinedExport={async (options: PredefinedExport) => { await new Promise((resolve) => setTimeout(resolve, 3000)); diff --git a/src/components/other/ExportModal/ExportModal.tsx b/src/components/other/ExportModal/ExportModal.tsx index b12b867..73801e7 100644 --- a/src/components/other/ExportModal/ExportModal.tsx +++ b/src/components/other/ExportModal/ExportModal.tsx @@ -131,9 +131,8 @@ export const ExportModalWithContext = (props: ExportModalProps) => { const onGetPredefinedExportsCallback = useCallback(async () => { const { predefinedExports, keysWithChilds } = await onGetPredefinedExports(); - if (keysWithChilds.length > 0) { - let updatedTree: ExportField[] = []; + let updatedTree; for (const entry of keysWithChilds) { const { key, childs } = entry; @@ -143,7 +142,7 @@ export const ExportModalWithContext = (props: ExportModalProps) => { updatedTree = updateTreeData(updatedTree, key, childs); } } - setDataSource(updatedTree); + setDataSource(updatedTree as ExportField[]); } return predefinedExports as PredefinedExportMandatoryId[]; diff --git a/src/context/LocaleContext.tsx b/src/context/LocaleContext.tsx index a9a9426..d2ed768 100644 --- a/src/context/LocaleContext.tsx +++ b/src/context/LocaleContext.tsx @@ -71,7 +71,7 @@ export const useLocale = (propLocale?: Locale): LocaleContextType => { } if (!context) { - console.error( + console.warn( "useLocale must be used within a LocaleContextProvider - assuming default locale value", ); return {