@malloy-publisher/sdk 0.3.1 → 0.4.1

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.
Files changed (136) hide show
  1. package/README.md +33 -9
  2. package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorage-BiFqO15i.es.js} +7126 -6943
  3. package/dist/DocumentStorage-CMyLifsz.cjs.js +134 -0
  4. package/dist/RenderedResult-CZzE8wv-.cjs.js +115 -0
  5. package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-CvrmYyr5.es.js} +64 -57
  6. package/dist/{ServerProvider-X2Ma0HRs.es.js → ServerProvider-BWOEKg0O.es.js} +1217 -1244
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +52 -52
  9. package/dist/builder/index.es.js +3961 -3960
  10. package/dist/client/api.d.ts +100 -42
  11. package/dist/client/index.cjs.js +1 -1
  12. package/dist/client/index.es.js +1 -1
  13. package/dist/components/AppDialog.d.ts +30 -0
  14. package/dist/components/BackLink.d.ts +32 -0
  15. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  16. package/dist/components/Dashboard/telemetry.d.ts +24 -7
  17. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
  18. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +20 -2
  19. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +21 -11
  20. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  21. package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
  22. package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
  23. package/dist/components/DocumentStorage/index.d.ts +1 -0
  24. package/dist/components/ItemRow.d.ts +38 -0
  25. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  26. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  27. package/dist/components/Materializations/Materializations.d.ts +7 -3
  28. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  29. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  30. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  31. package/dist/components/Materializations/index.d.ts +0 -1
  32. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  33. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  34. package/dist/components/Package/index.d.ts +0 -1
  35. package/dist/components/PackageSection.d.ts +23 -0
  36. package/dist/components/buttons.d.ts +53 -0
  37. package/dist/components/index.d.ts +5 -0
  38. package/dist/components/styles.d.ts +49 -40
  39. package/dist/hooks/useCrudMutation.d.ts +42 -0
  40. package/dist/index.cjs.js +22 -26
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.es.js +17431 -20676
  43. package/dist/telemetry/consoleEvents.d.ts +60 -0
  44. package/dist/utils/sha256.d.ts +2 -0
  45. package/package.json +1 -1
  46. package/src/components/AppDialog.tsx +115 -0
  47. package/src/components/BackLink.tsx +83 -0
  48. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  49. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  50. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  51. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  52. package/src/components/Dashboard/telemetry.ts +24 -5
  53. package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
  54. package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
  55. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
  56. package/src/components/DashboardBuilder/DashboardBuilder.tsx +202 -171
  57. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
  58. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  59. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
  60. package/src/components/DashboardBuilder/DashboardEditor.tsx +442 -94
  61. package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
  62. package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
  63. package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
  64. package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
  65. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  66. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  67. package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
  68. package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
  69. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
  70. package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
  71. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
  72. package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
  73. package/src/components/DocumentStorage/index.ts +1 -0
  74. package/src/components/Environment/About.tsx +14 -28
  75. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  76. package/src/components/Environment/Connections.tsx +125 -205
  77. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  78. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  79. package/src/components/Environment/Environment.tsx +34 -36
  80. package/src/components/Environment/Packages.tsx +63 -128
  81. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  82. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  83. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  84. package/src/components/Home/Home.tsx +101 -214
  85. package/src/components/ItemRow.tsx +165 -0
  86. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  87. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  88. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  89. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  90. package/src/components/Materializations/Materializations.tsx +137 -140
  91. package/src/components/Materializations/ScopeButton.tsx +85 -0
  92. package/src/components/Materializations/SectionLabel.tsx +7 -4
  93. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  94. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  95. package/src/components/Materializations/cron.spec.ts +113 -0
  96. package/src/components/Materializations/index.ts +0 -1
  97. package/src/components/Materializations/utils.spec.ts +182 -0
  98. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  99. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  100. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  101. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  102. package/src/components/Package/Package.tsx +184 -238
  103. package/src/components/Package/index.ts +0 -1
  104. package/src/components/PackageSection.tsx +85 -0
  105. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  106. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  107. package/src/components/ResultsDialog.tsx +8 -32
  108. package/src/components/buttons.tsx +114 -0
  109. package/src/components/designSystem.spec.tsx +316 -0
  110. package/src/components/given/paramCodec.spec.ts +1 -1
  111. package/src/components/index.ts +10 -0
  112. package/src/components/styles.ts +49 -85
  113. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  114. package/src/hooks/useCrudMutation.tsx +85 -0
  115. package/src/index.ts +9 -0
  116. package/src/telemetry/consoleEvents.spec.ts +130 -0
  117. package/src/telemetry/consoleEvents.ts +124 -0
  118. package/src/theme/defaults.ts +34 -23
  119. package/src/theme/resolveTheme.spec.ts +9 -4
  120. package/src/theme/resolveTheme.ts +12 -8
  121. package/src/utils/sha256.ts +13 -0
  122. package/test/README.md +1 -1
  123. package/test/serverProvider.tsx +5 -2
  124. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
  125. package/dist/RenderedResult-CPi6uQWq.cjs.js +0 -115
  126. package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
  127. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  128. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  129. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  130. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  131. package/dist/components/Package/Models.d.ts +0 -6
  132. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  133. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  134. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  135. package/src/components/Materializations/TriggerChip.tsx +0 -44
  136. package/src/components/Package/Models.tsx +0 -71
