@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
@@ -6,25 +6,24 @@ import FolderOutlinedIcon from "@mui/icons-material/FolderOutlined";
6
6
  import {
7
7
  Box,
8
8
  Button,
9
- Card,
10
- CardContent,
11
9
  Container,
12
10
  Divider,
13
11
  Grid,
14
12
  IconButton,
15
13
  Menu,
16
14
  Stack,
17
- Tooltip,
18
15
  Typography,
19
16
  } from "@mui/material";
20
17
  import { useState } from "react";
21
18
  import { Environment } from "../../client";
22
19
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
23
- import { serverBaseUrl } from "../../utils/dataAppEmbed";
24
20
  import { getEnvironmentDescription } from "../../utils/parsing";
25
21
  import { DOC_LINKS } from "../../constants/docLinks";
26
22
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
27
23
  import { Loading } from "../Loading";
24
+ import { ItemRow } from "../ItemRow";
25
+ import { PackageSection } from "../PackageSection";
26
+ import { SURFACE_TINT } from "../styles";
28
27
  import { useServer } from "../ServerProvider";
29
28
  import AddEnvironmentDialog from "./AddEnvironmentDialog";
30
29
  import DeleteEnvironmentDialog from "./DeleteEnvironmentDialog";
@@ -42,29 +41,19 @@ interface HomeProps {
42
41
  */
43
42
  const FEATURES: Array<{ title: string; body: string; href: string }> = [
44
43
  {
45
- title: "Ad-hoc analysis",
46
- body: "Browse the semantic sources on this server and build nested queries in Explorer. Every click writes valid Malloy, so metrics stay correct even across joins.",
47
- href: DOC_LINKS.explorer,
44
+ title: "Model",
45
+ body: "An agent writes what the data means in Malloy — sources, joins, measures — from a warehouse or a file, and validates each edit without a restart.",
46
+ href: DOC_LINKS.publishing,
48
47
  },
49
48
  {
50
- title: "Notebooks",
51
- body: "A data story: markdown and live query cells in one file, versioned beside the model it reads. Any givens it imports become a panel of filter controls above the cells.",
52
- href: DOC_LINKS.surfaces,
53
- },
54
- {
55
- title: "Dashboards",
56
- body: "A tagged Malloy file is the page. Tags lay out the grid, the filter row is rendered from the query's parameters, and a tagged dimension clicks through to a detail page. No front-end code.",
57
- href: DOC_LINKS.dashboards,
58
- },
59
- {
60
- title: "Data apps",
61
- body: "Hand-author an HTML page in a package's public directory and Publisher serves it, backed by that package's models. No build step, and it embeds in a host page.",
62
- href: DOC_LINKS.dataApps,
49
+ title: "Analyze",
50
+ body: "Claude, Cursor, Codex or an agent you build asks over MCP; applications and BI tools use REST. Every question runs against the model, never the raw tables.",
51
+ href: DOC_LINKS.mcpAgents,
63
52
  },
64
53
  {
65
- title: "AI data agents",
66
- body: "One MCP endpoint. Agents discover the sources, compile-check the Malloy they write, and ask well-formed questions instead of guessing at raw tables.",
67
- href: DOC_LINKS.mcpAgents,
54
+ title: "Surface",
55
+ body: "Dashboards declared in Malloy, notebooks, and no-build HTML data apps, all shipped inside the package, plus this Console for browsing them.",
56
+ href: DOC_LINKS.surfaces,
68
57
  },
69
58
  {
70
59
  // Deliberately not "so every caller sees only their rows". Givens are
@@ -72,10 +61,20 @@ const FEATURES: Array<{ title: string; body: string; href: string }> = [
72
61
  // a boundary on its own; `#(authorize)` is the thing that refuses. What is
73
62
  // true, and what this says, is that the declarations live in the model, so
74
63
  // no surface can define its own.
75
- title: "Governed access",
76
- body: "Runtime parameters, row-level filters, and per-source access gates are declared in the model, so every surface reads the same rules rather than reimplementing them.",
64
+ title: "Govern",
65
+ body: "Runtime parameters, row-level filters and per-source gates are declared in the model, so every surface reads the same rules rather than writing its own.",
77
66
  href: DOC_LINKS.givens,
78
67
  },
68
+ {
69
+ title: "Optimize",
70
+ body: "One annotation materializes an expensive source into a table, and another rolls a measure up to a coarser grain, rebuilt on demand or on a schedule.",
71
+ href: DOC_LINKS.materialization,
72
+ },
73
+ {
74
+ title: "Run anywhere",
75
+ body: "DuckDB is built in for CSV, Parquet, JSON and Excel; BigQuery, Snowflake, Postgres, Databricks, MotherDuck and more connect by configuration.",
76
+ href: DOC_LINKS.connections,
77
+ },
79
78
  ];
80
79
 
81
80
  /**
@@ -106,7 +105,7 @@ function InlineLink({
106
105
  }
107
106
 
108
107
  export default function Home({ onClickEnvironment }: HomeProps) {
109
- const { apiClients, mutable, server } = useServer();
108
+ const { apiClients, mutable } = useServer();
110
109
 
111
110
  const { data, isSuccess, isError, error } = useQueryWithApiError({
112
111
  queryKey: ["environments"],
@@ -134,19 +133,18 @@ export default function Home({ onClickEnvironment }: HomeProps) {
134
133
  Publisher
135
134
  </Typography>
136
135
  <Typography variant="body1" color="text.secondary" sx={{ mb: 3 }}>
137
- The open-source semantic model server for the Malloy data
138
- language.
136
+ The analytics engine for Malloy.
139
137
  </Typography>
140
138
  <Typography
141
139
  variant="body2"
142
140
  color="text.secondary"
143
141
  sx={{ maxWidth: 720, lineHeight: 1.6 }}
144
142
  >
145
- Define semantic models once and use them everywhere. Publisher
146
- serves Malloy models over a REST API and a single MCP endpoint,
147
- so applications, BI tools, and AI agents compose queries against
148
- the model instead of writing SQL, and the numbers come back right
149
- by construction.
143
+ One data model, served over MCP and REST to AI agents,
144
+ applications and BI tools. Write down what your data means — the
145
+ sources, the joins, the measures, who may see what — and every
146
+ surface asks the same model, so the same question returns the
147
+ same numbers tomorrow.
150
148
  </Typography>
151
149
  </Box>
152
150
 
@@ -191,44 +189,22 @@ export default function Home({ onClickEnvironment }: HomeProps) {
191
189
  <Divider sx={{ my: 4 }} />
192
190
 
193
191
  {environments.length > 0 ? (
194
- <Box sx={{ mb: 4 }}>
195
- <Stack
196
- direction="row"
197
- justifyContent="space-between"
198
- alignItems="flex-start"
199
- sx={{ mb: 3 }}
200
- >
201
- <Box>
202
- <Typography
203
- variant="h5"
204
- sx={{
205
- fontWeight: 500,
206
- letterSpacing: "-0.025em",
207
- mb: 0.5,
208
- }}
209
- >
210
- Environments
211
- </Typography>
212
- <Typography variant="body2" color="text.secondary">
213
- Published environments available on this server
214
- </Typography>
215
- </Box>
216
- {mutable && <AddEnvironmentDialog />}
217
- </Stack>
218
- <Grid container spacing={2}>
192
+ <PackageSection
193
+ title="Environments"
194
+ count={environments.length}
195
+ description="Published environments available on this server"
196
+ {...(mutable ? { action: <AddEnvironmentDialog /> } : {})}
197
+ >
198
+ <Stack>
219
199
  {environments.map((environment) => (
220
- <Grid
221
- size={{ xs: 12, sm: 6, md: 4 }}
200
+ <EnvironmentRow
222
201
  key={environment.name}
223
- >
224
- <EnvironmentCard
225
- environment={environment}
226
- onClickEnvironment={onClickEnvironment}
227
- />
228
- </Grid>
202
+ environment={environment}
203
+ {...(onClickEnvironment ? { onClickEnvironment } : {})}
204
+ />
229
205
  ))}
230
- </Grid>
231
- </Box>
206
+ </Stack>
207
+ </PackageSection>
232
208
  ) : (
233
209
  <Box sx={{ mb: 4 }}>
234
210
  <Typography
@@ -263,43 +239,12 @@ export default function Home({ onClickEnvironment }: HomeProps) {
263
239
 
264
240
  <Divider sx={{ my: 4 }} />
265
241
 
266
- <Typography
267
- variant="body2"
268
- color="text.secondary"
269
- sx={{ maxWidth: 720, lineHeight: 1.6 }}
270
- >
271
- {/* Six of the ten types in the api-doc.yaml enum. connections.md
272
- names eight. Two of the six named here, mysql and trino,
273
- appear in connections.md exactly once, in the parenthetical that
274
- ends "etc."; Databricks and MotherDuck it never names at all. "And more"
275
- rather than a full list, because a list that reads as complete
276
- while omitting Databricks is worse than a short one that says
277
- it is short. */}
278
- Also here:{" "}
279
- <InlineLink href={DOC_LINKS.connections}>connections</InlineLink> to
280
- BigQuery, Snowflake, Postgres, MySQL, Trino, DuckDB and more;{" "}
281
- <InlineLink href={DOC_LINKS.materialization}>
282
- materialized tables
283
- </InlineLink>{" "}
284
- built on demand or on a schedule; and a{" "}
285
- {/* Built from the configured server rather than written as
286
- "/api-doc.html". The spec is a static file off the Publisher
287
- server's root, and an SDK consumer's page origin need not be
288
- that server: a root-relative href resolves against the host and
289
- 404s. serverBaseUrl exists for exactly this. */}
290
- <InlineLink href={`${serverBaseUrl(server)}/api-doc.html`}>
291
- REST API
292
- </InlineLink>{" "}
293
- that does everything this console does.
294
- </Typography>
295
-
296
242
  <Typography
297
243
  variant="body2"
298
244
  color="text.secondary"
299
245
  sx={{ maxWidth: 720, lineHeight: 1.6, mt: 2 }}
300
246
  >
301
- Publisher is built on fully open infrastructure and designed for the
302
- AI era. Join the{" "}
247
+ Join the{" "}
303
248
  <InlineLink href="https://join.slack.com/t/malloy-community/shared_invite/zt-1kgfwgi5g-CrsdaRqs81QY67QW0~t_uw">
304
249
  Malloy Slack community
305
250
  </InlineLink>{" "}
@@ -309,7 +254,7 @@ export default function Home({ onClickEnvironment }: HomeProps) {
309
254
  );
310
255
  }
