fix: gate creation until workspace summaries load
This commit is contained in:
@@ -12,7 +12,7 @@ export interface WorkspaceDraft {
|
||||
type PolicySelection = {
|
||||
workspaceId: string;
|
||||
generation: number;
|
||||
state: "pending" | "ready" | "error";
|
||||
state: "summary" | "pending" | "ready" | "error";
|
||||
error?: Error;
|
||||
settled: Promise<void>;
|
||||
settle: () => void;
|
||||
@@ -23,13 +23,13 @@ type PolicySelection = {
|
||||
let selection: PolicySelection | undefined;
|
||||
let nextGeneration = 0;
|
||||
|
||||
function pendingSelection(workspaceId: string): PolicySelection {
|
||||
function pendingSelection(workspaceId: string, state: "summary" | "pending"): PolicySelection {
|
||||
let settle!: () => void;
|
||||
let supersede!: () => void;
|
||||
return {
|
||||
workspaceId,
|
||||
generation: ++nextGeneration,
|
||||
state: "pending",
|
||||
state,
|
||||
settled: new Promise<void>((resolve) => { settle = resolve; }),
|
||||
settle,
|
||||
superseded: new Promise<void>((resolve) => { supersede = resolve; }),
|
||||
@@ -39,10 +39,30 @@ function pendingSelection(workspaceId: string): PolicySelection {
|
||||
|
||||
/** In-memory coordination between the footer's selected policy and session creation. */
|
||||
export const workspacePolicyGate = {
|
||||
select(workspaceId: string): void {
|
||||
if (selection?.workspaceId === workspaceId) return;
|
||||
beginSummary(workspaceId: string): void {
|
||||
if (selection?.workspaceId === workspaceId && selection.state === "summary") return;
|
||||
selection?.supersede();
|
||||
selection = pendingSelection(workspaceId);
|
||||
selection = pendingSelection(workspaceId, "summary");
|
||||
},
|
||||
|
||||
select(workspaceId: string): void {
|
||||
if (selection?.workspaceId === workspaceId) {
|
||||
if (selection.state === "summary") selection.state = "pending";
|
||||
if (selection.state === "pending") return;
|
||||
}
|
||||
selection?.supersede();
|
||||
selection = pendingSelection(workspaceId, "pending");
|
||||
},
|
||||
|
||||
allowLegacy(workspaceId: string): void {
|
||||
if (selection?.workspaceId !== workspaceId) {
|
||||
this.clear();
|
||||
return;
|
||||
}
|
||||
if (selection.state === "summary") {
|
||||
selection.state = "ready";
|
||||
selection.settle();
|
||||
}
|
||||
},
|
||||
|
||||
clear(): void {
|
||||
|
||||
Reference in New Issue
Block a user