@@ -0,0 +1,36 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Tooltip, Typography } from "@mui/material";
5
+ import { MaterializationMetadata, triggerLabel } from "./utils";
6
+
7
+ /**
8
+ * How a run was initiated — Scheduled (the standalone scheduler fired the
9
+ * package's cron) or Manual (an API or UI create) — with the tooltip that says
10
+ * which. One source of truth for the label, so the runs list and the detail
11
+ * dialog cannot drift.
12
+ *
13
+ * A word, like every other cell in the row. A two-value distinction needs no
14
+ * pictogram, and a bordered pill here made a value look like something to
15
+ * click.
16
+ */
17
+ export default function TriggerLabel({
18
+ meta,
19
+ }: {
20
+ meta: MaterializationMetadata;
21
+ }) {
22
+ const scheduled = meta.trigger === "SCHEDULER";
23
+ return (
24
+ <Tooltip
25
+ title={
26
+ scheduled
27
+ ? "Fired by the materialization schedule"
28
+ : "Triggered manually"
29
+ }
30
+ >
31
+ <Typography variant="body2" color="text.secondary">
32
+ {triggerLabel(meta)}
33
+ </Typography>
34
+ </Tooltip>
35
+ );
36
+ }
@@ -0,0 +1,113 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { describeCron, formatNextRun } from "./cron";
6
+
7
+ /**
8
+ * `describeCron` is the only thing standing between a typed cron and a
9
+ * schedule that publishes and then never fires. It drives four things at once
10
+ * in `SetScheduleDialog` — the error state, the helper text, whether Save is
11
+ * enabled, and the section's summary line — and its whole job is to agree with
12
+ * the server's `CronEvaluator` about what counts as a cron. Agreeing is not
13
+ * something a screenshot can show, which is why it is asserted here.
14
+ */
15
+ describe("describeCron: what it accepts", () => {
16
+ it("describes a valid five-field expression and says when it next fires", () => {
17
+ const info = describeCron("0 6 * * *");
18
+ expect(info.valid).toBe(true);
19
+ expect(info.description).toContain("06:00");
20
+ expect(info.nextRun).toBeInstanceOf(Date);
21
+ expect(info.error).toBeUndefined();
22
+ });
23
+
24
+ it("takes the three-letter month and day names UNIX cron defines", () => {
25
+ for (const expr of ["0 0 1 JAN *", "0 0 * * MON", "0 0 * * mon-fri"]) {
26
+ expect(describeCron(expr).valid).toBe(true);
27
+ }
28
+ });
29
+
30
+ it("takes lists, ranges and steps", () => {
31
+ for (const expr of ["0,30 * * * *", "0 9-17 * * *", "*/15 * * * *"]) {
32
+ expect(describeCron(expr).valid).toBe(true);
33
+ }
34
+ });
35
+
36
+ it("ignores surrounding and repeated whitespace", () => {
37
+ expect(describeCron(" 0 6 * * * ").valid).toBe(true);
38
+ });
39
+
40
+ it("computes the next run in UTC, not in the machine's zone", () => {
41
+ // A daily 06:00 job fires at 06:00 UTC wherever the browser is. Reading
42
+ // it back in UTC is the only way to assert that without the suite
43
+ // passing or failing by timezone.
44
+ const next = describeCron("0 6 * * *").nextRun;
45
+ expect(next?.getUTCHours()).toBe(6);
46
+ expect(next?.getUTCMinutes()).toBe(0);
47
+ });
48
+ });
49
+
50
+ describe("describeCron: what it refuses", () => {
51
+ it("refuses anything that is not five fields", () => {
52
+ // Six fields is the trap: cron-parser reads a leading SECONDS field, so
53
+ // "0 0 6 * * *" parses happily and means something else entirely. The
54
+ // manifest contract is five fields, so it has to be refused here rather
55
+ // than silently reinterpreted.
56
+ for (const expr of ["", " ", "0 6 * *", "0 0 6 * * *"]) {
57
+ const info = describeCron(expr);
58
+ expect(info.valid).toBe(false);
59
+ expect(info.error).toContain("5-field");
60
+ expect(info.nextRun).toBeNull();
61
+ expect(info.description).toBe("");
62
+ }
63
+ });
64
+
65
+ it("refuses the Quartz extensions the server does not implement", () => {
66
+ // Each of these parses in cron-parser and would describe itself
67
+ // plausibly, then never arm after publish.
68
+ for (const expr of [
69
+ "0 0 L * *",
70
+ "0 0 15W * *",
71
+ "0 0 * * 6#3",
72
+ "0 0 * * ?",
73
+ ]) {
74
+ const info = describeCron(expr);
75
+ expect(info.valid).toBe(false);
76
+ expect(info.error).toContain("Unsupported cron syntax");
77
+ }
78
+ });
79
+
80
+ it("refuses a word that is not a month or a day", () => {
81
+ const info = describeCron("0 0 * * FUNDAY");
82
+ expect(info.valid).toBe(false);
83
+ expect(info.error).toContain("Unsupported cron syntax");
84
+ });
85
+
86
+ it("refuses an out-of-range field with the parser's own reason", () => {
87
+ const info = describeCron("0 99 * * *");
88
+ expect(info.valid).toBe(false);
89
+ expect(info.error).toBeTruthy();
90
+ expect(info.nextRun).toBeNull();
91
+ });
92
+
93
+ it("treats a null or undefined expression as empty rather than throwing", () => {
94
+ for (const expr of [null, undefined]) {
95
+ const info = describeCron(expr as unknown as string);
96
+ expect(info.valid).toBe(false);
97
+ expect(info.error).toContain("5-field");
98
+ }
99
+ });
100
+ });
101
+
102
+ describe("formatNextRun", () => {
103
+ it("renders an instant in UTC and says so", () => {
104
+ const label = formatNextRun(new Date("2026-07-14T06:00:00Z"));
105
+ expect(label).toContain("2026");
106
+ expect(label).toContain("06:00");
107
+ expect(label.endsWith(" UTC")).toBe(true);
108
+ });
109
+
110
+ it("renders an em dash when there is no next run", () => {
111
+ expect(formatNextRun(null)).toBe("—");
112
+ });
113
+ });
@@ -2,4 +2,3 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  export { default as Materializations } from "./Materializations";
5
- export { default as EnvironmentMaterializations } from "./EnvironmentMaterializations";
@@ -0,0 +1,182 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { MaterializationStatus, type Materialization } from "../../client";
6
+ import {
7
+ formatDuration,
8
+ formatRelativeTime,
9
+ formatTimestamp,
10
+ isActiveStatus,
11
+ isTerminalStatus,
12
+ parseMetadata,
13
+ statusColor,
14
+ statusLabel,
15
+ triggerLabel,
16
+ } from "./utils";
17
+
18
+ /**
19
+ * The materializations table is entirely these functions: every cell it draws
20
+ * is one of them, and the polling loop that keeps it live is driven by the two
21
+ * predicates. None of it was covered, in either direction — a status the
22
+ * publisher adds later would fall through to "Unknown" and be polled forever,
23
+ * and nothing would say so.
24
+ */
25
+
26
+ const ALL = Object.values(MaterializationStatus);
27
+
28
+ describe("status predicates", () => {
29
+ it("treats the two in-flight phases as active", () => {
30
+ expect(isActiveStatus(MaterializationStatus.Pending)).toBe(true);
31
+ expect(isActiveStatus(MaterializationStatus.ManifestRowsReady)).toBe(
32
+ true,
33
+ );
34
+ });
35
+
36
+ it("treats the three settled phases as terminal", () => {
37
+ expect(isTerminalStatus(MaterializationStatus.ManifestFileReady)).toBe(
38
+ true,
39
+ );
40
+ expect(isTerminalStatus(MaterializationStatus.Failed)).toBe(true);
41
+ expect(isTerminalStatus(MaterializationStatus.Cancelled)).toBe(true);
42
+ });
43
+
44
+ /**
45
+ * The one that matters for the polling loop: every status the client knows
46
+ * is on exactly one side. A status that is neither is polled until the page
47
+ * is closed, because the loop stops on terminal and nothing else.
48
+ */
49
+ it("puts every known status on exactly one side", () => {
50
+ for (const status of ALL) {
51
+ expect([isActiveStatus(status), isTerminalStatus(status)]).toContain(
52
+ true,
53
+ );
54
+ expect(isActiveStatus(status) && isTerminalStatus(status)).toBe(false);
55
+ }
56
+ });
57
+
58
+ it("says an absent status is neither, so a half-loaded row is not polled", () => {
59
+ expect(isActiveStatus(undefined)).toBe(false);
60
+ expect(isTerminalStatus(undefined)).toBe(false);
61
+ });
62
+ });
63
+
64
+ describe("statusLabel", () => {
65
+ it("collapses both in-flight phases to one word", () => {
66
+ // The publisher drives the phases itself, so the distinction between
67
+ // them is not one a reader can act on.
68
+ expect(statusLabel(MaterializationStatus.Pending)).toBe("Pending");
69
+ expect(statusLabel(MaterializationStatus.ManifestRowsReady)).toBe(
70
+ "Pending",
71
+ );
72
+ });
73
+
74
+ it("names the settled phases apart", () => {
75
+ expect(statusLabel(MaterializationStatus.ManifestFileReady)).toBe("Done");
76
+ expect(statusLabel(MaterializationStatus.Failed)).toBe("Failed");
77
+ expect(statusLabel(MaterializationStatus.Cancelled)).toBe("Cancelled");
78
+ });
79
+
80
+ it("never renders a raw enum value at a reader", () => {
81
+ for (const status of ALL) {
82
+ expect(statusLabel(status)).not.toContain("_");
83
+ }
84
+ expect(statusLabel(undefined)).toBe("Unknown");
85
+ });
86
+ });
87
+
88
+ describe("statusColor", () => {
89
+ it("pairs failure with error and success with success", () => {
90
+ expect(statusColor(MaterializationStatus.Failed)).toBe("error");
91
+ expect(statusColor(MaterializationStatus.ManifestFileReady)).toBe(
92
+ "success",
93
+ );
94
+ expect(statusColor(MaterializationStatus.Cancelled)).toBe("warning");
95
+ });
96
+
97
+ it("gives every known status a colour the theme defines", () => {
98
+ const allowed = ["default", "info", "success", "error", "warning"];
99
+ for (const status of ALL) expect(allowed).toContain(statusColor(status));
100
+ expect(allowed).toContain(statusColor(undefined));
101
+ });
102
+ });
103
+
104
+ describe("parseMetadata and triggerLabel", () => {
105
+ const run = (metadata: unknown) =>
106
+ ({ metadata }) as unknown as Materialization;
107
+
108
+ it("reads the fields a run carries", () => {
109
+ const meta = parseMetadata(
110
+ run({ trigger: "SCHEDULER", sourcesBuilt: 3 }),
111
+ );
112
+ expect(meta.trigger).toBe("SCHEDULER");
113
+ expect(meta.sourcesBuilt).toBe(3);
114
+ });
115
+
116
+ it("hands back an empty object when there is no metadata", () => {
117
+ // The generated client types this as `object | null`, so every caller
118
+ // reads through here rather than risking a null dereference per cell.
119
+ expect(parseMetadata(run(null))).toEqual({});
120
+ expect(parseMetadata(run(undefined))).toEqual({});
121
+ });
122
+
123
+ it("calls a run manual unless the scheduler says otherwise", () => {
124
+ expect(triggerLabel({ trigger: "SCHEDULER" })).toBe("Scheduled");
125
+ expect(triggerLabel({ trigger: "ON_DEMAND" })).toBe("Manual");
126
+ expect(triggerLabel({})).toBe("Manual");
127
+ });
128
+ });
129
+
130
+ describe("formatDuration", () => {
131
+ const from = "2026-07-14T06:00:00.000Z";
132
+ const plus = (ms: number) => new Date(Date.parse(from) + ms).toISOString();
133
+
134
+ it("steps through the units as the run gets longer", () => {
135
+ expect(formatDuration(from, plus(250))).toBe("250ms");
136
+ expect(formatDuration(from, plus(4_000))).toBe("4s");
137
+ expect(formatDuration(from, plus(90_000))).toBe("1m 30s");
138
+ expect(formatDuration(from, plus(3_600_000 + 120_000))).toBe("1h 2m");
139
+ });
140
+
141
+ it("measures an open run against now rather than reporting nothing", () => {
142
+ const started = new Date(Date.now() - 5_000).toISOString();
143
+ expect(formatDuration(started, null)).toMatch(/^[45]s$/);
144
+ });
145
+
146
+ it("clamps a completion that precedes its start instead of going negative", () => {
147
+ expect(formatDuration(plus(5_000), from)).toBe("0ms");
148
+ });
149
+
150
+ it("renders a dash for a run that never started", () => {
151
+ expect(formatDuration(undefined, plus(1000))).toBe("-");
152
+ expect(formatDuration(null, null)).toBe("-");
153
+ });
154
+ });
155
+
156
+ describe("formatTimestamp", () => {
157
+ it("renders an instant", () => {
158
+ expect(formatTimestamp("2026-07-14T06:00:00Z")).toContain("2026");
159
+ });
160
+
161
+ it("renders an em dash rather than 'Invalid Date' for junk", () => {
162
+ expect(formatTimestamp("not a date")).toBe("—");
163
+ expect(formatTimestamp(null)).toBe("—");
164
+ expect(formatTimestamp(undefined)).toBe("—");
165
+ });
166
+ });
167
+
168
+ describe("formatRelativeTime", () => {
169
+ const ago = (ms: number) => new Date(Date.now() - ms).toISOString();
170
+
171
+ it("steps through the units as the instant recedes", () => {
172
+ expect(formatRelativeTime(ago(2_000))).toBe("just now");
173
+ expect(formatRelativeTime(ago(5 * 60_000))).toBe("5m ago");
174
+ expect(formatRelativeTime(ago(2 * 3_600_000))).toBe("2h ago");
175
+ expect(formatRelativeTime(ago(3 * 86_400_000))).toBe("3d ago");
176
+ });
177
+
178
+ it("renders a dash when there is no instant", () => {
179
+ expect(formatRelativeTime(null)).toBe("-");
180
+ expect(formatRelativeTime(undefined)).toBe("-");
181
+ });
182
+ });
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import { MALLOY_ACCENT } from "../styles";
6
- import { CONTENT_TINT, type ContentType } from "./ContentTypeIcon";
5
+ import { PALETTE } from "../styles";
6
+ import { CONTENT_TINT } from "./ContentTypeIcon";
7
7
 
