From d9d19f836898d80162cd3a9c13415efc68a70558 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Sun, 6 Oct 2024 22:08:26 -0700 Subject: [PATCH] allow metadata to override the frame title, icon, and text (#972) --- frontend/app/block/block.tsx | 4 ---- frontend/app/block/blockframe.tsx | 16 +++++++++++++--- frontend/app/view/term/term.tsx | 6 ------ frontend/types/gotypes.d.ts | 4 +++- pkg/waveobj/metaconsts.go | 5 +++-- pkg/waveobj/wtypemeta.go | 4 +++- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/frontend/app/block/block.tsx b/frontend/app/block/block.tsx index 857783375..314ca7606 100644 --- a/frontend/app/block/block.tsx +++ b/frontend/app/block/block.tsx @@ -113,10 +113,6 @@ function makeDefaultViewModel(blockId: string, viewType: string): ViewModel { const blockData = get(blockDataAtom); return blockViewToName(blockData?.meta?.view); }), - viewText: jotai.atom((get) => { - const blockData = get(blockDataAtom); - return blockData?.meta?.title; - }), preIconButton: jotai.atom(null), endIconButtons: jotai.atom(null), }; diff --git a/frontend/app/block/blockframe.tsx b/frontend/app/block/blockframe.tsx index 13dd61874..f94a90865 100644 --- a/frontend/app/block/blockframe.tsx +++ b/frontend/app/block/blockframe.tsx @@ -160,15 +160,25 @@ const BlockFrame_Header = ({ error, }: BlockFrameProps & { changeConnModalAtom: jotai.PrimitiveAtom; error?: Error }) => { const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", nodeModel.blockId)); - const viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(blockData?.meta?.view); + let viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(blockData?.meta?.view); const showBlockIds = jotai.useAtomValue(useSettingsKeyAtom("blockheader:showblockids")); - const viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view); + let viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view); const preIconButton = util.useAtomValueSafe(viewModel?.preIconButton); - const headerTextUnion = util.useAtomValueSafe(viewModel?.viewText); + let headerTextUnion = util.useAtomValueSafe(viewModel?.viewText); const magnified = jotai.useAtomValue(nodeModel.isMagnified); const manageConnection = util.useAtomValueSafe(viewModel?.manageConnection); const dragHandleRef = preview ? null : nodeModel.dragHandleRef; + if (blockData?.meta?.["frame:title"]) { + viewName = blockData.meta["frame:title"]; + } + if (blockData?.meta?.["frame:icon"]) { + viewIconUnion = blockData.meta["frame:icon"]; + } + if (blockData?.meta?.["frame:text"]) { + headerTextUnion = blockData.meta["frame:text"]; + } + const onContextMenu = React.useCallback( (e: React.MouseEvent) => { handleHeaderContextMenu(e, blockData, viewModel, magnified, nodeModel.toggleMagnify, nodeModel.onClose); diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 5a4ff85b6..92e385a39 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -107,7 +107,6 @@ class TermViewModel { htmlElemFocusRef: React.RefObject; blockId: string; viewIcon: jotai.Atom; - viewText: jotai.Atom; viewName: jotai.Atom; blockBg: jotai.Atom; manageConnection: jotai.Atom; @@ -132,11 +131,6 @@ class TermViewModel { return "Terminal"; }); this.manageConnection = jotai.atom(true); - this.viewText = jotai.atom((get) => { - const blockData = get(this.blockAtom); - const titleText: HeaderText = { elemtype: "text", text: blockData?.meta?.title ?? "" }; - return [titleText] as HeaderElem[]; - }); this.blockBg = jotai.atom((get) => { const blockData = get(this.blockAtom); const fullConfig = get(atoms.fullConfigAtom); diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 30fbbaf1f..026862856 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -264,7 +264,6 @@ declare global { type MetaType = { view?: string; controller?: string; - title?: string; file?: string; url?: string; connection?: string; @@ -279,6 +278,9 @@ declare global { "frame:*"?: boolean; "frame:bordercolor"?: string; "frame:bordercolor:focused"?: string; + "frame:title"?: string; + "frame:icon"?: string; + "frame:text"?: string; cmd?: string; "cmd:*"?: boolean; "cmd:interactive"?: boolean; diff --git a/pkg/waveobj/metaconsts.go b/pkg/waveobj/metaconsts.go index 5de9fc3b4..4f719368e 100644 --- a/pkg/waveobj/metaconsts.go +++ b/pkg/waveobj/metaconsts.go @@ -10,8 +10,6 @@ const ( MetaKey_Controller = "controller" - MetaKey_Title = "title" - MetaKey_File = "file" MetaKey_Url = "url" @@ -33,6 +31,9 @@ const ( MetaKey_FrameClear = "frame:*" MetaKey_FrameBorderColor = "frame:bordercolor" MetaKey_FrameBorderColor_Focused = "frame:bordercolor:focused" + MetaKey_FrameTitle = "frame:title" + MetaKey_FrameIcon = "frame:icon" + MetaKey_FrameText = "frame:text" MetaKey_Cmd = "cmd" MetaKey_CmdClear = "cmd:*" diff --git a/pkg/waveobj/wtypemeta.go b/pkg/waveobj/wtypemeta.go index 6bedb5004..e1431b560 100644 --- a/pkg/waveobj/wtypemeta.go +++ b/pkg/waveobj/wtypemeta.go @@ -14,7 +14,6 @@ type MetaTSType struct { // shared View string `json:"view,omitempty"` Controller string `json:"controller,omitempty"` - Title string `json:"title,omitempty"` File string `json:"file,omitempty"` Url string `json:"url,omitempty"` Connection string `json:"connection,omitempty"` @@ -32,6 +31,9 @@ type MetaTSType struct { FrameClear bool `json:"frame:*,omitempty"` FrameBorderColor string `json:"frame:bordercolor,omitempty"` FrameBorderColor_Focused string `json:"frame:bordercolor:focused,omitempty"` + FrameTitle string `json:"frame:title,omitempty"` + FrameIcon string `json:"frame:icon,omitempty"` + FrameText string `json:"frame:text,omitempty"` Cmd string `json:"cmd,omitempty"` CmdClear bool `json:"cmd:*,omitempty"`