@malloy-publisher/sdk 0.0.247 → 0.0.249

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 (98) hide show
  1. package/README.md +32 -17
  2. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  3. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  4. package/dist/client/api.d.ts +298 -7
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +74 -70
  7. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  9. package/dist/components/Dashboard/index.d.ts +2 -0
  10. package/dist/components/Notebook/Notebook.d.ts +46 -8
  11. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  12. package/dist/components/Notebook/runPlan.d.ts +29 -0
  13. package/dist/components/Notebook/types.d.ts +10 -0
  14. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  15. package/dist/components/Package/Package.d.ts +1 -4
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  18. package/dist/components/ResultsDialog.d.ts +4 -1
  19. package/dist/components/ServerProvider.d.ts +2 -1
  20. package/dist/components/click_helper.d.ts +10 -1
  21. package/dist/components/drill/index.d.ts +3 -0
  22. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  23. package/dist/components/drill/resolveDrill.d.ts +159 -0
  24. package/dist/components/drill/useDrill.d.ts +63 -0
  25. package/dist/components/given/GivenInput.d.ts +27 -3
  26. package/dist/components/given/GivensPanel.d.ts +36 -7
  27. package/dist/components/given/filterValue.d.ts +117 -0
  28. package/dist/components/given/index.d.ts +1 -1
  29. package/dist/components/given/paramCodec.d.ts +60 -0
  30. package/dist/components/index.d.ts +4 -1
  31. package/dist/components/styles.d.ts +23 -0
  32. package/dist/constants/docLinks.d.ts +6 -0
  33. package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
  34. package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
  35. package/dist/hooks/givenValue.d.ts +10 -0
  36. package/dist/hooks/index.d.ts +3 -1
  37. package/dist/hooks/useGivensState.d.ts +64 -0
  38. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  39. package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
  40. package/dist/index-CWQXhe0D.cjs.js +338 -0
  41. package/dist/index.cjs.js +1 -1
  42. package/dist/index.es.js +77 -62
  43. package/dist/theme/types.d.ts +9 -0
  44. package/package.json +3 -1
  45. package/src/components/Connections/AddConnectionDialog.tsx +10 -1
  46. package/src/components/Dashboard/Dashboard.tsx +395 -0
  47. package/src/components/Dashboard/DashboardTile.tsx +150 -0
  48. package/src/components/Dashboard/index.ts +2 -0
  49. package/src/components/Home/Home.tsx +114 -23
  50. package/src/components/Notebook/Notebook.tsx +444 -390
  51. package/src/components/Notebook/NotebookCell.tsx +117 -3
  52. package/src/components/Notebook/runPlan.spec.ts +152 -0
  53. package/src/components/Notebook/runPlan.ts +64 -0
  54. package/src/components/Notebook/types.ts +11 -0
  55. package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
  56. package/src/components/Package/ContentTypeIcon.tsx +77 -6
  57. package/src/components/Package/Package.tsx +148 -38
  58. package/src/components/RenderedResult/RenderedResult.tsx +309 -19
  59. package/src/components/RenderedResult/ResultContainer.tsx +28 -1
  60. package/src/components/ResultsDialog.tsx +5 -0
  61. package/src/components/ServerProvider.tsx +2 -0
  62. package/src/components/click_helper.ts +14 -1
  63. package/src/components/drill/index.ts +25 -0
  64. package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
  65. package/src/components/drill/markDrillableCells.spec.ts +106 -0
  66. package/src/components/drill/markDrillableCells.ts +311 -0
  67. package/src/components/drill/resolveDrill.spec.ts +446 -0
  68. package/src/components/drill/resolveDrill.ts +372 -0
  69. package/src/components/drill/useDrill.tsx +200 -0
  70. package/src/components/given/GivenInput.spec.tsx +495 -15
  71. package/src/components/given/GivenInput.tsx +562 -30
  72. package/src/components/given/GivensPanel.spec.tsx +172 -0
  73. package/src/components/given/GivensPanel.tsx +139 -32
  74. package/src/components/given/filterValue.spec.ts +361 -0
  75. package/src/components/given/filterValue.ts +204 -0
  76. package/src/components/given/index.ts +5 -1
  77. package/src/components/given/paramCodec.spec.ts +854 -0
  78. package/src/components/given/paramCodec.ts +480 -0
  79. package/src/components/index.ts +4 -1
  80. package/src/components/styles.ts +27 -3
  81. package/src/constants/docLinks.spec.ts +51 -0
  82. package/src/constants/docLinks.ts +26 -0
  83. package/src/hooks/givenValue.ts +10 -0
  84. package/src/hooks/index.ts +6 -4
  85. package/src/hooks/useGivensState.spec.ts +446 -0
  86. package/src/hooks/useGivensState.ts +337 -0
  87. package/src/hooks/useSuggestOptions.spec.ts +109 -0
  88. package/src/hooks/useSuggestOptions.ts +260 -0
  89. package/src/theme/buildTableCssVars.ts +4 -0
  90. package/src/theme/resolveTheme.spec.ts +13 -0
  91. package/src/theme/resolveTheme.ts +3 -0
  92. package/src/theme/types.ts +9 -0
  93. package/test/README.md +16 -10
  94. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  95. package/dist/hooks/useGivensForm.d.ts +0 -35
  96. package/dist/index-MES4MGpQ.cjs.js +0 -309
  97. package/src/hooks/useGivensForm.spec.ts +0 -99
  98. package/src/hooks/useGivensForm.ts +0 -107
