推进 INI 面板 readonly status API
This commit is contained in:
41
wasm-port/runtime/ui/ini-panel/readonly-status-api.js
Normal file
41
wasm-port/runtime/ui/ini-panel/readonly-status-api.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export function createMachineSessionReadonlyStatus({
|
||||
stateBundle = null,
|
||||
workflowStatus = null,
|
||||
controlView = null,
|
||||
} = {}) {
|
||||
const overview = stateBundle?.overview ?? workflowStatus?.overview ?? null;
|
||||
return {
|
||||
stateBundle,
|
||||
workflowStatus,
|
||||
overview,
|
||||
controlView,
|
||||
report: stateBundle?.report ?? null,
|
||||
runReadiness: workflowStatus?.runReadiness ?? stateBundle?.report?.runReadiness ?? null,
|
||||
run: workflowStatus?.run ?? stateBundle?.report?.run ?? null,
|
||||
session: workflowStatus?.session ?? stateBundle?.report?.session ?? null,
|
||||
status: {
|
||||
lastAction: workflowStatus?.lastAction ?? overview?.status?.lastAction ?? null,
|
||||
error: workflowStatus?.error ?? overview?.status?.error ?? null,
|
||||
runStatus: workflowStatus?.run?.status ?? stateBundle?.report?.run?.status ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function readMachineSessionReadonlyStatus({ getPanelApi, getControlView } = {}) {
|
||||
if (typeof getPanelApi !== "function") {
|
||||
throw new Error("A panel API getter is required.");
|
||||
}
|
||||
if (typeof getControlView !== "function") {
|
||||
throw new Error("A control view getter is required.");
|
||||
}
|
||||
|
||||
const panelApi = getPanelApi();
|
||||
if (!panelApi) {
|
||||
return createMachineSessionReadonlyStatus();
|
||||
}
|
||||
return createMachineSessionReadonlyStatus({
|
||||
stateBundle: panelApi.getMachineSessionStateBundle?.() ?? null,
|
||||
workflowStatus: panelApi.getMachineSessionWorkflowStatus?.() ?? null,
|
||||
controlView: getControlView(),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user