@malloy-publisher/sdk 0.3.1 → 0.4.0

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 (129) hide show
  1. package/README.md +14 -9
  2. package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorageProvider-CyOJ0hqf.es.js} +7114 -6939
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-BnPzJ9Jf.es.js} +64 -57
  5. package/dist/{RenderedResult-CPi6uQWq.cjs.js → RenderedResult-Dp22kZsQ.cjs.js} +2 -2
  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 +41 -41
  9. package/dist/builder/index.es.js +2752 -2831
  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 +10 -5
  17. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
  18. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +8 -2
  19. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +8 -10
  20. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  21. package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
  22. package/dist/components/ItemRow.d.ts +38 -0
  23. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  24. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  25. package/dist/components/Materializations/Materializations.d.ts +7 -3
  26. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  27. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  28. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  29. package/dist/components/Materializations/index.d.ts +0 -1
  30. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  31. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  32. package/dist/components/Package/index.d.ts +0 -1
  33. package/dist/components/PackageSection.d.ts +23 -0
  34. package/dist/components/buttons.d.ts +53 -0
  35. package/dist/components/index.d.ts +5 -0
  36. package/dist/components/styles.d.ts +49 -40
  37. package/dist/hooks/useCrudMutation.d.ts +42 -0
  38. package/dist/index.cjs.js +22 -26
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.es.js +17425 -20672
  41. package/dist/telemetry/consoleEvents.d.ts +60 -0
  42. package/dist/utils/sha256.d.ts +2 -0
  43. package/package.json +1 -1
  44. package/src/components/AppDialog.tsx +115 -0
  45. package/src/components/BackLink.tsx +83 -0
  46. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  47. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  48. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  49. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  50. package/src/components/Dashboard/telemetry.ts +10 -3
  51. package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
  52. package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
  53. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
  54. package/src/components/DashboardBuilder/DashboardBuilder.tsx +184 -171
  55. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  56. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
  57. package/src/components/DashboardBuilder/DashboardEditor.tsx +135 -61
  58. package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
  59. package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
  60. package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
  61. package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
  62. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  63. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  64. package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
  65. package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
  66. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
  67. package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
  68. package/src/components/Environment/About.tsx +14 -28
  69. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  70. package/src/components/Environment/Connections.tsx +125 -205
  71. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  72. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  73. package/src/components/Environment/Environment.tsx +34 -36
  74. package/src/components/Environment/Packages.tsx +63 -128
  75. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  76. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  77. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  78. package/src/components/Home/Home.tsx +101 -214
  79. package/src/components/ItemRow.tsx +165 -0
  80. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  81. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  82. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  83. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  84. package/src/components/Materializations/Materializations.tsx +137 -140
  85. package/src/components/Materializations/ScopeButton.tsx +85 -0
  86. package/src/components/Materializations/SectionLabel.tsx +7 -4
  87. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  88. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  89. package/src/components/Materializations/cron.spec.ts +113 -0
  90. package/src/components/Materializations/index.ts +0 -1
  91. package/src/components/Materializations/utils.spec.ts +182 -0
  92. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  93. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  94. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  95. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  96. package/src/components/Package/Package.tsx +179 -238
  97. package/src/components/Package/index.ts +0 -1
  98. package/src/components/PackageSection.tsx +85 -0
  99. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  100. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  101. package/src/components/ResultsDialog.tsx +8 -32
  102. package/src/components/buttons.tsx +114 -0
  103. package/src/components/designSystem.spec.tsx +316 -0
  104. package/src/components/given/paramCodec.spec.ts +1 -1
  105. package/src/components/index.ts +10 -0
  106. package/src/components/styles.ts +49 -85
  107. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  108. package/src/hooks/useCrudMutation.tsx +85 -0
  109. package/src/index.ts +9 -0
  110. package/src/telemetry/consoleEvents.spec.ts +130 -0
  111. package/src/telemetry/consoleEvents.ts +124 -0
  112. package/src/theme/defaults.ts +34 -23
  113. package/src/theme/resolveTheme.spec.ts +9 -4
  114. package/src/theme/resolveTheme.ts +12 -8
  115. package/src/utils/sha256.ts +13 -0
  116. package/test/README.md +1 -1
  117. package/test/serverProvider.tsx +5 -2
  118. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
  119. package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
  120. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  121. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  122. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  123. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  124. package/dist/components/Package/Models.d.ts +0 -6
  125. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  126. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  127. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  128. package/src/components/Materializations/TriggerChip.tsx +0 -44
  129. package/src/components/Package/Models.tsx +0 -71
