mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
update blockservice to use wstore types
This commit is contained in:
parent
2317ce87f3
commit
8173bc3c61
@ -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<string, jotai.Atom<BlockData>>();
|
||||
const blockDataMap = new Map<string, jotai.Atom<wstore.Block>>();
|
||||
const blockAtomCache = new Map<string, Map<string, jotai.Atom<any>>>();
|
||||
|
||||
const atoms = {
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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/*"],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user