ui for source container

This commit is contained in:
Nishtha Ahuja
2025-02-19 16:36:52 +05:30
parent 468a391e0c
commit 610547850f
3 changed files with 86 additions and 5 deletions

View File

@@ -184,7 +184,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
this.shouldShowComputedPropertiesEditor = userContext.apiType === "SQL";
this.shouldShowIndexingPolicyEditor = userContext.apiType !== "Cassandra" && userContext.apiType !== "Mongo";
this.shouldShowPartitionKeyEditor = userContext.apiType === "SQL" && isRunningOnPublicCloud();
this.isMaterializedView = !!this.collection?.materializedViewDefinition();
this.isMaterializedView =
!!this.collection?.materializedViewDefinition() || !!this.collection?.materializedViews();
console.log("Is Materialized View:", this.isMaterializedView);
this.isVectorSearchEnabled = isVectorSearchEnabled() && !hasDatabaseSharedThroughput(this.collection);
this.isFullTextSearchEnabled = isFullTextSearchEnabled() && !hasDatabaseSharedThroughput(this.collection);

View File

@@ -1,13 +1,47 @@
import { Text } from "@fluentui/react";
import { Link, PrimaryButton, Stack, Text } from "@fluentui/react";
import React from "react";
import * as ViewModels from "../../../../Contracts/ViewModels";
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
export interface MaterializedViewComponentProps {
collection: ViewModels.Collection;
}
export const MaterializedViewComponent: React.FC<MaterializedViewComponentProps> = ({ collection }) => {
console.log("collection", collection);
const sourceId = collection.materializedViewDefinition()?.sourceCollectionId;
return <Text>{`Source ID: ${sourceId}`}</Text>;
const isTargetContainer = !!collection?.materializedViewDefinition();
const materializedViews = collection?.materializedViews() ?? [];
if (isTargetContainer) {
return null;
}
const showEditor = materializedViews.length > 0;
const jsonValue = JSON.stringify(
materializedViews.map((view) => ({
name: view.id,
definition: view.id,
})),
null,
2,
);
return (
<Stack tokens={{ childrenGap: 12 }} styles={{ root: { maxWidth: 600 } }}>
<Stack horizontal verticalAlign="center" wrap tokens={{ childrenGap: 8 }}>
<Text styles={{ root: { fontWeight: 600 } }}>This container has the following views defined for it</Text>
<Link target="_blank" href="https://aka.ms/MicrosoftCopilotForAzureInCDBHowTo">
Learn more
</Link>
<Text>about how to define materialized views and how to use them.</Text>
</Stack>
{showEditor && <MaterializedViewSourceComponent jsonValue={jsonValue} />}
<PrimaryButton
text="Add view"
styles={{ root: { width: "fit-content" } }}
onClick={() => console.log("Add view clicked")}
/>
</Stack>
);
};

View File

@@ -0,0 +1,46 @@
import { loadMonaco } from "Explorer/LazyMonaco";
import * as monaco from "monaco-editor";
import React, { useEffect, useRef } from "react";
export interface MaterializedViewSourceComponentProps {
jsonValue: string;
}
export const MaterializedViewSourceComponent: React.FC<MaterializedViewSourceComponentProps> = ({ jsonValue }) => {
const editorContainerRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(null);
useEffect(() => {
let disposed = false;
const initMonaco = async () => {
const monacoInstance = await loadMonaco();
if (disposed || !editorContainerRef.current) return;
editorRef.current = monacoInstance.editor.create(editorContainerRef.current, {
value: jsonValue,
language: "json",
ariaLabel: "Materialized Views JSON",
});
};
initMonaco();
return () => {
disposed = true;
editorRef.current?.dispose();
};
}, []);
useEffect(() => {
if (editorRef.current) {
editorRef.current.setValue(jsonValue);
}
}, [jsonValue]);
return (
<div
ref={editorContainerRef}
style={{ height: 250, border: "1px solid #ccc", borderRadius: 4, overflow: "hidden" }}
/>
);
};