From 57ae34e0fffc4c2c42c8b29e29ff84243a122611 Mon Sep 17 00:00:00 2001 From: Alexander Vinokurov Date: Wed, 31 Jan 2024 15:44:13 +0300 Subject: [PATCH 1/4] moved canEdit and canRun permissions to props --- ui/packages/portal/src/controls/NotebookEditorControl.tsx | 2 ++ ui/packages/portal/src/features/notebook/NotebookEditor.tsx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/packages/portal/src/controls/NotebookEditorControl.tsx b/ui/packages/portal/src/controls/NotebookEditorControl.tsx index 6de1ac1d3..6a274f957 100644 --- a/ui/packages/portal/src/controls/NotebookEditorControl.tsx +++ b/ui/packages/portal/src/controls/NotebookEditorControl.tsx @@ -24,6 +24,8 @@ export default function NotebookEditorControl({notebook}: NotebookEditorView) { return ( ); } diff --git a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx index 0f71cd157..7456ce088 100644 --- a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx +++ b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx @@ -59,6 +59,8 @@ export function useElementsStore() { interface NotebookEditorProps { notebook: NotebookDto; + canEdit: boolean; + canRun: boolean; } export function NotebookEditor({notebook}: NotebookEditorProps) { @@ -71,8 +73,6 @@ export function NotebookEditor({notebook}: NotebookEditorProps) { useEffect(() => { (async function () { const {elementIds} = notebook; - const canEdit = await EnvAccessControlApi.getPermission(projectId, 'Edit', envId, notebook.id); - const canRun = await EnvAccessControlApi.getPermission(projectId, 'Session', envId, notebook.id); const elementModels = elementIds.map(elementId => getElementModel(elementId)); const elementsById = keyBy(elementModels, c => c.elementId); // const markdown = getDocumentMarkdown(elementIds, elementsById, projectId, envId, notebookPath); From 74143bbf9253520f25cacd8cd5244caa3c9ee57a Mon Sep 17 00:00:00 2001 From: Alexander Vinokurov Date: Fri, 2 Feb 2024 12:28:53 +0300 Subject: [PATCH 2/4] projectId added to NotebookEditorState --- ui/packages/portal/src/controls/NotebookEditorControl.tsx | 2 ++ ui/packages/portal/src/features/notebook/NotebookEditor.tsx | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/packages/portal/src/controls/NotebookEditorControl.tsx b/ui/packages/portal/src/controls/NotebookEditorControl.tsx index 6a274f957..78793db85 100644 --- a/ui/packages/portal/src/controls/NotebookEditorControl.tsx +++ b/ui/packages/portal/src/controls/NotebookEditorControl.tsx @@ -18,12 +18,14 @@ export interface NotebookDto { readonly evaluationStatus?: EvaluationStatus; readonly sessionDialog?: ControlDef; readonly elementIds: string[]; + readonly projectId: string; } export default function NotebookEditorControl({notebook}: NotebookEditorView) { return ( diff --git a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx index 7456ce088..f9a73f0e1 100644 --- a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx +++ b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx @@ -59,12 +59,12 @@ export function useElementsStore() { interface NotebookEditorProps { notebook: NotebookDto; + projectId: string; canEdit: boolean; canRun: boolean; } -export function NotebookEditor({notebook}: NotebookEditorProps) { - const {project: {id: projectId}} = useProject(); +export function NotebookEditor({notebook, projectId, canEdit, canRun}: NotebookEditorProps) { const {envId} = useEnv(); const {path: notebookPath} = useProjectSelector("activeFile"); const [contextValue, setContextValue] = useState(); @@ -84,6 +84,7 @@ export function NotebookEditor({notebook}: NotebookEditorProps) { const initialState = { notebook, + projectId, elementIds, selectedElementIds, activeElementId, From 6da450944c1b7df5933a36d55def2351ae5c9978 Mon Sep 17 00:00:00 2001 From: Alexander Vinokurov Date: Mon, 5 Feb 2024 18:25:14 +0300 Subject: [PATCH 3/4] removed envId dependancy, removed useProject hook dependancy --- .../portal/src/controls/NotebookEditorControl.tsx | 1 + .../portal/src/features/notebook/Elements.tsx | 8 +++----- .../portal/src/features/notebook/NotebookEditor.tsx | 7 +++---- .../portal/src/features/notebook/SessionButton.tsx | 10 ++++------ .../features/notebook/documentStore/documentState.ts | 2 ++ .../documentStore/hooks/useUpdateMarkdown.ts | 12 +++++------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ui/packages/portal/src/controls/NotebookEditorControl.tsx b/ui/packages/portal/src/controls/NotebookEditorControl.tsx index 78793db85..db87e7223 100644 --- a/ui/packages/portal/src/controls/NotebookEditorControl.tsx +++ b/ui/packages/portal/src/controls/NotebookEditorControl.tsx @@ -26,6 +26,7 @@ export default function NotebookEditorControl({notebook}: NotebookEditorView) { diff --git a/ui/packages/portal/src/features/notebook/Elements.tsx b/ui/packages/portal/src/features/notebook/Elements.tsx index 4892d3ce5..b308c04dc 100644 --- a/ui/packages/portal/src/features/notebook/Elements.tsx +++ b/ui/packages/portal/src/features/notebook/Elements.tsx @@ -7,15 +7,13 @@ import { debounce } from "lodash"; import { usePrefixHashFragment } from "../../shared/hooks/usePrefixHashFragment"; import { useNotebookEditorSelector } from "./NotebookEditor"; import { ControlStarter } from "@open-smc/application/ControlStarter"; -import { useProject } from "../project/projectStore/hooks/useProject"; -import { useEnv } from "../project/projectStore/hooks/useEnv"; export function Elements() { const permissions = useNotebookEditorSelector("permissions"); const elementIds = useNotebookEditorSelector("elementIds"); const {canEdit} = permissions; - const {project} = useProject(); - const {envId} = useEnv(); + const projectId = useNotebookEditorSelector("projectId"); + const envId = useNotebookEditorSelector("envId"); const notebook = useNotebookEditorSelector("notebook"); usePrefixHashFragment(); @@ -23,7 +21,7 @@ export function Elements() { const renderedElements = elementIds.map(elementId => { return (
- + {canEdit && }
); diff --git a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx index f9a73f0e1..2a55ef8c6 100644 --- a/ui/packages/portal/src/features/notebook/NotebookEditor.tsx +++ b/ui/packages/portal/src/features/notebook/NotebookEditor.tsx @@ -27,8 +27,6 @@ import { Elements } from "./Elements"; import { NotebookSessionDialog } from "./NotebookSessionDialog"; import { useSubscribeToNewElements } from "./documentStore/hooks/useSubscribeToNewElements"; import { NotebookElementDto } from "../../controls/ElementEditorControl"; -import { useProject } from "../project/projectStore/hooks/useProject"; -import { useEnv } from "../project/projectStore/hooks/useEnv"; import { useProjectSelector } from "../project/projectStore/projectStore"; import { useApi } from "../../ApiProvider"; import { getUseSelector } from "@open-smc/store/useSelector"; @@ -60,12 +58,12 @@ export function useElementsStore() { interface NotebookEditorProps { notebook: NotebookDto; projectId: string; + envId: string; canEdit: boolean; canRun: boolean; } -export function NotebookEditor({notebook, projectId, canEdit, canRun}: NotebookEditorProps) { - const {envId} = useEnv(); +export function NotebookEditor({notebook, projectId, envId, canEdit, canRun}: NotebookEditorProps) { const {path: notebookPath} = useProjectSelector("activeFile"); const [contextValue, setContextValue] = useState(); const {EnvAccessControlApi} = useApi(); @@ -85,6 +83,7 @@ export function NotebookEditor({notebook, projectId, canEdit, canRun}: NotebookE const initialState = { notebook, projectId, + envId, elementIds, selectedElementIds, activeElementId, diff --git a/ui/packages/portal/src/features/notebook/SessionButton.tsx b/ui/packages/portal/src/features/notebook/SessionButton.tsx index f20bf06fa..ba145bbbe 100644 --- a/ui/packages/portal/src/features/notebook/SessionButton.tsx +++ b/ui/packages/portal/src/features/notebook/SessionButton.tsx @@ -10,9 +10,7 @@ import { useEffect, useState } from "react"; import { isEmpty, round } from "lodash"; import { SessionSpecification } from "../../app/notebookFormat"; import { SessionTierOverlay } from "./SessionTierOverlay"; -import { useProject } from "../project/projectStore/hooks/useProject"; import button from "@open-smc/ui-kit/components/buttons.module.scss" -import { useEnv } from "../project/projectStore/hooks/useEnv"; import { ImageSettingsDto, SessionTierSpecificationDto } from "../project/projectSessionApi"; import { rcTooltipOptions } from "../../shared/tooltipOptions"; import { useNotebookEditorSelector } from "./NotebookEditor"; @@ -27,8 +25,8 @@ export function SessionButton() { const [specification, setSpecification] = useState(); const [availableTiers, setAvailableTiers] = useState(); const [availableImages, setAvailableImages] = useState(); - const {project} = useProject(); - const {env} = useEnv(); + const projectId = useNotebookEditorSelector("projectId"); + const envId = useNotebookEditorSelector("envId"); const {canRun} = useNotebookEditorSelector("permissions"); const [overlayOpen, setOverlayOpen] = useState(false); const {ProjectSessionApi, EnvSessionApi} = useApi(); @@ -44,7 +42,7 @@ export function SessionButton() { if (sessionStatus === "Running") { setSpecification(notebook?.currentSession?.specification); } else if (!isEmpty(tiers)) { - const settings = await EnvSessionApi.getSessionSettings(project.id, env.id, notebook.id); + const settings = await EnvSessionApi.getSessionSettings(projectId, envId, notebook.id); const defaultTier = tiers[0]; const defaultImage = images[0]; const {cpu, memory, systemName: tier} = (settings.tier ?? defaultTier); @@ -53,7 +51,7 @@ export function SessionButton() { } } )() - }, [env.id, project.id, notebook.id]) + }, [envId, projectId, notebook.id]) const getText = () => { if (sessionStatus === 'Starting' || sessionStatus === 'Initializing') { diff --git a/ui/packages/portal/src/features/notebook/documentStore/documentState.ts b/ui/packages/portal/src/features/notebook/documentStore/documentState.ts index b5e4ebab1..702410b15 100644 --- a/ui/packages/portal/src/features/notebook/documentStore/documentState.ts +++ b/ui/packages/portal/src/features/notebook/documentStore/documentState.ts @@ -20,6 +20,8 @@ export interface NotebookEditorState { readonly permissions: NotebookPermissions, readonly notebook: NotebookDto; readonly elementIds: string[]; + readonly projectId: string; + readonly envId: string; readonly markdown?: Record; readonly updateMarkdownDebouncedFunc: DebouncedFunc<(func: () => void) => void>; readonly activeElementId?: string; diff --git a/ui/packages/portal/src/features/notebook/documentStore/hooks/useUpdateMarkdown.ts b/ui/packages/portal/src/features/notebook/documentStore/hooks/useUpdateMarkdown.ts index 36229aa1f..e6f891396 100644 --- a/ui/packages/portal/src/features/notebook/documentStore/hooks/useUpdateMarkdown.ts +++ b/ui/packages/portal/src/features/notebook/documentStore/hooks/useUpdateMarkdown.ts @@ -1,22 +1,20 @@ -import { useElementsStore, useNotebookEditorStore } from "../../NotebookEditor"; +import {useElementsStore, useNotebookEditorSelector, useNotebookEditorStore} from "../../NotebookEditor"; import { getCompiler, getParser } from "../../markdownParser"; import { ElementMarkdown } from "../documentState"; -import { useProject } from "../../../project/projectStore/hooks/useProject"; -import { useEnv } from "../../../project/projectStore/hooks/useEnv"; import { useProjectSelector } from "../../../project/projectStore/projectStore"; import { useCallback } from "react"; export function useUpdateMarkdown() { const notebookEditorStore = useNotebookEditorStore(); const elementsStore = useElementsStore(); - const {env} = useEnv(); - const {project: {id: projectId}} = useProject(); + const projectId = useNotebookEditorSelector("projectId"); + const envId = useNotebookEditorSelector("envId"); const activeFile = useProjectSelector("activeFile"); return useCallback((updatedElementIds?: string[]) => { const {elementIds, markdown} = notebookEditorStore.getState(); const models = elementsStore.getState(); - const parse = getParser(true, projectId, env.id, activeFile.path); + const parse = getParser(true, projectId, envId, activeFile.path); const compile = getCompiler(true); notebookEditorStore.setState(state => { @@ -42,5 +40,5 @@ export function useUpdateMarkdown() { state.markdown = newMarkdown; }); - }, [notebookEditorStore, elementsStore, env, projectId, activeFile]); + }, [notebookEditorStore, elementsStore, envId, projectId, activeFile]); } \ No newline at end of file From 58664cd4923047333333df09a3ac5ecd4e1f6836 Mon Sep 17 00:00:00 2001 From: Alexander Vinokurov Date: Tue, 6 Feb 2024 13:51:50 +0300 Subject: [PATCH 4/4] revert projectId prop in NotebookEditorControl --- ui/packages/portal/src/controls/NotebookEditorControl.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/packages/portal/src/controls/NotebookEditorControl.tsx b/ui/packages/portal/src/controls/NotebookEditorControl.tsx index db87e7223..05a49165f 100644 --- a/ui/packages/portal/src/controls/NotebookEditorControl.tsx +++ b/ui/packages/portal/src/controls/NotebookEditorControl.tsx @@ -18,7 +18,6 @@ export interface NotebookDto { readonly evaluationStatus?: EvaluationStatus; readonly sessionDialog?: ControlDef; readonly elementIds: string[]; - readonly projectId: string; } export default function NotebookEditorControl({notebook}: NotebookEditorView) {