Skip to content

Commit 1949aab

Browse files
authored
new rpc call to get focused block data from a tab (#2833)
1 parent 16877fe commit 1949aab

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

frontend/app/store/tabrpcclient.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { WaveAIModel } from "@/app/aipanel/waveai-model";
5-
import { getApi } from "@/app/store/global";
5+
import { getApi, getBlockComponentModel, getConnStatusAtom, globalStore, WOS } from "@/app/store/global";
6+
import type { TermViewModel } from "@/app/view/term/term-model";
67
import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model";
78
import { getLayoutModelForStaticTab } from "@/layout/index";
89
import { base64ToArrayBuffer } from "@/util/util";
910
import { RpcResponseHelper, WshClient } from "./wshclient";
11+
import { RpcApi } from "./wshclientapi";
1012

1113
export class TabClient extends WshClient {
1214
constructor(routeId: string) {
@@ -103,4 +105,73 @@ export class TabClient extends WshClient {
103105

104106
layoutModel.focusNode(node.id);
105107
}
108+
109+
async handle_getfocusedblockdata(rh: RpcResponseHelper): Promise<FocusedBlockData> {
110+
const layoutModel = getLayoutModelForStaticTab();
111+
if (!layoutModel) {
112+
throw new Error("Layout model not found");
113+
}
114+
115+
const focusedNode = globalStore.get(layoutModel.focusedNode);
116+
const blockId = focusedNode?.data?.blockId;
117+
118+
if (!blockId) {
119+
return null;
120+
}
121+
122+
const blockAtom = WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", blockId));
123+
const blockData = globalStore.get(blockAtom);
124+
125+
if (!blockData) {
126+
return null;
127+
}
128+
129+
const viewType = blockData.meta?.view ?? "";
130+
const controller = blockData.meta?.controller ?? "";
131+
const connName = blockData.meta?.connection ?? "";
132+
133+
const result: FocusedBlockData = {
134+
blockid: blockId,
135+
viewtype: viewType,
136+
controller: controller,
137+
connname: connName,
138+
blockmeta: blockData.meta ?? {},
139+
};
140+
141+
if (viewType === "term" && controller === "shell") {
142+
const jobStatus = await RpcApi.BlockJobStatusCommand(this, blockId);
143+
if (jobStatus) {
144+
result.termjobstatus = jobStatus;
145+
}
146+
}
147+
148+
if (connName) {
149+
const connStatusAtom = getConnStatusAtom(connName);
150+
const connStatus = globalStore.get(connStatusAtom);
151+
if (connStatus) {
152+
result.connstatus = connStatus;
153+
}
154+
}
155+
156+
if (viewType === "term") {
157+
try {
158+
const bcm = getBlockComponentModel(blockId);
159+
if (bcm?.viewModel) {
160+
const termViewModel = bcm.viewModel as TermViewModel;
161+
if (termViewModel.termRef?.current?.shellIntegrationStatusAtom) {
162+
const shellIntegrationStatus = globalStore.get(termViewModel.termRef.current.shellIntegrationStatusAtom);
163+
result.termshellintegrationstatus = shellIntegrationStatus || "";
164+
}
165+
if (termViewModel.termRef?.current?.lastCommandAtom) {
166+
const lastCommand = globalStore.get(termViewModel.termRef.current.lastCommandAtom);
167+
result.termlastcommand = lastCommand || "";
168+
}
169+
}
170+
} catch (e) {
171+
console.log("error getting term-specific data", e);
172+
}
173+
}
174+
175+
return result;
176+
}
106177
}

frontend/app/store/wshclientapi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ class RpcApiType {
332332
return client.wshRpcCall("getbuilderstatus", data, opts);
333333
}
334334

335+
// command "getfocusedblockdata" [call]
336+
GetFocusedBlockDataCommand(client: WshClient, opts?: RpcOpts): Promise<FocusedBlockData> {
337+
return client.wshRpcCall("getfocusedblockdata", null, opts);
338+
}
339+
335340
// command "getfullconfig" [call]
336341
GetFullConfigCommand(client: WshClient, opts?: RpcOpts): Promise<FullConfigType> {
337342
return client.wshRpcCall("getfullconfig", null, opts);

frontend/types/gotypes.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,19 @@ declare global {
912912
append?: boolean;
913913
};
914914

915+
// wshrpc.FocusedBlockData
916+
type FocusedBlockData = {
917+
blockid: string;
918+
viewtype: string;
919+
controller: string;
920+
connname: string;
921+
blockmeta: MetaType;
922+
termjobstatus?: BlockJobStatusData;
923+
connstatus?: ConnStatus;
924+
termshellintegrationstatus?: string;
925+
termlastcommand?: string;
926+
};
927+
915928
// wconfig.FullConfigType
916929
type FullConfigType = {
917930
settings: SettingsType;

pkg/wshrpc/wshclient/wshclient.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ func GetBuilderStatusCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpt
404404
return resp, err
405405
}
406406

407+
// command "getfocusedblockdata", wshserver.GetFocusedBlockDataCommand
408+
func GetFocusedBlockDataCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (*wshrpc.FocusedBlockData, error) {
409+
resp, err := sendRpcRequestCallHelper[*wshrpc.FocusedBlockData](w, "getfocusedblockdata", nil, opts)
410+
return resp, err
411+
}
412+
407413
// command "getfullconfig", wshserver.GetFullConfigCommand
408414
func GetFullConfigCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (wconfig.FullConfigType, error) {
409415
resp, err := sendRpcRequestCallHelper[wconfig.FullConfigType](w, "getfullconfig", nil, opts)

pkg/wshrpc/wshrpctypes.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type WshRpcInterface interface {
154154

155155
// block focus
156156
SetBlockFocusCommand(ctx context.Context, blockId string) error
157+
GetFocusedBlockDataCommand(ctx context.Context) (*FocusedBlockData, error)
157158

158159
// rtinfo
159160
GetRTInfoCommand(ctx context.Context, data CommandGetRTInfoData) (*waveobj.ObjRTInfo, error)
@@ -880,3 +881,15 @@ type BlockJobStatusData struct {
880881
CmdExitCode *int `json:"cmdexitcode,omitempty"`
881882
CmdExitSignal string `json:"cmdexitsignal,omitempty"`
882883
}
884+
885+
type FocusedBlockData struct {
886+
BlockId string `json:"blockid"`
887+
ViewType string `json:"viewtype"`
888+
Controller string `json:"controller"`
889+
ConnName string `json:"connname"`
890+
BlockMeta waveobj.MetaMapType `json:"blockmeta"`
891+
TermJobStatus *BlockJobStatusData `json:"termjobstatus,omitempty"`
892+
ConnStatus *ConnStatus `json:"connstatus,omitempty"`
893+
TermShellIntegrationStatus string `json:"termshellintegrationstatus,omitempty"`
894+
TermLastCommand string `json:"termlastcommand,omitempty"`
895+
}

0 commit comments

Comments
 (0)