Skip to content

Commit e435ca4

Browse files
authored
feat(runner): launch wish.tsx when passing a generic query to wish (commontoolsinc#2169)
1 parent 2bebdbc commit e435ca4

File tree

4 files changed

+273
-172
lines changed

4 files changed

+273
-172
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <cts-enable />
2+
import { NAME, pattern, UI, wish } from "commontools";
3+
4+
export default pattern<Record<string, never>>((_) => {
5+
const wishResult = wish<{ content: string }>({ query: "#note" });
6+
7+
return {
8+
[NAME]: "Wish tester",
9+
[UI]: (
10+
<div>
11+
<pre>{wishResult.result.content}</pre>
12+
<hr />
13+
{wishResult.result}
14+
<hr />
15+
{wishResult}
16+
</div>
17+
),
18+
};
19+
});

packages/patterns/wish.tsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
/// <cts-enable />
2-
import { NAME, pattern, UI, wish } from "commontools";
2+
import {
3+
type Cell,
4+
computed,
5+
type Default,
6+
pattern,
7+
UI,
8+
type WishState,
9+
} from "commontools";
310

4-
export default pattern<Record<string, never>>((_) => {
5-
const wishResult = wish<{ content: string }>({ query: "#note" });
11+
// Copy of the original with less fancy types, since we ran into limits of the
12+
// schema translation here.
13+
export type WishParams = {
14+
query: string;
15+
path?: string[];
16+
context?: Record<string, any>;
17+
schema?: any;
18+
scope?: string[];
19+
};
620

7-
return {
8-
[NAME]: "Wish tester",
9-
[UI]: (
10-
<div>
11-
<pre>{wishResult.result.content}</pre>
12-
<hr />
13-
{wishResult.result}
14-
<hr />
15-
{wishResult[UI]}
16-
</div>
17-
),
18-
};
19-
});
21+
export default pattern<
22+
WishParams & { candidates: Default<Cell<never>[], []> },
23+
WishState<never>
24+
>(
25+
({ query: _query, context: _context, candidates }) => {
26+
return {
27+
result: computed(() => candidates.length > 0 ? candidates[0] : undefined),
28+
[UI]: (
29+
<div>
30+
{candidates.map((candidate) => (
31+
/* TODO(seefeld/ben): Implement picker that updates `result` */
32+
<div>
33+
<ct-cell-link
34+
$cell={candidate}
35+
/>
36+
</div>
37+
))}
38+
</div>
39+
),
40+
};
41+
},
42+
);

0 commit comments

Comments
 (0)