diff --git a/src/Explorer/Controls/Settings/SettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsComponent.tsx index 2c97b8fe9..bb3c030de 100644 --- a/src/Explorer/Controls/Settings/SettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsComponent.tsx @@ -184,7 +184,8 @@ export class SettingsComponent extends React.Component = ({ collection }) => { - console.log("collection", collection); - const sourceId = collection.materializedViewDefinition()?.sourceCollectionId; - return {`Source ID: ${sourceId}`}; + 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 ( + + + This container has the following views defined for it + + Learn more + + about how to define materialized views and how to use them. + + + {showEditor && } + + console.log("Add view clicked")} + /> + + ); }; diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx new file mode 100644 index 000000000..e7cf076b9 --- /dev/null +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.tsx @@ -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 = ({ jsonValue }) => { + const editorContainerRef = useRef(null); + const editorRef = useRef(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 ( +
+ ); +};