From 82ea06e3d0d80981217f105091bfc411803e2397 Mon Sep 17 00:00:00 2001 From: Nishtha Ahuja Date: Fri, 21 Feb 2025 15:13:46 +0530 Subject: [PATCH] added partitionKey --- .../MaterializedViewComponent.tsx | 15 ++++++---- .../MaterializedViewSourceComponent.tsx | 30 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.tsx index 0d0adc64e..0798711d8 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.tsx @@ -15,13 +15,16 @@ export const MaterializedViewComponent: React.FC } return ( - + - This container has the following views defined for it - - Learn more - - about how to define materialized views and how to use them. + This container has the following views defined for it. + {/* change href */} + + + Learn more + {" "} + about how to define materialized views and how to use them. + diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx index b8c532e66..3f52fb252 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx @@ -13,29 +13,34 @@ export const MaterializedViewSourceComponent: React.FC(null); const editorRef = useRef(null); - // Get the materialized views from the provided collection. const materializedViews = collection?.materializedViews() ?? []; - // Helper function to fetch the view definition by matching viewId with collection id. - const getViewDefinition = (viewId: string): string => { + // Helper function to fetch the definition and partition key of targetContainer by traversing through all collections and matching id from MaterializedViews[] with collection id. + const getViewDetails = (viewId: string): { definition: string; partitionKey: string[] } => { let definition = ""; + let partitionKey: string[] = []; useDatabases.getState().databases.forEach((database) => { database.collections().forEach((coll) => { - const materializedViewDefinition = coll.materializedViewDefinition(); - if (materializedViewDefinition && coll.id() === viewId) { - definition = materializedViewDefinition.definition; + if (coll.id() === viewId) { + const materializedViewDefinition = coll.materializedViewDefinition(); + materializedViewDefinition && (definition = materializedViewDefinition.definition); + coll.partitionKey?.paths && (partitionKey = coll.partitionKey.paths); } }); }); - return definition; + return { definition, partitionKey }; }; - // Build the JSON value for the editor using the fetched definitions. + //JSON value for the editor using the fetched id and definitions. const jsonValue = JSON.stringify( - materializedViews.map((view) => ({ - name: view.id, - definition: getViewDefinition(view.id), - })), + materializedViews.map((view) => { + const { definition, partitionKey } = getViewDetails(view.id); + return { + name: view.id, + partitionKey: partitionKey.join(", "), + definition, + }; + }), null, 2, ); @@ -51,6 +56,7 @@ export const MaterializedViewSourceComponent: React.FC