311
256
 
312
- function EnvironmentCard({
257
+ function EnvironmentRow({
313
258
  environment,
314
259
  onClickEnvironment,
315
260
  }: {
@@ -322,124 +267,66 @@ function EnvironmentCard({
322
267
 
323
268
  const description = getEnvironmentDescription(environment.readme);
324
269
 
325
- const handleClick = (event: React.MouseEvent) => {
326
- if (environment.name && onClickEnvironment) {
327
- onClickEnvironment(`/${environment.name}/`, event);
328
- }
329
- };
330
-
331
270
  const handleMenuClick = (event: React.MouseEvent<HTMLElement>) => {
332
271
  event.stopPropagation();
333
272
  setMenuAnchorEl(event.currentTarget);
334
273
  };
335
-
336
- const handleMenuClose = () => {
337
- setMenuAnchorEl(null);
338
- };
274
+ const handleMenuClose = () => setMenuAnchorEl(null);
339
275
 
340
276
  return (
341
- <Card
342
- variant="outlined"
343
- onClick={handleClick}
344
- sx={{
345
- height: "100%",
346
- cursor: "pointer",
347
- borderRadius: 3,
348
- borderColor: "divider",
349
- boxShadow: "none",
350
- transition: "all 0.2s ease-in-out",
351
- "&:hover": { boxShadow: 2, borderColor: "primary.main" },
352
- }}
353
- >
354
- <CardContent sx={{ p: 2.5, "&:last-child": { pb: 2.5 } }}>
355
- <Box
356
- sx={{
357
- display: "flex",
358
- alignItems: "flex-start",
359
- gap: 1.5,
360
- }}
361
- >
362
- <Box
363
- sx={(theme) => ({
364
- width: 36,
365
- height: 36,
366
- borderRadius: 1.5,
367
- bgcolor:
368
- theme.palette.mode === "dark"
369
- ? "rgba(255, 255, 255, 0.08)"
370
- : "grey.100",
371
- display: "flex",
372
- alignItems: "center",
373
- justifyContent: "center",
374
- flexShrink: 0,
375
- color: "text.primary",
376
- })}
377
- >
378
- <FolderOutlinedIcon sx={{ fontSize: 20 }} />
379
- </Box>
380
- <Box sx={{ flex: 1, minWidth: 0 }}>
381
- <Typography
382
- variant="subtitle1"
383
- component="h6"
384
- noWrap
385
- sx={{ fontWeight: 600, mb: 0.5 }}
386
- >
387
- {environment.name}
388
- </Typography>
389
- <Tooltip title={description} followCursor enterDelay={1000}>
390
- <Typography
391
- variant="body2"
392
- color="text.secondary"
393
- sx={{
394
- overflow: "hidden",
395
- textOverflow: "ellipsis",
396
- display: "-webkit-box",
397
- WebkitLineClamp: 2,
398
- WebkitBoxOrient: "vertical",
399
- lineHeight: 1.5,
400
- }}
401
- >
402
- {description}
403
- </Typography>
404
- </Tooltip>
405
- </Box>
406
- {mutable && (
407
- <>
408
- <IconButton
409
- size="small"
410
- onClick={handleMenuClick}
411
- aria-label={`Environment actions for ${environment.name}`}
412
- sx={{ flexShrink: 0, mt: -0.5, mr: -0.5 }}
413
- >
414
- <MoreVert fontSize="small" />
415
- </IconButton>
416
- <Menu
417
- anchorEl={menuAnchorEl}
418
- open={menuOpen}
419
- onClose={handleMenuClose}
420
- onClick={(e) => e.stopPropagation()}
421
- anchorOrigin={{
422
- vertical: "bottom",
423
- horizontal: "right",
424
- }}
425
- transformOrigin={{
426
- vertical: "top",
427
- horizontal: "right",
428
- }}
429
- >
430
- <EditEnvironmentDialog
431
- environment={environment}
432
- onCloseDialog={handleMenuClose}
433
- />
434
- <DeleteEnvironmentDialog
435
- environment={environment}
436
- onCloseDialog={handleMenuClose}
437
- />
438
- </Menu>
439
- </>
440
- )}
441
- </Box>
442
- </CardContent>
443
- </Card>
277
+ <ItemRow
278
+ icon={<FolderOutlinedIcon sx={{ fontSize: 18 }} />}
279
+ tint={SURFACE_TINT.environment}
280
+ label={environment.name ?? ""}
281
+ // The row's name is the environment's, not the row's whole text: a
282
+ // description in the accessible name makes every exact-name lookup,
283
+ // ours and a reader's, a guessing game about the author's prose.
284
+ ariaLabel={environment.name ?? ""}
285
+ {...(description ? { description } : {})}
286
+ {...(environment.name && onClickEnvironment
287
+ ? {
288
+ onClick: (event: React.MouseEvent) =>
289
+ onClickEnvironment(`/${environment.name}/`, event),
290
+ }
291
+ : {})}
292
+ {...(mutable
293
+ ? {
294
+ trailingAction: (
295
+ <>
296
+ <IconButton
297
+ size="small"
298
+ onClick={handleMenuClick}
299
+ aria-label={`Environment actions for ${environment.name}`}
300
+ >
301
+ <MoreVert fontSize="small" />
302
+ </IconButton>
303
+ <Menu
304
+ anchorEl={menuAnchorEl}
305
+ open={menuOpen}
306
+ onClose={handleMenuClose}
307
+ onClick={(event) => event.stopPropagation()}
308
+ anchorOrigin={{
309
+ vertical: "bottom",
310
+ horizontal: "right",
311
+ }}
312
+ transformOrigin={{
313
+ vertical: "top",
314
+ horizontal: "right",
315
+ }}
316
+ >
317
+ <EditEnvironmentDialog
318
+ environment={environment}
319
+ onCloseDialog={handleMenuClose}
320
+ />
321
+ <DeleteEnvironmentDialog
322
+ environment={environment}
323
+ onCloseDialog={handleMenuClose}
324
+ />
325
+ </Menu>
326
+ </>
327
+ ),
328
+ }
329
+ : {})}
330
+ />
444
331
  );
445
332
  }
@@ -0,0 +1,165 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box, Typography } from "@mui/material";
5
+ import * as React from "react";
6
+ import { MONO_FONT_FAMILY } from "./styles";
7
+
8
+ /**
9
+ * One thing in a list, anywhere in the Console: a colored icon plate, the
10
+ * thing's name, what it is, and whatever acts on it at the right edge. One per
11
+ * row.
12
+ *
13
+ * The rule is that a list is a list: everything a reader scans down is drawn
14
+ * this way, so the same reading task looks the same on every page. A grid of
15
+ * cards says "these are tiles to arrange", which is not what any of these
16
+ * lists are; a row also lets the description be a description rather than two
17
+ * clamped lines.
18
+ *
19
+ * The color is passed rather than derived here: the package page keys it off
20
+ * content type (see `CONTENT_TINT`), and the environment-scoped lists off what
21
+ * kind of thing the list holds (see `SURFACE_TINT`). Both are exhaustive maps,
22
+ * so the color stays a property of the kind and not of the call site.
23
+ */
24
+ export function ItemRow({
25
+ icon,
26
+ tint,
27
+ label,
28
+ mono,
29
+ description,
30
+ rightLabel,
31
+ trailingAction,
32
+ onClick,
33
+ ariaLabel,
34
+ }: {
35
+ /** The glyph, drawn white on the tinted plate. */
36
+ icon: React.ReactNode;
37
+ tint: string;
38
+ label: string;
39
+ /** Monospace label, for a name that is a file path. */
40
+ mono?: boolean;
41
+ /** What this one is, in the author's words. One line, then ellipsis. */
42
+ description?: string;
43
+ /** A fact about the row, right-aligned before any action: "1.0 K rows". */
44
+ rightLabel?: string;
45
+ /**
46
+ * Rendered at the end of the row: a menu, an open-in-new-tab button. Clicks
47
+ * on it should `event.stopPropagation()` so the row's own click does not
48
+ * also fire.
49
+ */
50
+ trailingAction?: React.ReactNode;
51
+ onClick?: (event: React.MouseEvent) => void;
52
+ /** Overrides the accessible name, which is otherwise the label. */
53
+ ariaLabel?: string;
54
+ }) {
55
+ const interactive = !!onClick;
56
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
57
+ if (!onClick) return;
58
+ if (event.key === "Enter" || event.key === " ") {
59
+ event.preventDefault();
60
+ onClick(event as unknown as React.MouseEvent);
61
+ }
62
+ };
63
+ return (
64
+ <Box
65
+ onClick={onClick}
66
+ onKeyDown={interactive ? handleKeyDown : undefined}
67
+ role={interactive ? "button" : undefined}
68
+ tabIndex={interactive ? 0 : undefined}
69
+ aria-label={ariaLabel}
70
+ sx={(theme) => ({
71
+ display: "flex",
72
+ alignItems: "center",
73
+ gap: 1.5,
74
+ py: 1,
75
+ px: 1,
76
+ mx: -1,
77
+ cursor: interactive ? "pointer" : "default",
78
+ borderRadius: 1.5,
79
+ transition: "background-color 0.1s",
80
+ "&:hover": interactive
81
+ ? {
82
+ backgroundColor:
83
+ theme.palette.mode === "dark"
84
+ ? "rgba(255, 255, 255, 0.08)"
85
+ : "grey.100",
86
+ }
87
+ : undefined,
88
+ "&:focus-visible": interactive
89
+ ? {
90
+ outline: "2px solid",
91
+ outlineColor: "primary.main",
92
+ outlineOffset: 2,
93
+ }
94
+ : undefined,
95
+ })}
96
+ >
97
+ <Box
98
+ sx={{
99
+ width: 32,
100
+ height: 32,
101
+ borderRadius: 1,
102
+ bgcolor: tint,
103
+ color: "#FFFFFF",
104
+ display: "flex",
105
+ alignItems: "center",
106
+ justifyContent: "center",
107
+ flexShrink: 0,
108
+ }}
109
+ >
110
+ {icon}
111
+ </Box>
112
+ <Box
113
+ sx={{
114
+ flex: 1,
115
+ minWidth: 0,
116
+ display: "flex",
117
+ alignItems: "baseline",
118
+ gap: 1.5,
119
+ }}
120
+ >
121
+ <Typography
122
+ variant="body2"
123
+ sx={{
124
+ ...(mono ? { fontFamily: MONO_FONT_FAMILY } : {}),
125
+ flexShrink: 0,
126
+ maxWidth: "100%",
127
+ overflow: "hidden",
128
+ textOverflow: "ellipsis",
129
+ whiteSpace: "nowrap",
130
+ }}
131
+ >
132
+ {label}
133
+ </Typography>
134
+ {description && (
135
+ <Typography
136
+ variant="body2"
137
+ color="text.secondary"
138
+ sx={{
139
+ minWidth: 0,
140
+ overflow: "hidden",
141
+ textOverflow: "ellipsis",
142
+ whiteSpace: "nowrap",
143
+ }}
144
+ >
145
+ {description}
146
+ </Typography>
147
+ )}
148
+ </Box>
149
+ {rightLabel && (
150
+ <Typography
151
+ variant="caption"
152
+ color="text.secondary"
153
+ sx={{ flexShrink: 0 }}
154
+ >
155
+ {rightLabel}
156
+ </Typography>
157
+ )}
158
+ {trailingAction && (
159
+ <Box sx={{ flexShrink: 0, display: "flex", alignItems: "center" }}>
160
+ {trailingAction}
161
+ </Box>
162
+ )}
163
+ </Box>
164
+ );
165
+ }