@malloy-publisher/sdk 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +14 -9
  2. package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorageProvider-CyOJ0hqf.es.js} +7114 -6939
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-BnPzJ9Jf.es.js} +64 -57
  5. package/dist/{RenderedResult-CPi6uQWq.cjs.js → RenderedResult-Dp22kZsQ.cjs.js} +2 -2
  6. package/dist/{ServerProvider-X2Ma0HRs.es.js → ServerProvider-BWOEKg0O.es.js} +1217 -1244
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +41 -41
  9. package/dist/builder/index.es.js +2752 -2831
  10. package/dist/client/api.d.ts +100 -42
  11. package/dist/client/index.cjs.js +1 -1
  12. package/dist/client/index.es.js +1 -1
  13. package/dist/components/AppDialog.d.ts +30 -0
  14. package/dist/components/BackLink.d.ts +32 -0
  15. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  16. package/dist/components/Dashboard/telemetry.d.ts +10 -5
  17. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
  18. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +8 -2
  19. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +8 -10
  20. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  21. package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
  22. package/dist/components/ItemRow.d.ts +38 -0
  23. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  24. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  25. package/dist/components/Materializations/Materializations.d.ts +7 -3
  26. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  27. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  28. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  29. package/dist/components/Materializations/index.d.ts +0 -1
  30. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  31. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  32. package/dist/components/Package/index.d.ts +0 -1
  33. package/dist/components/PackageSection.d.ts +23 -0
  34. package/dist/components/buttons.d.ts +53 -0
  35. package/dist/components/index.d.ts +5 -0
  36. package/dist/components/styles.d.ts +49 -40
  37. package/dist/hooks/useCrudMutation.d.ts +42 -0
  38. package/dist/index.cjs.js +22 -26
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.es.js +17425 -20672
  41. package/dist/telemetry/consoleEvents.d.ts +60 -0
  42. package/dist/utils/sha256.d.ts +2 -0
  43. package/package.json +1 -1
  44. package/src/components/AppDialog.tsx +115 -0
  45. package/src/components/BackLink.tsx +83 -0
  46. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  47. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  48. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  49. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  50. package/src/components/Dashboard/telemetry.ts +10 -3
  51. package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
  52. package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
  53. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
  54. package/src/components/DashboardBuilder/DashboardBuilder.tsx +184 -171
  55. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  56. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
  57. package/src/components/DashboardBuilder/DashboardEditor.tsx +135 -61
  58. package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
  59. package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
  60. package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
  61. package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
  62. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  63. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  64. package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
  65. package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
  66. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
  67. package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
  68. package/src/components/Environment/About.tsx +14 -28
  69. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  70. package/src/components/Environment/Connections.tsx +125 -205
  71. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  72. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  73. package/src/components/Environment/Environment.tsx +34 -36
  74. package/src/components/Environment/Packages.tsx +63 -128
  75. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  76. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  77. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  78. package/src/components/Home/Home.tsx +101 -214
  79. package/src/components/ItemRow.tsx +165 -0
  80. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  81. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  82. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  83. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  84. package/src/components/Materializations/Materializations.tsx +137 -140
  85. package/src/components/Materializations/ScopeButton.tsx +85 -0
  86. package/src/components/Materializations/SectionLabel.tsx +7 -4
  87. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  88. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  89. package/src/components/Materializations/cron.spec.ts +113 -0
  90. package/src/components/Materializations/index.ts +0 -1
  91. package/src/components/Materializations/utils.spec.ts +182 -0
  92. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  93. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  94. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  95. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  96. package/src/components/Package/Package.tsx +179 -238
  97. package/src/components/Package/index.ts +0 -1
  98. package/src/components/PackageSection.tsx +85 -0
  99. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  100. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  101. package/src/components/ResultsDialog.tsx +8 -32
  102. package/src/components/buttons.tsx +114 -0
  103. package/src/components/designSystem.spec.tsx +316 -0
  104. package/src/components/given/paramCodec.spec.ts +1 -1
  105. package/src/components/index.ts +10 -0
  106. package/src/components/styles.ts +49 -85
  107. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  108. package/src/hooks/useCrudMutation.tsx +85 -0
  109. package/src/index.ts +9 -0
  110. package/src/telemetry/consoleEvents.spec.ts +130 -0
  111. package/src/telemetry/consoleEvents.ts +124 -0
  112. package/src/theme/defaults.ts +34 -23
  113. package/src/theme/resolveTheme.spec.ts +9 -4
  114. package/src/theme/resolveTheme.ts +12 -8
  115. package/src/utils/sha256.ts +13 -0
  116. package/test/README.md +1 -1
  117. package/test/serverProvider.tsx +5 -2
  118. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
  119. package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
  120. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  121. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  122. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  123. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  124. package/dist/components/Package/Models.d.ts +0 -6
  125. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  126. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  127. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  128. package/src/components/Materializations/TriggerChip.tsx +0 -44
  129. package/src/components/Package/Models.tsx +0 -71
