update blockservice to use wstore types

This commit is contained in:
sawka 2024-05-22 09:23:16 -07:00
parent 2317ce87f3
commit 8173bc3c61
4 changed files with 9 additions and 18 deletions

View File

@ -9,13 +9,14 @@ import type { WailsEvent } from "@wailsio/runtime/types/events";
import { Events } from "@wailsio/runtime"; import { Events } from "@wailsio/runtime";
import { produce } from "immer"; import { produce } from "immer";
import { BlockService } from "@/bindings/blockservice"; import { BlockService } from "@/bindings/blockservice";
import * as wstore from "@/gopkg/wstore";
const globalStore = jotai.createStore(); const globalStore = jotai.createStore();
const tabId1 = uuidv4(); const tabId1 = uuidv4();
const tabArr: TabData[] = [{ name: "Tab 1", tabid: tabId1, blockIds: [] }]; const tabArr: TabData[] = [{ name: "Tab 1", tabid: tabId1, blockIds: [] }];
const blockDataMap = new Map<string, jotai.Atom<BlockData>>(); const blockDataMap = new Map<string, jotai.Atom<wstore.Block>>();
const blockAtomCache = new Map<string, Map<string, jotai.Atom<any>>>(); const blockAtomCache = new Map<string, Map<string, jotai.Atom<any>>>();
const atoms = { const atoms = {

View File

@ -8,6 +8,7 @@ import { clsx } from "clsx";
import { atoms, addBlockIdToTab, blockDataMap } from "@/store/global"; import { atoms, addBlockIdToTab, blockDataMap } from "@/store/global";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { BlockService } from "@/bindings/blockservice"; import { BlockService } from "@/bindings/blockservice";
import * as wstore from "@/gopkg/wstore";
import "./workspace.less"; import "./workspace.less";
@ -49,7 +50,7 @@ function Widgets() {
async function createBlock(blockDef: BlockDef) { async function createBlock(blockDef: BlockDef) {
const rtOpts = { termsize: { rows: 25, cols: 80 } }; 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); const newBlockAtom = jotai.atom(rtnBlock);
blockDataMap.set(rtnBlock.blockid, newBlockAtom); blockDataMap.set(rtnBlock.blockid, newBlockAtom);
addBlockIdToTab(activeTabId, rtnBlock.blockid); addBlockIdToTab(activeTabId, rtnBlock.blockid);

View File

@ -16,7 +16,7 @@ import (
type BlockService struct{} 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 var bdef wstore.BlockDef
err := utilfn.JsonMapToStruct(bdefMap, &bdef) err := utilfn.JsonMapToStruct(bdefMap, &bdef)
if err != nil { if err != nil {
@ -31,33 +31,21 @@ func (bs *BlockService) CreateBlock(bdefMap map[string]any, rtOptsMap map[string
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating block: %w", err) return nil, fmt.Errorf("error creating block: %w", err)
} }
rtnMap, err := utilfn.StructToJsonMap(blockData) return blockData, nil
if err != nil {
return nil, fmt.Errorf("error marshalling BlockData: %w", err)
}
return rtnMap, nil
} }
func (bs *BlockService) CloseBlock(blockId string) { func (bs *BlockService) CloseBlock(blockId string) {
blockcontroller.CloseBlock(blockId) 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) ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFn() defer cancelFn()
blockData, err := wstore.BlockGet(ctx, blockId) blockData, err := wstore.BlockGet(ctx, blockId)
if err != nil { if err != nil {
return nil, fmt.Errorf("error getting block data: %w", err) return nil, fmt.Errorf("error getting block data: %w", err)
} }
if blockData == nil { return 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
} }
func (bs *BlockService) SendCommand(blockId string, cmdMap map[string]any) error { func (bs *BlockService) SendCommand(blockId string, cmdMap map[string]any) error {

View File

@ -20,6 +20,7 @@
"@/store/*": ["frontend/app/store/*"], "@/store/*": ["frontend/app/store/*"],
"@/element/*": ["frontend/app/element/*"], "@/element/*": ["frontend/app/element/*"],
"@/bindings/*": ["frontend/bindings/github.com/wavetermdev/thenextwave/pkg/service/*"], "@/bindings/*": ["frontend/bindings/github.com/wavetermdev/thenextwave/pkg/service/*"],
"@/gopkg/*": ["frontend/bindings/github.com/wavetermdev/thenextwave/pkg/*"],
} }
} }
} }