Add hidden agent tab intent for workspace reconcile
This commit is contained in:
@@ -65,6 +65,7 @@ interface WorkspaceLayoutStore {
|
||||
layoutByWorkspace: Record<string, WorkspaceLayout>;
|
||||
splitSizesByWorkspace: Record<string, Record<string, number[]>>;
|
||||
pinnedAgentIdsByWorkspace: Record<string, Set<string>>;
|
||||
hiddenAgentIdsByWorkspace: Record<string, Set<string>>;
|
||||
openTab: (workspaceKey: string, target: WorkspaceTabTarget) => string | null;
|
||||
closeTab: (workspaceKey: string, tabId: string) => void;
|
||||
focusTab: (workspaceKey: string, tabId: string) => void;
|
||||
@@ -94,6 +95,8 @@ interface WorkspaceLayoutStore {
|
||||
reorderTabsInPane: (workspaceKey: string, paneId: string, tabIds: string[]) => void;
|
||||
pinAgent: (workspaceKey: string, agentId: string) => void;
|
||||
unpinAgent: (workspaceKey: string, agentId: string) => void;
|
||||
hideAgent: (workspaceKey: string, agentId: string) => void;
|
||||
unhideAgent: (workspaceKey: string, agentId: string) => void;
|
||||
}
|
||||
|
||||
const MAX_TREE_DEPTH = 4;
|
||||
@@ -106,6 +109,48 @@ function trimNonEmpty(value: string | null | undefined): string | null {
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function addAgentIdToWorkspaceSet(
|
||||
state: Record<string, Set<string>>,
|
||||
workspaceKey: string,
|
||||
agentId: string,
|
||||
): Record<string, Set<string>> {
|
||||
const currentAgentIds = state[workspaceKey] ?? null;
|
||||
if (currentAgentIds?.has(agentId)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const nextAgentIds = new Set(currentAgentIds ?? []);
|
||||
nextAgentIds.add(agentId);
|
||||
return {
|
||||
...state,
|
||||
[workspaceKey]: nextAgentIds,
|
||||
};
|
||||
}
|
||||
|
||||
function removeAgentIdFromWorkspaceSet(
|
||||
state: Record<string, Set<string>>,
|
||||
workspaceKey: string,
|
||||
agentId: string,
|
||||
): Record<string, Set<string>> {
|
||||
const currentAgentIds = state[workspaceKey] ?? null;
|
||||
if (!currentAgentIds?.has(agentId)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (currentAgentIds.size === 1) {
|
||||
const nextState = { ...state };
|
||||
delete nextState[workspaceKey];
|
||||
return nextState;
|
||||
}
|
||||
|
||||
const nextAgentIds = new Set(currentAgentIds);
|
||||
nextAgentIds.delete(agentId);
|
||||
return {
|
||||
...state,
|
||||
[workspaceKey]: nextAgentIds,
|
||||
};
|
||||
}
|
||||
|
||||
function getWorkspaceLayout(
|
||||
state: Record<string, WorkspaceLayout>,
|
||||
workspaceKey: string,
|
||||
@@ -119,6 +164,7 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
layoutByWorkspace: {},
|
||||
splitSizesByWorkspace: {},
|
||||
pinnedAgentIdsByWorkspace: {},
|
||||
hiddenAgentIdsByWorkspace: {},
|
||||
openTab: (workspaceKey, target) => {
|
||||
const normalizedWorkspaceKey = trimNonEmpty(workspaceKey);
|
||||
const normalizedTarget = normalizeWorkspaceTabTarget(target);
|
||||
@@ -133,6 +179,14 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
});
|
||||
|
||||
set((state) => ({
|
||||
hiddenAgentIdsByWorkspace:
|
||||
normalizedTarget.kind !== "agent"
|
||||
? state.hiddenAgentIdsByWorkspace
|
||||
: removeAgentIdFromWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedTarget.agentId,
|
||||
),
|
||||
layoutByWorkspace: {
|
||||
...state.layoutByWorkspace,
|
||||
[normalizedWorkspaceKey]: result.layout,
|
||||
@@ -207,6 +261,14 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
hiddenAgentIdsByWorkspace:
|
||||
normalizedTarget.kind !== "agent"
|
||||
? state.hiddenAgentIdsByWorkspace
|
||||
: removeAgentIdFromWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedTarget.agentId,
|
||||
),
|
||||
layoutByWorkspace: {
|
||||
...state.layoutByWorkspace,
|
||||
[normalizedWorkspaceKey]: result.layout,
|
||||
@@ -233,6 +295,11 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
hiddenAgentIdsByWorkspace: removeAgentIdFromWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedAgentId,
|
||||
),
|
||||
layoutByWorkspace: {
|
||||
...state.layoutByWorkspace,
|
||||
[normalizedWorkspaceKey]: result.layout,
|
||||
@@ -253,6 +320,7 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
{
|
||||
layout: currentLayout,
|
||||
pinnedAgentIds: state.pinnedAgentIdsByWorkspace[normalizedWorkspaceKey] ?? null,
|
||||
hiddenAgentIds: state.hiddenAgentIdsByWorkspace[normalizedWorkspaceKey] ?? null,
|
||||
},
|
||||
snapshot,
|
||||
);
|
||||
@@ -478,6 +546,11 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
nextPinnedAgentIds.add(normalizedAgentId);
|
||||
|
||||
return {
|
||||
hiddenAgentIdsByWorkspace: removeAgentIdFromWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedAgentId,
|
||||
),
|
||||
pinnedAgentIdsByWorkspace: {
|
||||
...state.pinnedAgentIdsByWorkspace,
|
||||
[normalizedWorkspaceKey]: nextPinnedAgentIds,
|
||||
@@ -520,6 +593,50 @@ export const useWorkspaceLayoutStore = create<WorkspaceLayoutStore>()(
|
||||
};
|
||||
});
|
||||
},
|
||||
hideAgent: (workspaceKey, agentId) => {
|
||||
const normalizedWorkspaceKey = trimNonEmpty(workspaceKey);
|
||||
const normalizedAgentId = trimNonEmpty(agentId);
|
||||
if (!normalizedWorkspaceKey || !normalizedAgentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
set((state) => {
|
||||
const nextHiddenAgentIdsByWorkspace = addAgentIdToWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedAgentId,
|
||||
);
|
||||
if (nextHiddenAgentIdsByWorkspace === state.hiddenAgentIdsByWorkspace) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
hiddenAgentIdsByWorkspace: nextHiddenAgentIdsByWorkspace,
|
||||
};
|
||||
});
|
||||
},
|
||||
unhideAgent: (workspaceKey, agentId) => {
|
||||
const normalizedWorkspaceKey = trimNonEmpty(workspaceKey);
|
||||
const normalizedAgentId = trimNonEmpty(agentId);
|
||||
if (!normalizedWorkspaceKey || !normalizedAgentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
set((state) => {
|
||||
const nextHiddenAgentIdsByWorkspace = removeAgentIdFromWorkspaceSet(
|
||||
state.hiddenAgentIdsByWorkspace,
|
||||
normalizedWorkspaceKey,
|
||||
normalizedAgentId,
|
||||
);
|
||||
if (nextHiddenAgentIdsByWorkspace === state.hiddenAgentIdsByWorkspace) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
hiddenAgentIdsByWorkspace: nextHiddenAgentIdsByWorkspace,
|
||||
};
|
||||
});
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "workspace-layout-state",
|
||||
|
||||
Reference in New Issue
Block a user