@@ -3,36 +3,28 @@
3
3
 
4
4
  import AddIcon from "@mui/icons-material/Add";
5
5
  import CheckIcon from "@mui/icons-material/Check";
6
- import GridViewIcon from "@mui/icons-material/GridView";
7
6
  import TuneIcon from "@mui/icons-material/Tune";
8
7
  import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
9
8
  import RedoIcon from "@mui/icons-material/Redo";
10
9
  import UndoIcon from "@mui/icons-material/Undo";
11
- import {
12
- Button,
13
- Chip,
14
- Divider,
15
- IconButton,
16
- ListItemIcon,
17
- ListItemText,
18
- Menu,
19
- MenuItem,
20
- Stack,
21
- Tooltip,
22
- Typography,
23
- } from "@mui/material";
24
- import { useState, type ReactNode } from "react";
10
+ import { Button, Chip, Divider, IconButton, Tooltip } from "@mui/material";
11
+ import type { ReactNode } from "react";
25
12
  import { usePublisherTheme } from "../../theme/ThemeContext";
13
+ import { DashboardBar } from "../Dashboard/DashboardBar";
26
14
  import { MOD } from "./useBuilderShortcuts";
27
15
 
28
16
  /**
29
- * The edit bar across the top of the builder, in the shape every builder has
30
- * settled on: that you are editing on the left, what you can do about it on
31
- * the right.
17
+ * The edit bar across the top of the builder: that you are editing on the
18
+ * left, what you can do about it on the right, in the same {@link DashboardBar}
19
+ * the reader's view uses, so switching modes swaps the contents of one bar
20
+ * rather than replacing one bar with a different one.
32
21
  *
33
- * Sticky, so undo and save stay in reach on a long dashboard; the reader's own
34
- * header (title and description) stays in the page below it rather than being
35
- * repeated here.
22
+ * The right-hand controls are grouped by what they do, separated rather than
23
+ * run together: change the page (a tile, its settings), take a change back or
24
+ * put it down (undo, redo, save), and leave (Done, where the reader's view has
25
+ * Edit). Sticky, so undo and save stay in reach on a long dashboard; the
26
+ * reader's own header (title and description) stays in the page below it
27
+ * rather than being repeated here.
36
28
  */