8
8
  /** Relative luminance, WCAG 2.x definition. */
9
9
  function luminance(hex: string): number {
@@ -34,18 +34,6 @@ describe("CONTENT_TINT", () => {
34
34
  });
35
35
  });
36
36
 
37
- /**
38
- * Content types whose colour predates this bar. `report` is backed by
39
- * `MALLOY_BRAND.teal` at 2.5:1, which is below it; that is inherited from the
40
- * logo and is a brand decision rather than a component one.
41
- *
42
- * Keyed by content TYPE rather than by colour, which is the whole point. A new
43
- * type handed teal is not grandfathered and fails, and fixing teal one day
44
- * leaves this entry merely unused rather than turning a correct fix into a red
45
- * suite.
46
- */
47
- const GRANDFATHERED: ContentType[] = ["report"];
48
-
49
37
  describe("CONTENT_TINT contrast", () => {
50
38
  /**
51
39
  * Every tint fills a 32px backplate behind an 18px white glyph, so it has to
@@ -58,34 +46,31 @@ describe("CONTENT_TINT contrast", () => {
58
46
  * what actually get painted. Asserting the accent palette alone left three of
59
47
  * the six painted values unchecked.
60
48
  */
61
- it.each(
62
- Object.entries(CONTENT_TINT).filter(
63
- ([type]) => !GRANDFATHERED.includes(type as ContentType),
64
- ),
65
- )("%s clears 3:1 against white", (_type, hex) => {
66
- expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
67
- });
68
-
69
- // Guards the exception list against drift: a grandfathered name that no
70
- // longer matches a `ContentType` fails here rather than silently exempting
71
- // nothing. It does NOT catch the list being emptied, which passes
72
- // vacuously; that case is caught instead by the contrast assertion for the
73
- // type that stops being skipped, and an empty list is the desired end state
74
- // anyway.
75
- it("grandfathers only types that exist", () => {
76
- for (const type of GRANDFATHERED) {
77
- expect(CONTENT_TINT).toHaveProperty(type);
78
- }
79
- });
49
+ it.each(Object.entries(CONTENT_TINT))(
50
+ "%s clears 3:1 against white",
51
+ (_type, hex) => {
52
+ expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
53
+ },
54
+ );
80
55
  });
