refactor: rename services to scripts and extract reusable components
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { ScriptStatusUpdateMessage } from "@server/shared/messages";
|
||||
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import { resolveWorkspaceMapKeyByIdentity } from "@/utils/workspace-execution";
|
||||
|
||||
export function patchWorkspaceScripts(
|
||||
workspaces: Map<string, WorkspaceDescriptor>,
|
||||
update: ScriptStatusUpdateMessage["payload"],
|
||||
): Map<string, WorkspaceDescriptor> {
|
||||
const workspaceKey = resolveWorkspaceMapKeyByIdentity({
|
||||
workspaces,
|
||||
workspaceIdentity: update.workspaceId,
|
||||
});
|
||||
if (!workspaceKey) {
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
const existing = workspaces.get(workspaceKey);
|
||||
if (!existing) {
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
const next = new Map(workspaces);
|
||||
next.set(workspaceKey, {
|
||||
...existing,
|
||||
scripts: update.scripts.map((s) => ({ ...s })),
|
||||
});
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user