37
29
  export interface BuilderToolbarProps {
38
30
  canUndo: boolean;
@@ -43,14 +35,12 @@ export interface BuilderToolbarProps {
43
35
  saving: boolean;
44
36
  /** Absent when the builder has nowhere to save: no Save, no unsaved marker. */
45
37
  onSave?: () => void;
46
- /** The host's actions, beside the builder's own: Export, Done. */
38
+ /** The host's way out of editing: Done, at the right edge. */
47
39
  actions?: ReactNode;
48
40
  /** Open the add-tile picker. Absent when the host passed no catalog to pick from. */
49
41
  onAddTile?: () => void;
50
42
  /** Open the page's settings, anchored to the button that asked. */
51
43
  onSettings: (anchor: HTMLElement) => void;
52
- /** Quick layout: every tile this file owns to one width. */
53
- onQuickLayout: (share: 1 | 2 | 3 | 4) => void;
54
44
  }
55
45
 
56
46
  export function BuilderToolbar({
@@ -64,207 +54,109 @@ export function BuilderToolbar({
64
54
  actions,
65
55
  onAddTile,
66
56
  onSettings,
67
- onQuickLayout,
68
57
  }: BuilderToolbarProps) {
69
58
  const { theme } = usePublisherTheme();
70
- const [layoutMenu, setLayoutMenu] = useState<HTMLElement | null>(null);
71
59
  return (
72
- <Stack
73
- direction="row"
74
- sx={{
75
- position: "sticky",
76
- top: 0,
77
- zIndex: 5,
78
- alignItems: "center",
79
- gap: 1,
80
- px: 1.5,
81
- py: 1,
82
- // Its own ground, so the tiles scrolling under it do not show
83
- // through, and an edge so it reads as a bar rather than a row.
84
- // The Publisher theme's ground and edge, like every other surface
85
- // here — MUI's own palette would not follow an instance theme or
86
- // its dark mode.
87
- bgcolor: theme.background,
88
- borderBottom: theme.border,
89
- borderRadius: 1,
90
- }}
60
+ <DashboardBar
61
+ left={
62
+ <Chip
63
+ // The app's theme makes every chip small; this one stands in a
64
+ // row of buttons, so it says otherwise and takes their height
65
+ // and type size. One size across the bar, or the state reads as
66
+ // a label that shrank away from the controls.
67
+ size="medium"
68
+ variant="outlined"
69
+ icon={<EditOutlinedIcon sx={{ fontSize: 20 }} />}
70
+ label="Editing"
71
+ sx={{
72
+ height: 37,
73
+ fontSize: "0.875rem",
74
+ fontWeight: 500,
75
+ // The app's own chip: the page's edge and its secondary
76
+ // text, not a filled blue badge borrowed from the drill
77
+ // link, which read as a notification rather than a state.
78
+ border: theme.border,
79
+ color: theme.tileTitle,
80
+ "& .MuiChip-icon": { color: "inherit" },
81
+ "& .MuiChip-label": { fontSize: "0.875rem" },
82
+ }}
83
+ />
84
+ }
91
85
  >
92
- <Chip
93
- size="small"
94
- icon={<EditOutlinedIcon sx={{ fontSize: 14 }} />}
95
- label="Editing"
96
- sx={{
97
- fontWeight: 500,
98
- bgcolor: theme.drillLink,
99
- color: theme.tile,
100
- "& .MuiChip-icon": { color: "inherit" },
101
- }}
102
- />
103
- <Typography
104
- variant="body2"
105
- sx={{
106
- color: theme.tileTitle,
107
- display: { xs: "none", md: "block" },
108
- }}
109
- >
110
- Drag a tile to move it, its right edge to resize it, or into the
111
- empty end of a row to move it up.
112
- </Typography>
113
-
114
- <Stack
115
- direction="row"
116
- sx={{
117
- ml: "auto",
118
- alignItems: "center",
119
- gap: 0.5,
120
- // The hint beside the chip is what gives way when the bar is
121
- // narrow; a button's label never wraps onto a second line.
122
- flexShrink: 0,
123
- "& .MuiButton-root": { whiteSpace: "nowrap" },
124
- }}
125
- >
126
- {onAddTile && (
127
- <Button
128
- size="small"
129
- startIcon={<AddIcon fontSize="small" />}
130
- onClick={onAddTile}
131
- >
132
- Add tile
133
- </Button>
134
- )}
86
+ {/* What the page is made of. */}
87
+ {onAddTile && (
135
88
  <Button
136
- size="small"
137
- startIcon={<GridViewIcon fontSize="small" />}
138
- onClick={(event) => setLayoutMenu(event.currentTarget)}
139
- aria-haspopup="menu"
89
+ startIcon={<AddIcon />}
90
+ onClick={onAddTile}
91
+ aria-label="Add tile"
140
92
  >
141
- Layout
93
+ Tile
142
94
  </Button>
143
- <Menu
144
- anchorEl={layoutMenu}
145
- open={layoutMenu !== null}
146
- onClose={() => setLayoutMenu(null)}
147
- >
148
- <Typography
149
- variant="caption"
150
- sx={{
151
- px: 2,
152
- py: 0.5,
153
- display: "block",
154
- color: theme.tileTitle,
155
- }}
95
+ )}
96
+ <Button
97
+ startIcon={<TuneIcon />}
98
+ onClick={(event) => onSettings(event.currentTarget)}
99
+ >
100
+ Settings
101
+ </Button>
102
+
103
+ {/* What happens to a change: take it back, or put it down. */}
104
+ <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
105
+ <Tooltip title={`Undo (${MOD}Z)`}>
106
+ {/* A span, because a disabled button dispatches no events and a
107
+ tooltip on one would never show. */}
108
+ <span>
109
+ <IconButton
110
+ aria-label="Undo"
111
+ disabled={!canUndo}
112
+ onClick={onUndo}
113
+ sx={{ width: 37, height: 37 }}
156
114
  >
157
- Set every tile to
158
- </Typography>
159
- {(
160
- [
161
- ["Full width", 1],
162
- ["Half width", 2],
163
- ["A third", 3],
164
- ["A quarter", 4],
165
- ] as const
166
- ).map(([label, share]) => (
167
- <MenuItem
168
- key={share}
169
- onClick={() => {
170
- setLayoutMenu(null);
171
- onQuickLayout(share);
172
- }}
173
- >
174
- <ListItemIcon>
175
- <GridViewIcon fontSize="small" />
176
- </ListItemIcon>
177
- <ListItemText>{label}</ListItemText>
178
- </MenuItem>
179
- ))}
180
- </Menu>
181
- <Button
182
- size="small"
183
- startIcon={<TuneIcon fontSize="small" />}
184
- onClick={(event) => onSettings(event.currentTarget)}
185
- >
186
- Settings
187
- </Button>
188
- {actions && (
189
- <>
190
- {actions}
191
- <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
192
- </>
193
- )}
194
- <Tooltip title={`Undo (${MOD}Z)`}>
195
- {/* A span, because a disabled button dispatches no events and a
196
- tooltip on one would never show. */}
197
- <span>
198
- <IconButton
199
- aria-label="Undo"
200
- size="small"
201
- disabled={!canUndo}
202
- onClick={onUndo}
203
- >
204
- <UndoIcon fontSize="small" />
205
- </IconButton>
206
- </span>
207
- </Tooltip>
208
- <Tooltip title={`Redo (${MOD}⇧Z)`}>
209
- <span>
210
- <IconButton
211
- aria-label="Redo"
212
- size="small"
213
- disabled={!canRedo}
214
- onClick={onRedo}
215
- >
216
- <RedoIcon fontSize="small" />
217
- </IconButton>
218
- </span>
219
- </Tooltip>
220
- {onSave && (
221
- <>
222
- <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
223
- {/* "Unsaved changes" beside Save: the button's label alone
224
- reads as a command, not as a state. */}
225
- <Typography
226
- variant="caption"
227
- aria-live="polite"
228
- sx={{
229
- color: theme.tileTitle,
230
- minWidth: 108,
231
- textAlign: "right",
232
- // Room between the state and the button that acts on
233
- // it: at the row's 4px gap the two read as one label.
234
- mr: 1.5,
235
- opacity: dirty && !saving ? 1 : 0,
236
- transition: "opacity 120ms",
237
- }}
238
- >
239
- Unsaved changes
240
- </Typography>
241
- <Tooltip title={dirty ? `Save (${MOD}S)` : ""}>
242
- <span>
243
- <Button
244
- variant={dirty ? "contained" : "outlined"}
245
- size="small"
246
- disabled={!dirty || saving}
247
- onClick={onSave}
248
- startIcon={
249
- !dirty && !saving ? (
250
- <CheckIcon fontSize="small" />
251
- ) : undefined
252
- }
253
- sx={{ minWidth: 124 }}
254
- >
255
- {/* Says what will happen, then that it is happening,
256
- then what did. */}
257
- {saving
258
- ? "Saving…"
259
- : dirty
260
- ? "Save changes"
261
- : "Saved"}
262
- </Button>
263
- </span>
264
- </Tooltip>
265
- </>
266
- )}
267
- </Stack>
268
- </Stack>
115
+ <UndoIcon fontSize="small" />
116
+ </IconButton>
117
+ </span>
118
+ </Tooltip>
119
+ <Tooltip title={`Redo (${MOD}⇧Z)`}>
120
+ <span>
121
+ <IconButton
122
+ aria-label="Redo"
123
+ disabled={!canRedo}
124
+ onClick={onRedo}
125
+ sx={{ width: 37, height: 37 }}
126
+ >
127
+ <RedoIcon fontSize="small" />
128
+ </IconButton>
129
+ </span>
130
+ </Tooltip>
131
+ {onSave && (
132
+ <>
133
+ <Tooltip title={dirty ? `Save (${MOD}S)` : ""}>
134
+ <span>
135
+ <Button
136
+ variant={dirty ? "contained" : "outlined"}
137
+ disabled={!dirty || saving}
138
+ onClick={onSave}
139
+ startIcon={
140
+ !dirty && !saving ? <CheckIcon /> : undefined
141
+ }
142
+ sx={{ minWidth: 124 }}
143
+ >
144
+ {/* Says what will happen, then that it is happening,
145
+ then what did. */}
146
+ {saving ? "Saving…" : dirty ? "Save changes" : "Saved"}
147
+ </Button>
148
+ </span>
149
+ </Tooltip>
150
+ </>
151
+ )}
152
+
153
+ {/* Leaving, where the reader's view has Edit. */}
154
+ {actions && (
155
+ <>
156
+ <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
157
+ {actions}
158
+ </>
159
+ )}
160
+ </DashboardBar>
269
161
  );
270
162
  }
@@ -625,17 +625,6 @@ describe("DashboardBuilder: widths and the page's own settings", () => {
625
625
  expect(itemStyleOf("by_brand")).toContain("grid-column: span 6");
626
626
  });
627
627
 
628
- it("lays every tile the file owns to one width, as one history entry", async () => {
629
- await mount();
630
- fireEvent.click(button("Layout"));
631
- fireEvent.click(screen.getByRole("menuitem", { name: "A quarter" }));
632
- expect(itemStyleOf("by_cat")).toContain("grid-column: span 3");
633
- expect(itemStyleOf("by_brand")).toContain("grid-column: span 3");
634
- fireEvent.click(button("Undo"));
635
- expect(itemStyleOf("by_cat")).toContain("grid-column: span 6");
636
- expect(itemStyleOf("by_brand")).toContain("grid-column: span 6");
637
- });
638
-
639
628
  it("edits the page's title, width and autorun, and writes them to the tag", async () => {
640
629
  let saved = "";
641
630
  await mount((source) => {
@@ -831,6 +820,11 @@ describe("DashboardBuilder: saving", () => {
831
820
  type: "dashboard.saved",
832
821
  tiles: 2,
833
822
  structural: false,
823
+ // Where it went: a save into the package is a change every reader of
824
+ // that server sees, and a browser save is one person's local copy.
825
+ // Reported, because the builder is handed a function and the two are
826
+ // indistinguishable from the outside.
827
+ where: "package",
834
828
  });
835
829
  });
836
830