81
56
 
82
- describe("MALLOY_ACCENT", () => {
83
- // The accents were chosen against this bar, so they hold it even before any
84
- // of them is assigned to a content type.
85
- it.each(Object.entries(MALLOY_ACCENT))(
57
+ describe("PALETTE", () => {
58
+ // Every hue holds the bar, whether or not it is assigned to a content type
59
+ // yet — so picking one for a new plate is always safe, and there is no
60
+ // exception list to grandfather anything into. There used to be one: the
61
+ // logo's teal sat at 2.5:1 and painted a row whose glyph did not meet the
62
+ // standard.
63
+ it.each(Object.entries(PALETTE))(
86
64
  "%s clears 3:1 against white",
87
65
  (_name, hex) => {
88
66
  expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
89
67
  },
90
68
  );
69
+
70
+ // Two kinds of thing painted the same colour is the failure the tints exist
71
+ // to prevent, so the palette they are drawn from must not repeat itself.
72
+ it("has no duplicate hues", () => {
73
+ const values = Object.values(PALETTE);
74
+ expect(new Set(values).size).toBe(values.length);
75
+ });
91
76
  });
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon";
5
- import { MALLOY_ACCENT, MALLOY_BRAND } from "../styles";
5
+ import { PALETTE } from "../styles";
6
6
 
7
7
  export type ContentType =
8
8
  | "report"
@@ -17,23 +17,21 @@ export type ContentType =
17
17
  * a page that lists all six, a shared color reads as a shared kind, and the
18
18
  * glyphs are small enough that color does most of the telling apart.
19
19
  *
20
- * The logo's three go to the three artifacts a reader opens to look at data,
21
- * dashboards and notebooks and the models under them, and the accents to the
22
- * rest, so the brand leads on the things the page is mostly for. Not a
23
- * seniority ranking: dashboards are the newest thing a package can hold, and
24
- * Package Data is among the oldest and takes an accent.
20
+ * Six hues from `PALETTE`, spaced far enough apart to survive being 18px of
21
+ * white on a 32px plate, and disjoint from the three `SURFACE_TINT` uses so a
22
+ * colour means one kind of thing everywhere in the Console.
25
23
  *
26
24
  * Exhaustive by type rather than by a default, so adding a `ContentType` is a
27
25
  * compile error here instead of a row that silently paints itself the same as
28
26
  * its neighbour.
29
27
  */
30
28
  export const CONTENT_TINT: Record<ContentType, string> = {
31
- dashboard: MALLOY_BRAND.orange,
32
- report: MALLOY_BRAND.teal,
33
- model: MALLOY_BRAND.darkBlue,
34
- dataApp: MALLOY_ACCENT.violet,
35
- data: MALLOY_ACCENT.moss,
36
- materialization: MALLOY_ACCENT.magenta,
29
+ dashboard: PALETTE.blue,
30
+ report: PALETTE.violet,
31
+ model: PALETTE.cyan,
32
+ dataApp: PALETTE.pink,
33
+ data: PALETTE.lime,
34
+ materialization: PALETTE.amber,
37
35
  };
38
36
 
39
37
  interface ContentTypeIconProps extends Omit<SvgIconProps, "fontSize"> {
@@ -0,0 +1,129 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
5
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
6
+ import {
7
+ clearCache,
8
+ mockServerProvider,
9
+ serverWrapper,
10
+ } from "../../../test/serverProvider";
11
+
12
+ const getModel = mock(() =>
13
+ Promise.resolve({
14
+ data: {
15
+ modelPath: "storefront.malloy",
16
+ sources: [
17
+ {
18
+ name: "order_items",
19
+ views: [{ name: "by_category" }, { name: "by_brand" }],
20
+ },
21
+ { name: "products", views: [] },
22
+ ],
23
+ },
24
+ }),
25
+ );
26
+ const updateModelSource = mock((_env: string, _pkg: string, path: string) =>
27
+ Promise.resolve({ data: { path, contentHash: "h", created: true } }),
28
+ );
29
+ mockServerProvider({ models: { getModel, updateModelSource } });
30
+
31
+ const { NewDashboardDialog } = await import("./NewDashboardDialog");
32
+
33
+ beforeEach(() => {
34
+ clearCache();
35
+ updateModelSource.mockClear();
36
+ });
37
+
38
+ describe("NewDashboardDialog", () => {
39
+ it("writes the picked view as the first tile and hands back the slug", async () => {
40
+ const onCreated = mock((_slug: string) => {});
41
+ render(
42
+ <NewDashboardDialog
43
+ open
44
+ environmentName="env"
45
+ packageName="pkg"
46
+ models={["storefront.malloy", "other.malloy"]}
47
+ existing={["overview"]}
48
+ onClose={() => {}}
49
+ onCreated={onCreated}
50
+ />,
51
+ { wrapper: serverWrapper },
52
+ );
53
+ // Nothing to choose until the package's models are read; then the one
54
+ // model with views, its first tile and a title are already filled in.
55
+ await waitFor(() =>
56
+ expect(screen.getByLabelText("Dashboard title")).toHaveProperty(
57
+ "value",
58
+ "by category",
59
+ ),
60
+ );
61
+ // A source with no views is not on the list, so a pair that cannot be
62
+ // written cannot be picked.
63
+ fireEvent.mouseDown(screen.getByRole("combobox", { name: /First tile/ }));
64
+ const options = screen
65
+ .getAllByRole("option")
66
+ .map((option) => option.textContent);
67
+ expect(options).toEqual([
68
+ "order_items → by_category",
69
+ "order_items → by_brand",
70
+ ]);
71
+ fireEvent.click(
72
+ screen.getByRole("option", { name: "order_items → by_category" }),
73
+ );
74
+ fireEvent.change(screen.getByLabelText("Dashboard title"), {
75
+ target: { value: "Sales by Region" },
76
+ });
77
+ expect(
78
+ screen.getByText(/Written as dashboards\/sales-by-region\.malloy/),
79
+ ).toBeDefined();
80
+
81
+ fireEvent.click(screen.getByRole("button", { name: "Create dashboard" }));
82
+ await waitFor(() =>
83
+ expect(onCreated).toHaveBeenCalledWith("sales-by-region"),
84
+ );
85
+ const [, , path, body] = updateModelSource.mock.calls[0] as unknown as [
86
+ string,
87
+ string,
88
+ string,
89
+ { source: string },
90
+ ];
91
+ expect(path).toBe("dashboards/sales-by-region.malloy");
92
+ expect(body.source).toContain(
93
+ 'tiles=["order_items_tiles -> by_category_tile"]',
94
+ );
95
+ expect(body.source).toContain(
96
+ 'import { order_items } from "../storefront.malloy"',
97
+ );
98
+ });
99
+
100
+ it("refuses a title whose file already exists", async () => {
101
+ render(
102
+ <NewDashboardDialog
103
+ open
104
+ environmentName="env"
105
+ packageName="pkg"
106
+ models={["storefront.malloy"]}
107
+ existing={["overview"]}
108
+ onClose={() => {}}
109
+ onCreated={() => {}}
110
+ />,
111
+ { wrapper: serverWrapper },
112
+ );
113
+ await waitFor(() =>
114
+ expect(screen.getByLabelText("Dashboard title")).toHaveProperty(
115
+ "value",
116
+ "by category",
117
+ ),
118
+ );
119
+ fireEvent.change(screen.getByLabelText("Dashboard title"), {
120
+ target: { value: "Overview" },
121
+ });
122
+ expect(screen.getByText(/already exists in this package/)).toBeDefined();
123
+ expect(
124
+ screen
125
+ .getByRole("button", { name: "Create dashboard" })
126
+ .hasAttribute("disabled"),
127
+ ).toBe(true);
128
+ });
129
+ });