@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.
- package/README.md +33 -9
- package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorage-BiFqO15i.es.js} +7126 -6943
- package/dist/DocumentStorage-CMyLifsz.cjs.js +134 -0
- package/dist/RenderedResult-CZzE8wv-.cjs.js +115 -0
- package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-CvrmYyr5.es.js} +64 -57
- package/dist/{ServerProvider-X2Ma0HRs.es.js → ServerProvider-BWOEKg0O.es.js} +1217 -1244
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +52 -52
- package/dist/builder/index.es.js +3961 -3960
- package/dist/client/api.d.ts +100 -42
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +30 -0
- package/dist/components/BackLink.d.ts +32 -0
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- package/dist/components/Dashboard/telemetry.d.ts +24 -7
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +20 -2
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +21 -11
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
- package/dist/components/DocumentStorage/index.d.ts +1 -0
- package/dist/components/ItemRow.d.ts +38 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
- package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
- package/dist/components/Materializations/Materializations.d.ts +7 -3
- package/dist/components/Materializations/ScopeButton.d.ts +18 -0
- package/dist/components/Materializations/SectionLabel.d.ts +7 -4
- package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
- package/dist/components/Materializations/index.d.ts +0 -1
- package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
- package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
- package/dist/components/Package/index.d.ts +0 -1
- package/dist/components/PackageSection.d.ts +23 -0
- package/dist/components/buttons.d.ts +53 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/styles.d.ts +49 -40
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/index.cjs.js +22 -26
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +17431 -20676
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/AppDialog.tsx +115 -0
- package/src/components/BackLink.tsx +83 -0
- package/src/components/Connections/AddConnectionDialog.tsx +50 -70
- package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
- package/src/components/Connections/EditConnectionDialog.tsx +54 -73
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- package/src/components/Dashboard/telemetry.ts +24 -5
- package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +202 -171
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
- package/src/components/DashboardBuilder/DashboardEditor.tsx +442 -94
- package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
- package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
- package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
- package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
- package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
- package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +14 -28
- package/src/components/Environment/AddPackageDialog.tsx +85 -154
- package/src/components/Environment/Connections.tsx +125 -205
- package/src/components/Environment/DeletePackageDialog.tsx +32 -77
- package/src/components/Environment/EditPackageDialog.tsx +46 -58
- package/src/components/Environment/Environment.tsx +34 -36
- package/src/components/Environment/Packages.tsx +63 -128
- package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
- package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
- package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
- package/src/components/Home/Home.tsx +101 -214
- package/src/components/ItemRow.tsx +165 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
- package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
- package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
- package/src/components/Materializations/Materializations.tsx +137 -140
- package/src/components/Materializations/ScopeButton.tsx +85 -0
- package/src/components/Materializations/SectionLabel.tsx +7 -4
- package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
- package/src/components/Materializations/TriggerLabel.tsx +36 -0
- package/src/components/Materializations/cron.spec.ts +113 -0
- package/src/components/Materializations/index.ts +0 -1
- package/src/components/Materializations/utils.spec.ts +182 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
- package/src/components/Package/ContentTypeIcon.tsx +10 -12
- package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
- package/src/components/Package/NewDashboardDialog.tsx +265 -0
- package/src/components/Package/Package.tsx +184 -238
- package/src/components/Package/index.ts +0 -1
- package/src/components/PackageSection.tsx +85 -0
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- package/src/components/ResultsDialog.tsx +8 -32
- package/src/components/buttons.tsx +114 -0
- package/src/components/designSystem.spec.tsx +316 -0
- package/src/components/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +10 -0
- package/src/components/styles.ts +49 -85
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/index.ts +9 -0
- package/src/telemetry/consoleEvents.spec.ts +130 -0
- package/src/telemetry/consoleEvents.ts +124 -0
- package/src/theme/defaults.ts +34 -23
- package/src/theme/resolveTheme.spec.ts +9 -4
- package/src/theme/resolveTheme.ts +12 -8
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
- package/dist/RenderedResult-CPi6uQWq.cjs.js +0 -115
- package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
- package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
- package/dist/components/Materializations/TriggerChip.d.ts +0 -10
- package/dist/components/Package/Models.d.ts +0 -6
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
- package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
- package/src/components/Materializations/ScheduleCard.tsx +0 -231
- package/src/components/Materializations/TriggerChip.tsx +0 -44
- package/src/components/Package/Models.tsx +0 -71
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import Snackbar from "@mui/material/Snackbar";
|
|
5
|
+
import { useQueryClient, type QueryKey } from "@tanstack/react-query";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { useMutationWithApiError } from "./useQueryWithApiError";
|
|
9
|
+
import { reporting, type ConsoleResource } from "../telemetry/consoleEvents";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A write from a dialog: run it, close the dialog, refetch what it changed,
|
|
13
|
+
* and say what happened.
|
|
14
|
+
*
|
|
15
|
+
* Every create/edit/delete dialog in the Console does those four things in the
|
|
16
|
+
* same order and reported failure in one of two different ways depending on
|
|
17
|
+
* which file you were in. The shape is here once so the two conventions cannot
|
|
18
|
+
* drift back apart: a thrown `Error` shows its own message, because the API
|
|
19
|
+
* layer already turns a failed response into one worth reading, and anything
|
|
20
|
+
* else falls back to a sentence rather than `[object Object]`.
|
|
21
|
+
*
|
|
22
|
+
* `notice` is the Snackbar, wired and ready to render. It is returned rather
|
|
23
|
+
* than portalled from in here so a caller keeps it as a sibling of its dialog,
|
|
24
|
+
* where it was.
|
|
25
|
+
*/
|
|
26
|
+
export function useCrudMutation<TVariables = void>({
|
|
27
|
+
mutationFn,
|
|
28
|
+
success,
|
|
29
|
+
invalidates,
|
|
30
|
+
closeDialog,
|
|
31
|
+
resource,
|
|
32
|
+
action,
|
|
33
|
+
}: {
|
|
34
|
+
mutationFn: (variables: TVariables) => Promise<unknown>;
|
|
35
|
+
/** What the snackbar says when the write lands: "Package created". */
|
|
36
|
+
success: string;
|
|
37
|
+
/** The query keys the write invalidates. Name the narrowest that covers it. */
|
|
38
|
+
invalidates: QueryKey[];
|
|
39
|
+
/**
|
|
40
|
+
* Closes the dialog. Runs on SUCCESS only — a write that failed leaves
|
|
41
|
+
* something to correct and retry, so the form has to stay — and before the
|
|
42
|
+
* refetch, so the dialog goes at once rather than after the list reloads.
|
|
43
|
+
*
|
|
44
|
+
* Not called `onSettled`: that name means "success or error" everywhere
|
|
45
|
+
* else in React Query, and this is the opposite of that.
|
|
46
|
+
*/
|
|
47
|
+
closeDialog: () => void;
|
|
48
|
+
/** What is being written, for the event; see `ConsoleEvent`. */
|
|
49
|
+
resource: ConsoleResource;
|
|
50
|
+
action: "create" | "update" | "delete";
|
|
51
|
+
}) {
|
|
52
|
+
const queryClient = useQueryClient();
|
|
53
|
+
const [message, setMessage] = useState("");
|
|
54
|
+
const mutation = useMutationWithApiError({
|
|
55
|
+
// The same wrapper Connections and Materializations use, so there is one
|
|
56
|
+
// implementation of "a Console write reports itself" rather than one per
|
|
57
|
+
// shape of write.
|
|
58
|
+
mutationFn: reporting(resource, action, mutationFn),
|
|
59
|
+
onSuccess() {
|
|
60
|
+
closeDialog();
|
|
61
|
+
for (const queryKey of invalidates)
|
|
62
|
+
queryClient.invalidateQueries({ queryKey });
|
|
63
|
+
setMessage(success);
|
|
64
|
+
},
|
|
65
|
+
onError(error) {
|
|
66
|
+
setMessage(
|
|
67
|
+
error instanceof Error
|
|
68
|
+
? error.message
|
|
69
|
+
: "An unknown error occurred",
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
mutate: mutation.mutate,
|
|
75
|
+
isPending: mutation.isPending,
|
|
76
|
+
notice: (
|
|
77
|
+
<Snackbar
|
|
78
|
+
open={message !== ""}
|
|
79
|
+
autoHideDuration={6000}
|
|
80
|
+
onClose={() => setMessage("")}
|
|
81
|
+
message={message}
|
|
82
|
+
/>
|
|
83
|
+
) as React.ReactNode,
|
|
84
|
+
};
|
|
85
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,15 @@ export { useServer } from "./components/ServerProvider";
|
|
|
7
7
|
export * from "./hooks";
|
|
8
8
|
export { useRawQueryData } from "./hooks/useRawQueryData";
|
|
9
9
|
export * from "./theme";
|
|
10
|
+
// The Console's write events, and the seam a host installs a sink into. Set
|
|
11
|
+
// once at boot: the dialogs that write are not mounted by the host, so there
|
|
12
|
+
// is nothing to hand a handler to.
|
|
13
|
+
export {
|
|
14
|
+
setConsoleEventHandler,
|
|
15
|
+
type ConsoleEvent,
|
|
16
|
+
type ConsoleEventHandler,
|
|
17
|
+
type ConsoleResource,
|
|
18
|
+
} from "./telemetry/consoleEvents";
|
|
10
19
|
export * from "./utils/formatting";
|
|
11
20
|
// How a package's own files are addressed. Exported because a host that renders
|
|
12
21
|
// its own "this path is not a model" state has to point at the URL that does
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
reportConsoleEvent,
|
|
7
|
+
reporting,
|
|
8
|
+
setConsoleEventHandler,
|
|
9
|
+
type ConsoleEvent,
|
|
10
|
+
} from "./consoleEvents";
|
|
11
|
+
|
|
12
|
+
const event = (over: Partial<ConsoleEvent> = {}): ConsoleEvent => ({
|
|
13
|
+
type: "console.mutation",
|
|
14
|
+
resource: "package",
|
|
15
|
+
action: "delete",
|
|
16
|
+
ok: true,
|
|
17
|
+
durationMs: 12,
|
|
18
|
+
...over,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("console event sink", () => {
|
|
22
|
+
afterEach(() => setConsoleEventHandler(undefined));
|
|
23
|
+
|
|
24
|
+
it("delivers to the installed handler", () => {
|
|
25
|
+
const sink = mock((_e: ConsoleEvent) => {});
|
|
26
|
+
setConsoleEventHandler(sink);
|
|
27
|
+
reportConsoleEvent(event());
|
|
28
|
+
expect(sink).toHaveBeenCalledTimes(1);
|
|
29
|
+
expect(sink.mock.calls[0][0]).toMatchObject({
|
|
30
|
+
resource: "package",
|
|
31
|
+
action: "delete",
|
|
32
|
+
ok: true,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("is a no-op when no host installed one", () => {
|
|
37
|
+
// An SDK embedded in someone else's app reports to nobody, and that has
|
|
38
|
+
// to be silent rather than a crash on every write.
|
|
39
|
+
expect(() => reportConsoleEvent(event())).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("replaces the handler rather than fanning out", () => {
|
|
43
|
+
const first = mock((_e: ConsoleEvent) => {});
|
|
44
|
+
const second = mock((_e: ConsoleEvent) => {});
|
|
45
|
+
setConsoleEventHandler(first);
|
|
46
|
+
setConsoleEventHandler(second);
|
|
47
|
+
reportConsoleEvent(event());
|
|
48
|
+
expect(first).not.toHaveBeenCalled();
|
|
49
|
+
expect(second).toHaveBeenCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("swallows a sink that throws, so telemetry cannot break a write", () => {
|
|
53
|
+
// This is called from the success path of a delete. A sink bug that
|
|
54
|
+
// surfaced as a failed delete would be worse than the line it lost.
|
|
55
|
+
setConsoleEventHandler(() => {
|
|
56
|
+
throw new Error("the sink is broken");
|
|
57
|
+
});
|
|
58
|
+
expect(() => reportConsoleEvent(event())).not.toThrow();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("carries the reason on a failure", () => {
|
|
62
|
+
const sink = mock((_e: ConsoleEvent) => {});
|
|
63
|
+
setConsoleEventHandler(sink);
|
|
64
|
+
reportConsoleEvent(event({ ok: false, reason: "Package is in use" }));
|
|
65
|
+
expect(sink.mock.calls[0][0]).toMatchObject({
|
|
66
|
+
ok: false,
|
|
67
|
+
reason: "Package is in use",
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The wrapper both shapes of Console write go through. Its contract is that
|
|
74
|
+
* nothing downstream can tell it is there: same value out, same rejection out,
|
|
75
|
+
* and an event either way.
|
|
76
|
+
*/
|
|
77
|
+
describe("reporting()", () => {
|
|
78
|
+
afterEach(() => setConsoleEventHandler(undefined));
|
|
79
|
+
|
|
80
|
+
it("returns the write's own value and reports a success", async () => {
|
|
81
|
+
const seen: ConsoleEvent[] = [];
|
|
82
|
+
setConsoleEventHandler((e) => seen.push(e));
|
|
83
|
+
const write = reporting("connection", "create", async (name: string) => ({
|
|
84
|
+
created: name,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
expect(await write("bigquery")).toEqual({ created: "bigquery" });
|
|
88
|
+
expect(seen).toHaveLength(1);
|
|
89
|
+
expect(seen[0]).toMatchObject({
|
|
90
|
+
resource: "connection",
|
|
91
|
+
action: "create",
|
|
92
|
+
ok: true,
|
|
93
|
+
});
|
|
94
|
+
expect(typeof seen[0].durationMs).toBe("number");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("re-throws the write's own error, unchanged, and reports the failure", async () => {
|
|
98
|
+
const seen: ConsoleEvent[] = [];
|
|
99
|
+
setConsoleEventHandler((e) => seen.push(e));
|
|
100
|
+
const boom = new Error("Connection is in use");
|
|
101
|
+
// Takes a variable like the real delete does, so the call below is the
|
|
102
|
+
// shape a caller actually uses.
|
|
103
|
+
const write = reporting("connection", "delete", async (_name: string) => {
|
|
104
|
+
throw boom;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// The SAME error object: a caller that matches on it must still match.
|
|
108
|
+
await expect(write("bigquery")).rejects.toBe(boom);
|
|
109
|
+
expect(seen).toHaveLength(1);
|
|
110
|
+
expect(seen[0]).toMatchObject({
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: "Connection is in use",
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("reports a rejection that is not an Error without inventing a message", async () => {
|
|
117
|
+
const seen: ConsoleEvent[] = [];
|
|
118
|
+
setConsoleEventHandler((e) => seen.push(e));
|
|
119
|
+
const write = reporting("package", "update", async (_name: string) => {
|
|
120
|
+
throw "a bare string";
|
|
121
|
+
});
|
|
122
|
+
await expect(write("storefront")).rejects.toBe("a bare string");
|
|
123
|
+
expect(seen[0].reason).toBe("An unknown error occurred");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("is transparent when no sink is installed", async () => {
|
|
127
|
+
const write = reporting("scope", "update", async (n: number) => n * 2);
|
|
128
|
+
expect(await write(21)).toBe(42);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What the Console reports about the things it CHANGES.
|
|
6
|
+
*
|
|
7
|
+
* The dashboard surfaces already report themselves through `DashboardEvent`,
|
|
8
|
+
* which the host wires per surface because each one is mounted with a
|
|
9
|
+
* dashboard's name. The Console's writes are not like that: create, edit and
|
|
10
|
+
* delete for environments, packages, connections and materializations happen
|
|
11
|
+
* inside dialogs the host never mounts directly, and there is no seam to pass
|
|
12
|
+
* a handler down through. So the sink is set once, by the host, at boot.
|
|
13
|
+
*
|
|
14
|
+
* Until now those writes reported to a six-second snackbar and nothing else.
|
|
15
|
+
* There was no record that a package had been deleted, or that a delete had
|
|
16
|
+
* failed — the operations whose outcome someone is most likely to be asked
|
|
17
|
+
* about afterwards.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** The thing being written. */
|
|
21
|
+
export type ConsoleResource =
|
|
22
|
+
| "environment"
|
|
23
|
+
| "package"
|
|
24
|
+
| "connection"
|
|
25
|
+
| "materialization"
|
|
26
|
+
| "schedule"
|
|
27
|
+
| "scope";
|
|
28
|
+
|
|
29
|
+
export type ConsoleEvent = {
|
|
30
|
+
type: "console.mutation";
|
|
31
|
+
resource: ConsoleResource;
|
|
32
|
+
/** What was done to it. */
|
|
33
|
+
action: "create" | "update" | "delete";
|
|
34
|
+
ok: boolean;
|
|
35
|
+
durationMs: number;
|
|
36
|
+
/** Present when `ok` is false: the message the operator was shown. */
|
|
37
|
+
reason?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type ConsoleEventHandler = (event: ConsoleEvent) => void;
|
|
41
|
+
|
|
42
|
+
let handler: ConsoleEventHandler | undefined;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Install the host's sink. Called once at boot; called again, it replaces.
|
|
46
|
+
* Passing `undefined` removes it, which is what a test wants between cases.
|
|
47
|
+
*/
|
|
48
|
+
export function setConsoleEventHandler(
|
|
49
|
+
next: ConsoleEventHandler | undefined,
|
|
50
|
+
): void {
|
|
51
|
+
handler = next;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Report one event, if anyone is listening.
|
|
56
|
+
*
|
|
57
|
+
* Never throws, and never lets a sink's own failure reach the caller: this is
|
|
58
|
+
* called from the success and error paths of a write, and a telemetry bug that
|
|
59
|
+
* turned a successful delete into a visible error would be worse than the
|
|
60
|
+
* missing line it is reporting.
|
|
61
|
+
*/
|
|
62
|
+
export function reportConsoleEvent(event: ConsoleEvent): void {
|
|
63
|
+
if (!handler) return;
|
|
64
|
+
try {
|
|
65
|
+
handler(event);
|
|
66
|
+
} catch {
|
|
67
|
+
// A sink that throws is the sink's problem, not the write's.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Wrap a mutation's function so it reports itself.
|
|
73
|
+
*
|
|
74
|
+
* The write that reports is the `mutationFn`, not the hook around it, because
|
|
75
|
+
* the Console has two shapes of write and only one of them fits a shared hook.
|
|
76
|
+
* The CRUD dialogs each own a mutation, a snackbar and a dialog to close, and
|
|
77
|
+
* {@link useCrudMutation} holds all three. Connections and Materializations do
|
|
78
|
+
* not: they `mutateAsync` from a caller that awaits the promise, and share one
|
|
79
|
+
* snackbar across several mutations at the component level. Forcing those onto
|
|
80
|
+
* the dialog hook would mean giving them a snackbar each and a dialog to close
|
|
81
|
+
* that they do not have.
|
|
82
|
+
*
|
|
83
|
+
* Wrapping the function instead fits both, and reports the same event either
|
|
84
|
+
* way: it times what the caller actually waits on, it sees the rejection
|
|
85
|
+
* before any handler has turned it into a message, and it re-throws unchanged
|
|
86
|
+
* so nothing downstream can tell it is there.
|
|
87
|
+
*/
|
|
88
|
+
export function reporting<F extends (variables: never) => Promise<unknown>>(
|
|
89
|
+
resource: ConsoleResource,
|
|
90
|
+
action: ConsoleEvent["action"],
|
|
91
|
+
mutationFn: F,
|
|
92
|
+
): F {
|
|
93
|
+
// Returns the SAME function type it was given, so the mutation hook infers
|
|
94
|
+
// its variables from the wrapped function exactly as it did from the bare
|
|
95
|
+
// one. Re-declaring the signature with fresh type parameters broke that
|
|
96
|
+
// inference and collapsed the variables type to `void`.
|
|
97
|
+
return (async (variables: Parameters<F>[0]) => {
|
|
98
|
+
const startedAt = Date.now();
|
|
99
|
+
try {
|
|
100
|
+
const result = await mutationFn(variables);
|
|
101
|
+
reportConsoleEvent({
|
|
102
|
+
type: "console.mutation",
|
|
103
|
+
resource,
|
|
104
|
+
action,
|
|
105
|
+
ok: true,
|
|
106
|
+
durationMs: Date.now() - startedAt,
|
|
107
|
+
});
|
|
108
|
+
return result;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
reportConsoleEvent({
|
|
111
|
+
type: "console.mutation",
|
|
112
|
+
resource,
|
|
113
|
+
action,
|
|
114
|
+
ok: false,
|
|
115
|
+
durationMs: Date.now() - startedAt,
|
|
116
|
+
reason:
|
|
117
|
+
error instanceof Error
|
|
118
|
+
? error.message
|
|
119
|
+
: "An unknown error occurred",
|
|
120
|
+
});
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}) as F;
|
|
124
|
+
}
|
package/src/theme/defaults.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { PALETTE } from "../components/styles";
|
|
5
5
|
import type { Theme } from "./types";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* The categorical series, from the Console's own `PALETTE`.
|
|
9
|
+
*
|
|
10
|
+
* Ordered by separation rather than by hue: consecutive series are the ones a
|
|
11
|
+
* reader most needs to tell apart, so the sequence alternates warm and cool
|
|
12
|
+
* instead of walking the colour wheel and putting two greens side by side. The
|
|
13
|
+
* first three carry most charts.
|
|
14
|
+
*/
|
|
7
15
|
const DEFAULT_SERIES = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
PALETTE.blue,
|
|
17
|
+
PALETTE.orange,
|
|
18
|
+
PALETTE.emerald,
|
|
19
|
+
PALETTE.pink,
|
|
20
|
+
PALETTE.violet,
|
|
21
|
+
PALETTE.amber,
|
|
22
|
+
PALETTE.cyan,
|
|
23
|
+
PALETTE.lime,
|
|
16
24
|
];
|
|
17
25
|
|
|
18
26
|
const DEFAULT_FONT_FAMILY =
|
|
@@ -36,39 +44,42 @@ export const DEFAULT_THEME: Required<Theme> = {
|
|
|
36
44
|
dark: "#1e293b",
|
|
37
45
|
},
|
|
38
46
|
tableHeader: {
|
|
39
|
-
light: "#
|
|
47
|
+
light: "#475569",
|
|
40
48
|
dark: "#cbd5e1",
|
|
41
49
|
},
|
|
42
50
|
// Background of the table header row, independent of the
|
|
43
51
|
// tile (dashboard tile container) so the operator can theme
|
|
44
52
|
// the header band on its own.
|
|
45
53
|
tableHeaderBackground: {
|
|
46
|
-
light: "#
|
|
54
|
+
light: "#f8fafc",
|
|
47
55
|
dark: "#1e293b",
|
|
48
56
|
},
|
|
49
57
|
tableBody: {
|
|
50
|
-
light: "#
|
|
58
|
+
light: "#475569",
|
|
51
59
|
dark: "#e2e8f0",
|
|
52
60
|
},
|
|
53
61
|
// The padded container that wraps each chart / table in a
|
|
54
|
-
// dashboard. Light mode: a faint
|
|
55
|
-
//
|
|
62
|
+
// dashboard. Light mode: a faint recess off white; dark mode:
|
|
63
|
+
// page-outer slate.
|
|
64
|
+
//
|
|
65
|
+
// Neutral slate, not a tint. This was `#f5fafc`, a cyan-cast
|
|
66
|
+
// near-white left from the logo palette, and it was the most visible
|
|
67
|
+
// survivor of it: every dashboard on the server painted a pale blue
|
|
68
|
+
// panel behind its tiles, under charts that were no longer blue-green.
|
|
56
69
|
tile: {
|
|
57
|
-
light: "#
|
|
70
|
+
light: "#f8fafc",
|
|
58
71
|
dark: "#0f172a",
|
|
59
72
|
},
|
|
60
73
|
tileTitle: {
|
|
61
|
-
light: "#
|
|
74
|
+
light: "#475569",
|
|
62
75
|
dark: "#94a3b8",
|
|
63
76
|
},
|
|
64
|
-
// Saturated end of the choropleth / heatmap gradient. The
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// get a brand-coherent gradient instead of the renderer's
|
|
68
|
-
// hardcoded blue ramp.
|
|
77
|
+
// Saturated end of the choropleth / heatmap gradient. The renderer
|
|
78
|
+
// pairs this with a near-neutral low end. Matches the first series
|
|
79
|
+
// colour, so a map and a chart on one page ramp to the same hue.
|
|
69
80
|
mapColor: {
|
|
70
|
-
light:
|
|
71
|
-
dark:
|
|
81
|
+
light: PALETTE.blue,
|
|
82
|
+
dark: PALETTE.blue,
|
|
72
83
|
},
|
|
73
84
|
},
|
|
74
85
|
font: {
|
|
@@ -82,14 +82,19 @@ describe("resolveTheme cascade", () => {
|
|
|
82
82
|
it("exposes derived mode values (border, foreground, axisFaint)", () => {
|
|
83
83
|
const light = resolveTheme([], "light");
|
|
84
84
|
const dark = resolveTheme([], "dark");
|
|
85
|
-
|
|
85
|
+
// All on one slate ramp, in both modes: these are the chrome around
|
|
86
|
+
// the data, and a neutral with a colour cast in it reads as a failed
|
|
87
|
+
// attempt at whatever the data is painted in.
|
|
88
|
+
expect(light.border).toBe("1px solid #e2e8f0");
|
|
86
89
|
expect(dark.border).toBe("1px solid #334155");
|
|
87
|
-
expect(light.foreground).toBe("#
|
|
90
|
+
expect(light.foreground).toBe("#0f172a");
|
|
88
91
|
expect(dark.foreground).toBe("#e2e8f0");
|
|
89
|
-
expect(light.axisFaint).toBe("#
|
|
92
|
+
expect(light.axisFaint).toBe("#cbd5e1");
|
|
90
93
|
expect(dark.axisFaint).toBe("#475569");
|
|
91
|
-
expect(light.valueColor).toBe("#
|
|
94
|
+
expect(light.valueColor).toBe("#0f172a");
|
|
92
95
|
expect(dark.valueColor).toBe("#f1f5f9");
|
|
96
|
+
expect(light.pinnedBorder).toBe("1px solid #cbd5e1");
|
|
97
|
+
expect(dark.pinnedBorder).toBe("1px solid #475569");
|
|
93
98
|
});
|
|
94
99
|
|
|
95
100
|
it("drillLink is a link colour per mode, not a series colour", () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { PALETTE } from "../components/styles";
|
|
4
5
|
import { DEFAULT_THEME } from "./defaults";
|
|
5
6
|
import { PER_MODE_COLOR_KEYS, type PerModeColorKey } from "./keys";
|
|
6
7
|
import type { ResolvedTheme, Theme, ThemeMode } from "./types";
|
|
@@ -86,11 +87,13 @@ export function resolveTheme(
|
|
|
86
87
|
// v1; they're consistent borders / readable foreground text for
|
|
87
88
|
// each mode. If a user later asks to customise them, expose them
|
|
88
89
|
// on the schema and the editor and replace the literals below.
|
|
89
|
-
border: isDark ? "1px solid #334155" : "1px solid #
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
border: isDark ? "1px solid #334155" : "1px solid #e2e8f0",
|
|
91
|
+
// Slate, not the teal-cast `#daedf3` this was: a pinned table header
|
|
92
|
+
// outlined in a hue no longer anywhere else on the page.
|
|
93
|
+
pinnedBorder: isDark ? "1px solid #475569" : "1px solid #cbd5e1",
|
|
94
|
+
valueColor: isDark ? "#f1f5f9" : "#0f172a",
|
|
95
|
+
foreground: isDark ? "#e2e8f0" : "#0f172a",
|
|
96
|
+
axisFaint: isDark ? "#475569" : "#cbd5e1",
|
|
94
97
|
// Dashboard panel background (area BETWEEN tiles). Light keeps
|
|
95
98
|
// white so the page stays visually unchanged. Dark uses slate so
|
|
96
99
|
// the panel doesn't read as a bright box against the dark page
|
|
@@ -98,9 +101,10 @@ export function resolveTheme(
|
|
|
98
101
|
// panel stays neutral so a bold accent on the chart canvas
|
|
99
102
|
// doesn't bleed into the surrounding chrome.
|
|
100
103
|
dashboardRoot: isDark ? "#1e293b" : "#ffffff",
|
|
101
|
-
// Drill link hover
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
+
// Drill link hover: the palette's anchor blue, so a drill reads as the
|
|
105
|
+
// same affordance as every other primary action; dark lightens it for
|
|
106
|
+
// contrast on the slate panel.
|
|
107
|
+
drillLink: isDark ? "#60a5fa" : PALETTE.blue,
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/** SHA-256 of a string, hex — the `expectedHash` a dashboard write carries. */
|
|
5
|
+
export async function sha256Hex(text: string): Promise<string> {
|
|
6
|
+
const digest = await crypto.subtle.digest(
|
|
7
|
+
"SHA-256",
|
|
8
|
+
new TextEncoder().encode(text),
|
|
9
|
+
);
|
|
10
|
+
return Array.from(new Uint8Array(digest), (byte) =>
|
|
11
|
+
byte.toString(16).padStart(2, "0"),
|
|
12
|
+
).join("");
|
|
13
|
+
}
|
package/test/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Run them the usual way:
|
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
cd packages/sdk && bun test # whole package
|
|
16
|
-
cd packages/sdk && bun test src/components/given
|
|
16
|
+
cd packages/sdk && bun test ./src/components/given # one directory
|
|
17
17
|
cd packages/sdk && bun test -t "explicit false" # one test by name
|
|
18
18
|
```
|
|
19
19
|
|
package/test/serverProvider.tsx
CHANGED
|
@@ -25,10 +25,13 @@ export const TEST_SERVER = "http://localhost/api/v0";
|
|
|
25
25
|
* module. `ServerProvider` itself is stubbed alongside `useServer` because
|
|
26
26
|
* `components/index.ts` re-exports both, and the barrel is in the graph.
|
|
27
27
|
*/
|
|
28
|
-
export function mockServerProvider(
|
|
28
|
+
export function mockServerProvider(
|
|
29
|
+
apiClients: unknown,
|
|
30
|
+
context: Record<string, unknown> = {},
|
|
31
|
+
) {
|
|
29
32
|
mock.module("../src/components/ServerProvider", () => ({
|
|
30
33
|
ServerProvider: () => null,
|
|
31
|
-
useServer: () => ({ server: TEST_SERVER, apiClients }),
|
|
34
|
+
useServer: () => ({ server: TEST_SERVER, apiClients, ...context }),
|
|
32
35
|
}));
|
|
33
36
|
}
|
|
34
37
|
|