@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
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-MES4MGpQ.cjs.js"),r=require("./ServerProvider-Dg5S1qBU.cjs.js");exports.AnalyzePackageButton=e.AnalyzePackageButton;exports.BrowserWorkbookStorage=e.BrowserWorkbookStorage;exports.ConnectionExplorer=e.ConnectionExplorer;exports.DOC_LINKS=e.DOC_LINKS;exports.DataAppViewer=e.DataAppViewer;exports.DimensionFilter=e.DimensionFilter;exports.EmbeddedQueryResult=e.EmbeddedQueryResult;exports.Environment=e.Environment;exports.EnvironmentMaterializations=e.EnvironmentMaterializations;exports.Home=e.Home;exports.Loading=e.Loading;exports.Materializations=e.Materializations;exports.Model=e.Model;exports.ModelExplorer=e.ModelExplorer;exports.ModelExplorerDialog=e.ModelExplorerDialog;exports.Models=e.Models;exports.Notebook=e.Notebook;exports.Package=e.Package;exports.Packages=e.Packages;exports.QueryResult=e.QueryResult;exports.RenderedResult=e.RenderedResult;exports.ResultContainer=e.ResultContainer;exports.SourceExplorerComponent=e.SourceExplorerComponent;exports.SourcesExplorer=e.SourcesExplorer;exports.Workbook=e.Workbook;exports.WorkbookList=e.WorkbookList;exports.WorkbookManager=e.WorkbookManager;exports.WorkbookStorageProvider=e.WorkbookStorageProvider;exports.buildMalloyExplicitTheme=e.buildMalloyExplicitTheme;exports.buildTableCssVars=e.buildTableCssVars;exports.buildVegaThemeOverride=e.buildVegaThemeOverride;exports.createEmbeddedQueryResult=e.createEmbeddedQueryResult;exports.encodeResourceUri=e.encodeResourceUri;exports.extractDimensionSpecs=e.extractDimensionSpecs;exports.extractSourceFromQuery=e.extractSourceFromQuery;exports.generateFilterClause=e.generateFilterClause;exports.getDimensionKey=e.getDimensionKey;exports.getJoinedSources=e.getJoinedSources;exports.injectWhereClause=e.injectWhereClause;exports.makeDimensionKey=e.makeDimensionKey;exports.packageFileUrl=e.packageFileUrl;exports.parseAllSourceInfos=e.parseAllSourceInfos;exports.parseDimensionFilterAnnotation=e.parseDimensionFilterAnnotation;exports.parseNotebookFilterAnnotation=e.parseNotebookFilterAnnotation;exports.parseResourceUri=e.parseResourceUri;exports.readChartAnnotations=e.readChartAnnotations;exports.useDimensionFilters=e.useDimensionFilters;exports.useDimensionFiltersFromSpec=e.useDimensionFiltersFromSpec;exports.useDimensionFiltersQuery=e.useDimensionFiltersQuery;exports.useDimensionalFilterRangeData=e.useDimensionalFilterRangeData;exports.useGivensForm=e.useGivensForm;exports.useModelData=e.useModelData;exports.useModelGivens=e.useModelGivens;exports.useRawQueryData=e.useRawQueryData;exports.useRouterClickHandler=e.useRouterClickHandler;exports.DEFAULT_THEME=r.DEFAULT_THEME;exports.ServerProvider=r.ServerProvider;exports.ThemeProvider=r.ThemeProvider;exports.resolveMode=r.resolveMode;exports.resolveTheme=r.resolveTheme;exports.usePublisherTheme=r.usePublisherTheme;exports.useServer=r.useServer;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CWQXhe0D.cjs.js"),r=require("./ServerProvider-CcfeBpt3.cjs.js");exports.AnalyzePackageButton=e.AnalyzePackageButton;exports.BrowserWorkbookStorage=e.BrowserWorkbookStorage;exports.ConnectionExplorer=e.ConnectionExplorer;exports.DOC_LINKS=e.DOC_LINKS;exports.DRILL_CELL_CLASS=e.DRILL_CELL_CLASS;exports.DRILL_SELF=e.DRILL_SELF;exports.Dashboard=e.Dashboard;exports.DashboardTile=e.DashboardTile;exports.DataAppViewer=e.DataAppViewer;exports.DimensionFilter=e.DimensionFilter;exports.EmbeddedQueryResult=e.EmbeddedQueryResult;exports.Environment=e.Environment;exports.EnvironmentMaterializations=e.EnvironmentMaterializations;exports.GivenInput=e.GivenInput;exports.GivensPanel=e.GivensPanel;exports.Home=e.Home;exports.Loading=e.Loading;exports.Materializations=e.Materializations;exports.Model=e.Model;exports.ModelExplorer=e.ModelExplorer;exports.ModelExplorerDialog=e.ModelExplorerDialog;exports.Models=e.Models;exports.Notebook=e.Notebook;exports.Package=e.Package;exports.Packages=e.Packages;exports.QueryResult=e.QueryResult;exports.RenderedResult=e.RenderedResult;exports.ResultContainer=e.ResultContainer;exports.SourceExplorerComponent=e.SourceExplorerComponent;exports.SourcesExplorer=e.SourcesExplorer;exports.Workbook=e.Workbook;exports.WorkbookList=e.WorkbookList;exports.WorkbookManager=e.WorkbookManager;exports.WorkbookStorageProvider=e.WorkbookStorageProvider;exports.buildMalloyExplicitTheme=e.buildMalloyExplicitTheme;exports.buildTableCssVars=e.buildTableCssVars;exports.buildVegaThemeOverride=e.buildVegaThemeOverride;exports.createEmbeddedQueryResult=e.createEmbeddedQueryResult;exports.drillDestinations=e.drillDestinations;exports.drillValueToFilter=e.drillValueToFilter;exports.drillableFieldNames=e.drillableFieldNames;exports.encodeDrillValue=e.encodeDrillValue;exports.encodeResourceUri=e.encodeResourceUri;exports.extractDimensionSpecs=e.extractDimensionSpecs;exports.extractSourceFromQuery=e.extractSourceFromQuery;exports.generateFilterClause=e.generateFilterClause;exports.getDimensionKey=e.getDimensionKey;exports.getJoinedSources=e.getJoinedSources;exports.humanizeSlug=e.humanizeSlug;exports.injectWhereClause=e.injectWhereClause;exports.makeDimensionKey=e.makeDimensionKey;exports.markDrillableCells=e.markDrillableCells;exports.packageFileUrl=e.packageFileUrl;exports.parseAllSourceInfos=e.parseAllSourceInfos;exports.parseDimensionFilterAnnotation=e.parseDimensionFilterAnnotation;exports.parseNotebookFilterAnnotation=e.parseNotebookFilterAnnotation;exports.parseResourceUri=e.parseResourceUri;exports.readChartAnnotations=e.readChartAnnotations;exports.resolveDrill=e.resolveDrill;exports.useDimensionFilters=e.useDimensionFilters;exports.useDimensionFiltersFromSpec=e.useDimensionFiltersFromSpec;exports.useDimensionFiltersQuery=e.useDimensionFiltersQuery;exports.useDimensionalFilterRangeData=e.useDimensionalFilterRangeData;exports.useDrill=e.useDrill;exports.useGivensState=e.useGivensState;exports.useModelData=e.useModelData;exports.useModelGivens=e.useModelGivens;exports.useRawQueryData=e.useRawQueryData;exports.useRouterClickHandler=e.useRouterClickHandler;exports.useSuggestOptions=e.useSuggestOptions;exports.DEFAULT_THEME=r.DEFAULT_THEME;exports.ServerProvider=r.ServerProvider;exports.ThemeProvider=r.ThemeProvider;exports.resolveMode=r.resolveMode;exports.resolveTheme=r.resolveTheme;exports.usePublisherTheme=r.usePublisherTheme;exports.useServer=r.useServer;
package/dist/index.es.js CHANGED
@@ -1,66 +1,81 @@
1
- import { A as s, U as o, C as r, a9 as i, D as n, g as t, I as l, E as u, r as d, H as m, L as c, M as k, t as p, v as D, x as g, G as b, N as E, F, P as M, Q as S, R as v, K as x, y as R, S as y, W as C, O as T, V as h, T as A, a3 as P, a4 as Q, a5 as W, J as L, a8 as N, i as U, j as H, k as K, $ as O, l as V, m as f, a0 as w, p as z, n as B, o as G, q as I, a7 as _, a6 as j, X as J, Y as q, Z as X, _ as Y, a2 as Z, B as $, a1 as ee, u as ae, e as se } from "./index-BdtAZ5k6.es.js";
2
- import { aM as re, S as ie, aO as ne, aN as te, aL as le, ax as ue, u as de } from "./ServerProvider-BxEh3nFI.es.js";
1
+ import { A as s, a7 as r, C as o, ao as i, j as l, l as n, D as t, g as u, i as d, x as m, a0 as D, E as c, R as k, L as p, M as S, N as b, O as g, Q as v, S as E, T as F, U as R, _ as C, Y as L, Z as M, P as h, $ as T, a2 as x, a3 as y, W as A, V as P, a4 as Q, a5 as W, a8 as I, a6 as V, ai as _, aj as G, ak as N, a1 as U, n as f, o as z, k as B, q as H, an as K, y as O, B as j, F as w, ad as J, G as q, r as X, H as Y, ae as Z, m as $, p as aa, I as ea, J as sa, K as ra, am as oa, al as ia, t as la, a9 as na, aa as ta, ab as ua, ac as da, v as ma, ag as Da, X as ca, af as ka, u as pa, e as Sa, ah as ba } from "./index-CLcRrkxd.es.js";
2
+ import { aR as va, S as Ea, aT as Fa, aS as Ra, aQ as Ca, aB as La, u as Ma } from "./ServerProvider-EqBlMMqx.es.js";
3
3
  export {
4
4
  s as AnalyzePackageButton,
5
- o as BrowserWorkbookStorage,
6
- r as ConnectionExplorer,
7
- re as DEFAULT_THEME,
5
+ r as BrowserWorkbookStorage,
6
+ o as ConnectionExplorer,
7
+ va as DEFAULT_THEME,
8
8
  i as DOC_LINKS,
9
- n as DataAppViewer,
10
- t as DimensionFilter,
11
- l as EmbeddedQueryResult,
12
- u as Environment,
13
- d as EnvironmentMaterializations,
14
- m as Home,
15
- c as Loading,
16
- k as Materializations,
17
- p as Model,
18
- D as ModelExplorer,
19
- g as ModelExplorerDialog,
20
- b as Models,
21
- E as Notebook,
22
- F as Package,
23
- M as Packages,
24
- S as QueryResult,
25
- v as RenderedResult,
26
- x as ResultContainer,
27
- ie as ServerProvider,
28
- R as SourceExplorerComponent,
29
- y as SourcesExplorer,
30
- ne as ThemeProvider,
31
- C as Workbook,
32
- T as WorkbookList,
33
- h as WorkbookManager,
34
- A as WorkbookStorageProvider,
35
- P as buildMalloyExplicitTheme,
36
- Q as buildTableCssVars,
37
- W as buildVegaThemeOverride,
38
- L as createEmbeddedQueryResult,
39
- N as encodeResourceUri,
40
- U as extractDimensionSpecs,
41
- H as extractSourceFromQuery,
42
- K as generateFilterClause,
43
- O as getDimensionKey,
44
- V as getJoinedSources,
45
- f as injectWhereClause,
46
- w as makeDimensionKey,
47
- z as packageFileUrl,
48
- B as parseAllSourceInfos,
49
- G as parseDimensionFilterAnnotation,
50
- I as parseNotebookFilterAnnotation,
51
- _ as parseResourceUri,
52
- j as readChartAnnotations,
53
- te as resolveMode,
54
- le as resolveTheme,
55
- J as useDimensionFilters,
56
- q as useDimensionFiltersFromSpec,
57
- X as useDimensionFiltersQuery,
58
- Y as useDimensionalFilterRangeData,
59
- Z as useGivensForm,
60
- $ as useModelData,
61
- ee as useModelGivens,
62
- ue as usePublisherTheme,
63
- ae as useRawQueryData,
64
- se as useRouterClickHandler,
65
- de as useServer
9
+ l as DRILL_CELL_CLASS,
10
+ n as DRILL_SELF,
11
+ t as Dashboard,
12
+ u as DashboardTile,
13
+ d as DataAppViewer,
14
+ m as DimensionFilter,
15
+ D as EmbeddedQueryResult,
16
+ c as Environment,
17
+ k as EnvironmentMaterializations,
18
+ p as GivenInput,
19
+ S as GivensPanel,
20
+ b as Home,
21
+ g as Loading,
22
+ v as Materializations,
23
+ E as Model,
24
+ F as ModelExplorer,
25
+ R as ModelExplorerDialog,
26
+ C as Models,
27
+ L as Notebook,
28
+ M as Package,
29
+ h as Packages,
30
+ T as QueryResult,
31
+ x as RenderedResult,
32
+ y as ResultContainer,
33
+ Ea as ServerProvider,
34
+ A as SourceExplorerComponent,
35
+ P as SourcesExplorer,
36
+ Fa as ThemeProvider,
37
+ Q as Workbook,
38
+ W as WorkbookList,
39
+ I as WorkbookManager,
40
+ V as WorkbookStorageProvider,
41
+ _ as buildMalloyExplicitTheme,
42
+ G as buildTableCssVars,
43
+ N as buildVegaThemeOverride,
44
+ U as createEmbeddedQueryResult,
45
+ f as drillDestinations,
46
+ z as drillValueToFilter,
47
+ B as drillableFieldNames,
48
+ H as encodeDrillValue,
49
+ K as encodeResourceUri,
50
+ O as extractDimensionSpecs,
51
+ j as extractSourceFromQuery,
52
+ w as generateFilterClause,
53
+ J as getDimensionKey,
54
+ q as getJoinedSources,
55
+ X as humanizeSlug,
56
+ Y as injectWhereClause,
57
+ Z as makeDimensionKey,
58
+ $ as markDrillableCells,
59
+ aa as packageFileUrl,
60
+ ea as parseAllSourceInfos,
61
+ sa as parseDimensionFilterAnnotation,
62
+ ra as parseNotebookFilterAnnotation,
63
+ oa as parseResourceUri,
64
+ ia as readChartAnnotations,
65
+ la as resolveDrill,
66
+ Ra as resolveMode,
67
+ Ca as resolveTheme,
68
+ na as useDimensionFilters,
69
+ ta as useDimensionFiltersFromSpec,
70
+ ua as useDimensionFiltersQuery,
71
+ da as useDimensionalFilterRangeData,
72
+ ma as useDrill,
73
+ Da as useGivensState,
74
+ ca as useModelData,
75
+ ka as useModelGivens,
76
+ La as usePublisherTheme,
77
+ pa as useRawQueryData,
78
+ Sa as useRouterClickHandler,
79
+ Ma as useServer,
80
+ ba as useSuggestOptions
66
81
  };
