Skip to content

Commit b418ca5

Browse files
authored
CT-518 add charm on navigateTo in jumble (#1343)
* add the charm to charm manager list when viewed with navigateTo in jumble * fix issues where compiler.tsx was only working once: - we were creating the charm cells improperly (a second charm would share cells with the first due to cause naming) - additionally navigate shouldn't navigate if it returns undefined
1 parent aea68c8 commit b418ca5

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

packages/charm/src/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class CharmManager {
251251
return this.charms;
252252
}
253253

254-
private async add(newCharms: Cell<Charm>[]) {
254+
async add(newCharms: Cell<Charm>[]) {
255255
await this.syncCharms(this.charms);
256256
await this.runtime.idle();
257257

packages/jumble/src/components/CommandCenter.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,15 @@ export function CommandCenter() {
436436
};
437437

438438
const handleNavigateToCharm = (event: CustomEvent) => {
439-
const { charmId, replicaName } = event.detail || {};
439+
const { charmId, charm, replicaName } = event.detail || {};
440+
441+
// If we have a charm object, ensure it's added to the charm manager
442+
if (charm && charmManager) {
443+
charmManager.add([charm]).catch((err) => {
444+
console.error("Failed to add charm to manager:", err);
445+
});
446+
}
447+
440448
if (charmId && replicaName) {
441449
navigate(
442450
createPath("charmShow", {
@@ -478,7 +486,7 @@ export function CommandCenter() {
478486
handleNavigateToCharm as EventListener,
479487
);
480488
};
481-
}, [focusedCharmId, allCommands, navigate, focusedReplicaId]);
489+
}, [focusedCharmId, allCommands, navigate, focusedReplicaId, charmManager]);
482490

483491
const handleBack = () => {
484492
if (commandPathIds.length === 1) {

packages/jumble/src/utils/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function navigateToCharm(charm: Cell<any>, replicaName?: string): void {
1515

1616
globalThis.dispatchEvent(
1717
new CustomEvent("navigate-to-charm", {
18-
detail: { charmId: id, replicaName },
18+
detail: { charmId: id, charm, replicaName },
1919
}),
2020
);
2121
}

packages/runner/src/builtins/navigate-to.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export function navigateTo(
2020
throw new Error("navigateCallback is not set");
2121
}
2222

23-
runtime.navigateCallback(target);
23+
if (target && target.get()) {
24+
runtime.navigateCallback(target);
25+
}
2426
};
2527
}

packages/runner/src/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ export class Runner implements IRunner {
735735
(result: any) =>
736736
sendValueToBinding(processCell, mappedOutputBindings, result),
737737
addCancel,
738-
inputCells, // cause
738+
{ inputs: inputsCell, parents: processCell.getDoc() },
739739
processCell,
740740
this.runtime,
741741
);

recipes/compiler.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,29 @@ const updateCode = handler<{ detail: { value: string } }, { code: string }>(
5555

5656
const visit = handler<
5757
{ detail: { value: string } },
58-
{ result: { [UI]: any; [NAME]: string } }
58+
{ code: string }
5959
>(
6060
(_, state) => {
61-
return navigateTo(state.result);
61+
const { result } = compileAndRun({
62+
files: [{ name: "/main.tsx", contents: state.code }],
63+
main: "/main.tsx",
64+
});
65+
66+
console.log("result", result);
67+
68+
return navigateTo(result);
6269
},
6370
);
6471

6572
export default recipe(
6673
InputSchema,
6774
OutputSchema,
6875
({ code }) => {
69-
const { result, error, errors } = compileAndRun({
76+
const { error, errors } = compileAndRun({
7077
files: [{ name: "/main.tsx", contents: code }],
7178
main: "/main.tsx",
7279
});
7380

74-
derive(result, (result) => {
75-
console.log("result", result);
76-
});
77-
7881
return {
7982
[NAME]: "My First Compiler",
8083
[UI]: (
@@ -87,9 +90,9 @@ export default recipe(
8790
/>
8891
{ifElse(
8992
error,
90-
<pre>{error}</pre>,
93+
<b>fix the errors</b>,
9194
<common-button
92-
onClick={visit({ result })}
95+
onClick={visit({ code })}
9396
>
9497
Navigate To Charm
9598
</common-button>,

0 commit comments

Comments
 (0)