Skip to content

Commit 828cc40

Browse files
authored
Merge pull request #316 from pathsim/refactor/toolbox-commit-helper
Extract commitToolbox() shared commit step
2 parents 446407c + 47ea53a commit 828cc40

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/lib/components/dialogs/ToolboxManagerDialog.svelte

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
TOOLBOX_CATALOG,
99
performInstall,
1010
discoverToolbox,
11-
registerToolbox,
11+
commitToolbox,
1212
uninstallToolbox,
13-
upsertToolbox,
1413
removeToolbox,
1514
toolboxes,
1615
toolboxSourceKey,
@@ -318,13 +317,10 @@
318317
blocks: blockSelections,
319318
events: eventSelections
320319
};
321-
registerToolbox(config, {
322-
blocks: discoveredBlocks,
323-
events: discoveredEvents,
320+
commitToolbox(config, { blocks: discoveredBlocks, events: discoveredEvents }, {
324321
defaultCategory,
325322
categoryByClass
326323
});
327-
upsertToolbox(config);
328324
onSaved?.(config);
329325
onClose();
330326
}

src/lib/toolbox/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export {
2727
performInstall,
2828
discoverToolbox,
2929
registerToolbox,
30+
commitToolbox,
3031
uninstallToolbox
3132
} from './register';
3233

src/lib/toolbox/installFlow.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
*/
1212

1313
import { get } from 'svelte/store';
14-
import { toolboxes, upsertToolbox } from './store';
15-
import { performInstall, discoverToolbox, registerToolbox } from './register';
14+
import { toolboxes } from './store';
15+
import { performInstall, discoverToolbox, commitToolbox } from './register';
1616
import { getCatalogEntry } from './catalog';
1717
import type { ToolboxConfig, ToolboxSource } from './types';
1818

@@ -65,13 +65,10 @@ export async function installAndRegisterToolbox(spec: InstallSpec): Promise<Tool
6565
};
6666

6767
const catalog = getCatalogEntry(spec.id);
68-
registerToolbox(config, {
69-
blocks: discovered.blocks,
70-
events: discovered.events,
68+
commitToolbox(config, discovered, {
7169
defaultCategory: catalog?.defaultCategory,
7270
categoryByClass: catalog?.categoryByClass
7371
});
74-
upsertToolbox(config);
7572

7673
return config;
7774
})();

src/lib/toolbox/register.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
type IntrospectedBlock,
2626
type IntrospectedEvent
2727
} from './installer';
28+
import { upsertToolbox } from './store';
2829
import type { BlockSelection, EventSelection, ToolboxConfig } from './types';
2930

3031
/**
@@ -247,6 +248,26 @@ export function registerToolbox(
247248
}
248249
}
249250

251+
/**
252+
* Commit a discovered toolbox: register its selected blocks/events and persist
253+
* the config. The shared tail of both install paths — the startup/required
254+
* orchestrator (`installFlow`) and the manager dialog — which run their own
255+
* install + discover + selection beforehand and then call this to land it.
256+
*/
257+
export function commitToolbox(
258+
config: ToolboxConfig,
259+
discovered: { blocks: IntrospectedBlock[]; events: IntrospectedEvent[] },
260+
hints: { defaultCategory?: string; categoryByClass?: Record<string, string> } = {}
261+
): void {
262+
registerToolbox(config, {
263+
blocks: discovered.blocks,
264+
events: discovered.events,
265+
defaultCategory: hints.defaultCategory,
266+
categoryByClass: hints.categoryByClass
267+
});
268+
upsertToolbox(config);
269+
}
270+
250271
/** Clean up a toolbox: drop registry entries and the Python module. */
251272
export async function uninstallToolbox(config: ToolboxConfig): Promise<void> {
252273
nodeRegistry.unregisterSource(config.id);

0 commit comments

Comments
 (0)