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>
{/* change href */}
<Text>
<Link target="_blank" href="https://aka.ms/MicrosoftCopilotForAzureInCDBHowTo"> <Link target="_blank" href="https://aka.ms/MicrosoftCopilotForAzureInCDBHowTo">
Learn more Learn more
</Link> </Link>{" "}
<Text>about how to define materialized views and how to use them.</Text> 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) => {
if (coll.id() === viewId) {
const materializedViewDefinition = coll.materializedViewDefinition(); const materializedViewDefinition = coll.materializedViewDefinition();
if (materializedViewDefinition && coll.id() === viewId) { materializedViewDefinition && (definition = materializedViewDefinition.definition);
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) => {
const { definition, partitionKey } = getViewDetails(view.id);
return {
name: view.id, name: view.id,
definition: getViewDefinition(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,
}); });
}; };