@@ -48,6 +48,15 @@ export interface ResolvedTheme {
48
48
  * box on the dark page chrome.
49
49
  */
50
50
  dashboardRoot: string;
51
+ /**
52
+ * Colour a `# drill` cell takes on hover, when it reads as a link. A link
53
+ * blue rather than anything from `palette.series`, deliberately: the
54
+ * affordance has to stay legible as a link against whatever the operator
55
+ * picked for the data, and a drillable bar or cell should not look like it
56
+ * belongs to a series. Mode-keyed and not operator-customizable, like
57
+ * `dashboardRoot`.
58
+ */
59
+ drillLink: string;
51
60
  /**
52
61
  * Background for the renderer's table interior. Follows the
53
62
  * operator's `palette.background` (the chart canvas colour) so
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.0.247",
4
+ "version": "0.0.249",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -71,6 +71,7 @@
71
71
  "react-router-dom": ">=7.6.2",
72
72
  "@tanstack/react-query": ">=5.59.16",
73
73
  "@malloydata/malloy-explorer": "0.0.338-dev260215172810",
74
+ "@malloydata/malloy-filter": "^0.0.427",
74
75
  "@malloydata/malloy-interfaces": "^0.0.427",
75
76
  "@malloydata/malloy-query-builder": "^0.0.427",
76
77
  "@malloydata/malloy-tag": "^0.0.427",
@@ -95,6 +96,7 @@
95
96
  "devDependencies": {
96
97
  "@happy-dom/global-registrator": "^20.11.1",
97
98
  "@malloydata/malloy-explorer": "0.0.338-dev260215172810",
99
+ "@malloydata/malloy-filter": "^0.0.427",
98
100
  "@malloydata/malloy-query-builder": "^0.0.427",
99
101
  "@malloydata/malloy-tag": "^0.0.427",
100
102
  "@openapitools/openapi-generator-cli": "^2.20.2",
@@ -355,7 +355,16 @@ export default function AddConnectionDialog({
355
355
 
356
356
  return (
357
357
  <React.Fragment>
358
- <Button variant="outlined" onClick={handleClickOpen}>
358
+ {/* Contained with a start icon, matching AddEnvironmentDialog and
359
+ AddPackageDialog. This was the only add-trigger of the three still
360
+ outlined and icon-less, which read as the secondary action on a
361
+ screen where it is the primary one. */}
362
+ <Button
363
+ variant="contained"
364
+ color="primary"
365
+ startIcon={<AddIcon />}
366
+ onClick={handleClickOpen}
367
+ >
359
368
  Add Connection