@@ -0,0 +1,316 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { fireEvent, render, screen, within } from "@testing-library/react";
5
+ import { describe, expect, it, mock } from "bun:test";
6
+ import { AppDialog } from "./AppDialog";
7
+ import { BackLink } from "./BackLink";
8
+ import { ItemRow } from "./ItemRow";
9
+ import { PackageSection } from "./PackageSection";
10
+ import { AddButton, SecondaryButton } from "./buttons";
11
+
12
+ /**
13
+ * The five components every Console screen is built out of. They carry the
14
+ * contracts the rest of the app assumes and the Playwright suite selects on —
15
+ * accessible names, landmark roles, keyboard reachability — and none of it was
16
+ * covered. A screenshot cannot show any of it: a row that is not reachable by
17
+ * keyboard and a row that is look exactly alike.
18
+ */
19
+
20
+ describe("AddButton", () => {
21
+ it("announces the verb while showing only the noun", () => {
22
+ // The plus carries "add", so the label is the thing being added. The
23
+ // accessible name has to put the verb back, or every add button on the
24
+ // page announces as a bare noun.
25
+ render(<AddButton label="Package" onClick={() => {}} />);
26
+ const button = screen.getByRole("button", { name: "Add package" });
27
+ expect(button.textContent).toContain("Package");
28
+ expect(button.textContent).not.toContain("Add package");
29
+ });
30
+
31
+ it("calls back when clicked", () => {
32
+ const onClick = mock(() => {});
33
+ render(<AddButton label="Connection" onClick={onClick} />);
34
+ fireEvent.click(screen.getByRole("button", { name: "Add connection" }));
35
+ expect(onClick).toHaveBeenCalledTimes(1);
36
+ });
37
+ });
38
+
39
+ describe("SecondaryButton", () => {
40
+ it("uses the label as its name unless given another", () => {
41
+ render(<SecondaryButton label="Edit" onClick={() => {}} />);
42
+ expect(screen.getByRole("button", { name: "Edit" })).toBeTruthy();
43
+ });
44
+
45
+ it("takes an explicit accessible name for a label that is not unique", () => {
46
+ render(
47
+ <SecondaryButton
48
+ label="Settings"
49
+ ariaLabel="Settings for Orders"
50
+ onClick={() => {}}
51
+ />,
52
+ );
53
+ expect(
54
+ screen.getByRole("button", { name: "Settings for Orders" }),
55
+ ).toBeTruthy();
56
+ });
57
+
58
+ it("does not fire while disabled", () => {
59
+ const onClick = mock(() => {});
60
+ render(
61
+ <SecondaryButton
62
+ label="Save"
63
+ disabled
64
+ disabledReason="Nothing to save"
65
+ onClick={onClick}
66
+ />,
67
+ );
68
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
69
+ expect(onClick).not.toHaveBeenCalled();
70
+ });
71
+ });
72
+
73
+ describe("PackageSection", () => {
74
+ it("is a landmark named by its own heading", () => {
75
+ // What makes "Dashboards" addressable to a screen reader moving by
76
+ // region, and to a test that wants the dashboards list rather than
77
+ // every row on the page sharing a word with it.
78
+ render(
79
+ <PackageSection title="Dashboards" count={2}>
80
+ <div>a row</div>
81
+ </PackageSection>,
82
+ );
83
+ const region = screen.getByRole("region", { name: "Dashboards" });
84
+ expect(within(region).getByText("a row")).toBeTruthy();
85
+ expect(
86
+ within(region).getByRole("heading", { name: "Dashboards", level: 6 }),
87
+ ).toBeTruthy();
88
+ });
89
+
90
+ it("shows a count of zero rather than hiding it", () => {
91
+ render(
92
+ <PackageSection title="Notebooks" count={0}>
93
+ <div />
94
+ </PackageSection>,
95
+ );
96
+ expect(screen.getByText("(0)")).toBeTruthy();
97
+ });
98
+
99
+ it("omits the count entirely when none is given", () => {
100
+ render(
101
+ <PackageSection title="Readme">
102
+ <div />
103
+ </PackageSection>,
104
+ );
105
+ expect(screen.queryByText(/^\(\d+\)$/)).toBeNull();
106
+ });
107
+
108
+ it("puts the action inside the section, on the heading's row", () => {
109
+ render(
110
+ <PackageSection
111
+ title="Packages"
112
+ action={<AddButton label="Package" onClick={() => {}} />}
113
+ >
114
+ <div />
115
+ </PackageSection>,
116
+ );
117
+ const region = screen.getByRole("region", { name: "Packages" });
118
+ expect(
119
+ within(region).getByRole("button", { name: "Add package" }),
120
+ ).toBeTruthy();
121
+ });
122
+ });
123
+
124
+ describe("ItemRow", () => {
125
+ const row = (props: Partial<Parameters<typeof ItemRow>[0]> = {}) =>
126
+ render(
127
+ <ItemRow
128
+ label="storefront"
129
+ description="An ecommerce model"
130
+ tint="#2563eb"
131
+ icon={<span />}
132
+ onClick={props.onClick ?? (() => {})}
133
+ {...props}
134
+ />,
135
+ );
136
+
137
+ it("is operable by keyboard, not only by pointer", () => {
138
+ // It is a div wearing role=button, so Enter and Space are the component's
139
+ // own responsibility; a real button would get them from the platform.
140
+ const onClick = mock(() => {});
141
+ row({ onClick, ariaLabel: "storefront" });
142
+ const target = screen.getByRole("button", { name: "storefront" });
143
+ fireEvent.keyDown(target, { key: "Enter" });
144
+ fireEvent.keyDown(target, { key: " " });
145
+ expect(onClick).toHaveBeenCalledTimes(2);
146
+ });
147
+
148
+ it("ignores keys that are not activation keys", () => {
149
+ const onClick = mock(() => {});
150
+ row({ onClick, ariaLabel: "storefront" });
151
+ fireEvent.keyDown(screen.getByRole("button", { name: "storefront" }), {
152
+ key: "a",
153
+ });
154
+ expect(onClick).not.toHaveBeenCalled();
155
+ });
156
+
157
+ it("takes an explicit name so a lookup is not a guess at concatenated text", () => {
158
+ // Without it the accessible name is the row's whole text content, label
159
+ // and description run together, which makes every exact-name lookup a
160
+ // guess at someone's prose.
161
+ row({ ariaLabel: "storefront package" });
162
+ const target = screen.getByRole("button", { name: "storefront package" });
163
+ expect(target.textContent).toContain("An ecommerce model");
164
+ });
165
+
166
+ it("falls back to the row's text when given no explicit name", () => {
167
+ row();
168
+ expect(
169
+ screen.getByRole("button", { name: /storefront.*ecommerce model/ }),
170
+ ).toBeTruthy();
171
+ });
172
+
173
+ it("still shows the description it does not put in the name", () => {
174
+ row({ ariaLabel: "storefront" });
175
+ expect(screen.getByText("An ecommerce model")).toBeTruthy();
176
+ });
177
+ });
178
+
179
+ describe("AppDialog", () => {
180
+ it("is named by its own title", () => {
181
+ render(
182
+ <AppDialog open onClose={() => {}} title="New dashboard">
183
+ <div>body</div>
184
+ </AppDialog>,
185
+ );
186
+ expect(
187
+ screen.getByRole("dialog", { name: "New dashboard" }),
188
+ ).toBeTruthy();
189
+ });
190
+
191
+ it("renders nothing while closed", () => {
192
+ render(
193
+ <AppDialog open={false} onClose={() => {}} title="New dashboard">
194
+ <div>body</div>
195
+ </AppDialog>,
196
+ );
197
+ expect(screen.queryByRole("dialog")).toBeNull();
198
+ });
199
+
200
+ it("shows the description and the actions it is given", () => {
201
+ render(
202
+ <AppDialog
203
+ open
204
+ onClose={() => {}}
205
+ title="Delete package"
206
+ description="This cannot be undone."
207
+ actions={<button>Delete package</button>}
208
+ >
209
+ <div />
210
+ </AppDialog>,
211
+ );
212
+ expect(screen.getByText("This cannot be undone.")).toBeTruthy();
213
+ expect(
214
+ screen.getByRole("button", { name: "Delete package" }),
215
+ ).toBeTruthy();
216
+ });
217
+
218
+ it("offers a way out only when asked for one", () => {
219
+ const onClose = mock(() => {});
220
+ const { rerender } = render(
221
+ <AppDialog open onClose={onClose} title="Rows">
222
+ <div />
223
+ </AppDialog>,
224
+ );
225
+ expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
226
+ rerender(
227
+ <AppDialog open onClose={onClose} title="Rows" showClose>
228
+ <div />
229
+ </AppDialog>,
230
+ );
231
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
232
+ expect(onClose).toHaveBeenCalledTimes(1);
233
+ });
234
+ });
235
+
236
+ describe("BackLink", () => {
237
+ it("names the parent it goes to", () => {
238
+ render(<BackLink label="storefront" onClick={() => {}} />);
239
+ expect(
240
+ screen.getByRole("button", { name: "Back to storefront" }),
241
+ ).toBeTruthy();
242
+ });
243
+
244
+ it("is a real link when there is a URL, so it can be opened in a new tab", () => {
245
+ // The regression: it used to render an `<a>` with no href, which is
246
+ // neither focusable nor announced as a link, and swallows a middle-click.
247
+ render(
248
+ <BackLink
249
+ label="storefront"
250
+ href="/examples/storefront"
251
+ onClick={() => {}}
252
+ />,
253
+ );
254
+ const link = screen.getByRole("link", { name: "Back to storefront" });
255
+ expect(link.getAttribute("href")).toBe("/examples/storefront");
256
+ });
257
+
258
+ it("is still focusable when there is no URL to point at", () => {
259
+ render(<BackLink label="Publisher" onClick={() => {}} />);
260
+ const control = screen.getByRole("button", { name: "Back to Publisher" });
261
+ control.focus();
262
+ expect(document.activeElement).toBe(control);
263
+ });
264
+
265
+ it("hands the host the click, with its event", () => {
266
+ const onClick = mock(() => {});
267
+ render(<BackLink label="Publisher" onClick={onClick} />);
268
+ fireEvent.click(
269
+ screen.getByRole("button", { name: "Back to Publisher" }),
270
+ );
271
+ expect(onClick).toHaveBeenCalledTimes(1);
272
+ });
273
+
274
+ it("suppresses the anchor's own navigation on a plain click", () => {
275
+ // The regression: with an href present and the default left alone, the
276
+ // page navigated twice — the host's router, and then a full document
277
+ // load that undid it.
278
+ const onClick = mock(() => {});
279
+ render(
280
+ <BackLink
281
+ label="storefront"
282
+ href="/examples/storefront"
283
+ onClick={onClick}
284
+ />,
285
+ );
286
+ const link = screen.getByRole("link", { name: "Back to storefront" });
287
+ const event = new MouseEvent("click", {
288
+ bubbles: true,
289
+ cancelable: true,
290
+ });
291
+ link.dispatchEvent(event);
292
+ expect(onClick).toHaveBeenCalledTimes(1);
293
+ expect(event.defaultPrevented).toBe(true);
294
+ });
295
+
296
+ it("leaves a modified click to the browser, so it opens a new tab", () => {
297
+ // The whole reason for the href. Handling this one would swallow it.
298
+ const onClick = mock(() => {});
299
+ render(
300
+ <BackLink
301
+ label="storefront"
302
+ href="/examples/storefront"
303
+ onClick={onClick}
304
+ />,
305
+ );
306
+ const link = screen.getByRole("link", { name: "Back to storefront" });
307
+ const event = new MouseEvent("click", {
308
+ bubbles: true,
309
+ cancelable: true,
310
+ metaKey: true,
311
+ });
312
+ link.dispatchEvent(event);
313
+ expect(onClick).not.toHaveBeenCalled();
314
+ expect(event.defaultPrevented).toBe(false);
315
+ });
316
+ });
@@ -510,7 +510,7 @@ describe("a naive timestamp is read as UTC, in any timezone", () => {
510
510
  // these assertions only bite when the suite runs outside UTC, and a UTC CI
511
511
  // cannot catch a regression here. Verified by hand across UTC,
512
512
  // America/New_York, Asia/Kolkata and Pacific/Auckland; to exercise it:
513
- // TZ=America/New_York bun test src/components/given/paramCodec.spec.ts
513
+ // TZ=America/New_York bun test ./src/components/given/paramCodec.spec.ts
514
514
  // Running one suite under a non-UTC zone in CI would close that gap.
515
515
  //
516
516
  // Each assertion below names its expected value outright rather than
@@ -5,6 +5,16 @@
5
5
  // failures through it; a host composing those needs the same presentation for
6
6
  // its own.
7
7
  export { ApiErrorDisplay, type ApiErrorDisplayProps } from "./ApiErrorDisplay";
8
+ // The Console's button roles; see `buttons.tsx`. Exported so a host — the
9
+ // Publisher app included — builds its own screens out of the same four.
10
+ export { AddButton, SecondaryButton } from "./buttons";
11
+ export { AppDialog } from "./AppDialog";
12
+ export { BackLink } from "./BackLink";
13
+ export { DashboardBar } from "./Dashboard/DashboardBar";
14
+ // The Console's palette, and the two maps drawn from it. Exported so a host
15
+ // paints its own chrome — the Publisher app's theme included — from the same
16
+ // hues rather than picking a near-miss beside them.
17
+ export { PALETTE, SURFACE_TINT } from "./styles";
8
18
  export { useRouterClickHandler, type NavigationClick } from "./click_helper";
9
19
  export * from "./Dashboard";
10
20
  export * from "./DataAppViewer";
@@ -4,51 +4,66 @@
4
4
  import { Card, CardContent, CardMedia, styled } from "@mui/material";
5
5
 
6
6
  /**
7
- * Malloy brand colors — exact hex values from
8
- * `publisher/packages/app/public/logo.svg`. Use these instead of hardcoding
9
- * the hex values inline so the brand can be retuned in one place.
7
+ * The Console's palette: one set of hues, used everywhere a colour carries
8
+ * meaning.
9
+ *
10
+ * These are the register data tools encode categories in — saturated, mid-dark,
11
+ * evenly spaced around the wheel — rather than colours lifted from a logo. A
12
+ * logo is drawn to be recognised at one size in one place; a palette has to
13
+ * distinguish a dozen kinds of thing in a list, behind a glyph, and along a
14
+ * chart's series, and the two jobs pull in different directions. The previous
15
+ * palette was the logo's three plus two families invented to extend it, which
16
+ * is how one screen ended up with three unrelated colour systems on it.
17
+ *
18
+ * **Every value clears 3:1 against white**, WCAG's minimum for a graphical
19
+ * object, because these are painted as small solid backplates behind white
20
+ * glyphs where the glyph has to stay readable. That is a hard constraint on
21
+ * anything added here, asserted in `ContentTypeIcon.spec.ts` rather than left
22
+ * to review: a too-light plate looks perfectly fine in a screenshot and simply
23
+ * stops being legible. Measured against white, lowest first: emerald 3.8:1,
24
+ * red 4.8:1, lime 5.0:1, amber 5.0:1, blue 5.2:1, orange 5.2:1, cyan 5.4:1,
25
+ * teal 5.5:1, violet 5.7:1, pink 6.0:1, indigo 6.3:1, slate 7.6:1.
10
26
  */
11
- export const MALLOY_BRAND = {
12
- teal: "#14b3cb", // light wing of the M
13
- orange: "#e47404", // right wing of the M
14
- darkBlue: "#1474a4", // deep shadow of the M
27
+ export const PALETTE = {
28
+ blue: "#2563eb",
29
+ indigo: "#4f46e5",
30
+ violet: "#7c3aed",
31
+ pink: "#be185d",
32
+ red: "#dc2626",
33
+ orange: "#c2410c",
34
+ amber: "#b45309",
35
+ lime: "#4d7c0f",
36
+ emerald: "#059669",
37
+ teal: "#0f766e",
38
+ cyan: "#0e7490",
39
+ slate: "#475569",
15
40
  } as const;
16
41
 
17
42
  /**
18
- * Accents that extend the logo's three, for the places that need more colors
19
- * than the brand supplies. The package page gives every kind of content its
20
- * own, and three kinds became six.
21
- *
22
- * Their own family rather than borrowings from the chart series
23
- * (`theme/defaults.ts`), because the two have opposite constraints. A series
24
- * color fills a large area and can be light; these sit behind a white icon as a
25
- * small solid backplate, where the icon has to stay legible. Measured against
26
- * white: violet 5.5:1, magenta 4.6:1, moss 3.9:1, so all three clear 3:1, the
27
- * WCAG minimum for a graphical object. The nearest series hues do not: `#aacd85`
28
- * sage is 1.8:1, `#ec72b8` pink 2.7:1, `#b87ced` violet 2.9:1.
43
+ * The tints for what a SERVER holds, as against what a package holds. Three
44
+ * kinds — an environment, a package, a connection — listed on the home and
45
+ * environment pages.
29
46
  *
30
- * These three were picked against the bar, but they are not the only colors it
31
- * now binds. `CONTENT_TINT` in `Package/ContentTypeIcon.tsx` paints all three of
32
- * `MALLOY_BRAND` behind glyphs as well, and `ContentTypeIcon.spec.ts` holds two
33
- * of them to the same 3:1: orange at 3.09:1 and darkBlue at 5.17:1. Orange
34
- * clears it by 0.09, so retuning it lighter turns that suite red, in a file a
35
- * brand change would not otherwise open. For those two the bar is a component
36
- * constraint, not only a brand decision.
47
+ * Kept clear of the hues `CONTENT_TINT` uses, so a colour means one kind of
48
+ * thing across the whole Console rather than one kind per page. All three are
49
+ * real colours rather than near-neutrals: a grey plate reads as chrome instead
50
+ * of as one of the coloured kinds, which is the plate's whole job.
37
51
  *
38
- * Teal is the exception at 2.5:1, below the bar and inherited from the logo, so
39
- * the row it backs carries a white-on-teal glyph that does not meet the
40
- * standard. Pre-existing, not introduced here. The spec grandfathers it by
41
- * content type rather than by color, so a new type handed teal still fails.
52
+ * Also kept clear of the primary. Packages were indigo, which sat a few degrees
53
+ * from the blue of the "Package" button on the same row and read as a failed
54
+ * attempt at the same colour. Teal is the furthest hue from blue still open,
55
+ * and packages and connections — the pair that actually share a screen — now
56
+ * sit on opposite sides of the wheel. Environments never appear beside either.
42
57
  */
43
- export const MALLOY_ACCENT = {
44
- violet: "#7c4dcc",
45
- magenta: "#c2478f",
46
- moss: "#5c8f3f",
58
+ export const SURFACE_TINT = {
59
+ environment: PALETTE.emerald,
60
+ package: PALETTE.teal,
61
+ connection: PALETTE.orange,
47
62
  } as const;
48
63
 
49
64
  /**
50
65
  * Monospace font stack used by code-like surfaces inside the SDK
51
- * (file-path labels in PackageItemRow, code blocks, etc.). Matches the
66
+ * (file-path labels in `ItemRow`, code blocks, etc.). Matches the
52
67
  * `MONO_FONT_FAMILY` defined in the publisher app's theme.
53
68
  */
54
69
  export const MONO_FONT_FAMILY =
@@ -107,59 +122,8 @@ export const StyledExplorerPage = styled("div")({
107
122
  height: "100%",
108
123
  });
109
124
 
110
- export const StyledExplorerBanner = styled("div")({
111
- height: "30px",
112
- backgroundColor: "rgba(225, 240, 255, 1)",
113
- display: "flex",
114
- padding: "4px",
115
- alignItems: "center",
116
- });
117
-
118
125
  export const StyledExplorerContent = styled("div")({
119
126
  height: "75vh",
120
127
  width: "100%",
121
128
  overflowY: "auto",
122
129
  });
123
-
124
- export const StyledExplorerPanel = styled("div")({
125
- position: "relative",
126
- height: "100%",
127
- flex: "0 0 auto",
128
- });
129
-
130
- // Package page styles
131
- export const PackageCard = styled(Card)(({ theme }) => ({
132
- backgroundColor: theme.palette.background.paper,
133
- padding: "24px",
134
- borderRadius: "8px",
135
- border: `1px solid ${theme.palette.divider}`,
136
- boxShadow: "0 1px 3px rgba(0, 0, 0, 0.04)",
137
- height: "100%",
138
- transition: "box-shadow 0.2s ease-in-out",
139
- "&:hover": {
140
- boxShadow: "0 2px 6px rgba(0, 0, 0, 0.08)",
141
- },
142
- }));
143
-
144
- export const PackageCardContent = styled(CardContent)({
145
- padding: "0",
146
- "&:last-child": {
147
- paddingBottom: "0",
148
- },
149
- });
150
-
151
- export const PackageSectionTitle = styled("div")(({ theme }) => ({
152
- fontSize: "0.875rem",
153
- fontWeight: 500,
154
- color: theme.palette.text.secondary,
155
- marginBottom: "16px",
156
- paddingBottom: "8px",
157
- borderBottom: `1px solid ${theme.palette.divider}`,
158
- }));
159
-
160
- export const PackageContainer = styled("div")({
161
- padding: "32px",
162
- maxWidth: "1400px",
163
- margin: "0 auto",
164
- minHeight: "100vh",
165
- });
@@ -0,0 +1,119 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { act, renderHook, waitFor } from "@testing-library/react";
5
+ import { afterEach, describe, expect, it, mock } from "bun:test";
6
+ import { QueryClientProvider } from "@tanstack/react-query";
7
+ import type { ReactNode } from "react";
8
+ import { globalQueryClient } from "../utils/queryClient";
9
+ import {
10
+ setConsoleEventHandler,
11
+ type ConsoleEvent,
12
+ } from "../telemetry/consoleEvents";
13
+ import { useCrudMutation } from "./useCrudMutation";
14
+
15
+ /**
16
+ * The shape every create, edit and delete dialog in the Console now runs
17
+ * through. Its job is four things in one order — run the write, close the
18
+ * dialog, refetch what changed, and say what happened — and the fourth used
19
+ * to be written out per file in two different ways.
20
+ */
21
+
22
+ const wrapper = ({ children }: { children: ReactNode }) => (
23
+ <QueryClientProvider client={globalQueryClient}>
24
+ {children}
25
+ </QueryClientProvider>
26
+ );
27
+
28
+ const mount = (
29
+ mutationFn: () => Promise<unknown>,
30
+ closeDialog = () => {},
31
+ invalidates: string[][] = [["packages", "examples"]],
32
+ ) =>
33
+ renderHook(
34
+ () =>
35
+ useCrudMutation({
36
+ mutationFn,
37
+ success: "Package deleted",
38
+ invalidates,
39
+ closeDialog,
40
+ resource: "package",
41
+ action: "delete",
42
+ }),
43
+ { wrapper },
44
+ );
45
+
46
+ describe("useCrudMutation", () => {
47
+ afterEach(() => setConsoleEventHandler(undefined));
48
+
49
+ it("closes the dialog and reports success once the write lands", async () => {
50
+ const events: ConsoleEvent[] = [];
51
+ setConsoleEventHandler((e) => events.push(e));
52
+ const closeDialog = mock(() => {});
53
+ const view = mount(() => Promise.resolve({ ok: true }), closeDialog);
54
+
55
+ act(() => view.result.current.mutate());
56
+ await waitFor(() => expect(closeDialog).toHaveBeenCalledTimes(1));
57
+ await waitFor(() => expect(events).toHaveLength(1));
58
+ expect(events[0]).toMatchObject({
59
+ type: "console.mutation",
60
+ resource: "package",
61
+ action: "delete",
62
+ ok: true,
63
+ });
64
+ expect(events[0].reason).toBeUndefined();
65
+ });
66
+
67
+ it("reports a failure with the reason the operator was shown", async () => {
68
+ // The gap this closes: a delete that failed left no trace at all once
69
+ // its six-second snackbar had gone.
70
+ const events: ConsoleEvent[] = [];
71
+ setConsoleEventHandler((e) => events.push(e));
72
+ const view = mount(() => Promise.reject(new Error("Package is in use")));
73
+
74
+ act(() => view.result.current.mutate());
75
+ await waitFor(() => expect(events).toHaveLength(1));
76
+ expect(events[0]).toMatchObject({
77
+ ok: false,
78
+ reason: "Package is in use",
79
+ });
80
+ });
81
+
82
+ it("does not close the dialog when the write fails", async () => {
83
+ // There is something to correct and retry, so the form has to stay.
84
+ const closeDialog = mock(() => {});
85
+ const view = mount(() => Promise.reject(new Error("nope")), closeDialog);
86
+ act(() => view.result.current.mutate());
87
+ await waitFor(() => expect(view.result.current.isPending).toBe(false));
88
+ expect(closeDialog).not.toHaveBeenCalled();
89
+ });
90
+
91
+ it("falls back to a sentence for a rejection that is not an Error", async () => {
92
+ // Every dialog had its own copy of this, and two of them did not have
93
+ // it at all — they read `error.message` off whatever was thrown.
94
+ const events: ConsoleEvent[] = [];
95
+ setConsoleEventHandler((e) => events.push(e));
96
+ const view = mount(() => Promise.reject("a bare string"));
97
+ act(() => view.result.current.mutate());
98
+ await waitFor(() => expect(events).toHaveLength(1));
99
+ expect(events[0].reason).toBe("An unknown error occurred");
100
+ });
101
+
102
+ it("invalidates the keys it was given", async () => {
103
+ const invalidate = mock(() => Promise.resolve());
104
+ const original = globalQueryClient.invalidateQueries;
105
+ globalQueryClient.invalidateQueries =
106
+ invalidate as unknown as typeof original;
107
+ try {
108
+ const view = mount(
109
+ () => Promise.resolve({}),
110
+ () => {},
111
+ [["packages", "examples"], ["environments"]],
112
+ );
113
+ act(() => view.result.current.mutate());
114
+ await waitFor(() => expect(invalidate).toHaveBeenCalledTimes(2));
115
+ } finally {
116
+ globalQueryClient.invalidateQueries = original;
117
+ }
118
+ });
119
+ });