diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 3c10cfa7b..3217eedf7 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -9,13 +9,14 @@ import type { WailsEvent } from "@wailsio/runtime/types/events"; import { Events } from "@wailsio/runtime"; import { produce } from "immer"; import { BlockService } from "@/bindings/blockservice"; +import * as wstore from "@/gopkg/wstore"; const globalStore = jotai.createStore(); const tabId1 = uuidv4(); const tabArr: TabData[] = [{ name: "Tab 1", tabid: tabId1, blockIds: [] }]; -const blockDataMap = new Map>(); +const blockDataMap = new Map>(); const blockAtomCache = new Map>>(); const atoms = { diff --git a/frontend/app/workspace/workspace.tsx b/frontend/app/workspace/workspace.tsx index e61c67f52..afe029c6d 100644 --- a/frontend/app/workspace/workspace.tsx +++ b/frontend/app/workspace/workspace.tsx @@ -8,6 +8,7 @@ import { clsx } from "clsx"; import { atoms, addBlockIdToTab, blockDataMap } from "@/store/global"; import { v4 as uuidv4 } from "uuid"; import { BlockService } from "@/bindings/blockservice"; +import * as wstore from "@/gopkg/wstore"; import "./workspace.less"; @@ -49,7 +50,7 @@ function Widgets() { async function createBlock(blockDef: BlockDef) { const rtOpts = { termsize: { rows: 25, cols: 80 } }; - const rtnBlock: BlockData = (await BlockService.CreateBlock(blockDef, rtOpts)) as BlockData; + const rtnBlock: wstore.Block = await BlockService.CreateBlock(blockDef, rtOpts); const newBlockAtom = jotai.atom(rtnBlock); blockDataMap.set(rtnBlock.blockid, newBlockAtom); addBlockIdToTab(activeTabId, rtnBlock.blockid); diff --git a/pkg/service/blockservice/blockservice.go b/pkg/service/blockservice/blockservice.go index 0815d814f..dfd3ef2e0 100644 --- a/pkg/service/blockservice/blockservice.go +++ b/pkg/service/blockservice/blockservice.go @@ -16,7 +16,7 @@ import ( type BlockService struct{} -func (bs *BlockService) CreateBlock(bdefMap map[string]any, rtOptsMap map[string]any) (map[string]any, error) { +func (bs *BlockService) CreateBlock(bdefMap map[string]any, rtOptsMap map[string]any) (*wstore.Block, error) { var bdef wstore.BlockDef err := utilfn.JsonMapToStruct(bdefMap, &bdef) if err != nil { @@ -31,33 +31,21 @@ func (bs *BlockService) CreateBlock(bdefMap map[string]any, rtOptsMap map[string if err != nil { return nil, fmt.Errorf("error creating block: %w", err) } - rtnMap, err := utilfn.StructToJsonMap(blockData) - if err != nil { - return nil, fmt.Errorf("error marshalling BlockData: %w", err) - } - return rtnMap, nil + return blockData, nil } func (bs *BlockService) CloseBlock(blockId string) { blockcontroller.CloseBlock(blockId) } -func (bs *BlockService) GetBlockData(blockId string) (map[string]any, error) { +func (bs *BlockService) GetBlockData(blockId string) (*wstore.Block, error) { ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) defer cancelFn() blockData, err := wstore.BlockGet(ctx, blockId) if err != nil { return nil, fmt.Errorf("error getting block data: %w", err) } - if blockData == nil { - return nil, nil - } - rtnMap, err := utilfn.StructToJsonMap(blockData) - if err != nil { - return nil, fmt.Errorf("error marshalling BlockData: %w", err) - } - return rtnMap, nil - + return blockData, nil } func (bs *BlockService) SendCommand(blockId string, cmdMap map[string]any) error { diff --git a/tsconfig.json b/tsconfig.json index 5a3c5ec78..c58021d82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,7 @@ "@/store/*": ["frontend/app/store/*"], "@/element/*": ["frontend/app/element/*"], "@/bindings/*": ["frontend/bindings/github.com/wavetermdev/thenextwave/pkg/service/*"], + "@/gopkg/*": ["frontend/bindings/github.com/wavetermdev/thenextwave/pkg/*"], } } }