360
369
  </Button>
361
370
  <Dialog open={open} onClose={handleClose}>
@@ -0,0 +1,395 @@
1
+ import { Alert, Box, Stack, Typography } from "@mui/material";
2
+ import { useCallback, useMemo } from "react";
3
+ import type { DashboardManifest } from "../../client";
4
+ import { useGivensState } from "../../hooks/useGivensState";
5
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
6
+ import { useSuggestOptions } from "../../hooks/useSuggestOptions";
7
+ import { parseResourceUri } from "../../utils/formatting";
8
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
9
+ import { encodeDrillValue, useDrill, type DrillNavigation } from "../drill";
10
+ import { GivensPanel } from "../given";
11
+ import { Loading } from "../Loading";
12
+ import { useServer } from "../ServerProvider";
13
+ import { DashboardTile } from "./DashboardTile";
14
+
15
+ export interface DashboardProps {
16
+ /** `publisher://environments/{env}/packages/{pkg}`, env and package only. */
17
+ resourceUri: string;
18
+ /** The dashboard's slug, as listed by the dashboards endpoint. */
19
+ dashboard: string;
20
+ /**
21
+ * Control values from the host, typically its URL query parameters. These
22
+ * beat the dashboard's own starting values, so a shared link shows what the
23
+ * sender was looking at.
24
+ */
25
+ givens?: Record<string, string>;
26
+ /**
27
+ * Applied control values, for a host that wants them in its URL. Fires with
28
+ * what the results reflect, not with every keystroke.
29
+ *
30
+ * `managed` is every given this dashboard declares, whether or not it
31
+ * currently holds a value, and a host writing to a shared query string needs
32
+ * it. `givens` alone says which parameters to write but not which to REMOVE,
33
+ * so a host that guesses by deleting everything it did not just receive
34
+ * deletes the unrelated parameters it has no business touching. Same contract
35
+ * as `Notebook`, so a host can treat the two surfaces alike.
36
+ */
37
+ onGivensChange?: (
38
+ givens: Record<string, string>,
39
+ managed: readonly string[],
40
+ ) => void;
41
+ /**
42
+ * Where to go when a `# drill` cell is clicked. Without it, drilling to
43
+ * another dashboard is inert: `to=self` still filters in place, since that
44
+ * never leaves the component.
45
+ */
46
+ onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
47
+ /**
48
+ * Height cap for a result panel. Left unset, each form gets the cap that
49
+ * suits its shape, see {@link TILE_HEIGHT} and {@link WHOLE_PAGE_HEIGHT}.
50
+ * Set it to hold a dashboard to a fixed box, as an embedding host might.
51
+ */
52
+ height?: number;
53
+ maxResultSize?: number;
54
+ }
55
+
56
+ /**
57
+ * Per-tile cap for the composite form. A tile is one panel among several, so
58
+ * capping them keeps the grid even instead of letting one long table set the
59
+ * height of its whole row.
60
+ */
61
+ const TILE_HEIGHT = 400;
62
+
63
+ /**
64
+ * Cap for the single-query form, where the one result *is* the dashboard and a
65
+ * cap would clip the page rather than tidy it. High enough to be no cap in
66
+ * practice, and still a guard against a pathological result.
67
+ *
68
+ * A result that REPORTS its own height, which a `# dashboard` grid does, renders
69
+ * at that height and the page scrolls, which is what a reader expects. A result
70
+ * that sizes to its CONTAINER instead, which a bare `# bar_chart` does, has no
71
+ * height to report and keeps whatever first-paint height it was handed, so it
72
+ * stretches: measured 1992px for a two-row bar chart against 227px for the same
73
+ * query under a grid tag. `INITIAL_RENDER_HEIGHT` bounds that near 2000 rather
74
+ * than removing it, and lowering the bound is NOT the fix, because the same seed
75
+ * sizes a notebook's chart cells (measured 700px there). Telling the two kinds of
76
+ * result apart needs something the renderer does not expose here.
77
+ */
78
+ const WHOLE_PAGE_HEIGHT = 20000;
79
+
80
+ /**
81
+ * A Malloyyo-style dashboard: a control row over one or more query results,
82
+ * declared entirely by tags in a package's `dashboards/*.malloy`.
83
+ *
84
+ * Host-agnostic on purpose. It takes props rather than reading a router, and
85
+ * hands navigation and URL state back to whoever mounted it, so the Publisher
86
+ * Console and an external React app render the same component and differ only
87
+ * in what they do with `onNavigate` and `onGivensChange`.
88
+ */
89
+ export function Dashboard({
90
+ resourceUri,
91
+ dashboard,
92
+ givens,
93
+ onGivensChange,
94
+ onNavigate,
95
+ height,
96
+ maxResultSize,
97
+ }: DashboardProps) {
98
+ const parsed = parseResourceUri(resourceUri);
99
+ const { apiClients } = useServer();
100
+
101
+ // Degraded, not thrown. `Notebook`, `Model` and `Package` all let a bad URI
102
+ // fail into an error display; a throw in the render body takes the host's
103
+ // whole tree down with it instead, which is a white screen rather than a
104
+ // message. The Console cannot reach this, because `DashboardPage` builds the
105
+ // URI from params `ModelPage` has already guarded, so the only caller a throw
106
+ // could punish is the embedding host the docs invite. Reported below rather
107
+ // than here, so every hook still runs in the same order.
108
+ const environmentName = parsed.environmentName ?? "";
109
+ const packageName = parsed.packageName ?? "";
110
+ const uriNamesBoth = !!parsed.environmentName && !!parsed.packageName;
111
+
112
+ const {
113
+ data: manifestResponse,
114
+ isSuccess,
115
+ isError,
116
+ error,
117
+ } = useQueryWithApiError({
118
+ queryKey: ["dashboard", environmentName, packageName, dashboard],
119
+ queryFn: () =>
120
+ apiClients.dashboards.getDashboard(
121
+ environmentName,
122
+ packageName,
123
+ dashboard,
124
+ ),
125
+ // No point asking for a dashboard under a name the URI never carried.
126
+ enabled: uriNamesBoth,
127
+ });
128
+ const manifest = manifestResponse?.data;
129
+
130
+ const specs = useMemo(() => manifest?.givens ?? [], [manifest]);
131
+ const declaredTypes = useMemo(
132
+ () =>
133
+ new Map(
134
+ specs
135
+ .filter((spec) => spec.name !== undefined)
136
+ .map((spec) => [spec.name as string, spec.type]),
137
+ ),
138
+ [specs],
139
+ );
140
+
141
+ // Hands the host the names this dashboard MANAGES alongside the values, so it
142
+ // can merge into a shared query string instead of replacing it. Guarded on
143
+ // `isSuccess` as well as at the call site, since an empty declared set before
144
+ // the manifest lands is the absence of an answer rather than the answer.
145
+ const reportGivens = useCallback(
146
+ (next: Record<string, string>) => {
147
+ if (!isSuccess) return;
148
+ onGivensChange?.(next, Array.from(declaredTypes.keys()));
149
+ },
150
+ [isSuccess, onGivensChange, declaredTypes],
151
+ );
152
+
153
+ const { draft, applied, setGiven, reset, apply, pending } = useGivensState({
154
+ declaredTypes,
155
+ startingValues: manifest?.startingGivens,
156
+ params: givens,
157
+ // Withheld until the manifest has loaded, for the same reason the notebook
158
+ // withholds it. Changing `dashboard` changes the query key, so `data` is
159
+ // undefined for one commit and `declaredTypes` is empty; `applied` prunes
160
+ // to nothing and the hook reports "no values, and I manage nothing". This
161
+ // component is reconciled rather than remounted on a dashboard-to-dashboard
162
+ // drill, so the hook's record of what it last reported still holds the
163
+ // PREVIOUS dashboard's values and does not suppress that report as a
164
+ // repeat. The host reasonably clears its query string, which is exactly the
165
+ // givens the drill just seeded for the dashboard now arriving.
166
+ onParamsChange: isSuccess ? reportGivens : undefined,
167
+ // Which document these edits belong to. Without it the edits are keyed by
168
+ // their starting VALUES alone, so two dashboards whose starting values
169
+ // coincide (the common case: both empty) look like one document, and the
170
+ // one you came from keeps filtering the one you drilled into.
171
+ documentKey: `${environmentName}/${packageName}/${dashboard}`,
172
+ // Absent means autorun; only an explicit `autorun=false` batches.
173
+ autorun: manifest?.autorun !== false,
174
+ });
175
+
176
+ const {
177
+ options,
178
+ isLoading: optionsLoading,
179
+ failed: optionsFailed,
180
+ } = useSuggestOptions(environmentName, packageName, manifest?.path, specs);
181
+
182
+ // A drill tag names its given as the model spells it, and `# drill` with no
183
+ // `given=` falls back to the DIMENSION's spelling, which need not match. The
184
+ // notebook folds case rather than picking a side, and this folds it the same
185
+ // way so one tag behaves identically on both surfaces.
186
+ const givenNamesByFold = useMemo(() => {
187
+ const byFold = new Map<string, string>();
188
+ for (const name of declaredTypes.keys()) {
189
+ // First declaration wins, so a model with `REGION` and `region` keeps
190
+ // the one it declared first rather than silently flipping.
191
+ if (!byFold.has(name.toLowerCase()))
192
+ byFold.set(name.toLowerCase(), name);
193
+ }
194
+ return byFold;
195
+ }, [declaredTypes]);
196
+
197
+ /** The declared given a drill tag's name refers to, or undefined. */
198
+ const resolveGiven = useCallback(
199
+ (given: string) =>
200
+ declaredTypes.has(given)
201
+ ? given
202
+ : givenNamesByFold.get(given.toLowerCase()),
203
+ [declaredTypes, givenNamesByFold],
204
+ );
205
+
206
+ // `to=self` filters in place, which only works for a given this dashboard
207
+ // actually surfaces: sending one it cannot bind would fail every tile's
208
+ // query. Asked here rather than checked after the click, so a cell that
209
+ // cannot be honoured is never painted as clickable in the first place.
210
+ const canSelf = useCallback(
211
+ (given: string) => resolveGiven(given) !== undefined,
212
+ [resolveGiven],
213
+ );
214
+
215
+ const onSelf = useCallback(
216
+ (given: string, rawValue: unknown) => {
217
+ const declared = resolveGiven(given);
218
+ if (declared === undefined) return;
219
+ // Encoded against the DECLARED type, which is knowable here and is not
220
+ // knowable at the click: `useDrill` hands over the raw cell value for
221
+ // exactly this reason. Passing it straight to `setGiven` skipped the
222
+ // encoder, so a clicked date reached a `number` given as epoch
223
+ // milliseconds and a filter value went unescaped. Set under the name
224
+ // the MODEL declares, so the value reaches the URL and the request
225
+ // under the one name the server knows.
226
+ const declaredType = declaredTypes.get(declared);
227
+ const value = encodeDrillValue(rawValue, declaredType);
228
+ if (value === undefined) {
229
+ // Say so, the way the notebook does. `canSelf` only checks that the
230
+ // NAME resolves, so a `given=` naming a type the clicked value
231
+ // cannot become still paints the whole column as clickable and then
232
+ // drops every click. That is an authoring mistake with no other
233
+ // symptom, and this is the likelier surface for it, because the
234
+ // givens are the dashboard's own.
235
+ console.warn(
236
+ `Drill declined: ${JSON.stringify(rawValue)} cannot be a value for given "${declared}"` +
237
+ (declaredType ? ` of type ${declaredType}` : ""),
238
+ );
239
+ return;
240
+ }
241
+ setGiven(declared, value);
242
+ },
243
+ [declaredTypes, resolveGiven, setGiven],
244
+ );
245
+
246
+ const { drill, drillMenu } = useDrill({
247
+ onNavigate,
248
+ onSelf,
249
+ canSelf,
250
+ selfLabel: "Filter this dashboard",
251
+ });
252
+
253
+ // After every hook, so the hook order does not depend on the URI.
254
+ if (!uriNamesBoth) {
255
+ return (
256
+ <Alert severity="error">
257
+ A dashboard resource URI must name an environment and a package.
258
+ Received: {resourceUri}
259
+ </Alert>
260
+ );
261
+ }
262
+
263
+ if (isError) {
264
+ return (
265
+ <ApiErrorDisplay
266
+ context={`${environmentName} > ${packageName} > ${dashboard}`}
267
+ error={error}
268
+ />
269
+ );
270
+ }
271
+ if (!isSuccess || !manifest) {
272
+ return <Loading text="Loading dashboard…" />;
273
+ }
274
+
275
+ // Reachable on the in-process load path only. Production loads a package
276
+ // through the worker pool, which aborts the package on the first compile
277
+ // error, so an uncompilable file answers 424 everywhere rather than serving a
278
+ // per-file error. Measured on this base with one bad file: the package
279
+ // endpoint, the dashboards listing, and the manifest of a dashboard that was
280
+ // FINE all answered 424. The earlier note here said such a dashboard "still
281
+ // lists and still resolves", which contradicted this repo's own docs and was
282
+ // the wrong half of the pair. Kept because the per-file error manifest still
283
+ // exists and an empty frame would be worse than saying why.
284
+ if (manifest.error) {
285
+ return (
286
+ <Stack spacing={2}>
287
+ <DashboardHeader manifest={manifest} />
288
+ <Alert severity="error">{manifest.error}</Alert>
289
+ </Stack>
290
+ );
291
+ }
292
+
293
+ const modelPath = manifest.path;
294
+ const tiles = manifest.tiles ?? [];
295
+
296
+ return (
297
+ <Stack spacing={2}>
298
+ <DashboardHeader manifest={manifest} />
299
+
300
+ <GivensPanel
301
+ givens={specs}
302
+ values={draft}
303
+ onChange={setGiven}
304
+ onReset={reset}
305
+ layout="bar"
306
+ options={options}
307
+ optionsLoading={optionsLoading}
308
+ optionsFailed={optionsFailed}
309
+ apply={
310
+ manifest.autorun === false
311
+ ? { onApply: apply, pending }
312
+ : undefined
313
+ }
314
+ />
315
+
316
+ {modelPath === undefined ? (
317
+ <Alert severity="error">
318
+ This dashboard has no model path, so there is nothing to run.
319
+ </Alert>
320
+ ) : manifest.query !== undefined ? (
321
+ // Single-query form: one query whose result IS the dashboard. Its
322
+ // `# dashboard {columns=N}` tag is the renderer's business, so no
323
+ // grid is imposed here: doing so would nest a grid in a grid.
324
+ <DashboardTile
325
+ environmentName={environmentName}
326
+ packageName={packageName}
327
+ modelPath={modelPath}
328
+ queryName={manifest.query}
329
+ givens={applied}
330
+ declaredTypes={declaredTypes}
331
+ height={height ?? WHOLE_PAGE_HEIGHT}
332
+ maxResultSize={maxResultSize}
333
+ drill={drill}
334
+ />
335
+ ) : tiles.length > 0 ? (
336
+ // Composite form: each tile runs on its own and the results are
337
+ // combined into one grid here, since no single Malloy result spans
338
+ // them.
339
+ <Box
340
+ sx={{
341
+ display: "grid",
342
+ gridTemplateColumns: {
343
+ xs: "1fr",
344
+ md: `repeat(${manifest.dashboardColumns ?? 2}, minmax(0, 1fr))`,
345
+ },
346
+ gap: 2,
347
+ }}
348
+ >
349
+ {tiles.map((tile, index) => (
350
+ <DashboardTile
351
+ // Position too, not the expression alone: `tiles=[…]` can
352
+ // repeat one, which is a typo rather than a request for two
353
+ // identical panels, and keying on the expression made the
354
+ // duplicate warn and reconcile onto its twin.
355
+ key={`${index}:${tile.query}`}
356
+ environmentName={environmentName}
357
+ packageName={packageName}
358
+ modelPath={modelPath}
359
+ tile={tile.query}
360
+ givens={applied}
361
+ declaredTypes={declaredTypes}
362
+ givenNames={tile.givenNames}
363
+ height={height ?? TILE_HEIGHT}
364
+ maxResultSize={maxResultSize}
365
+ drill={drill}
366
+ />
367
+ ))}
368
+ </Box>
369
+ ) : (
370
+ <Alert severity="warning">
371
+ This dashboard names neither a query nor any tiles.
372
+ </Alert>
373
+ )}
374
+
375
+ {drillMenu}
376
+ </Stack>
377
+ );
378
+ }
379
+
380
+ function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
381
+ return (
382
+ <Box>
383
+ <Typography variant="h5" sx={{ fontWeight: 600 }}>
384
+ {manifest.title ?? manifest.name}
385
+ </Typography>
386
+ {manifest.description && (
387
+ <Typography variant="body2" color="text.secondary">
388
+ {manifest.description}
389
+ </Typography>
390
+ )}
391
+ </Box>
392
+ );
393
+ }
394
+
395
+ export default Dashboard;