@malloy-publisher/sdk 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -65
- package/dist/{DocumentStorage-BZqn0x5r.es.js → Dashboard-DnqWRijB.es.js} +23691 -23538
- package/dist/Dashboard-FD3-Af-_.cjs.js +136 -0
- package/dist/{RenderedResult-DKOl0FQ8.es.js → RenderedResult-6UKAHaAj.es.js} +18 -18
- package/dist/{RenderedResult-Bu25oAAr.cjs.js → RenderedResult-CetSzFgW.cjs.js} +1 -1
- package/dist/ServerProvider-BsjJvkML.cjs.js +1 -0
- package/dist/{ServerProvider-CfUFleYe.es.js → ServerProvider-DgRFJ43L.es.js} +983 -957
- package/dist/builder/index.cjs.js +50 -50
- package/dist/builder/index.es.js +2587 -2511
- package/dist/client/api.d.ts +157 -44
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +62 -59
- package/dist/components/DashboardBuilder/malloyText.d.ts +49 -0
- package/dist/components/DashboardBuilder/malloyTree.d.ts +2 -18
- package/dist/components/DashboardBuilder/readDocument.d.ts +2 -0
- package/dist/components/Notebook/NotebookCell.d.ts +3 -2
- package/dist/components/Notebook/cellKind.d.ts +20 -0
- package/dist/components/given/filterValue.d.ts +11 -0
- package/dist/index.cjs.js +15 -12
- package/dist/index.es.js +4528 -4435
- package/package.json +1 -1
- package/src/components/DashboardBuilder/malloyText.spec.ts +70 -1
- package/src/components/DashboardBuilder/malloyText.ts +171 -3
- package/src/components/DashboardBuilder/malloyTree.spec.ts +35 -0
- package/src/components/DashboardBuilder/malloyTree.ts +28 -4
- package/src/components/DashboardBuilder/readDocument.spec.ts +180 -1
- package/src/components/DashboardBuilder/readDocument.ts +52 -14
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +396 -2
- package/src/components/DashboardBuilder/spliceDocument.ts +121 -18
- package/src/components/Notebook/Notebook.served.spec.tsx +175 -0
- package/src/components/Notebook/Notebook.spec.tsx +33 -2
- package/src/components/Notebook/Notebook.tsx +13 -7
- package/src/components/Notebook/NotebookCell.tsx +124 -63
- package/src/components/Notebook/cellKind.spec.ts +191 -0
- package/src/components/Notebook/cellKind.ts +74 -0
- package/src/components/Package/Package.notebooks.spec.tsx +90 -0
- package/src/components/Package/Package.tsx +18 -4
- package/src/components/given/GivenInput.spec.tsx +66 -0
- package/src/components/given/GivenInput.tsx +99 -0
- package/src/components/given/filterValue.ts +21 -0
- package/dist/DocumentStorage-B0_YgSzt.cjs.js +0 -134
- package/dist/ServerProvider-CuYLH_Yi.cjs.js +0 -1
|
@@ -8,7 +8,11 @@ import type {
|
|
|
8
8
|
DashboardTile,
|
|
9
9
|
} from "./document";
|
|
10
10
|
import type { LocalGiven } from "./document";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
artifactLine,
|
|
13
|
+
descriptionNotes,
|
|
14
|
+
hasNonQuotedTiles,
|
|
15
|
+
} from "./malloyText";
|
|
12
16
|
import {
|
|
13
17
|
parseMalloy,
|
|
14
18
|
parseRefused,
|
|
@@ -408,6 +412,13 @@ function planOrder(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
408
412
|
reason: "Could not find the `## artifact` tag to reorder.",
|
|
409
413
|
};
|
|
410
414
|
}
|
|
415
|
+
if (hasNonQuotedTiles(lines[artifactAt])) {
|
|
416
|
+
return {
|
|
417
|
+
ok: false,
|
|
418
|
+
reason:
|
|
419
|
+
"The `tiles=[…]` list holds an entry the builder does not model, such as a text tile, and rewriting the list would drop it. Reorder, add and remove tiles in the file's text.",
|
|
420
|
+
};
|
|
421
|
+
}
|
|
411
422
|
const written = [...lines[artifactAt].matchAll(/"([^"]+)"/g)].map(
|
|
412
423
|
(m) => m[1],
|
|
413
424
|
);
|
|
@@ -444,6 +455,81 @@ function planOrder(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
444
455
|
return undefined;
|
|
445
456
|
}
|
|
446
457
|
|
|
458
|
+
/**
|
|
459
|
+
* `line` without one property of the artifact tag's own braces: spelled with
|
|
460
|
+
* any spacing round the `=`, and never matched inside a quoted string or a
|
|
461
|
+
* nested block.
|
|
462
|
+
*/
|
|
463
|
+
function removeArtifactProperty(line: string, key: string): string {
|
|
464
|
+
let depth = 0;
|
|
465
|
+
let groups = 0;
|
|
466
|
+
for (let i = 0; i < line.length; i++) {
|
|
467
|
+
const c = line[i];
|
|
468
|
+
if (c === '"') {
|
|
469
|
+
i = endOfString(line, i);
|
|
470
|
+
} else if (c === "{" || c === "[") {
|
|
471
|
+
if (depth++ === 0) groups++;
|
|
472
|
+
} else if (c === "}" || c === "]") {
|
|
473
|
+
depth--;
|
|
474
|
+
} else if (
|
|
475
|
+
groups === 1 &&
|
|
476
|
+
depth === 1 &&
|
|
477
|
+
line.startsWith(key, i) &&
|
|
478
|
+
!/[A-Za-z0-9_]/.test(line[i - 1] ?? " ")
|
|
479
|
+
) {
|
|
480
|
+
const eq = /^\s*=\s*/.exec(line.slice(i + key.length));
|
|
481
|
+
if (!eq) continue;
|
|
482
|
+
const valueAt = i + key.length + eq[0].length;
|
|
483
|
+
const valueEnd =
|
|
484
|
+
line[valueAt] === '"'
|
|
485
|
+
? endOfString(line, valueAt) + 1
|
|
486
|
+
: valueAt +
|
|
487
|
+
(/^[^\s}]*/.exec(line.slice(valueAt))?.[0].length ?? 0);
|
|
488
|
+
const from = i - (/\s*$/.exec(line.slice(0, i))?.[0].length ?? 0);
|
|
489
|
+
return line.slice(0, from) + line.slice(valueEnd);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return line;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** `line` without its `dashboard { … }` block: outside the artifact braces and never inside a string. */
|
|
496
|
+
function removeDashboardBlock(line: string): string {
|
|
497
|
+
let depth = 0;
|
|
498
|
+
for (let i = 0; i < line.length; i++) {
|
|
499
|
+
const c = line[i];
|
|
500
|
+
if (c === '"') i = endOfString(line, i);
|
|
501
|
+
else if (c === "{" || c === "[") depth++;
|
|
502
|
+
else if (c === "}" || c === "]") depth--;
|
|
503
|
+
else if (
|
|
504
|
+
depth === 0 &&
|
|
505
|
+
line.startsWith("dashboard", i) &&
|
|
506
|
+
!/[A-Za-z0-9_]/.test(line[i - 1] ?? " ")
|
|
507
|
+
) {
|
|
508
|
+
const open = /^dashboard\s*\{/.exec(line.slice(i));
|
|
509
|
+
if (!open) continue;
|
|
510
|
+
let inner = 1;
|
|
511
|
+
let j = i + open[0].length;
|
|
512
|
+
for (; j < line.length && inner > 0; j++) {
|
|
513
|
+
if (line[j] === '"') j = endOfString(line, j);
|
|
514
|
+
else if (line[j] === "{") inner++;
|
|
515
|
+
else if (line[j] === "}") inner--;
|
|
516
|
+
}
|
|
517
|
+
const from = i - (/\s*$/.exec(line.slice(0, i))?.[0].length ?? 0);
|
|
518
|
+
return line.slice(0, from) + line.slice(j);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return line;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** The index of the quote closing the string that opens at `open`. */
|
|
525
|
+
function endOfString(line: string, open: number): number {
|
|
526
|
+
for (let i = open + 1; i < line.length; i++) {
|
|
527
|
+
if (line[i] === "\\") i++;
|
|
528
|
+
else if (line[i] === '"') return i;
|
|
529
|
+
}
|
|
530
|
+
return line.length;
|
|
531
|
+
}
|
|
532
|
+
|
|
447
533
|
function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
448
534
|
const { lines, wholeLine, current, next, edits } = ctx;
|
|
449
535
|
// THE PAGE'S OWN SETTINGS. Title, autorun and starting values are
|
|
@@ -523,7 +609,9 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
523
609
|
inner = inner.replace(/\s{2,}/g, " ");
|
|
524
610
|
line = `${line.slice(0, braceOpen + 1)}${inner.startsWith(" ") ? inner : ` ${inner}`}${inner.endsWith(" ") ? "" : " "}${line.slice(braceClose)}`;
|
|
525
611
|
if (current.columns !== next.columns) {
|
|
526
|
-
|
|
612
|
+
// The deprecated alias would otherwise sit beside the new width and conflict with it.
|
|
613
|
+
line = removeArtifactProperty(line, "dashboard_columns");
|
|
614
|
+
line = removeDashboardBlock(line);
|
|
527
615
|
if (next.columns !== undefined)
|
|
528
616
|
line = `${line.trimEnd()} dashboard { columns=${next.columns} }`;
|
|
529
617
|
}
|
|
@@ -531,25 +619,35 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
531
619
|
else edits.push({ ...wholeLine(artifactAt), text: `${line}\n` });
|
|
532
620
|
}
|
|
533
621
|
if (current.description !== next.description) {
|
|
534
|
-
//
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
622
|
+
// Written above the tag, where the server reads it. A description read
|
|
623
|
+
// from below (the legacy spot) moves there, and the lines it came from go.
|
|
624
|
+
const { read, blankAbove, below, belowBlock, inBlock } =
|
|
625
|
+
descriptionNotes(lines);
|
|
626
|
+
if (inBlock || (next.description === undefined && belowBlock)) {
|
|
627
|
+
return {
|
|
628
|
+
ok: false,
|
|
629
|
+
reason:
|
|
630
|
+
"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text.",
|
|
631
|
+
};
|
|
632
|
+
}
|
|
538
633
|
const text = (next.description ?? "")
|
|
539
634
|
.split("\n")
|
|
540
635
|
.map((para) => (para.trim() === "" ? '##"' : `##" ${para.trim()}`))
|
|
541
636
|
.join("\n");
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
637
|
+
const above = read.length > 0 && read[0] < artifactLine(lines);
|
|
638
|
+
// Clearing it must not let the server fall back to notes left below the tag.
|
|
639
|
+
const clearing = next.description === undefined;
|
|
640
|
+
const removed = above
|
|
641
|
+
? [...read.slice(1), ...(clearing ? below : [])]
|
|
642
|
+
: [...read, ...blankAbove];
|
|
643
|
+
for (const at of removed) edits.push({ ...wholeLine(at), text: "" });
|
|
644
|
+
if (above) {
|
|
545
645
|
edits.push({
|
|
546
|
-
|
|
547
|
-
end: wholeLine(last).end,
|
|
646
|
+
...wholeLine(read[0]),
|
|
548
647
|
text: next.description === undefined ? "" : `${text}\n`,
|
|
549
648
|
});
|
|
550
649
|
} else if (next.description !== undefined) {
|
|
551
|
-
const
|
|
552
|
-
const at = wholeLine(artifactAt).start;
|
|
650
|
+
const at = wholeLine(artifactLine(lines)).start;
|
|
553
651
|
edits.push({ start: at, end: at, text: `${text}\n` });
|
|
554
652
|
}
|
|
555
653
|
}
|
|
@@ -585,7 +683,7 @@ function planGivens(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
585
683
|
// removed declaration is the exception and takes every tag with it: a
|
|
586
684
|
// `#` line left behind does not lapse, it attaches to whatever is
|
|
587
685
|
// declared next, so an orphaned `#(secure)` would silently move.
|
|
588
|
-
const { tags } = blockAbove(parsed, lines, at.line);
|
|
686
|
+
const { tags, prose } = blockAbove(parsed, lines, at.line);
|
|
589
687
|
const owned =
|
|
590
688
|
want === undefined
|
|
591
689
|
? tags
|
|
@@ -593,9 +691,14 @@ function planGivens(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
593
691
|
const key = tagKey(tag.text);
|
|
594
692
|
return key !== undefined && MODELLED_GIVEN_TAG_KEYS.has(key);
|
|
595
693
|
});
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
694
|
+
// Prose leaves with a removed declaration for the same reason.
|
|
695
|
+
const ownedLines = [
|
|
696
|
+
...owned.map((tag) => tag.line),
|
|
697
|
+
...(want === undefined ? prose : []),
|
|
698
|
+
];
|
|
699
|
+
for (const line of ownedLines) {
|
|
700
|
+
edits.push({ ...wholeLine(line), text: "" });
|
|
701
|
+
removedLines.add(line);
|
|
599
702
|
}
|
|
600
703
|
// A declaration can run past its first line -- `NAME :: string is` with
|
|
601
704
|
// its default below it is ordinary Malloy -- so the lines to take come
|
|
@@ -611,7 +714,7 @@ function planGivens(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
611
714
|
for (let l = at.line; l <= lastLine; l++) removedLines.add(l);
|
|
612
715
|
// A declaration set off by blank lines takes one of them with it, or
|
|
613
716
|
// the two separators meet and the file gains an empty line per edit.
|
|
614
|
-
const first = Math.min(at.line, ...
|
|
717
|
+
const first = Math.min(at.line, ...ownedLines);
|
|
615
718
|
const above = at.blockHeader ?? first;
|
|
616
719
|
const belowIsBlank = (lines[lastLine + 1] ?? "x").trim() === "";
|
|
617
720
|
const aboveIsBlank = above === 0 || lines[above - 1].trim() === "";
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { beforeEach, expect, it, mock } from "bun:test";
|
|
5
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import type { RawNotebook } from "../../client";
|
|
13
|
+
|
|
14
|
+
const SERVED = {
|
|
15
|
+
format: "malloy",
|
|
16
|
+
notebookCells: [
|
|
17
|
+
{
|
|
18
|
+
type: "code",
|
|
19
|
+
kind: "definition",
|
|
20
|
+
text: 'import { orders } from "../orders.malloy"',
|
|
21
|
+
},
|
|
22
|
+
{ type: "markdown", kind: "markdown", text: "Served prose" },
|
|
23
|
+
{
|
|
24
|
+
type: "code",
|
|
25
|
+
kind: "definition",
|
|
26
|
+
text: "source: recent is orders extend { where: year = 2025 }",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "code",
|
|
30
|
+
kind: "query",
|
|
31
|
+
text: '#" Revenue by month\n# bar_chart\nrun: orders -> by_month',
|
|
32
|
+
caption: "Revenue by month",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
} as RawNotebook;
|
|
36
|
+
|
|
37
|
+
let current: RawNotebook = SERVED;
|
|
38
|
+
const getNotebook = mock(() => Promise.resolve({ data: current }));
|
|
39
|
+
const executeNotebookCell = mock(
|
|
40
|
+
(
|
|
41
|
+
_env: string,
|
|
42
|
+
_pkg: string,
|
|
43
|
+
_path: string,
|
|
44
|
+
_index: number,
|
|
45
|
+
): Promise<never> => pending(),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
mockServerProvider({
|
|
49
|
+
notebooks: { getNotebook, executeNotebookCell },
|
|
50
|
+
models: { executeQueryModel: () => pending() },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const { default: Notebook } = await import("./Notebook");
|
|
54
|
+
|
|
55
|
+
const URI =
|
|
56
|
+
"publisher://environments/env/packages/pkg/models/notebooks/ops.malloy";
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
current = SERVED;
|
|
60
|
+
clearCache();
|
|
61
|
+
getNotebook.mockClear();
|
|
62
|
+
executeNotebookCell.mockClear();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("runs only the query cell of a served notebook", async () => {
|
|
66
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
67
|
+
|
|
68
|
+
await waitFor(() => expect(executeNotebookCell).toHaveBeenCalled());
|
|
69
|
+
expect(executeNotebookCell.mock.calls.map((call) => call[3])).toEqual([3]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("shows a query cell's caption above its result", async () => {
|
|
73
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
74
|
+
|
|
75
|
+
expect(await screen.findByText("Served prose")).toBeTruthy();
|
|
76
|
+
expect(await screen.findByText("Revenue by month")).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("folds a definition cell to a one-line summary and expands it to the code", async () => {
|
|
80
|
+
const { container } = render(<Notebook resourceUri={URI} />, {
|
|
81
|
+
wrapper: serverWrapper,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const toggle = await screen.findByRole("button", {
|
|
85
|
+
name: /source: recent/,
|
|
86
|
+
});
|
|
87
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("false");
|
|
88
|
+
expect(container.textContent).not.toContain("year = 2025");
|
|
89
|
+
|
|
90
|
+
fireEvent.click(toggle);
|
|
91
|
+
|
|
92
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("true");
|
|
93
|
+
await waitFor(() => expect(container.textContent).toContain("year = 2025"));
|
|
94
|
+
const region = container.querySelector(
|
|
95
|
+
`[id="${toggle.getAttribute("aria-controls")}"]`,
|
|
96
|
+
);
|
|
97
|
+
expect(region?.textContent).toContain("year = 2025");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("puts the copy-link icon on the first markdown cell, not on a leading definition", async () => {
|
|
101
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
102
|
+
|
|
103
|
+
await screen.findByText("Served prose");
|
|
104
|
+
expect(screen.getAllByTestId("LinkOutlinedIcon")).toHaveLength(1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("keeps the copy-link icon off a .malloynb that opens with a code cell", async () => {
|
|
108
|
+
current = {
|
|
109
|
+
format: "malloynb",
|
|
110
|
+
notebookCells: [
|
|
111
|
+
{ type: "code", text: "import { orders } from '../orders.malloy'" },
|
|
112
|
+
{ type: "markdown", text: "Legacy prose" },
|
|
113
|
+
],
|
|
114
|
+
} as RawNotebook;
|
|
115
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
116
|
+
|
|
117
|
+
await screen.findByText("Legacy prose");
|
|
118
|
+
expect(screen.queryAllByTestId("LinkOutlinedIcon")).toHaveLength(0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("renders a query cell's markdown above its caption, without repeating it in the code", async () => {
|
|
122
|
+
current = {
|
|
123
|
+
format: "malloy",
|
|
124
|
+
notebookCells: [
|
|
125
|
+
{
|
|
126
|
+
type: "code",
|
|
127
|
+
kind: "query",
|
|
128
|
+
text: '#|(markdown)\n### Revenue by month\n|#\n#" Shown caption\nrun: orders -> by_month',
|
|
129
|
+
markdown: "### Revenue by month",
|
|
130
|
+
proseLines: [[0, 2]],
|
|
131
|
+
caption: "Shown caption",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
} as RawNotebook;
|
|
135
|
+
const { container } = render(<Notebook resourceUri={URI} />, {
|
|
136
|
+
wrapper: serverWrapper,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const heading = await screen.findByText("Revenue by month");
|
|
140
|
+
const caption = await screen.findByText("Shown caption");
|
|
141
|
+
expect(
|
|
142
|
+
heading.compareDocumentPosition(caption) &
|
|
143
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
144
|
+
).toBeTruthy();
|
|
145
|
+
expect(container.textContent?.split("Revenue by month")).toHaveLength(2);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("shows a folded definition cell's markdown above the fold", async () => {
|
|
149
|
+
current = {
|
|
150
|
+
format: "malloy",
|
|
151
|
+
notebookCells: [
|
|
152
|
+
{
|
|
153
|
+
type: "code",
|
|
154
|
+
kind: "definition",
|
|
155
|
+
text: "#|(markdown)\nThe orders source.\n|#\nsource: o is t",
|
|
156
|
+
markdown: "The orders source.",
|
|
157
|
+
proseLines: [[0, 2]],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
} as RawNotebook;
|
|
161
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
162
|
+
|
|
163
|
+
const prose = await screen.findByText("The orders source.");
|
|
164
|
+
const toggle = await screen.findByRole("button", { name: /source: o/ });
|
|
165
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("false");
|
|
166
|
+
expect(
|
|
167
|
+
prose.compareDocumentPosition(toggle) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
168
|
+
).toBeTruthy();
|
|
169
|
+
|
|
170
|
+
fireEvent.click(toggle);
|
|
171
|
+
await waitFor(() =>
|
|
172
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("true"),
|
|
173
|
+
);
|
|
174
|
+
expect(screen.getAllByText("The orders source.")).toHaveLength(1);
|
|
175
|
+
});
|
|
@@ -50,13 +50,15 @@ const NOTEBOOK: RawNotebook = {
|
|
|
50
50
|
],
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
let current: RawNotebook = NOTEBOOK;
|
|
54
|
+
|
|
53
55
|
const getNotebook = mock(
|
|
54
56
|
(
|
|
55
57
|
_environmentName: string,
|
|
56
58
|
_packageName: string,
|
|
57
59
|
_notebookPath: string,
|
|
58
60
|
_versionId?: string,
|
|
59
|
-
) => Promise.resolve({ data:
|
|
61
|
+
) => Promise.resolve({ data: current }),
|
|
60
62
|
);
|
|
61
63
|
const executeQueryModel = mock(
|
|
62
64
|
(
|
|
@@ -69,7 +71,14 @@ const executeQueryModel = mock(
|
|
|
69
71
|
// The notebook's real run path for a code cell, distinct from
|
|
70
72
|
// `executeQueryModel`: without it, the cell this spec adds (for the "Data
|
|
71
73
|
// sources" dialog) fails with "not a function" on every render.
|
|
72
|
-
const executeNotebookCell = mock(
|
|
74
|
+
const executeNotebookCell = mock(
|
|
75
|
+
(
|
|
76
|
+
_environmentName: string,
|
|
77
|
+
_packageName: string,
|
|
78
|
+
_notebookPath: string,
|
|
79
|
+
_cellIndex: number,
|
|
80
|
+
) => pending(),
|
|
81
|
+
);
|
|
73
82
|
|
|
74
83
|
// Stubbed rather than let the cell's "Data sources" dialog reach the real
|
|
75
84
|
// ModelExplorer: that pulls in the lazy-loaded, WASM-backed
|
|
@@ -104,6 +113,7 @@ const URI =
|
|
|
104
113
|
"publisher://environments/env/packages/pkg/models/notebooks/ops.malloynb";
|
|
105
114
|
|
|
106
115
|
beforeEach(() => {
|
|
116
|
+
current = NOTEBOOK;
|
|
107
117
|
clearCache();
|
|
108
118
|
getNotebook.mockClear();
|
|
109
119
|
executeQueryModel.mockClear();
|
|
@@ -150,3 +160,24 @@ it("opens a cell's 'Data sources' dialog with the notebook's current values", as
|
|
|
150
160
|
"TENANT",
|
|
151
161
|
);
|
|
152
162
|
});
|
|
163
|
+
|
|
164
|
+
it("renders a .malloynb as before: runs every code cell, no caption, no folded definition", async () => {
|
|
165
|
+
current = {
|
|
166
|
+
notebookCells: [
|
|
167
|
+
{ type: "markdown", text: "Prose" },
|
|
168
|
+
{ type: "code", text: "run: a -> b" },
|
|
169
|
+
{ type: "code", text: '#" x\nrun: a -> c' },
|
|
170
|
+
],
|
|
171
|
+
} as RawNotebook;
|
|
172
|
+
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
173
|
+
|
|
174
|
+
await screen.findByText("Prose");
|
|
175
|
+
await waitFor(() => expect(executeNotebookCell).toHaveBeenCalledTimes(2));
|
|
176
|
+
expect(executeNotebookCell.mock.calls.map((call) => call[3])).toEqual([
|
|
177
|
+
1, 2,
|
|
178
|
+
]);
|
|
179
|
+
expect(screen.queryByText("x")).toBeNull();
|
|
180
|
+
expect(
|
|
181
|
+
screen.queryByRole("button", { name: /^(run|source|import)/ }),
|
|
182
|
+
).toBeNull();
|
|
183
|
+
});
|
|
@@ -19,6 +19,7 @@ import { givensToParams, givensToRequest } from "../given/paramCodec";
|
|
|
19
19
|
import { Loading } from "../Loading";
|
|
20
20
|
import { useServer } from "../ServerProvider";
|
|
21
21
|
import { CleanNotebookContainer, CleanNotebookSection } from "../styles";
|
|
22
|
+
import { cellRuns } from "./cellKind";
|
|
22
23
|
import { NotebookCell } from "./NotebookCell";
|
|
23
24
|
import { EnhancedNotebookCell } from "./types";
|
|
24
25
|
|
|
@@ -303,8 +304,8 @@ export default function Notebook({
|
|
|
303
304
|
for (let i = 0; i < notebook.notebookCells.length; i++) {
|
|
304
305
|
const rawCell = notebook.notebookCells[i];
|
|
305
306
|
|
|
306
|
-
//
|
|
307
|
-
if (rawCell
|
|
307
|
+
// Prose and definitions have nothing to run.
|
|
308
|
+
if (!cellRuns(rawCell)) continue;
|
|
308
309
|
|
|
309
310
|
// Capture cell index for closure
|
|
310
311
|
const cellIndex = i;
|
|
@@ -507,6 +508,14 @@ export default function Notebook({
|
|
|
507
508
|
executeCells,
|
|
508
509
|
]);
|
|
509
510
|
|
|
511
|
+
const shownCells =
|
|
512
|
+
enhancedCells.length > 0 ? enhancedCells : notebook?.notebookCells || [];
|
|
513
|
+
// A served notebook can open with definition cells; a .malloynb keeps the icon on its first cell.
|
|
514
|
+
const copyLinkIndex =
|
|
515
|
+
notebook?.format === "malloy"
|
|
516
|
+
? shownCells.findIndex((cell) => cell.type === "markdown")
|
|
517
|
+
: 0;
|
|
518
|
+
|
|
510
519
|
return (
|
|
511
520
|
<CleanNotebookContainer>
|
|
512
521
|
<CleanNotebookSection>
|
|
@@ -521,14 +530,11 @@ export default function Notebook({
|
|
|
521
530
|
|
|
522
531
|
{/* Notebook Cells */}
|
|
523
532
|
{isSuccess &&
|
|
524
|
-
(
|
|
525
|
-
? enhancedCells
|
|
526
|
-
: notebook?.notebookCells || []
|
|
527
|
-
).map((cell, index) => (
|
|
533
|
+
shownCells.map((cell, index) => (
|
|
528
534
|
<NotebookCell
|
|
529
535
|
cell={cell as EnhancedNotebookCell}
|
|
530
536
|
key={index}
|
|
531
|
-
|
|
537
|
+
showCopyLink={index === copyLinkIndex}
|
|
532
538
|
resourceUri={resourceUri}
|
|
533
539
|
maxResultSize={maxResultSize}
|
|
534
540
|
isExecuting={isExecuting}
|