@@ -22,28 +22,27 @@ import React, { useState } from "react";
22
22
  import { Database } from "../../client";
23
23
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
24
24
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
25
- import { RetrievalFunction } from "../filter/DimensionFilter";
26
25
  import { Loading } from "../Loading";
27
26
  import { Notebook } from "../Notebook";
28
27
  import { useServer } from "../ServerProvider";
29
28
  import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
30
29
  import { serverBaseUrl } from "../../utils/dataAppEmbed";
31
- import { MALLOY_BRAND, MONO_FONT_FAMILY } from "../styles";
32
- import ContentTypeIcon from "./ContentTypeIcon";
30
+ import { MONO_FONT_FAMILY } from "../styles";
31
+ import ContentTypeIcon, {
32
+ CONTENT_TINT,
33
+ type ContentType,
34
+ } from "./ContentTypeIcon";
33
35
 
34
36
  const README_NOTEBOOK = "README.malloynb";
35
37
 
36
38
  interface PackageProps {
37
39
  onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
38
40
  resourceUri: string;
39
- /** Optional retrieval function for semantic search filters */
40
- retrievalFn?: RetrievalFunction;
41
41
  }
42
42
 
43
43
  export default function Package({
44
44
  onClickPackageFile,
45
45
  resourceUri,
46
- retrievalFn,
47
46
  }: PackageProps) {
48
47
  const { apiClients, server } = useServer();
49
48
  const onClick =
@@ -128,11 +127,65 @@ export default function Package({
128
127
  });
129
128
  const dataApps = dataAppsQuery.data?.data ?? [];
130
129
 
130
+ // No versionId, for the same reason as data apps: the dashboards endpoint
131
+ // takes only env + package.
132
+ const dashboardsQuery = useQueryWithApiError({
133
+ queryKey: ["dashboards", environmentName, packageName],
134
+ queryFn: async () => {
135
+ try {
136
+ return await apiClients.dashboards.listDashboards(
137
+ environmentName,
138
+ packageName,
139
+ );
140
+ } catch (e) {
141
+ // Non-fatal for the same reasons as the data-apps list above: an
142
+ // older Publisher without the route should render a package page
143
+ // without a Dashboards section, not an error.
144
+ const status = (e as { response?: { status?: number } })?.response
145
+ ?.status;
146
+ if (status === 404 || status === undefined) {
147
+ return { data: [] } as Awaited<
148
+ ReturnType<typeof apiClients.dashboards.listDashboards>
149
+ >;
150
+ }
151
+ throw e;
152
+ }
153
+ },
154
+ });
155
+ // Sorted by the string the row actually SHOWS, not by the slug or the path
156
+ // underneath it. A list labelled by title and ordered by filename reads as
157
+ // unsorted: `overview` titled "Business Overview" sorts ahead of `regions`
158
+ // titled "Regional Sales". Notebooks acquired that mismatch here too, when
159
+ // they started being listed by title while still being ordered by path.
160
+ const dashboardLabel = (dashboard: { name?: string; title?: string }) =>
161
+ dashboard.title && dashboard.title !== dashboard.name
162
+ ? dashboard.title
163
+ : (dashboard.name ?? "");
164
+ const notebookLabel = (notebook: { path?: string; title?: string }) =>
165
+ notebook.title && notebook.title !== notebook.path
166
+ ? notebook.title
167
+ : (notebook.path ?? "");
168
+
169
+ const dashboards = (dashboardsQuery.data?.data ?? [])
170
+ .slice()
171
+ .sort((a, b) => dashboardLabel(a).localeCompare(dashboardLabel(b)));
172
+
131
173
  const notebooks = (notebooksQuery.data?.data ?? [])
132
174
  .slice()
133
- .sort((a, b) => a.path.localeCompare(b.path));
175
+ .sort((a, b) => notebookLabel(a).localeCompare(notebookLabel(b)));
176
+ // A dashboard is listed once, under Dashboards. Its file is a model like any
177
+ // other, so it would otherwise appear a second time under Semantic Models
178
+ // where clicking it opens the Explorer rather than the dashboard. Untagged
179
+ // shared includes in `dashboards/` are not dashboards and stay in the model
180
+ // list, which is where they belong.
181
+ const dashboardPaths = new Set(
182
+ dashboards
183
+ .map((dashboard) => dashboard.path)
184
+ .filter((path): path is string => path !== undefined),
185
+ );
134
186
  const models = (modelsQuery.data?.data ?? [])
135
187
  .slice()
188
+ .filter((model) => !dashboardPaths.has(model.path))
136
189
  .sort((a, b) => a.path.localeCompare(b.path));
137
190
  const databases = (databasesQuery.data?.data ?? [])
138
191
  .slice()
@@ -147,7 +200,16 @@ export default function Package({
147
200
  modelPath: README_NOTEBOOK,
148
201
  });
149
202
 
150
- const isLoading = !notebooksQuery.isSuccess && !notebooksQuery.isError;
203
+ // The dashboards list is part of the gate, not just the notebooks one,
204
+ // because the models list is FILTERED by it. Gated on notebooks alone, a
205
+ // dashboards call that resolves after the models call rendered the sections
206
+ // with an empty `dashboardPaths`, so `dashboards/overview.malloy` appeared
207
+ // under Semantic Models and then vanished: the double listing the filter
208
+ // exists to prevent, briefly on screen. It cannot hang the page: the query
209
+ // above turns a 404 or a transport failure into an empty list.
210
+ const isLoading =
211
+ (!notebooksQuery.isSuccess && !notebooksQuery.isError) ||
212
+ (!dashboardsQuery.isSuccess && !dashboardsQuery.isError);
151
213
 
152
214
  if (pkgQuery.isError) {
153
215
  return (
@@ -205,21 +267,66 @@ export default function Package({
205
267
 
206
268
  {!isLoading && (
207
269
  <>
270
+ {/* First: the at-a-glance artifact a visitor most likely wants,
271
+ ahead of the notebooks and models it is built on. Hidden when
272
+ empty, like Data Apps. */}
273
+ {dashboards.length > 0 && (
274
+ <PackageSection title="Dashboards" count={dashboards.length}>
275
+ {dashboards.map((dashboard) => {
276
+ // A title equal to the slug is what the server falls
277
+ // back to when the file names itself neither way, so
278
+ // showing both would print the same word twice.
279
+ const hasTitle =
280
+ !!dashboard.title &&
281
+ dashboard.title !== dashboard.name;
282
+ return (
283
+ <PackageItemRow
284
+ key={dashboard.name}
285
+ type="dashboard"
286
+ label={
287
+ hasTitle ? dashboard.title! : dashboard.name!
288
+ }
289
+ rightLabel={hasTitle ? dashboard.name : undefined}
290
+ onClick={(event) =>
291
+ onClick(
292
+ `/${environmentName}/${packageName}/dashboards/` +
293
+ // The slug comes from a filename, which
294
+ // can hold characters that would read as
295
+ // structure in a path. The server encodes
296
+ // it in `resource` for the same reason.
297
+ encodeURIComponent(dashboard.name ?? ""),
298
+ event,
299
+ )
300
+ }
301
+ />
302
+ );
303
+ })}
304
+ </PackageSection>
305
+ )}
306
+
208
307
  <PackageSection title="Notebooks" count={notebooks.length}>
209
- {notebooks.map((notebook) => (
210
- <PackageItemRow
211
- key={notebook.path}
212
- icon={<ContentTypeIcon type="report" />}
213
- tint={MALLOY_BRAND.teal}
214
- label={notebook.path}
215
- onClick={(event) =>
216
- onClick(
217
- `/${environmentName}/${packageName}/${notebook.path}`,
218
- event,
219
- )
220
- }
221
- />
222
- ))}
308
+ {notebooks.map((notebook) => {
309
+ // Named the way dashboards and data apps are: a notebook
310
+ // that titles itself is listed by that title, with the
311
+ // filename kept as the secondary label so the path a
312
+ // reader needs to find the file is never lost.
313
+ const hasTitle =
314
+ !!notebook.title && notebook.title !== notebook.path;
315
+ return (
316
+ <PackageItemRow
317
+ key={notebook.path}
318
+ type="report"
319
+ label={hasTitle ? notebook.title! : notebook.path}
320
+ rightLabel={hasTitle ? notebook.path : undefined}
321
+ onClick={(event) =>
322
+ onClick(
323
+ `/${environmentName}/${packageName}/${notebook.path}`,
324
+ event,
325
+ )
326
+ }
327
+ />
328
+ );
329
+ })}
223
330
  {notebooks.length === 0 && <EmptyRow label="No notebooks" />}
224
331
  </PackageSection>
225
332
 
@@ -239,8 +346,7 @@ export default function Package({
239
346
  return (
240
347
  <PackageItemRow
241
348
  key={dataApp.path}
242
- icon={<ContentTypeIcon type="dataApp" />}
243
- tint={MALLOY_BRAND.teal}
349
+ type="dataApp"
244
350
  label={hasTitle ? dataApp.title : dataApp.path}
245
351
  rightLabel={hasTitle ? dataApp.path : undefined}
246
352
  onClick={(event) => {
@@ -255,7 +361,7 @@ export default function Package({
255
361
  event,
256
362
  );
257
363
  } else {
258
- // No host app — navigate to standalone HTML.
364
+ // No host app: navigate to standalone HTML.
259
365
  if (
260
366
  event &&
261
367
  (event.metaKey || event.ctrlKey)
@@ -293,8 +399,7 @@ export default function Package({
293
399
  {models.map((model) => (
294
400
  <PackageItemRow
295
401
  key={model.path}
296
- icon={<ContentTypeIcon type="model" />}
297
- tint={MALLOY_BRAND.orange}
402
+ type="model"
298
403
  label={model.path}
299
404
  onClick={(event) =>
300
405
  onClick(
@@ -311,8 +416,7 @@ export default function Package({
311
416
  {databases.map((database) => (
312
417
  <PackageItemRow
313
418
  key={database.path}
314
- icon={<ContentTypeIcon type="data" />}
315
- tint={MALLOY_BRAND.darkBlue}
419
+ type="data"
316
420
  label={database.path}
317
421
  rightLabel={
318
422
  // A file the server could not probe is listed with
@@ -330,8 +434,7 @@ export default function Package({
330
434
 
331
435
  <PackageSection title="Materializations">
332
436
  <PackageItemRow
333
- icon={<ContentTypeIcon type="materialization" />}
334
- tint={MALLOY_BRAND.teal}
437
+ type="materialization"
335
438
  label="Materializations"
336
439
  onClick={(event) =>
337
440
  onClick(
@@ -346,7 +449,6 @@ export default function Package({
346
449
  <Box sx={{ mt: 6 }}>
347
450
  <Notebook
348
451
  resourceUri={readmeResourceUri}
349
- retrievalFn={retrievalFn}
350
452
  onNavigate={onClick}
351
453
  />
352
454
  </Box>
@@ -436,16 +538,24 @@ function PackageSection({
436
538
  );
437
539
  }
438
540
 
541
+ /**
542
+ * A row names its content type once. The glyph and the color behind it are two
543
+ * halves of one signal, so the row derives both rather than letting a caller
544
+ * pair a dashboard's icon with a model's color.
545
+ *
546
+ * That is not hypothetical tidying: with the two passed separately, four of the
547
+ * six rows on this page had been handed the same teal, so color told a reader
548
+ * nothing about four of the kinds it was there to distinguish. A rule each call
549
+ * site has to remember is a rule some call sites will forget.
550
+ */
439
551
  function PackageItemRow({
440
- icon,
441
- tint,
552
+ type,
442
553
  label,
443
554
  rightLabel,
444
555
  onClick,
445
556
  trailingAction,
446
557
  }: {
447
- icon: React.ReactNode;
448
- tint: string;
558
+ type: ContentType;
449
559
  label: string;
450
560
  rightLabel?: string;
451
561
  onClick?: (event: React.MouseEvent) => void;
@@ -500,7 +610,7 @@ function PackageItemRow({
500
610
  width: 32,
501
611
  height: 32,
502
612
  borderRadius: 1,
503
- bgcolor: tint,
613
+ bgcolor: CONTENT_TINT[type],
504
614
  color: "#FFFFFF",
505
615
  display: "flex",
506
616
  alignItems: "center",
@@ -508,7 +618,7 @@ function PackageItemRow({
508
618
  flexShrink: 0,
509
619
  }}
510
620
  >
511
- {icon}
621
+ <ContentTypeIcon type={type} />
512
622
  </Box>
513
623
  <Typography
514
624
  variant="body2"