@malloy-publisher/sdk 0.3.0 → 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.
- package/README.md +22 -9
- package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
- package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
- package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9482 -0
- package/dist/builder-entry.d.ts +8 -0
- 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/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +48 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -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/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/buttons.d.ts +53 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +6 -0
- package/dist/components/styles.d.ts +49 -44
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +22 -273
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +16888 -44451
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- 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/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- package/src/components/Dashboard/telemetry.ts +51 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +16 -62
- 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/FloatingIconButton.tsx +41 -0
- 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/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- 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 +179 -238
- package/src/components/Package/index.ts +0 -1
- package/src/components/PackageSection.tsx +85 -0
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- package/src/components/RenderedResult/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- 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/drill/index.ts +1 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +16 -0
- package/src/components/styles.ts +49 -122
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -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/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.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,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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -4,17 +4,11 @@
|
|
|
4
4
|
import "@malloydata/malloy-explorer/styles.css";
|
|
5
5
|
import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
|
|
6
6
|
import SearchIcon from "@mui/icons-material/Search";
|
|
7
|
-
import {
|
|
8
|
-
Box,
|
|
9
|
-
IconButton,
|
|
10
|
-
Snackbar,
|
|
11
|
-
Stack,
|
|
12
|
-
Tooltip,
|
|
13
|
-
Typography,
|
|
14
|
-
} from "@mui/material";
|
|
7
|
+
import { Box, Snackbar, Stack, Tooltip, Typography } from "@mui/material";
|
|
15
8
|
import React, { useState } from "react";
|
|
16
9
|
import { parseResourceUri } from "../../utils/formatting";
|
|
17
10
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
11
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
18
12
|
import { Loading } from "../Loading";
|
|
19
13
|
import { ModelCell } from "./ModelCell";
|
|
20
14
|
import { ModelExplorer } from "./ModelExplorer";
|
|
@@ -151,29 +145,18 @@ export default function Model({
|
|
|
151
145
|
/>
|
|
152
146
|
|
|
153
147
|
{/* Magnifying glass icon */}
|
|
154
|
-
<
|
|
148
|
+
<FloatingIconButton
|
|
149
|
+
aria-label="Expand results"
|
|
155
150
|
sx={{
|
|
156
151
|
position: "absolute",
|
|
157
152
|
top: "90px",
|
|
158
153
|
right: "4px",
|
|
159
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
160
|
-
"&:hover": {
|
|
161
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
162
|
-
},
|
|
163
|
-
width: "32px",
|
|
164
|
-
height: "32px",
|
|
165
154
|
zIndex: 2,
|
|
166
155
|
}}
|
|
167
156
|
onClick={() => setDialogOpen(true)}
|
|
168
157
|
>
|
|
169
|
-
<SearchIcon
|
|
170
|
-
|
|
171
|
-
fontSize: "18px",
|
|
172
|
-
color: "text.secondary",
|
|
173
|
-
marginBottom: "5px",
|
|
174
|
-
}}
|
|
175
|
-
/>
|
|
176
|
-
</IconButton>
|
|
158
|
+
<SearchIcon />
|
|
159
|
+
</FloatingIconButton>
|
|
177
160
|
</Stack>
|
|
178
161
|
)}
|
|
179
162
|
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
|
|
5
5
|
import SearchIcon from "@mui/icons-material/Search";
|
|
6
|
-
import { Box, Button,
|
|
6
|
+
import { Box, Button, Typography } from "@mui/material";
|
|
7
7
|
import React, { useEffect } from "react";
|
|
8
|
-
import {
|
|
8
|
+
import { useQueryResult } from "../../hooks/useQueryResult";
|
|
9
9
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
10
10
|
import { parseResourceUri } from "../../utils/formatting";
|
|
11
|
-
import {
|
|
11
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
12
12
|
import { highlight } from "../highlighter";
|
|
13
|
-
import
|
|
13
|
+
import { ResultPanel } from "../RenderedResult/ResultPanel";
|
|
14
14
|
import { MODEL_CELL_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
15
15
|
import ResultsDialog from "../ResultsDialog";
|
|
16
|
-
import {
|
|
17
|
-
import { CleanMetricCard, CleanNotebookCell } from "../styles";
|
|
16
|
+
import { CleanMetricCard } from "../styles";
|
|
18
17
|
|
|
19
18
|
interface ModelCellProps {
|
|
20
19
|
sourceName?: string;
|
|
@@ -40,29 +39,13 @@ export function ModelCell({
|
|
|
40
39
|
|
|
41
40
|
const { packageName, environmentName, versionId, modelPath } =
|
|
42
41
|
parseResourceUri(resourceUri);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
queryKey: ["namedQueryResult", resourceUri, queryName],
|
|
51
|
-
queryFn: () =>
|
|
52
|
-
apiClients.models.executeQueryModel(
|
|
53
|
-
environmentName,
|
|
54
|
-
packageName,
|
|
55
|
-
modelPath,
|
|
56
|
-
{
|
|
57
|
-
query: undefined,
|
|
58
|
-
sourceName: undefined,
|
|
59
|
-
queryName: queryName,
|
|
60
|
-
versionId: versionId,
|
|
61
|
-
},
|
|
62
|
-
),
|
|
63
|
-
enabled: runOnDemand ? hasRun : true, // Execute on demand or always
|
|
64
|
-
...CHART_RESULT_QUERY_OPTIONS,
|
|
65
|
-
});
|
|
42
|
+
// Run on demand or always; a query not yet asked for is not fetched.
|
|
43
|
+
const shouldRun = !runOnDemand || hasRun;
|
|
44
|
+
const state = useQueryResult(
|
|
45
|
+
{ environmentName, packageName, modelPath, versionId, queryName },
|
|
46
|
+
{ enabled: shouldRun },
|
|
47
|
+
);
|
|
48
|
+
const queryData = state.data;
|
|
66
49
|
|
|
67
50
|
const { mode } = usePublisherTheme();
|
|
68
51
|
useEffect(() => {
|
|
@@ -77,7 +60,7 @@ export function ModelCell({
|
|
|
77
60
|
}, [annotations, mode]);
|
|
78
61
|
|
|
79
62
|
return (
|
|
80
|
-
<
|
|
63
|
+
<Box>
|
|
81
64
|
{highlightedAnnotations && (
|
|
82
65
|
<Box sx={{ marginBottom: "16px" }}>
|
|
83
66
|
<Typography
|
|
@@ -110,29 +93,24 @@ export function ModelCell({
|
|
|
110
93
|
variant="body2"
|
|
111
94
|
sx={{
|
|
112
95
|
fontSize: "15px",
|
|
113
|
-
fontWeight:
|
|
114
|
-
color: "
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
96
|
+
fontWeight: 600,
|
|
97
|
+
color: "text.primary",
|
|
98
|
+
px: 2,
|
|
99
|
+
py: 1,
|
|
100
|
+
bgcolor: "action.hover",
|
|
101
|
+
borderRadius: 1.5,
|
|
102
|
+
border: 1,
|
|
103
|
+
borderColor: "divider",
|
|
119
104
|
}}
|
|
120
105
|
>
|
|
121
106
|
{queryName}
|
|
122
107
|
</Typography>
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
126
|
-
"&:hover": {
|
|
127
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
128
|
-
},
|
|
129
|
-
width: "32px",
|
|
130
|
-
height: "32px",
|
|
131
|
-
}}
|
|
108
|
+
<FloatingIconButton
|
|
109
|
+
aria-label="Expand results"
|
|
132
110
|
onClick={() => setResultsDialogOpen(true)}
|
|
133
111
|
>
|
|
134
|
-
<SearchIcon
|
|
135
|
-
</
|
|
112
|
+
<SearchIcon />
|
|
113
|
+
</FloatingIconButton>
|
|
136
114
|
</Box>
|
|
137
115
|
|
|
138
116
|
<CleanMetricCard
|
|
@@ -158,36 +136,19 @@ export function ModelCell({
|
|
|
158
136
|
variant="contained"
|
|
159
137
|
startIcon={<PlayArrowIcon />}
|
|
160
138
|
onClick={() => setHasRun(true)}
|
|
161
|
-
sx={{
|
|
162
|
-
backgroundColor: "#1976d2",
|
|
163
|
-
"&:hover": {
|
|
164
|
-
backgroundColor: "#1565c0",
|
|
165
|
-
},
|
|
166
|
-
textTransform: "none",
|
|
167
|
-
fontSize: "14px",
|
|
168
|
-
fontWeight: 600,
|
|
169
|
-
padding: "8px 24px",
|
|
170
|
-
}}
|
|
171
139
|
>
|
|
172
140
|
Run Query
|
|
173
141
|
</Button>
|
|
174
142
|
</Box>
|
|
175
143
|
)}
|
|
176
|
-
{
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
144
|
+
{shouldRun && (
|
|
145
|
+
<ResultPanel
|
|
146
|
+
state={state}
|
|
147
|
+
context={queryName}
|
|
148
|
+
maxHeight={MODEL_CELL_MAX_HEIGHT}
|
|
149
|
+
maxResultSize={maxResultSize}
|
|
150
|
+
/>
|
|
180
151
|
)}
|
|
181
|
-
{(!runOnDemand || hasRun) &&
|
|
182
|
-
isSuccess &&
|
|
183
|
-
queryData?.data?.result && (
|
|
184
|
-
<ResultContainer
|
|
185
|
-
result={queryData.data.result}
|
|
186
|
-
maxHeight={MODEL_CELL_MAX_HEIGHT}
|
|
187
|
-
maxResultSize={maxResultSize}
|
|
188
|
-
renderLogs={queryData.data.renderLogs}
|
|
189
|
-
/>
|
|
190
|
-
)}
|
|
191
152
|
</CleanMetricCard>
|
|
192
153
|
|
|
193
154
|
{/* Results Dialog */}
|
|
@@ -198,6 +159,6 @@ export function ModelCell({
|
|
|
198
159
|
renderLogs={queryData?.data?.renderLogs}
|
|
199
160
|
title={`Query: ${queryName}`}
|
|
200
161
|
/>
|
|
201
|
-
</
|
|
162
|
+
</Box>
|
|
202
163
|
);
|
|
203
164
|
}
|