added partitionKey

This commit is contained in:
Nishtha Ahuja 2025-02-21 15:13:46 +05:30
parent a5f12ddd23
commit 82ea06e3d0
2 changed files with 27 additions and 18 deletions

View File

@ -15,13 +15,16 @@ export const MaterializedViewComponent: React.FC<MaterializedViewComponentProps>
} }
return ( return (
<Stack tokens={{ childrenGap: 12 }} styles={{ root: { maxWidth: 600 } }}> <Stack tokens={{ childrenGap: 8 }} styles={{ root: { maxWidth: 600 } }}>
<Stack horizontal verticalAlign="center" wrap tokens={{ childrenGap: 8 }}> <Stack horizontal verticalAlign="center" wrap tokens={{ childrenGap: 8 }}>
<Text styles={{ root: { fontWeight: 600 } }}>This container has the following views defined for it</Text> <Text styles={{ root: { fontWeight: 600 } }}>This container has the following views defined for it.</Text>
<Link target="_blank" href="https://aka.ms/MicrosoftCopilotForAzureInCDBHowTo"> {/* change href */}
Learn more <Text>
</Link> <Link target="_blank" href="https://aka.ms/MicrosoftCopilotForAzureInCDBHowTo">
<Text>about how to define materialized views and how to use them.</Text> Learn more
</Link>{" "}
about how to define materialized views and how to use them.
</Text>
</Stack> </Stack>
<MaterializedViewSourceComponent collection={collection} /> <MaterializedViewSourceComponent collection={collection} />
</Stack> </Stack>

View File

@ -13,29 +13,34 @@ export const MaterializedViewSourceComponent: React.FC<MaterializedViewSourceCom
const editorContainerRef = useRef<HTMLDivElement>(null); const editorContainerRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(null); const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(null);
// Get the materialized views from the provided collection.
const materializedViews = collection?.materializedViews() ?? []; const materializedViews = collection?.materializedViews() ?? [];
// Helper function to fetch the view definition by matching viewId with collection id. // 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 getViewDefinition = (viewId: string): string => { const getViewDetails = (viewId: string): { definition: string; partitionKey: string[] } => {
let definition = ""; let definition = "";
let partitionKey: string[] = [];
useDatabases.getState().databases.forEach((database) => { useDatabases.getState().databases.forEach((database) => {
database.collections().forEach((coll) => { database.collections().forEach((coll) => {
const materializedViewDefinition = coll.materializedViewDefinition(); if (coll.id() === viewId) {
if (materializedViewDefinition && coll.id() === viewId) { const materializedViewDefinition = coll.materializedViewDefinition();
definition = materializedViewDefinition.definition; 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( const jsonValue = JSON.stringify(
materializedViews.map((view) => ({ materializedViews.map((view) => {
name: view.id, const { definition, partitionKey } = getViewDetails(view.id);
definition: getViewDefinition(view.id), return {
})), name: view.id,
partitionKey: partitionKey.join(", "),
definition,
};
}),
null, null,
2, 2,
); );
@ -51,6 +56,7 @@ export const MaterializedViewSourceComponent: React.FC<MaterializedViewSourceCom
value: jsonValue, value: jsonValue,
language: "json", language: "json",
ariaLabel: "Materialized Views JSON", ariaLabel: "Materialized Views JSON",
readOnly: true,
}); });
}; };