@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,120 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Box,
|
|
6
|
+
Paper,
|
|
7
|
+
Typography,
|
|
8
|
+
type SxProps,
|
|
9
|
+
type Theme,
|
|
10
|
+
} from "@mui/material";
|
|
11
|
+
import type { ReactNode } from "react";
|
|
12
|
+
import { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
|
|
13
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The card a dashboard tile sits in, and nothing else — so the builder, which
|
|
17
|
+
* draws a stand-in tile when it has no server to run one, draws the same card
|
|
18
|
+
* the reader does rather than restating its geometry.
|
|
19
|
+
*
|
|
20
|
+
* The instance theme's border, not MUI's `divider`: the renderer card's edge is
|
|
21
|
+
* this same value, and a card that agrees with the theme everywhere except its
|
|
22
|
+
* outline still reads as a different card. Radius stays on the host's
|
|
23
|
+
* `shape.borderRadius`, which the renderer card is pointed at too. The
|
|
24
|
+
* background is `theme.tile`, the value the renderer card paints — left unset,
|
|
25
|
+
* on a theme whose page is also white the composite tiles lost the tint that
|
|
26
|
+
* separates a card from the page while the single-query form kept it.
|
|
27
|
+
*
|
|
28
|
+
* `borderless` is `# borderless` on the view: the result with no card, which
|
|
29
|
+
* the renderer honours by dropping background, border, radius and most padding
|
|
30
|
+
* on its own `.dashboard-item`. Same here, so the tag reads the same on both
|
|
31
|
+
* forms.
|
|
32
|
+
*
|
|
33
|
+
* `overflow: hidden` and `minWidth: 0` are load-bearing for RESIZING, not
|
|
34
|
+
* tidiness: this card is a grid item, and a grid item that clips gets a
|
|
35
|
+
* minimum width of zero instead of its content's, which is what lets it
|
|
36
|
+
* narrow below the chart it holds so the renderer redraws the chart to fit.
|
|
37
|
+
* See the `minWidth: 0` note in `DashboardGrid` for the rest of that chain.
|
|
38
|
+
*/
|
|
39
|
+
export function TileCard({
|
|
40
|
+
borderless = false,
|
|
41
|
+
sx,
|
|
42
|
+
children,
|
|
43
|
+
}: {
|
|
44
|
+
borderless?: boolean;
|
|
45
|
+
sx?: SxProps<Theme>;
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}) {
|
|
48
|
+
const { theme } = usePublisherTheme();
|
|
49
|
+
return (
|
|
50
|
+
<Paper
|
|
51
|
+
elevation={0}
|
|
52
|
+
sx={[
|
|
53
|
+
{
|
|
54
|
+
border: borderless ? "none" : theme.border,
|
|
55
|
+
borderRadius: borderless ? 0 : 1,
|
|
56
|
+
background: borderless ? "none" : theme.tile,
|
|
57
|
+
overflow: "hidden",
|
|
58
|
+
minWidth: 0,
|
|
59
|
+
minHeight: 120,
|
|
60
|
+
p: borderless ? "12px 0" : `${DASHBOARD_CARD_PADDING_PX}px`,
|
|
61
|
+
},
|
|
62
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
63
|
+
]}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</Paper>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A tile's heading: its `# label`, and its `# subtitle` under it. In the
|
|
72
|
+
* instance theme's title colour and face, so a tile is titled the same
|
|
73
|
+
* whichever surface draws it.
|
|
74
|
+
*/
|
|
75
|
+
export function TileHeading({
|
|
76
|
+
title,
|
|
77
|
+
subtitle,
|
|
78
|
+
tooltip,
|
|
79
|
+
action,
|
|
80
|
+
}: {
|
|
81
|
+
title: string;
|
|
82
|
+
subtitle?: string;
|
|
83
|
+
/** What actually ran, kept reachable without being the heading. */
|
|
84
|
+
tooltip?: string;
|
|
85
|
+
/** A control on the heading's row, hard right — the tile's Explore button. */
|
|
86
|
+
action?: ReactNode;
|
|
87
|
+
}) {
|
|
88
|
+
const { theme } = usePublisherTheme();
|
|
89
|
+
return (
|
|
90
|
+
<Box sx={{ pb: 1.5, display: "flex", alignItems: "flex-start", gap: 1 }}>
|
|
91
|
+
<Box sx={{ minWidth: 0, flex: 1 }}>
|
|
92
|
+
<Typography
|
|
93
|
+
variant="subtitle2"
|
|
94
|
+
sx={{
|
|
95
|
+
fontWeight: 500,
|
|
96
|
+
color: theme.tileTitle,
|
|
97
|
+
fontFamily: theme.font.family,
|
|
98
|
+
}}
|
|
99
|
+
title={tooltip}
|
|
100
|
+
>
|
|
101
|
+
{title}
|
|
102
|
+
</Typography>
|
|
103
|
+
{subtitle !== undefined && (
|
|
104
|
+
<Typography
|
|
105
|
+
variant="caption"
|
|
106
|
+
sx={{
|
|
107
|
+
display: "block",
|
|
108
|
+
color: theme.tileTitle,
|
|
109
|
+
fontFamily: theme.font.family,
|
|
110
|
+
opacity: 0.8,
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
{subtitle}
|
|
114
|
+
</Typography>
|
|
115
|
+
)}
|
|
116
|
+
</Box>
|
|
117
|
+
{action}
|
|
118
|
+
</Box>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -94,7 +94,77 @@ describe("promoteMeasureRowToKpis", () => {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The row as the SERVER actually sends it. Every output field is a
|
|
99
|
+
* `dimension`; an aggregate is marked by the `calculation` token in its
|
|
100
|
+
* internal annotation. Captured from `order_items -> key_figures` on the
|
|
101
|
+
* storefront package, trimmed to what the promotion reads.
|
|
102
|
+
*/
|
|
103
|
+
const serverMeasureRow = () => ({
|
|
104
|
+
schema: {
|
|
105
|
+
fields: [
|
|
106
|
+
{
|
|
107
|
+
kind: "dimension",
|
|
108
|
+
name: "total_sales",
|
|
109
|
+
type: { kind: "number_type", subtype: "decimal" },
|
|
110
|
+
annotations: [
|
|
111
|
+
{ value: "#(doc) Total revenue\n" },
|
|
112
|
+
{ value: "# currency\n" },
|
|
113
|
+
{ value: '# label="Revenue"\n' },
|
|
114
|
+
{
|
|
115
|
+
value: '#(malloy) reference_id = "276f77be" calculation drill_expression { kind = field_reference name = total_sales }\n',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
kind: "dimension",
|
|
121
|
+
name: "order_count",
|
|
122
|
+
type: { kind: "number_type", subtype: "integer" },
|
|
123
|
+
annotations: [
|
|
124
|
+
{ value: '# label="Orders"\n' },
|
|
125
|
+
{
|
|
126
|
+
value: '#(malloy) reference_id = "97a73061" calculation drill_expression { kind = field_reference name = order_count }\n',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
data: measureRow().data,
|
|
133
|
+
annotations: [
|
|
134
|
+
{ value: "#(doc) Revenue and orders\n" },
|
|
135
|
+
{ value: "#(malloy) source.name = order_items\n" },
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
|
|
97
139
|
describe("isMeasureRow", () => {
|
|
140
|
+
// The case that matters: real output. Until the aggregate marker was read,
|
|
141
|
+
// this returned false for every result the server ever produced, and the
|
|
142
|
+
// KPI strip drew as a one-row table whenever its view did not carry
|
|
143
|
+
// `# big_value` itself.
|
|
144
|
+
it("recognises the server's own shape, where aggregates are dimensions marked calculation", () => {
|
|
145
|
+
const row = serverMeasureRow();
|
|
146
|
+
expect(isMeasureRow(row)).toBe(true);
|
|
147
|
+
expect(
|
|
148
|
+
annotationsOf(promoteMeasureRowToKpis(JSON.stringify(row)))[0],
|
|
149
|
+
).toBe("# big_value\n");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("refuses a grouped result in the server's shape", () => {
|
|
153
|
+
const row = serverMeasureRow();
|
|
154
|
+
row.schema.fields.unshift({
|
|
155
|
+
kind: "dimension",
|
|
156
|
+
name: "category",
|
|
157
|
+
type: { kind: "string_type", subtype: "text" },
|
|
158
|
+
annotations: [
|
|
159
|
+
{ value: '# label="Category"\n' },
|
|
160
|
+
{
|
|
161
|
+
value: '#(malloy) reference_id = "4d02e53c" drill_expression { kind = field_reference name = category }\n',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
expect(isMeasureRow(row)).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
|
|
98
168
|
it("accepts a single record cell as well as a one-element array", () => {
|
|
99
169
|
const row = measureRow();
|
|
100
170
|
expect(isMeasureRow(row)).toBe(true);
|
|
@@ -50,12 +50,43 @@ const RENDER_TAGS = new Set([
|
|
|
50
50
|
|
|
51
51
|
const BIG_VALUE_ANNOTATION = { value: "# big_value\n" };
|
|
52
52
|
|
|
53
|
+
interface ResultField {
|
|
54
|
+
kind?: string;
|
|
55
|
+
annotations?: Array<{ value?: string }>;
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
interface ResultShape {
|
|
54
|
-
schema?: { fields?:
|
|
59
|
+
schema?: { fields?: ResultField[] };
|
|
55
60
|
data?: { kind?: string; array_value?: unknown[] };
|
|
56
61
|
annotations?: Array<{ value?: string }>;
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Whether an output field is an aggregate.
|
|
66
|
+
*
|
|
67
|
+
* Measured against the server: every output field of a query comes back
|
|
68
|
+
* `kind: "dimension"` — a result's columns are its dimensions, whatever they
|
|
69
|
+
* were in the source — and what marks an aggregate is the `calculation` token
|
|
70
|
+
* in the field's internal annotation:
|
|
71
|
+
*
|
|
72
|
+
* #(malloy) reference_id = "…" calculation drill_expression { … }
|
|
73
|
+
*
|
|
74
|
+
* `kind === "measure"` is kept for a renderer that says so directly, but no
|
|
75
|
+
* real result has yet. Until this read the annotation the promotion never
|
|
76
|
+
* fired on real output, and only its own fixture — written with `"measure"` —
|
|
77
|
+
* ever passed it.
|
|
78
|
+
*/
|
|
79
|
+
const MALLOY_CALCULATION = /^#\(malloy\)[\s\S]*\bcalculation\b/;
|
|
80
|
+
function isMeasureField(field: ResultField | undefined): boolean {
|
|
81
|
+
if (!field) return false;
|
|
82
|
+
if (field.kind === "measure") return true;
|
|
83
|
+
return (field.annotations ?? []).some(
|
|
84
|
+
(annotation) =>
|
|
85
|
+
typeof annotation?.value === "string" &&
|
|
86
|
+
MALLOY_CALCULATION.test(annotation.value.trim()),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
59
90
|
/**
|
|
60
91
|
* True when the result is one row consisting solely of measures: the shape a
|
|
61
92
|
* `view: kpis is { aggregate: … }` tile produces.
|
|
@@ -63,7 +94,7 @@ interface ResultShape {
|
|
|
63
94
|
export function isMeasureRow(result: ResultShape): boolean {
|
|
64
95
|
const fields = result.schema?.fields;
|
|
65
96
|
if (!Array.isArray(fields) || fields.length === 0) return false;
|
|
66
|
-
if (!fields.every(
|
|
97
|
+
if (!fields.every(isMeasureField)) return false;
|
|
67
98
|
const data = result.data;
|
|
68
99
|
if (!data) return false;
|
|
69
100
|
if (data.kind === "record_cell") return true;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a dashboard surface reports about itself, for the host to log or
|
|
6
|
+
* count: the operations that matter (open, save, the rows behind a value,
|
|
7
|
+
* exploring a tile), each with its outcome and how long it took.
|
|
8
|
+
*
|
|
9
|
+
* Context-free on purpose — the host that mounted the surface knows which
|
|
10
|
+
* environment, package and dashboard it is, and adds that when it logs.
|
|
11
|
+
*/
|
|
12
|
+
export type DashboardEvent =
|
|
13
|
+
| {
|
|
14
|
+
type: "dashboard.opened";
|
|
15
|
+
/** The package file, or a draft the host had saved. */
|
|
16
|
+
from: "package" | "draft";
|
|
17
|
+
tiles: number;
|
|
18
|
+
durationMs: number;
|
|
19
|
+
}
|
|
20
|
+
| { type: "dashboard.open_refused"; reason: string }
|
|
21
|
+
| {
|
|
22
|
+
type: "dashboard.saved";
|
|
23
|
+
tiles: number;
|
|
24
|
+
/** Whether a tile was added or removed, which moves declarations. */
|
|
25
|
+
structural: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Where it went. A save into the package is a change every reader of
|
|
28
|
+
* that server sees; a browser save is one person's copy on one
|
|
29
|
+
* machine. Counting them together makes "dashboards are being edited"
|
|
30
|
+
* unreadable, because a read-only server reports exactly as much
|
|
31
|
+
* saving as a writable one.
|
|
32
|
+
*/
|
|
33
|
+
where: "package" | "browser";
|
|
34
|
+
durationMs: number;
|
|
35
|
+
}
|
|
36
|
+
| { type: "dashboard.save_refused"; reason: string }
|
|
37
|
+
| {
|
|
38
|
+
type: "dashboard.rows_shown";
|
|
39
|
+
source: string;
|
|
40
|
+
view: string;
|
|
41
|
+
field: string;
|
|
42
|
+
ok: boolean;
|
|
43
|
+
durationMs: number;
|
|
44
|
+
}
|
|
45
|
+
| { type: "dashboard.explored"; tile: string };
|
|
46
|
+
|
|
47
|
+
export type DashboardEventHandler = (event: DashboardEvent) => void;
|
|
48
|
+
|
|
49
|
+
/** A monotonic clock in milliseconds, for durations. */
|
|
50
|
+
export const now = (): number =>
|
|
51
|
+
typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
-
import { tileGridColumn } from "./
|
|
5
|
+
import { tileGridColumn } from "./DashboardGrid";
|
|
6
6
|
|
|
7
7
|
describe("tileGridColumn", () => {
|
|
8
8
|
it("spans one column when the view carries no colspan", () => {
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Box,
|
|
6
|
+
Button,
|
|
7
|
+
Chip,
|
|
8
|
+
List,
|
|
9
|
+
ListItemButton,
|
|
10
|
+
ListItemText,
|
|
11
|
+
MenuItem,
|
|
12
|
+
Stack,
|
|
13
|
+
TextField,
|
|
14
|
+
Typography,
|
|
15
|
+
} from "@mui/material";
|
|
16
|
+
import { useEffect, useMemo, useState } from "react";
|
|
17
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
18
|
+
import type { CatalogSource, PackageCatalog } from "./catalog";
|
|
19
|
+
import type { DashboardDocument } from "./document";
|
|
20
|
+
import { AppDialog } from "../AppDialog";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What a new tile is: a view, picked from the package, on a source this file
|
|
24
|
+
* can reach.
|
|
25
|
+
*
|
|
26
|
+
* The picker is what makes a tile expression correct BY CONSTRUCTION. Every
|
|
27
|
+
* `source -> view` it offers came from the catalog, so the builder never emits
|
|
28
|
+
* a tile that does not resolve — which is why saving needs no compile step
|
|
29
|
+
* beyond the reader's own round-trip.
|
|
30
|
+
*
|
|
31
|
+
* "Can reach" is the rule the writer enforces and the reason some sources are
|
|
32
|
+
* not offered: a tile's view is declared in an extension of a model source, and
|
|
33
|
+
* that source has to be in this file's scope. The builder never adds an
|
|
34
|
+
* import, so a model source is offered only when the file already extends it,
|
|
35
|
+
* or imports it BY NAME. A bare `import "../m.malloy"` may well bring it in,
|
|
36
|
+
* but the file cannot say so, and a guess here fails the whole package load.
|
|
37
|
+
*/
|
|
38
|
+
export interface NewTile {
|
|
39
|
+
/** The model source the view lives on. */
|
|
40
|
+
base: string;
|
|
41
|
+
/** The view, as the catalog names it. */
|
|
42
|
+
view: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
colspan: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AddTileDialogProps {
|
|
48
|
+
open: boolean;
|
|
49
|
+
document: DashboardDocument;
|
|
50
|
+
catalog: PackageCatalog | undefined;
|
|
51
|
+
columns: number;
|
|
52
|
+
onClose: () => void;
|
|
53
|
+
onAdd: (tile: NewTile) => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The catalog sources this file can put a tile on; see the note above. */
|
|
57
|
+
function reachableSources(
|
|
58
|
+
document: DashboardDocument,
|
|
59
|
+
catalog: PackageCatalog | undefined,
|
|
60
|
+
): CatalogSource[] {
|
|
61
|
+
if (!catalog) return [];
|
|
62
|
+
const reachable = new Set<string>();
|
|
63
|
+
for (const source of document.sources) reachable.add(source.base);
|
|
64
|
+
for (const imported of document.imports)
|
|
65
|
+
if (imported.kind === "names")
|
|
66
|
+
for (const name of imported.names) reachable.add(name);
|
|
67
|
+
return catalog.sources.filter((source) => reachable.has(source.name));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function AddTileDialog({
|
|
71
|
+
open,
|
|
72
|
+
document,
|
|
73
|
+
catalog,
|
|
74
|
+
columns,
|
|
75
|
+
onClose,
|
|
76
|
+
onAdd,
|
|
77
|
+
}: AddTileDialogProps) {
|
|
78
|
+
const { theme } = usePublisherTheme();
|
|
79
|
+
const sources = useMemo(
|
|
80
|
+
() => reachableSources(document, catalog),
|
|
81
|
+
[document, catalog],
|
|
82
|
+
);
|
|
83
|
+
const [base, setBase] = useState<string>("");
|
|
84
|
+
const [view, setView] = useState<string>("");
|
|
85
|
+
const [label, setLabel] = useState("");
|
|
86
|
+
const [colspan, setColspan] = useState<number>(Math.ceil(columns / 2));
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!open) return;
|
|
90
|
+
// Open on the source the tiles already read, so the common case is one
|
|
91
|
+
// click on a view.
|
|
92
|
+
setBase(document.sources[0]?.base ?? sources[0]?.name ?? "");
|
|
93
|
+
setView("");
|
|
94
|
+
setLabel("");
|
|
95
|
+
setColspan(Math.ceil(columns / 2));
|
|
96
|
+
}, [open, document, sources, columns]);
|
|
97
|
+
|
|
98
|
+
const source = sources.find((s) => s.name === base);
|
|
99
|
+
const canAdd = base !== "" && view !== "";
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<AppDialog
|
|
103
|
+
open={open}
|
|
104
|
+
onClose={onClose}
|
|
105
|
+
title="Add a tile"
|
|
106
|
+
description="A tile shows one view of one source this dashboard imports."
|
|
107
|
+
actions={
|
|
108
|
+
<>
|
|
109
|
+
<Button onClick={onClose}>Cancel</Button>
|
|
110
|
+
<Button
|
|
111
|
+
variant="contained"
|
|
112
|
+
disabled={!canAdd}
|
|
113
|
+
onClick={() =>
|
|
114
|
+
onAdd({
|
|
115
|
+
base,
|
|
116
|
+
view,
|
|
117
|
+
...(label.trim() ? { label: label.trim() } : {}),
|
|
118
|
+
colspan,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
>
|
|
122
|
+
Add tile
|
|
123
|
+
</Button>
|
|
124
|
+
</>
|
|
125
|
+
}
|
|
126
|
+
>
|
|
127
|
+
<Stack sx={{ gap: 2, pt: 1 }}>
|
|
128
|
+
{sources.length === 0 ? (
|
|
129
|
+
<Typography variant="body2" sx={{ color: theme.tileTitle }}>
|
|
130
|
+
{catalog
|
|
131
|
+
? "This dashboard imports no source by name, so there is nothing to put a tile on. Import a source in the file first."
|
|
132
|
+
: "The package's sources are still loading."}
|
|
133
|
+
</Typography>
|
|
134
|
+
) : (
|
|
135
|
+
<>
|
|
136
|
+
<TextField
|
|
137
|
+
select
|
|
138
|
+
size="small"
|
|
139
|
+
label="Source"
|
|
140
|
+
value={base}
|
|
141
|
+
onChange={(event) => {
|
|
142
|
+
setBase(event.target.value);
|
|
143
|
+
setView("");
|
|
144
|
+
}}
|
|
145
|
+
inputProps={{ "aria-label": "Source" }}
|
|
146
|
+
>
|
|
147
|
+
{sources.map((s) => (
|
|
148
|
+
<MenuItem key={s.name} value={s.name}>
|
|
149
|
+
{s.name}
|
|
150
|
+
{s.description && (
|
|
151
|
+
<Typography
|
|
152
|
+
component="span"
|
|
153
|
+
variant="caption"
|
|
154
|
+
sx={{ ml: 1, opacity: 0.6 }}
|
|
155
|
+
>
|
|
156
|
+
{s.description}
|
|
157
|
+
</Typography>
|
|
158
|
+
)}
|
|
159
|
+
</MenuItem>
|
|
160
|
+
))}
|
|
161
|
+
</TextField>
|
|
162
|
+
<Box>
|
|
163
|
+
<Typography variant="subtitle2" sx={{ mb: 0.5 }}>
|
|
164
|
+
View
|
|
165
|
+
</Typography>
|
|
166
|
+
<List
|
|
167
|
+
dense
|
|
168
|
+
disablePadding
|
|
169
|
+
aria-label="Views"
|
|
170
|
+
sx={{
|
|
171
|
+
maxHeight: 280,
|
|
172
|
+
overflowY: "auto",
|
|
173
|
+
border: theme.border,
|
|
174
|
+
borderRadius: 1,
|
|
175
|
+
}}
|
|
176
|
+
>
|
|
177
|
+
{(source?.views ?? []).map((v) => (
|
|
178
|
+
<ListItemButton
|
|
179
|
+
key={v.name}
|
|
180
|
+
selected={view === v.name}
|
|
181
|
+
onClick={() => setView(v.name)}
|
|
182
|
+
aria-label={`View ${v.name}`}
|
|
183
|
+
>
|
|
184
|
+
<ListItemText
|
|
185
|
+
primary={v.name}
|
|
186
|
+
secondary={v.description}
|
|
187
|
+
primaryTypographyProps={{
|
|
188
|
+
fontFamily: "ui-monospace, monospace",
|
|
189
|
+
fontSize: 13,
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
{v.chart && (
|
|
193
|
+
<Chip
|
|
194
|
+
size="small"
|
|
195
|
+
variant="outlined"
|
|
196
|
+
label={v.chart.replace(/_chart$/, "")}
|
|
197
|
+
/>
|
|
198
|
+
)}
|
|
199
|
+
</ListItemButton>
|
|
200
|
+
))}
|
|
201
|
+
{source && source.views.length === 0 && (
|
|
202
|
+
<Typography
|
|
203
|
+
variant="body2"
|
|
204
|
+
sx={{ p: 1.5, color: theme.tileTitle }}
|
|
205
|
+
>
|
|
206
|
+
This source declares no views.
|
|
207
|
+
</Typography>
|
|
208
|
+
)}
|
|
209
|
+
</List>
|
|
210
|
+
</Box>
|
|
211
|
+
<Stack direction="row" sx={{ gap: 1.5 }}>
|
|
212
|
+
<TextField
|
|
213
|
+
size="small"
|
|
214
|
+
label="Title"
|
|
215
|
+
placeholder="Uses the view's name"
|
|
216
|
+
value={label}
|
|
217
|
+
onChange={(event) => setLabel(event.target.value)}
|
|
218
|
+
inputProps={{ "aria-label": "Tile title" }}
|
|
219
|
+
sx={{ flex: 1 }}
|
|
220
|
+
/>
|
|
221
|
+
<TextField
|
|
222
|
+
size="small"
|
|
223
|
+
type="number"
|
|
224
|
+
label={`Width (of ${columns})`}
|
|
225
|
+
value={colspan}
|
|
226
|
+
onChange={(event) =>
|
|
227
|
+
setColspan(
|
|
228
|
+
Math.min(
|
|
229
|
+
Math.max(Number(event.target.value) || 1, 1),
|
|
230
|
+
columns,
|
|
231
|
+
),
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
inputProps={{
|
|
235
|
+
min: 1,
|
|
236
|
+
max: columns,
|
|
237
|
+
"aria-label": "Tile width",
|
|
238
|
+
}}
|
|
239
|
+
sx={{ width: 140 }}
|
|
240
|
+
/>
|
|
241
|
+
</Stack>
|
|
242
|
+
</>
|
|
243
|
+
)}
|
|
244
|
+
</Stack>
|
|
245
|
+
</AppDialog>
|
|
246
|
+
);
|
|
247
|
+
}
|