You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by zh...@apache.org on 2026/09/01 15:07:31 UTC
(maka) 08/10: fix(desktop): observe onboarding save uncertainty
This is an automated email from the ASF dual-hosted git repository.
me2seeks pushed a commit to branch feat/desktop-api-key-host-onboarding
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 9ee1bd44e8e713cf77ab66fdad4aad1b7f363db8
Author: me2seeks <me...@gmail.com>
AuthorDate: Tue Sep 1 15:42:20 2026 +0800
fix(desktop): observe onboarding save uncertainty
---
.../main/__tests__/provider-add-submission.test.ts | 131 +++++++++++++++++----
.../renderer/features/connection-settings/index.ts | 1 +
.../renderer/features/connection-settings/ports.ts | 5 +-
.../connection-settings/services-context.tsx | 19 ++-
.../desktop/create-connection-settings-services.ts | 39 ++++--
.../src/renderer/settings/provider-add-form.tsx | 30 ++---
.../renderer/settings/provider-add-submission.ts | 9 +-
.../renderer/settings/provider-catalog-page.tsx | 8 +-
.../src/renderer/settings/providers-panel.tsx | 42 +++----
.../stories/settings/provider-settings.stories.tsx | 30 +++--
10 files changed, 221 insertions(+), 93 deletions(-)
diff --git a/apps/desktop/src/main/__tests__/provider-add-submission.test.ts b/apps/desktop/src/main/__tests__/provider-add-submission.test.ts
index 7abf64b8ae..6e5432cc48 100644
--- a/apps/desktop/src/main/__tests__/provider-add-submission.test.ts
+++ b/apps/desktop/src/main/__tests__/provider-add-submission.test.ts
@@ -18,18 +18,24 @@
*/
import assert from 'node:assert/strict';
-import { test } from 'node:test';
+import { afterEach, test } from 'node:test';
+import { act, createElement } from 'react';
import {
createProviderWithDiscovery,
apiKeyOnboardingRoute,
initialOnboardingModelIds,
- initialManagedOnboardingPhase,
+ shouldShowManagedOnboardingOutcomeUnknown,
stableOnboardingModels,
validateAddProviderDraft,
type AddProviderDraft,
type AddProviderField,
} from '../../renderer/settings/provider-add-submission.js';
import { createDesktopConnectionSettingsServices } from '../../renderer/platform/desktop/create-connection-settings-services.js';
+import { cleanupFakeDom, installReactRenderer } from './fake-dom.js';
+import {
+ ConnectionSaveUncertaintyObserver,
+ type ApiKeyOnboardingBridge,
+} from '../../renderer/features/connection-settings/index.js';
import {
PROVIDER_REGISTRY,
providerSupportsModelDiscovery,
@@ -44,6 +50,23 @@ type NoModelRule = 'defaultModel' extends AddProviderField ? never : true;
const _fieldGateHasNoModelRule: NoModelRule = true;
void _fieldGateHasNoModelRule;
+afterEach(cleanupFakeDom);
+
+function deferred<T>() {
+ let resolve!: (value: T) => void;
+ const promise = new Promise<T>((accept) => {
+ resolve = accept;
+ });
+ return { promise, resolve };
+}
+
+const onboardingSaveInput: Parameters<ApiKeyOnboardingBridge['save']>[0] = {
+ target: { kind: 'create', providerType: 'openai' },
+ apiKey: 'test-key',
+ baseUrl: null,
+ enabledModelIds: ['gpt-5'],
+};
+
const RELAY_TYPES: readonly ProviderType[] = ['openai-compatible', 'openai-responses-compatible'];
function draft(over: Partial<AddProviderDraft> = {}): AddProviderDraft {
@@ -271,47 +294,115 @@ test('uses a stable discovered-model order and prefers the registered recommenda
assert.deepEqual(initialOnboardingModelIds([], 'missing'), []);
});
-test('a remounted setup becomes uncertain only after save dispatch', () => {
- assert.equal(initialManagedOnboardingPhase(false), 'input');
- assert.equal(initialManagedOnboardingPhase(true), 'outcome_unknown');
+test('only an idle form projects a dispatched save as outcome unknown', () => {
+ assert.equal(shouldShowManagedOnboardingOutcomeUnknown(false, false), false);
+ assert.equal(shouldShowManagedOnboardingOutcomeUnknown(true, true), false);
+ assert.equal(shouldShowManagedOnboardingOutcomeUnknown(true, false), true);
});
-test('a late old save cannot clear the uncertainty lease for a newer attempt', () => {
+test('a late old save cannot clear the uncertainty lease for a newer attempt', async () => {
+ const saves = [
+ deferred<{ kind: 'not_saved' }>(),
+ deferred<{ kind: 'not_saved' }>(),
+ ];
+ let saveIndex = 0;
const services = createDesktopConnectionSettingsServices(() => ({
- // This test exercises only the in-process attempt lease. Transport calls
- // remain behind the adapter and are intentionally unavailable here.
- connections: {},
+ connections: {
+ saveOnboarding: () => saves[saveIndex++]!.promise,
+ },
} as unknown as ReturnType<NonNullable<Parameters<typeof createDesktopConnectionSettingsServices>[0]>>));
const firstView = services.forHost({
profileId: 'local',
hostId: 'same-host',
}).apiKeyOnboarding;
- const oldAttempt = firstView.saveUncertainty.markDispatched();
+ const oldSave = firstView.save(onboardingSaveInput);
firstView.saveUncertainty.restart();
const replacementView = services.forHost({
profileId: 'local',
hostId: 'same-host',
}).apiKeyOnboarding;
- const newAttempt = replacementView.saveUncertainty.markDispatched();
- firstView.saveUncertainty.settle(oldAttempt);
- assert.equal(replacementView.saveUncertainty.isUncertain(), true);
+ const newSave = replacementView.save(onboardingSaveInput);
+ saves[0]!.resolve({ kind: 'not_saved' });
+ await oldSave;
+ assert.equal(replacementView.saveUncertainty.getSnapshot(), true);
- replacementView.saveUncertainty.settle(newAttempt);
- assert.equal(firstView.saveUncertainty.isUncertain(), false);
+ saves[1]!.resolve({ kind: 'not_saved' });
+ await newSave;
+ assert.equal(firstView.saveUncertainty.getSnapshot(), false);
});
-test('save uncertainty is isolated between Runtime Host targets', () => {
+test('save uncertainty is isolated between Runtime Host targets', async () => {
+ const pending = deferred<{ kind: 'outcome_unknown' }>();
const services = createDesktopConnectionSettingsServices(() => ({
- connections: {},
+ connections: { saveOnboarding: () => pending.promise },
} as unknown as ReturnType<NonNullable<Parameters<typeof createDesktopConnectionSettingsServices>[0]>>));
const firstHost = services.forHost({ profileId: 'local', hostId: 'host-a' }).apiKeyOnboarding;
const secondHost = services.forHost({ profileId: 'local', hostId: 'host-b' }).apiKeyOnboarding;
- firstHost.saveUncertainty.markDispatched();
+ const save = firstHost.save(onboardingSaveInput);
+
+ assert.equal(firstHost.saveUncertainty.getSnapshot(), true);
+ assert.equal(secondHost.saveUncertainty.getSnapshot(), false);
+ pending.resolve({ kind: 'outcome_unknown' });
+ await save;
+});
- assert.equal(firstHost.saveUncertainty.isUncertain(), true);
- assert.equal(secondHost.saveUncertainty.isUncertain(), false);
+test('a definitive save settlement reaches a generation-remounted React consumer', async () => {
+ const pending = deferred<{ kind: 'not_saved' }>();
+ const services = createDesktopConnectionSettingsServices(() => ({
+ connections: { saveOnboarding: () => pending.promise },
+ } as unknown as ReturnType<NonNullable<Parameters<typeof createDesktopConnectionSettingsServices>[0]>>));
+ const onboarding = services.forHost({
+ profileId: 'local',
+ hostId: 'same-host',
+ }).apiKeyOnboarding;
+ const { root } = installReactRenderer();
+ let showsUnknown = false;
+
+ function Probe(props: {
+ uncertainty: ApiKeyOnboardingBridge['saveUncertainty'];
+ busy: boolean;
+ }) {
+ return createElement(
+ ConnectionSaveUncertaintyObserver,
+ {
+ store: props.uncertainty,
+ children: (uncertain: boolean) => {
+ showsUnknown = shouldShowManagedOnboardingOutcomeUnknown(uncertain, props.busy);
+ return null;
+ },
+ },
+ );
+ }
+
+ let save!: ReturnType<ApiKeyOnboardingBridge['save']>;
+ await act(async () => {
+ root.render(createElement(Probe, {
+ key: 'generation-a',
+ uncertainty: onboarding.saveUncertainty,
+ busy: true,
+ }));
+ save = onboarding.save(onboardingSaveInput);
+ });
+ assert.equal(onboarding.saveUncertainty.getSnapshot(), true);
+ assert.equal(showsUnknown, false, 'the form that owns the pending save keeps showing progress');
+
+ await act(async () => {
+ root.render(createElement(Probe, {
+ key: 'generation-b',
+ uncertainty: onboarding.saveUncertainty,
+ busy: false,
+ }));
+ });
+ assert.equal(showsUnknown, true, 'a generation-remounted form fails closed');
+
+ await act(async () => {
+ pending.resolve({ kind: 'not_saved' });
+ await save;
+ });
+ assert.equal(onboarding.saveUncertainty.getSnapshot(), false);
+ assert.equal(showsUnknown, false, 'definitive settlement actively restores the remounted form');
});
test('onboarding transport forwards the selected Runtime Host target', async () => {
diff --git a/apps/desktop/src/renderer/features/connection-settings/index.ts b/apps/desktop/src/renderer/features/connection-settings/index.ts
index b7a6c5048f..c323608c01 100644
--- a/apps/desktop/src/renderer/features/connection-settings/index.ts
+++ b/apps/desktop/src/renderer/features/connection-settings/index.ts
@@ -20,6 +20,7 @@
export {
ConnectionSettingsServicesProvider,
ConnectionSettingsServicesConsumer,
+ ConnectionSaveUncertaintyObserver,
} from './services-context.js';
export type {
ApiKeyOnboardingBridge,
diff --git a/apps/desktop/src/renderer/features/connection-settings/ports.ts b/apps/desktop/src/renderer/features/connection-settings/ports.ts
index bb107c4dc4..445d95eb7b 100644
--- a/apps/desktop/src/renderer/features/connection-settings/ports.ts
+++ b/apps/desktop/src/renderer/features/connection-settings/ports.ts
@@ -71,9 +71,8 @@ export interface RuntimeHostSettingsConnectionsBridge extends ConnectionsBridge
export interface ApiKeyOnboardingBridge {
readonly saveUncertainty: {
- isUncertain(): boolean;
- markDispatched(): number;
- settle(attemptId: number): void;
+ getSnapshot(): boolean;
+ subscribe(listener: () => void): () => void;
restart(): void;
};
verify(input: ConnectionOnboardingVerifyInput): Promise<ConnectionOnboardingVerifyResult>;
diff --git a/apps/desktop/src/renderer/features/connection-settings/services-context.tsx b/apps/desktop/src/renderer/features/connection-settings/services-context.tsx
index cfa3464f83..695fae2dbd 100644
--- a/apps/desktop/src/renderer/features/connection-settings/services-context.tsx
+++ b/apps/desktop/src/renderer/features/connection-settings/services-context.tsx
@@ -17,8 +17,8 @@
* under the License.
*/
-import { createContext, useContext, type ReactNode } from 'react';
-import type { ConnectionSettingsServices } from './ports.js';
+import { createContext, useContext, useSyncExternalStore, type ReactNode } from 'react';
+import type { ApiKeyOnboardingBridge, ConnectionSettingsServices } from './ports.js';
const ConnectionSettingsServicesContext = createContext<ConnectionSettingsServices | null>(null);
@@ -44,3 +44,18 @@ export function ConnectionSettingsServicesConsumer(props: {
}) {
return props.children(useConnectionSettingsServices());
}
+
+const noSaveUncertainty = () => false;
+const subscribeNoSaveUncertainty = () => () => {};
+
+export function ConnectionSaveUncertaintyObserver(props: {
+ readonly store?: ApiKeyOnboardingBridge['saveUncertainty'];
+ readonly children: (hasSaveUncertainty: boolean) => ReactNode;
+}) {
+ const hasSaveUncertainty = useSyncExternalStore(
+ props.store?.subscribe ?? subscribeNoSaveUncertainty,
+ props.store?.getSnapshot ?? noSaveUncertainty,
+ noSaveUncertainty,
+ );
+ return props.children(hasSaveUncertainty);
+}
diff --git a/apps/desktop/src/renderer/platform/desktop/create-connection-settings-services.ts b/apps/desktop/src/renderer/platform/desktop/create-connection-settings-services.ts
index f2353febc9..781261546b 100644
--- a/apps/desktop/src/renderer/platform/desktop/create-connection-settings-services.ts
+++ b/apps/desktop/src/renderer/platform/desktop/create-connection-settings-services.ts
@@ -24,8 +24,13 @@ export function createDesktopConnectionSettingsServices(
bridge: () => Pick<MakaBridge, 'connections'> = () => window.maka,
): ConnectionSettingsServices {
const uncertainTargets = new Map<string, number>();
+ const uncertaintyListeners = new Map<string, Set<() => void>>();
let nextAttemptId = 1;
+ const notifyUncertaintyChanged = (targetKey: string) => {
+ for (const listener of [...(uncertaintyListeners.get(targetKey) ?? [])]) listener();
+ };
+
return {
forHost: (host) => {
const targetKey = `${host.profileId}\u0000${host.hostId}`;
@@ -47,21 +52,35 @@ export function createDesktopConnectionSettingsServices(
},
apiKeyOnboarding: {
saveUncertainty: {
- isUncertain: () => uncertainTargets.has(targetKey),
- markDispatched: () => {
- const attemptId = nextAttemptId++;
- uncertainTargets.set(targetKey, attemptId);
- return attemptId;
+ getSnapshot: () => uncertainTargets.has(targetKey),
+ subscribe: (listener) => {
+ const listeners = uncertaintyListeners.get(targetKey) ?? new Set<() => void>();
+ listeners.add(listener);
+ uncertaintyListeners.set(targetKey, listeners);
+ return () => {
+ listeners.delete(listener);
+ if (listeners.size === 0) uncertaintyListeners.delete(targetKey);
+ };
},
- settle: (attemptId) => {
+ restart: () => {
+ if (uncertainTargets.delete(targetKey)) notifyUncertaintyChanged(targetKey);
+ },
+ },
+ verify: (input) => bridge().connections.verifyOnboarding(input, host),
+ save: async (input) => {
+ const attemptId = nextAttemptId++;
+ const wasUncertain = uncertainTargets.has(targetKey);
+ uncertainTargets.set(targetKey, attemptId);
+ if (!wasUncertain) notifyUncertaintyChanged(targetKey);
+ const outcome = await bridge().connections.saveOnboarding(input, host);
+ if (outcome.kind !== 'outcome_unknown') {
if (uncertainTargets.get(targetKey) === attemptId) {
uncertainTargets.delete(targetKey);
+ notifyUncertaintyChanged(targetKey);
}
- },
- restart: () => uncertainTargets.delete(targetKey),
+ }
+ return outcome;
},
- verify: (input) => bridge().connections.verifyOnboarding(input, host),
- save: (input) => bridge().connections.saveOnboarding(input, host),
},
};
},
diff --git a/apps/desktop/src/renderer/settings/provider-add-form.tsx b/apps/desktop/src/renderer/settings/provider-add-form.tsx
index f43feaec38..78b0ecc6de 100644
--- a/apps/desktop/src/renderer/settings/provider-add-form.tsx
+++ b/apps/desktop/src/renderer/settings/provider-add-form.tsx
@@ -56,7 +56,7 @@ import {
createProviderWithDiscovery,
apiKeyOnboardingRoute,
initialOnboardingModelIds,
- initialManagedOnboardingPhase,
+ shouldShowManagedOnboardingOutcomeUnknown,
stableOnboardingModels,
validateAddProviderDraft,
type AddProviderIssue,
@@ -79,8 +79,7 @@ type ManagedOnboardingPhase =
readonly kind: 'models';
readonly models: ReturnType<typeof stableOnboardingModels>;
readonly selectedIds: readonly string[];
- }
- | { readonly kind: 'outcome_unknown' };
+ };
export function AddProviderForm(props: {
bridge: ConnectionsBridge;
@@ -91,9 +90,7 @@ export function AddProviderForm(props: {
onCreated(slug: string, modelDiscoveryError?: unknown): Promise<void>;
onOnboarded?(identity: DesktopConnectionOnboardingIdentity): Promise<void>;
onOnboardingOutcomeUnknown?(): Promise<void>;
- managedSaveDispatched?: boolean;
- onManagedSaveDispatched?(): number | undefined;
- onManagedSaveSettled?(attemptId: number | undefined): void;
+ hasSaveUncertainty?: boolean;
}) {
const locale = useUiLocale();
const copy = getProviderSettingsCopy(locale).add;
@@ -115,7 +112,7 @@ export function AddProviderForm(props: {
readonly managedPhase: ManagedOnboardingPhase;
readonly error: ProviderFormError | null;
}>(() => ({
- managedPhase: { kind: initialManagedOnboardingPhase(props.managedSaveDispatched === true) },
+ managedPhase: { kind: 'input' },
error: null,
}));
const { managedPhase, error } = formState;
@@ -198,12 +195,6 @@ export function AddProviderForm(props: {
return copy.onboardingUnavailable;
}
- function enterOutcomeUnknown() {
- setApiKey('');
- setBusy(false);
- setManagedPhase({ kind: 'outcome_unknown' });
- }
-
async function verifyManagedApiKey(normalizedApiKey: string) {
const onboarding = props.apiKeyOnboardingBridge;
if (!onboarding) return;
@@ -261,7 +252,6 @@ export function AddProviderForm(props: {
stableIds.unshift(recommendedDefaultModel);
}
submitGuard.begin('submit');
- const attemptId = props.onManagedSaveDispatched?.();
setBusy(true);
try {
const outcome = await onboarding.save({
@@ -270,10 +260,9 @@ export function AddProviderForm(props: {
baseUrl: null,
enabledModelIds: stableIds,
});
- if (outcome.kind !== 'outcome_unknown') props.onManagedSaveSettled?.(attemptId);
if (!addProviderMountedRef.current) return;
if (outcome.kind === 'outcome_unknown') {
- enterOutcomeUnknown();
+ setApiKey('');
return;
}
if (outcome.kind === 'not_saved') {
@@ -300,10 +289,10 @@ export function AddProviderForm(props: {
message: onboardingFailureMessage(result),
});
} catch {
- if (addProviderMountedRef.current) enterOutcomeUnknown();
+ if (addProviderMountedRef.current) setApiKey('');
} finally {
submitGuard.finish();
- if (addProviderMountedRef.current && managedPhase.kind !== 'outcome_unknown') setBusy(false);
+ if (addProviderMountedRef.current) setBusy(false);
}
}
@@ -437,7 +426,10 @@ export function AddProviderForm(props: {
}).kind === 'host',
);
- if (usesApiKeyDialog && managedPhase.kind === 'outcome_unknown') {
+ if (
+ usesApiKeyDialog &&
+ shouldShowManagedOnboardingOutcomeUnknown(props.hasSaveUncertainty === true, busy)
+ ) {
return (
<VStack gap={3} data-maka-contract="api-key-onboarding-outcome-unknown">
<Banner
diff --git a/apps/desktop/src/renderer/settings/provider-add-submission.ts b/apps/desktop/src/renderer/settings/provider-add-submission.ts
index dfc0b7ba39..286370f6a1 100644
--- a/apps/desktop/src/renderer/settings/provider-add-submission.ts
+++ b/apps/desktop/src/renderer/settings/provider-add-submission.ts
@@ -39,10 +39,11 @@ export type ApiKeyOnboardingRoute =
| 'request_body';
};
-export function initialManagedOnboardingPhase(
- saveDispatched: boolean,
-): 'input' | 'outcome_unknown' {
- return saveDispatched ? 'outcome_unknown' : 'input';
+export function shouldShowManagedOnboardingOutcomeUnknown(
+ hasSaveUncertainty: boolean,
+ busy: boolean,
+): boolean {
+ return hasSaveUncertainty && !busy;
}
/** Decide the only writer before either writer performs a side effect. */
diff --git a/apps/desktop/src/renderer/settings/provider-catalog-page.tsx b/apps/desktop/src/renderer/settings/provider-catalog-page.tsx
index 36406c0fd9..10e7346cc0 100644
--- a/apps/desktop/src/renderer/settings/provider-catalog-page.tsx
+++ b/apps/desktop/src/renderer/settings/provider-catalog-page.tsx
@@ -236,9 +236,7 @@ export function ProviderSetupPage(props: {
onCreated(slug: string, modelDiscoveryError?: unknown): Promise<void>;
onOnboarded?(identity: DesktopConnectionOnboardingIdentity): Promise<void>;
onOnboardingOutcomeUnknown?(): Promise<void>;
- managedSaveDispatched?: boolean;
- onManagedSaveDispatched?(): number | undefined;
- onManagedSaveSettled?(attemptId: number | undefined): void;
+ hasSaveUncertainty?: boolean;
onAccountCreated(connection?: CreatedOAuthConnectionIdentity): Promise<void>;
labelledBy?: string;
}) {
@@ -261,9 +259,7 @@ export function ProviderSetupPage(props: {
onCreated={props.onCreated}
onOnboarded={props.onOnboarded}
onOnboardingOutcomeUnknown={props.onOnboardingOutcomeUnknown}
- managedSaveDispatched={props.managedSaveDispatched}
- onManagedSaveDispatched={props.onManagedSaveDispatched}
- onManagedSaveSettled={props.onManagedSaveSettled}
+ hasSaveUncertainty={props.hasSaveUncertainty}
/>
</div>
);
diff --git a/apps/desktop/src/renderer/settings/providers-panel.tsx b/apps/desktop/src/renderer/settings/providers-panel.tsx
index 99a23da49d..ffa68347b0 100644
--- a/apps/desktop/src/renderer/settings/providers-panel.tsx
+++ b/apps/desktop/src/renderer/settings/providers-panel.tsx
@@ -58,6 +58,7 @@ import { oauthPanelSubtitle } from './provider-oauth-section';
import {
getProviderSettingsCopy,
providerPanelActionErrorMessage,
+ ConnectionSaveUncertaintyObserver,
type ApiKeyOnboardingBridge,
type ConnectionsBridge,
type DesktopConnectionOnboardingIdentity,
@@ -93,7 +94,6 @@ type PanelRoute =
kind: 'setup';
target: SetupTarget;
origin: 'list' | 'catalog';
- managedSaveDispatched?: true;
}
| {
kind: 'adopting-connection';
@@ -106,7 +106,7 @@ function backTarget(route: PanelRoute): PanelRoute {
return { kind: 'list' };
}
-export function ProvidersPanel({ bridge, apiKeyOnboardingBridge, initialPage = 'connections', initialConnectionSlug, initialCreateProviderType, onInitialCatalogConsumed, onInitialCreateProviderConsumed }: {
+type ProvidersPanelProps = {
bridge: ConnectionsBridge;
apiKeyOnboardingBridge?: ApiKeyOnboardingBridge;
initialPage?: 'connections' | 'catalog';
@@ -124,6 +124,23 @@ export function ProvidersPanel({ bridge, apiKeyOnboardingBridge, initialPage = '
onInitialCatalogConsumed?: () => void;
/** Called once the setup level has been entered. */
onInitialCreateProviderConsumed?: () => void;
+};
+
+export function ProvidersPanel(props: ProvidersPanelProps) {
+ return (
+ <ConnectionSaveUncertaintyObserver store={props.apiKeyOnboardingBridge?.saveUncertainty}>
+ {(hasOnboardingUncertainty) => (
+ <ProvidersPanelContent
+ {...props}
+ hasOnboardingUncertainty={hasOnboardingUncertainty}
+ />
+ )}
+ </ConnectionSaveUncertaintyObserver>
+ );
+}
+
+function ProvidersPanelContent({ bridge, apiKeyOnboardingBridge, initialPage = 'connections', initialConnectionSlug, initialCreateProviderType, onInitialCatalogConsumed, onInitialCreateProviderConsumed, hasOnboardingUncertainty }: ProvidersPanelProps & {
+ hasOnboardingUncertainty: boolean;
}) {
const reportHostError = useRuntimeHostSettingsErrorReporter();
// Projected, not merely identified: the detail editor renders the Host's
@@ -132,8 +149,6 @@ export function ProvidersPanel({ bridge, apiKeyOnboardingBridge, initialPage = '
const [connections, setConnections] = useState<ProjectedLlmConnection[]>([]);
const [defaultSlug, setDefaultSlug] = useState<string | null>(null);
const [route, setRoute] = useState<PanelRoute>({ kind: 'list' });
- const hasOnboardingUncertainty =
- apiKeyOnboardingBridge?.saveUncertainty.isUncertain() === true;
// Browsing state, not navigation state: it outlives the catalog so that
// backing out of a provider returns the user to the search they typed.
const [catalogFilter, setCatalogFilter] = useState<CatalogFilter>(CATALOG_INITIAL_FILTER);
@@ -427,7 +442,7 @@ export function ProvidersPanel({ bridge, apiKeyOnboardingBridge, initialPage = '
<VStack gap={5}>
<SettingsRouteHeader
onBack={goBack}
- isBackDisabled={route.managedSaveDispatched === true}
+ isBackDisabled={hasOnboardingUncertainty}
backLabel={route.origin === 'catalog' ? copy.backToCatalog : copy.backToList}
logo={<ProviderLogo type={route.target.providerType} compact />}
titleId={setupTitleId}
@@ -445,22 +460,7 @@ export function ProvidersPanel({ bridge, apiKeyOnboardingBridge, initialPage = '
target={route.target}
existingSlugs={connections.map((connection) => connection.slug)}
labelledBy={setupTitleId}
- managedSaveDispatched={route.managedSaveDispatched}
- onManagedSaveDispatched={() => {
- const attemptId = apiKeyOnboardingBridge?.saveUncertainty.markDispatched();
- setRoute((current) => current.kind === 'setup'
- ? { ...current, managedSaveDispatched: true }
- : current);
- return attemptId;
- }}
- onManagedSaveSettled={(attemptId) => {
- if (attemptId !== undefined) {
- apiKeyOnboardingBridge?.saveUncertainty.settle(attemptId);
- }
- setRoute((current) => current.kind === 'setup'
- ? { kind: 'setup', target: current.target, origin: current.origin }
- : current);
- }}
+ hasSaveUncertainty={hasOnboardingUncertainty}
onCancel={goBack}
onAccountCreated={async (identity) => {
if (!identity) return;
diff --git a/apps/desktop/stories/settings/provider-settings.stories.tsx b/apps/desktop/stories/settings/provider-settings.stories.tsx
index 059a388cc7..8c2d5ec115 100644
--- a/apps/desktop/stories/settings/provider-settings.stories.tsx
+++ b/apps/desktop/stories/settings/provider-settings.stories.tsx
@@ -384,18 +384,24 @@ function createApiKeyOnboardingFixture(options: {
};
let uncertainAttemptId: number | undefined;
let nextAttemptId = 1;
+ const uncertaintyListeners = new Set<() => void>();
+ const settleUncertainty = (attemptId: number) => {
+ if (uncertainAttemptId !== attemptId) return;
+ uncertainAttemptId = undefined;
+ for (const listener of [...uncertaintyListeners]) listener();
+ };
const apiKeyOnboardingBridge: ApiKeyOnboardingBridge = {
saveUncertainty: {
- isUncertain: () => uncertainAttemptId !== undefined,
- markDispatched: () => {
- const attemptId = nextAttemptId++;
- uncertainAttemptId = attemptId;
- return attemptId;
+ getSnapshot: () => uncertainAttemptId !== undefined,
+ subscribe: (listener) => {
+ uncertaintyListeners.add(listener);
+ return () => uncertaintyListeners.delete(listener);
},
- settle: (attemptId) => {
- if (uncertainAttemptId === attemptId) uncertainAttemptId = undefined;
+ restart: () => {
+ if (uncertainAttemptId === undefined) return;
+ uncertainAttemptId = undefined;
+ for (const listener of [...uncertaintyListeners]) listener();
},
- restart: () => { uncertainAttemptId = undefined; },
},
async verify() {
return {
@@ -407,8 +413,15 @@ function createApiKeyOnboardingFixture(options: {
};
},
async save() {
+ const attemptId = nextAttemptId++;
+ const wasUncertain = uncertainAttemptId !== undefined;
+ uncertainAttemptId = attemptId;
+ if (!wasUncertain) {
+ for (const listener of [...uncertaintyListeners]) listener();
+ }
if (options.save === 'outcome_unknown') return { kind: 'outcome_unknown' };
if (options.save === 'auth_failed') {
+ settleUncertainty(attemptId);
return {
kind: 'result',
result: { kind: 'failed', errorClass: 'auth' },
@@ -427,6 +440,7 @@ function createApiKeyOnboardingFixture(options: {
});
bridge.addFixtureConnection(connection);
failNextSnapshot = options.failRefreshAfterSave === true;
+ settleUncertainty(attemptId);
return {
kind: 'result',
result: {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org