@surfaces-ui/components 0.0.0-stage → 0.3.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 (270) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +51 -2
  4. package/dist/appComponents.d.ts +86 -0
  5. package/dist/appComponents.js +555 -0
  6. package/dist/appComponents.js.map +1 -0
  7. package/dist/chart/BulletGraph.d.ts +44 -0
  8. package/dist/chart/BulletGraph.js +41 -0
  9. package/dist/chart/BulletGraph.js.map +1 -0
  10. package/dist/chart/Chart.d.ts +178 -0
  11. package/dist/chart/Chart.js +285 -0
  12. package/dist/chart/Chart.js.map +1 -0
  13. package/dist/chart/Sparkline.d.ts +35 -0
  14. package/dist/chart/Sparkline.js +38 -0
  15. package/dist/chart/Sparkline.js.map +1 -0
  16. package/dist/chart/advice.d.ts +32 -0
  17. package/dist/chart/advice.js +48 -0
  18. package/dist/chart/advice.js.map +1 -0
  19. package/dist/chart/option.d.ts +90 -0
  20. package/dist/chart/option.js +252 -0
  21. package/dist/chart/option.js.map +1 -0
  22. package/dist/chart/wheel.d.ts +12 -0
  23. package/dist/chart/wheel.js +21 -0
  24. package/dist/chart/wheel.js.map +1 -0
  25. package/dist/controls/Combobox.d.ts +39 -0
  26. package/dist/controls/Combobox.js +75 -0
  27. package/dist/controls/Combobox.js.map +1 -0
  28. package/dist/controls/ConfirmDialog.d.ts +35 -0
  29. package/dist/controls/ConfirmDialog.js +84 -0
  30. package/dist/controls/ConfirmDialog.js.map +1 -0
  31. package/dist/controls/ItemControls.d.ts +115 -0
  32. package/dist/controls/ItemControls.js +109 -0
  33. package/dist/controls/ItemControls.js.map +1 -0
  34. package/dist/controls/Popover.d.ts +31 -0
  35. package/dist/controls/Popover.js +114 -0
  36. package/dist/controls/Popover.js.map +1 -0
  37. package/dist/controls/ResizeHandle.d.ts +48 -0
  38. package/dist/controls/ResizeHandle.js +91 -0
  39. package/dist/controls/ResizeHandle.js.map +1 -0
  40. package/dist/controls/SegmentedControl.d.ts +27 -0
  41. package/dist/controls/SegmentedControl.js +17 -0
  42. package/dist/controls/SegmentedControl.js.map +1 -0
  43. package/dist/controls/StatusBadge.d.ts +17 -0
  44. package/dist/controls/StatusBadge.js +10 -0
  45. package/dist/controls/StatusBadge.js.map +1 -0
  46. package/dist/controls/context.d.ts +17 -0
  47. package/dist/controls/context.js +2 -0
  48. package/dist/controls/context.js.map +1 -0
  49. package/dist/controls/placement.d.ts +43 -0
  50. package/dist/controls/placement.js +19 -0
  51. package/dist/controls/placement.js.map +1 -0
  52. package/dist/controls/resize.d.ts +23 -0
  53. package/dist/controls/resize.js +49 -0
  54. package/dist/controls/resize.js.map +1 -0
  55. package/dist/data/DataNotes.d.ts +13 -0
  56. package/dist/data/DataNotes.js +18 -0
  57. package/dist/data/DataNotes.js.map +1 -0
  58. package/dist/data/DataSourceProvider.d.ts +11 -0
  59. package/dist/data/DataSourceProvider.js +21 -0
  60. package/dist/data/DataSourceProvider.js.map +1 -0
  61. package/dist/data/export.d.ts +33 -0
  62. package/dist/data/export.js +77 -0
  63. package/dist/data/export.js.map +1 -0
  64. package/dist/data/format.d.ts +44 -0
  65. package/dist/data/format.js +127 -0
  66. package/dist/data/format.js.map +1 -0
  67. package/dist/data/messages.d.ts +13 -0
  68. package/dist/data/messages.js +2 -0
  69. package/dist/data/messages.js.map +1 -0
  70. package/dist/data/useRowWindow.d.ts +70 -0
  71. package/dist/data/useRowWindow.js +175 -0
  72. package/dist/data/useRowWindow.js.map +1 -0
  73. package/dist/discovery/AskData.d.ts +22 -0
  74. package/dist/discovery/AskData.js +49 -0
  75. package/dist/discovery/AskData.js.map +1 -0
  76. package/dist/discovery/ContextBuilder.d.ts +49 -0
  77. package/dist/discovery/ContextBuilder.js +167 -0
  78. package/dist/discovery/ContextBuilder.js.map +1 -0
  79. package/dist/discovery/DataSearch.d.ts +27 -0
  80. package/dist/discovery/DataSearch.js +73 -0
  81. package/dist/discovery/DataSearch.js.map +1 -0
  82. package/dist/discovery/ObjectDetail.d.ts +38 -0
  83. package/dist/discovery/ObjectDetail.js +129 -0
  84. package/dist/discovery/ObjectDetail.js.map +1 -0
  85. package/dist/discovery/RelationshipGraph.d.ts +19 -0
  86. package/dist/discovery/RelationshipGraph.js +64 -0
  87. package/dist/discovery/RelationshipGraph.js.map +1 -0
  88. package/dist/discovery/shared.d.ts +38 -0
  89. package/dist/discovery/shared.js +64 -0
  90. package/dist/discovery/shared.js.map +1 -0
  91. package/dist/editor/SqlEditor.d.ts +41 -0
  92. package/dist/editor/SqlEditor.js +181 -0
  93. package/dist/editor/SqlEditor.js.map +1 -0
  94. package/dist/explore/Explorer.d.ts +110 -0
  95. package/dist/explore/Explorer.js +471 -0
  96. package/dist/explore/Explorer.js.map +1 -0
  97. package/dist/explore/ModelLineage.d.ts +22 -0
  98. package/dist/explore/ModelLineage.js +70 -0
  99. package/dist/explore/ModelLineage.js.map +1 -0
  100. package/dist/explore/ReportBuilder.d.ts +39 -0
  101. package/dist/explore/ReportBuilder.js +98 -0
  102. package/dist/explore/ReportBuilder.js.map +1 -0
  103. package/dist/explore/SemanticModelEditor.d.ts +60 -0
  104. package/dist/explore/SemanticModelEditor.js +220 -0
  105. package/dist/explore/SemanticModelEditor.js.map +1 -0
  106. package/dist/explore/SemanticRows.d.ts +42 -0
  107. package/dist/explore/SemanticRows.js +121 -0
  108. package/dist/explore/SemanticRows.js.map +1 -0
  109. package/dist/explore/SemanticsProvider.d.ts +31 -0
  110. package/dist/explore/SemanticsProvider.js +72 -0
  111. package/dist/explore/SemanticsProvider.js.map +1 -0
  112. package/dist/explore/model.d.ts +151 -0
  113. package/dist/explore/model.js +344 -0
  114. package/dist/explore/model.js.map +1 -0
  115. package/dist/explore/report.d.ts +60 -0
  116. package/dist/explore/report.js +92 -0
  117. package/dist/explore/report.js.map +1 -0
  118. package/dist/explore/semantic-proposal.d.ts +44 -0
  119. package/dist/explore/semantic-proposal.js +67 -0
  120. package/dist/explore/semantic-proposal.js.map +1 -0
  121. package/dist/explore/semantic.d.ts +44 -0
  122. package/dist/explore/semantic.js +154 -0
  123. package/dist/explore/semantic.js.map +1 -0
  124. package/dist/files/FileBrowser.d.ts +42 -0
  125. package/dist/files/FileBrowser.js +314 -0
  126. package/dist/files/FileBrowser.js.map +1 -0
  127. package/dist/files/files.d.ts +65 -0
  128. package/dist/files/files.js +165 -0
  129. package/dist/files/files.js.map +1 -0
  130. package/dist/filter/FilterBar.d.ts +49 -0
  131. package/dist/filter/FilterBar.js +153 -0
  132. package/dist/filter/FilterBar.js.map +1 -0
  133. package/dist/filter/QueryFilters.d.ts +25 -0
  134. package/dist/filter/QueryFilters.js +58 -0
  135. package/dist/filter/QueryFilters.js.map +1 -0
  136. package/dist/form/Form.d.ts +76 -0
  137. package/dist/form/Form.js +131 -0
  138. package/dist/form/Form.js.map +1 -0
  139. package/dist/graph/NodeGraph.d.ts +30 -0
  140. package/dist/graph/NodeGraph.js +89 -0
  141. package/dist/graph/NodeGraph.js.map +1 -0
  142. package/dist/graph/model.d.ts +68 -0
  143. package/dist/graph/model.js +122 -0
  144. package/dist/graph/model.js.map +1 -0
  145. package/dist/grid/DataGrid.d.ts +98 -0
  146. package/dist/grid/DataGrid.js +400 -0
  147. package/dist/grid/DataGrid.js.map +1 -0
  148. package/dist/index.d.ts +85 -0
  149. package/dist/index.js +87 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/locale/SurfacesText.d.ts +17 -0
  152. package/dist/locale/SurfacesText.js +17 -0
  153. package/dist/locale/SurfacesText.js.map +1 -0
  154. package/dist/locale/locale.d.ts +305 -0
  155. package/dist/locale/locale.js +359 -0
  156. package/dist/locale/locale.js.map +1 -0
  157. package/dist/menu/ContextMenu.d.ts +31 -0
  158. package/dist/menu/ContextMenu.js +95 -0
  159. package/dist/menu/ContextMenu.js.map +1 -0
  160. package/dist/metric/Metric.d.ts +33 -0
  161. package/dist/metric/Metric.js +64 -0
  162. package/dist/metric/Metric.js.map +1 -0
  163. package/dist/metric/useMeasure.d.ts +25 -0
  164. package/dist/metric/useMeasure.js +44 -0
  165. package/dist/metric/useMeasure.js.map +1 -0
  166. package/dist/model/ModelDiagram.d.ts +142 -0
  167. package/dist/model/ModelDiagram.js +700 -0
  168. package/dist/model/ModelDiagram.js.map +1 -0
  169. package/dist/panzoom/usePanZoom.d.ts +117 -0
  170. package/dist/panzoom/usePanZoom.js +313 -0
  171. package/dist/panzoom/usePanZoom.js.map +1 -0
  172. package/dist/pipeline/DatasetReview.d.ts +48 -0
  173. package/dist/pipeline/DatasetReview.js +157 -0
  174. package/dist/pipeline/DatasetReview.js.map +1 -0
  175. package/dist/pipeline/IngestWizard.d.ts +51 -0
  176. package/dist/pipeline/IngestWizard.js +79 -0
  177. package/dist/pipeline/IngestWizard.js.map +1 -0
  178. package/dist/pipeline/Pipeline.d.ts +171 -0
  179. package/dist/pipeline/Pipeline.js +203 -0
  180. package/dist/pipeline/Pipeline.js.map +1 -0
  181. package/dist/pipeline/PipelineView.d.ts +63 -0
  182. package/dist/pipeline/PipelineView.js +239 -0
  183. package/dist/pipeline/PipelineView.js.map +1 -0
  184. package/dist/pivot/PivotTable.d.ts +94 -0
  185. package/dist/pivot/PivotTable.js +176 -0
  186. package/dist/pivot/PivotTable.js.map +1 -0
  187. package/dist/plan/QueryPlan.d.ts +29 -0
  188. package/dist/plan/QueryPlan.js +79 -0
  189. package/dist/plan/QueryPlan.js.map +1 -0
  190. package/dist/result/QueryResult.d.ts +51 -0
  191. package/dist/result/QueryResult.js +256 -0
  192. package/dist/result/QueryResult.js.map +1 -0
  193. package/dist/review/ActionReceipt.d.ts +52 -0
  194. package/dist/review/ActionReceipt.js +32 -0
  195. package/dist/review/ActionReceipt.js.map +1 -0
  196. package/dist/review/PiiReview.d.ts +37 -0
  197. package/dist/review/PiiReview.js +29 -0
  198. package/dist/review/PiiReview.js.map +1 -0
  199. package/dist/review/PlanReview.d.ts +42 -0
  200. package/dist/review/PlanReview.js +37 -0
  201. package/dist/review/PlanReview.js.map +1 -0
  202. package/dist/review/StepFlow.d.ts +25 -0
  203. package/dist/review/StepFlow.js +21 -0
  204. package/dist/review/StepFlow.js.map +1 -0
  205. package/dist/review/pii.d.ts +21 -0
  206. package/dist/review/pii.js +67 -0
  207. package/dist/review/pii.js.map +1 -0
  208. package/dist/rows/RowList.d.ts +41 -0
  209. package/dist/rows/RowList.js +72 -0
  210. package/dist/rows/RowList.js.map +1 -0
  211. package/dist/schema/ObjectBrowser.d.ts +78 -0
  212. package/dist/schema/ObjectBrowser.js +467 -0
  213. package/dist/schema/ObjectBrowser.js.map +1 -0
  214. package/dist/schema/ObjectInfo.d.ts +25 -0
  215. package/dist/schema/ObjectInfo.js +69 -0
  216. package/dist/schema/ObjectInfo.js.map +1 -0
  217. package/dist/schema/SchemaExplorer.d.ts +32 -0
  218. package/dist/schema/SchemaExplorer.js +175 -0
  219. package/dist/schema/SchemaExplorer.js.map +1 -0
  220. package/dist/schema/refs.d.ts +32 -0
  221. package/dist/schema/refs.js +65 -0
  222. package/dist/schema/refs.js.map +1 -0
  223. package/dist/site/Site.d.ts +191 -0
  224. package/dist/site/Site.js +138 -0
  225. package/dist/site/Site.js.map +1 -0
  226. package/dist/source/ConnectionBuilder.d.ts +54 -0
  227. package/dist/source/ConnectionBuilder.js +115 -0
  228. package/dist/source/ConnectionBuilder.js.map +1 -0
  229. package/dist/source/SourceList.d.ts +17 -0
  230. package/dist/source/SourceList.js +71 -0
  231. package/dist/source/SourceList.js.map +1 -0
  232. package/dist/styles.css +9930 -0
  233. package/dist/styles.layer.css +9934 -0
  234. package/dist/table/DataTable.d.ts +72 -0
  235. package/dist/table/DataTable.js +68 -0
  236. package/dist/table/DataTable.js.map +1 -0
  237. package/dist/table/Pagination.d.ts +20 -0
  238. package/dist/table/Pagination.js +16 -0
  239. package/dist/table/Pagination.js.map +1 -0
  240. package/dist/table/SelectionBar.d.ts +43 -0
  241. package/dist/table/SelectionBar.js +18 -0
  242. package/dist/table/SelectionBar.js.map +1 -0
  243. package/dist/text/Markdown.d.ts +71 -0
  244. package/dist/text/Markdown.js +187 -0
  245. package/dist/text/Markdown.js.map +1 -0
  246. package/dist/text/highlight.d.ts +23 -0
  247. package/dist/text/highlight.js +196 -0
  248. package/dist/text/highlight.js.map +1 -0
  249. package/dist/theme/ThemePicker.d.ts +16 -0
  250. package/dist/theme/ThemePicker.js +50 -0
  251. package/dist/theme/ThemePicker.js.map +1 -0
  252. package/dist/theme/ThemeProvider.d.ts +52 -0
  253. package/dist/theme/ThemeProvider.js +111 -0
  254. package/dist/theme/ThemeProvider.js.map +1 -0
  255. package/dist/workspace/NavBar.d.ts +23 -0
  256. package/dist/workspace/NavBar.js +171 -0
  257. package/dist/workspace/NavBar.js.map +1 -0
  258. package/dist/workspace/SideNav.d.ts +61 -0
  259. package/dist/workspace/SideNav.js +149 -0
  260. package/dist/workspace/SideNav.js.map +1 -0
  261. package/dist/workspace/Workspace.d.ts +53 -0
  262. package/dist/workspace/Workspace.js +243 -0
  263. package/dist/workspace/Workspace.js.map +1 -0
  264. package/dist/workspace/icons.d.ts +34 -0
  265. package/dist/workspace/icons.js +37 -0
  266. package/dist/workspace/icons.js.map +1 -0
  267. package/dist/workspace/layout.d.ts +74 -0
  268. package/dist/workspace/layout.js +276 -0
  269. package/dist/workspace/layout.js.map +1 -0
  270. package/package.json +85 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReportBuilder.js","sourceRoot":"","sources":["../../src/explore/ReportBuilder.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAA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AAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,EAC9N,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAC3B,YAAG,SAAS,EAAC,kBAAkB,YAC5B,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,GACtE,CACL,CAAC,CAAC,CAAC,CACF,KAAK,CACN,IACO,EACV,YAAG,SAAS,EAAC,iBAAiB,EAAC,IAAI,EAAC,QAAQ,YACzC,IAAI,GACH,IACA,CACP,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,SAAS,aAAa,CAAC,MAAmB;IACxC,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { DataSource } from \"@surfaces-ui/data\";\nimport type { SemanticModel } from \"@surfaces-ui/proto\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { OnContext } from \"../controls/context.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { ItemControls, standardControls } from \"../controls/ItemControls.js\";\nimport { SegmentedControl } from \"../controls/SegmentedControl.js\";\nimport { chosenValues, toggleValueFilter } from \"@surfaces-ui/data\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport { QueryFilters } from \"../filter/QueryFilters.js\";\nimport { ExploreView, Explorer, exploreReading } from \"./Explorer.js\";\nimport { ModelLineage } from \"./ModelLineage.js\";\nimport type { Pill } from \"./model.js\";\nimport { MAX_TILES, type ReportState, type ReportTile, draftState, editTile, emptyReport, keepDraft, moveTile, normalizeReport, removeTile, setTile, tileState, withDraft } from \"./report.js\";\n\nexport interface ReportBuilderProps {\n /** Where the query runs. Left out, the model's source. */\n sourceId?: string;\n /** The query the report is over: a table, or a join wide enough for every view. Left out, the model's query. */\n sql?: string;\n /** The semantic model the report's fields come from: its metrics mean the same in this report as in every other on it. */\n model?: SemanticModel;\n /** Offers \"Add to the model\" on a field that is not the model's own. See `Explorer`. */\n onPromote?(pill: Pill, all: Pill[]): Promise<string | void> | string | void;\n /** The report, when the host holds it. With no fields, pills are generated from the query's columns. */\n value?: ReportState;\n defaultValue?: ReportState;\n onChange?(report: ReportState): void;\n /** \"build\" shows the pills and shelves above the report; \"view\" shows the report alone, with its filters. A person can switch unless the host sets it. */\n mode?: \"build\" | \"view\";\n onModeChange?(mode: \"build\" | \"view\"): void;\n /** Shows a box to ask for a field, a view or a whole report in words. The host passes the words to its agent, which answers by setting `value`. */\n onAsk?(text: string, report: ReportState): void;\n /** Name recorded on pills a person makes or edits. Defaults to \"you\". */\n editor?: string;\n /** Told what a person does to the report as they do it (a view added, changed, moved or removed, a filter set, a bar clicked, a mode switched), for an agent's context. */\n onContext?: OnContext;\n dataSource?: DataSource;\n className?: string;\n}\n\n/**\n * Building a report from pills. The pills are the report's own: defined\n * once, used by every view, so a metric means the same thing in each tile.\n * A person (or an agent) puts pills on the shelves to make a view, keeps it\n * as a tile, and makes the next from where they are. Every tile follows one\n * set of filters, and a click on a bar filters the whole report. Switched\n * to \"view\" it is the dashboard alone. The whole report is plain data.\n */\nexport function ReportBuilder(props: ReportBuilderProps) {\n const { onChange, onAsk, editor, model } = props;\n const sourceId = props.sourceId ?? model?.sourceId ?? \"\";\n const sql = props.sql ?? model?.sql ?? \"\";\n const dataSource = useDataSource(props.dataSource);\n const [own, setOwn] = useState<ReportState>(props.defaultValue ?? emptyReport);\n const report = useMemo(() => normalizeReport(props.value ?? own), [props.value, own]);\n const set = useCallback(\n (next: ReportState) => {\n const clean = normalizeReport(next);\n setOwn(clean);\n onChange?.(clean);\n },\n [onChange],\n );\n const [ownMode, setOwnMode] = useState<\"build\" | \"view\">(\"build\");\n const mode = props.mode ?? ownMode;\n const setMode = (next: \"build\" | \"view\") => {\n setOwnMode(next);\n props.onModeChange?.(next);\n props.onContext?.({ kind: \"mode.changed\", summary: next === \"view\" ? \"Switched to viewing the report.\" : \"Switched to building the report.\", subject: { mode: next } });\n };\n const [note, setNote] = useState(\"\");\n /** Says what happened to the person, and tells the host the same as context for an agent. */\n const say = (kind: string, summary: string, subject?: Record<string, unknown>) => {\n setNote(summary);\n props.onContext?.({ kind, summary, ...(subject ? { subject } : {}) });\n };\n const shelves = (tile: Pick<ReportTile, \"rows\" | \"split\" | \"values\" | \"view\">) => ({ rows: tile.rows, split: tile.split ?? null, values: tile.values, view: tile.view ?? \"chart\" });\n\n const draft = useMemo(() => draftState(report), [report]);\n const editing = report.tiles.find((t) => t.id === report.editing);\n const full = !editing && report.tiles.length >= MAX_TILES;\n const titleOf = (tile: ReportTile) => tile.title || exploreReading(tileState(report, tile)) || text(\"report.untitled\");\n\n const keep = () => {\n const next = keepDraft(report);\n if (next === report) return setNote(full ? text(\"report.maxViews\", { max: MAX_TILES }) : text(\"report.needMeasure\"));\n set(next);\n const kept = editing ? next.tiles.find((t) => t.id === editing.id) : next.tiles.at(-1);\n say(editing ? \"view.changed\" : \"view.added\", editing ? `${titleOf(editing)} updated: it now shows ${exploreReading(normalizeTile(report))}.` : `Added to the report: ${exploreReading(normalizeTile(report)) || \"a view\"}. The shelves are as you left them, for the next one.`, kept ? { tile: kept.id, ...shelves(kept) } : undefined);\n };\n\n const tiles = (\n <div className=\"sf-report-tiles\" data-mode={mode}>\n {report.tiles.map((tile, index) => {\n const state = tileState(report, tile);\n const title = titleOf(tile);\n return (\n <section key={tile.id} className=\"sf-report-tile sf-controls-host\" data-controls=\"corner\" data-span={tile.span ?? 1} data-editing={report.editing === tile.id || undefined} aria-label={title}>\n <header className=\"sf-report-tile-head\">\n {mode === \"build\" ? (\n <input className=\"sf-report-tile-title\" aria-label={text(\"report.tileTitle\", { title })} value={tile.title ?? \"\"} placeholder={exploreReading(state)} onChange={(e) => set(setTile(report, tile.id, { title: e.target.value || undefined }))} />\n ) : (\n <h4 className=\"sf-report-tile-title\">{title}</h4>\n )}\n {mode === \"build\" && (\n <ItemControls\n label={text(\"report.tileControls\", { title })}\n controls={standardControls(title, {\n edit: () => (set(editTile(report, tile.id)), say(\"view.opened\", `${title} is on the shelves. Change it, then press “Update view”.`, { tile: tile.id, ...shelves(tile) })),\n ...(state.rows.length > 0 ? { view: { now: tile.view ?? \"chart\", toggle: () => (set(setTile(report, tile.id, { view: (tile.view ?? \"chart\") === \"chart\" ? \"table\" : \"chart\" })), say(\"view.changed\", `${title} is shown as a ${(tile.view ?? \"chart\") === \"chart\" ? \"table\" : \"chart\"}.`, { tile: tile.id, view: (tile.view ?? \"chart\") === \"chart\" ? \"table\" : \"chart\" })) } } : {}),\n wider: (tile.span ?? 1) < 3 ? () => (set(setTile(report, tile.id, { span: ((tile.span ?? 1) + 1) as 2 | 3 })), say(\"view.resized\", `${title} made wider.`, { tile: tile.id, span: (tile.span ?? 1) + 1 })) : false,\n narrower: (tile.span ?? 1) > 1 ? () => (set(setTile(report, tile.id, { span: ((tile.span ?? 1) - 1) as 1 | 2 })), say(\"view.resized\", `${title} made narrower.`, { tile: tile.id, span: (tile.span ?? 1) - 1 })) : false,\n earlier: index > 0 ? () => (set(moveTile(report, tile.id, -1)), say(\"view.moved\", `${title} moved earlier.`, { tile: tile.id, order: moveTile(report, tile.id, -1).tiles.map((t) => t.id) })) : false,\n later: index < report.tiles.length - 1 ? () => (set(moveTile(report, tile.id, 1)), say(\"view.moved\", `${title} moved later.`, { tile: tile.id, order: moveTile(report, tile.id, 1).tiles.map((t) => t.id) })) : false,\n remove: () => (set(removeTile(report, tile.id)), say(\"view.removed\", `${title} removed from the report.`, { tile: tile.id, ...shelves(tile) })),\n })}\n />\n )}\n </header>\n <ExploreView\n dataSource={dataSource}\n sourceId={sourceId}\n sql={sql}\n state={state}\n height={240}\n label={title}\n onPointClick={(column, value) => {\n const filters = toggleValueFilter(report.filters, column, value);\n set({ ...report, filters });\n const chosen = chosenValues(filters, column);\n const on = chosen.some((v) => String(v) === String(value));\n say(\n \"point.selected\",\n on\n ? `Clicked ${value} in “${title}”: the report is filtered to ${column} ${chosen.length === 1 ? \"is\" : \"is one of\"} ${chosen.join(\", \")}. Click the bar again to take it out.`\n : `Clicked ${value} in “${title}” again: ${value} is taken out of the filter on ${column}${chosen.length === 0 ? \", which is now cleared\" : \"\"}.`,\n { tile: tile.id, column, value, filters },\n );\n }}\n />\n </section>\n );\n })}\n </div>\n );\n\n return (\n <div className={[\"sf-report\", props.className].filter(Boolean).join(\" \")} data-mode={mode}>\n <header className=\"sf-report-head\">\n {mode === \"build\" ? (\n <input className=\"sf-report-title\" aria-label={text(\"report.title\")} placeholder={text(\"report.untitledReport\")} value={report.title ?? \"\"} onChange={(e) => set({ ...report, title: e.target.value || undefined })} />\n ) : (\n <h3 className=\"sf-report-title\">{report.title || text(\"report.untitledReport\")}</h3>\n )}\n <SegmentedControl\n label={text(\"report.mode\")}\n value={mode}\n onChange={setMode}\n options={[\n { value: \"build\", label: text(\"report.build\") },\n { value: \"view\", label: text(\"report.view\") },\n ]}\n />\n </header>\n {model?.dataset && <ModelLineage model={model} compact />}\n\n {mode === \"build\" && (\n <section className=\"sf-report-builder\" aria-label={text(\"report.builder\")}>\n {editing && (\n <p className=\"sf-report-editing\" role=\"status\">\n {text(\"report.changing\", { title: titleOf(editing) })}{\" \"}\n <button type=\"button\" className=\"sf-button\" onClick={() => (set({ ...report, editing: undefined }), setNote(text(\"report.leftAsItWas\")))}>\n {text(\"report.leaveAsItWas\")}\n </button>\n </p>\n )}\n <Explorer\n dataSource={dataSource}\n sourceId={sourceId}\n sql={sql}\n model={model}\n onPromote={props.onPromote}\n value={draft}\n onChange={(state) => set(withDraft(report, state))}\n onAsk={onAsk ? (text) => onAsk(text, report) : undefined}\n editor={editor}\n onContext={props.onContext}\n chartHeight={240}\n controls={[\n {\n id: \"keep\",\n label: editing ? text(\"report.updateView\") : text(\"report.addToReport\"),\n icon: editing ? \"confirm\" : \"add\",\n onSelect: keep,\n disabled: full,\n // The one thing a person has to be able to find without pointing at the chart first.\n pinned: true,\n },\n ]}\n />\n </section>\n )}\n\n <section className=\"sf-report-body\" aria-label={text(\"report.body\")}>\n {mode === \"view\" && report.fields.length > 0 && <QueryFilters dataSource={dataSource} sourceId={sourceId} sql={sql} filters={report.filters} onChange={(filters) => set({ ...report, filters })} onContext={props.onContext} />}\n {report.tiles.length === 0 ? (\n <p className=\"sf-explore-empty\">\n {mode === \"build\" ? text(\"report.emptyBuild\") : text(\"report.emptyView\")}\n </p>\n ) : (\n tiles\n )}\n </section>\n <p className=\"sf-explore-note\" role=\"status\">\n {note}\n </p>\n </div>\n );\n}\n\n/** The draft as it would be kept, for saying what was added. */\nfunction normalizeTile(report: ReportState) {\n return tileState(report, report.draft ?? { rows: [], values: [] });\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { type DataSource, type Pipelines, aggregateWord } from "@surfaces-ui/data";
2
+ import { type SemanticModel } from "@surfaces-ui/proto";
3
+ import type { OnContext } from "../controls/context.js";
4
+ export interface SemanticModelEditorProps {
5
+ /**
6
+ * The model as saved. A model of version 0 is not saved yet: the editor
7
+ * creates it, asking for its name, what one row is and its key, and keeps
8
+ * it as version 1 when a person saves.
9
+ */
10
+ model: SemanticModel;
11
+ /**
12
+ * Changes not saved yet: a person's edits, or what an agent proposes. Held
13
+ * by the host when given; each change comes back through `onDraftChange`.
14
+ * Nothing is kept until a person presses Save.
15
+ */
16
+ draft?: SemanticModel;
17
+ defaultDraft?: SemanticModel;
18
+ onDraftChange?(draft: SemanticModel | undefined): void;
19
+ /** Who proposed the draft, when it was not the person looking at it: an agent's name. Shown above the changes. */
20
+ proposedBy?: string;
21
+ /** Keeps the draft as the model's next version. Left out, the model is shown and cannot be changed. Resolve to the saved model, or undefined when it was refused. */
22
+ onSave?(draft: SemanticModel, note: string): Promise<SemanticModel | undefined> | SemanticModel | undefined | void;
23
+ /** A problem the store reported on the last save, shown with the changes. */
24
+ problem?: string;
25
+ /** Name recorded on fields a person adds or changes. Defaults to "you". */
26
+ editor?: string;
27
+ /** Told what a person does here (a field added, changed or removed, the rows changed, the changes saved or dropped), for an agent's context. */
28
+ onContext?: OnContext;
29
+ /**
30
+ * Hands a person's words to the host's agent with the draft as it stands,
31
+ * so the agent can propose or redo it. The editor never calls a model.
32
+ * Left out, there is no box to ask in.
33
+ */
34
+ onAsk?(text: string, draft: SemanticModel): void;
35
+ /** Who `onAsk` reaches, as the box names it. Defaults to "the agent". */
36
+ askLabel?: string;
37
+ /** Open the join builder at once: a new model built from tables. */
38
+ building?: boolean;
39
+ dataSource?: DataSource;
40
+ /**
41
+ * Where pipeline datasets come from. Left out, the one from
42
+ * `PipelinesProvider`. With one, a new model can start from a built
43
+ * dataset (its grain, key and columns), and a model on a dataset shows
44
+ * when it was built, how its checks went and what it reads.
45
+ */
46
+ pipelines?: Pipelines;
47
+ /** Opens a model's dataset in the host's pipeline view. */
48
+ onOpenDataset?(pipelineId: string, dataset: string): void;
49
+ className?: string;
50
+ }
51
+ /**
52
+ * A semantic model, to read and to change: its query, and its dimensions,
53
+ * measures and metrics with who defined each. Changes, a person's or an
54
+ * agent's, are a draft marked field by field against what is saved, checked
55
+ * as they are made, and kept only when a person saves them as the next
56
+ * version. Every report and explorer on the model takes its fields from it.
57
+ */
58
+ export declare function SemanticModelEditor(props: SemanticModelEditorProps): import("react").JSX.Element;
59
+ /** The aggregate words the editor shows, by the contract's function. */
60
+ export declare const aggregateLabel: (fn: Parameters<typeof aggregateWord>[0]) => string;
@@ -0,0 +1,220 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clone, create } from "@bufbuild/protobuf";
3
+ import { aggregateWord, collect, datasetSql, draftSemanticFields, semanticModelFromDataset, semanticModelProblems, thePipeline } from "@surfaces-ui/data";
4
+ import { DatasetKind, DimensionKind, DimensionSchema, MeasureSchema, SemanticModelSchema } from "@surfaces-ui/proto";
5
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
6
+ import { CONTROLS_HOST, ItemControls, standardControls } from "../controls/ItemControls.js";
7
+ import { useDataSource } from "../data/DataSourceProvider.js";
8
+ import { messageOf } from "../data/useRowWindow.js";
9
+ import { useOptionalPipelines } from "../pipeline/PipelineView.js";
10
+ import { piiHints } from "../review/pii.js";
11
+ import { ModelLineage } from "./ModelLineage.js";
12
+ import { PillEditor } from "./Explorer.js";
13
+ import { fieldNamed, modelChanges, pillsFromModel, setModelField } from "./semantic.js";
14
+ import { SemanticRows } from "./SemanticRows.js";
15
+ const KIND = {
16
+ attribute: { title: "Dimensions", one: "dimension", hint: "Ways to break the rows down: a category, or a date grouped by month." },
17
+ metric: { title: "Measures", one: "measure", hint: "A column summarised: a sum, an average, a count." },
18
+ derived: { title: "Metrics", one: "metric", hint: "Arithmetic over measures, worked out by the database after summarising: a rate, a margin." },
19
+ };
20
+ const AGGREGATE_WORDS = { sum: "Sum", avg: "Average", count: "Count", count_distinct: "Distinct count", min: "Smallest", max: "Largest", median: "Median", stddev: "Standard deviation", variance: "Variance" };
21
+ const CHANGE_WORDS = { added: "Added", changed: "Changed", removed: "Removed" };
22
+ /** The parts of a model that are not fields, as a change list names them. */
23
+ const PART_WORDS = { "(name)": "the name", "(label)": "the label", "(description)": "the description", "(sql)": "the query", "(grain)": "what one row is", "(primaryKey)": "the key", "(joins)": "the tables and joins", "(dataset)": "the pipeline dataset" };
24
+ const changeText = ([name, kind]) => (PART_WORDS[name] ? `Changed ${PART_WORDS[name]}` : `${CHANGE_WORDS[kind]} ${name}`);
25
+ const modelName = (label) => label
26
+ .toLowerCase()
27
+ .replace(/[^a-z0-9]+/g, "_")
28
+ .replace(/^[^a-z]+|_+$/g, "")
29
+ .slice(0, 64);
30
+ function definition(model, pill) {
31
+ if (pill.kind === "attribute") {
32
+ const dimension = model.dimensions.find((d) => d.name === pill.id);
33
+ return dimension?.kind === DimensionKind.TIME ? `${pill.column}, by ${pill.grain ?? "month"}` : (pill.column ?? "");
34
+ }
35
+ if (pill.kind === "metric")
36
+ return pill.column ? `${AGGREGATE_WORDS[pill.aggregate ?? ""] ?? pill.aggregate} of ${pill.column}` : "Count of rows";
37
+ return pill.expression ?? "";
38
+ }
39
+ /**
40
+ * A semantic model, to read and to change: its query, and its dimensions,
41
+ * measures and metrics with who defined each. Changes, a person's or an
42
+ * agent's, are a draft marked field by field against what is saved, checked
43
+ * as they are made, and kept only when a person saves them as the next
44
+ * version. Every report and explorer on the model takes its fields from it.
45
+ */
46
+ export function SemanticModelEditor(props) {
47
+ const { model, onSave, editor = "you" } = props;
48
+ const isNew = model.version === 0;
49
+ const dataSource = useDataSource(props.dataSource);
50
+ const id = useId();
51
+ const [ownDraft, setOwnDraft] = useState(props.defaultDraft);
52
+ const draft = props.draft !== undefined || props.onDraftChange ? props.draft : ownDraft;
53
+ const shown = draft ?? model;
54
+ const setDraft = (next) => {
55
+ setOwnDraft(next);
56
+ props.onDraftChange?.(next);
57
+ };
58
+ const context = useRef(props.onContext);
59
+ context.current = props.onContext;
60
+ const [note, setNote] = useState("");
61
+ const say = (kind, summary, subject) => {
62
+ setNote(summary);
63
+ context.current?.({ kind, summary, ...(subject ? { subject } : {}) });
64
+ };
65
+ const [columns, setColumns] = useState([]);
66
+ const [queryProblem, setQueryProblem] = useState();
67
+ useEffect(() => {
68
+ if (!shown.sql.trim() || !shown.sourceId)
69
+ return setColumns([]), setQueryProblem(undefined);
70
+ const controller = new AbortController();
71
+ collect(dataSource.execute({ sourceId: shown.sourceId, query: { baseSql: shown.sql, page: { limit: 1 } } }, { signal: controller.signal }))
72
+ .then((result) => !controller.signal.aborted && (setColumns(result.table.schema.fields), setQueryProblem(undefined)))
73
+ .catch((error) => !controller.signal.aborted && setQueryProblem(messageOf(error)));
74
+ return () => controller.abort();
75
+ }, [dataSource, shown.sourceId, shown.sql]);
76
+ const pipelines = useOptionalPipelines(props.pipelines);
77
+ const [built, setBuilt] = useState([]);
78
+ const [datasetChoice, setDatasetChoice] = useState("");
79
+ useEffect(() => {
80
+ if (!isNew || !onSave || !pipelines)
81
+ return;
82
+ const controller = new AbortController();
83
+ const options = { signal: controller.signal };
84
+ pipelines
85
+ .listPipelines({}, options)
86
+ .then((list) => Promise.all(list.pipelines.filter((p) => !model.sourceId || p.sourceId === model.sourceId).map((p) => pipelines.getPipeline({ id: p.id }, options).then((r) => r.pipeline))))
87
+ .then((found) => !controller.signal.aborted && setBuilt(found.filter((p) => !!p && p.datasets.some((d) => d.kind !== DatasetKind.SOURCE))))
88
+ .catch(() => !controller.signal.aborted && setBuilt([]));
89
+ return () => controller.abort();
90
+ }, [pipelines, isNew, !!onSave, model.sourceId]); // eslint-disable-line react-hooks/exhaustive-deps
91
+ const fromDataset = () => {
92
+ const [pi, di] = datasetChoice.split(":").map(Number);
93
+ const pipeline = built[pi ?? -1];
94
+ const dataset = pipeline?.datasets[di ?? -1]?.name;
95
+ const pipelineId = pipeline?.summary?.id ?? "";
96
+ if (!pipeline || !dataset)
97
+ return;
98
+ const next = semanticModelFromDataset(pipeline, dataset, { ...(shown.name ? { name: shown.name } : {}), ...(shown.label ? { label: shown.label } : {}) });
99
+ if (shown.description)
100
+ next.description = shown.description;
101
+ keep(next);
102
+ setNameTouched(true);
103
+ say("rows.changed", `Started from the dataset ${dataset} of ${thePipeline(pipeline.summary?.name || pipelineId)}: its grain, key and ${next.dimensions.length + next.measures.length} fields from its columns, for you to check.`, { pipeline: pipelineId, dataset });
104
+ };
105
+ const pills = useMemo(() => pillsFromModel(shown), [shown]);
106
+ const changes = useMemo(() => (draft ? modelChanges(model, draft) : new Map()), [model, draft]);
107
+ const removed = useMemo(() => pillsFromModel(model).filter((p) => changes.get(p.id) === "removed"), [model, changes]);
108
+ const names = columns.map((c) => c.name);
109
+ const problems = useMemo(() => {
110
+ const found = draft ? semanticModelProblems(draft, { isNew }) : [];
111
+ if (columns.length > 0)
112
+ for (const p of pills)
113
+ if (p.column && !names.includes(p.column))
114
+ found.push(`"${p.id}" names the column "${p.column}", which the query does not return.`);
115
+ return found;
116
+ }, [draft, pills, columns]); // eslint-disable-line react-hooks/exhaustive-deps
117
+ const [editing, setEditing] = useState();
118
+ const [saveNote, setSaveNote] = useState("");
119
+ const [saving, setSaving] = useState(false);
120
+ const blank = (kind) => ({ id: "", kind, label: "", by: editor, ...(kind === "metric" ? { aggregate: "sum", column: columns.find((c) => /Int|Float|Decimal/.test(String(c.type)))?.name } : kind === "attribute" ? { column: columns[0]?.name } : { expression: "", format: "number" }) });
121
+ // A draft that comes back to what is saved is no draft; a new model's draft is kept, as it is all there is.
122
+ const keep = (next) => setDraft(!isNew && modelChanges(model, next).size === 0 ? undefined : next);
123
+ const change = (name, pill) => keep(setModelField(shown, name, pill, editor));
124
+ const setPart = (patch) => keep(create(SemanticModelSchema, { ...shown, ...patch }));
125
+ const [nameTouched, setNameTouched] = useState(!isNew || !!model.name);
126
+ const draftFields = () => {
127
+ const personal = new Set(piiHints(columns.map((c) => c.name)).map((h) => h.column));
128
+ const fields = draftSemanticFields(columns.map((c) => ({ name: c.name, type: String(c.type), personal: personal.has(c.name) })), { grain: shown.grain });
129
+ const next = clone(SemanticModelSchema, shown);
130
+ next.dimensions = (fields.dimensions ?? []).map((d) => create(DimensionSchema, d));
131
+ next.measures = (fields.measures ?? []).map((m) => create(MeasureSchema, m));
132
+ keep(next);
133
+ say("fields.drafted", `Fields drafted from the query's ${columns.length} columns by name and type${personal.size ? `, leaving out ${personal.size} that may hold personal data` : ""}. Check them before saving.`);
134
+ };
135
+ const [ask, setAsk] = useState("");
136
+ const sendAsk = () => {
137
+ const text = ask.trim();
138
+ if (!text || !props.onAsk)
139
+ return;
140
+ props.onAsk(text, shown);
141
+ setAsk("");
142
+ setNote(`Sent to ${props.askLabel ?? "the agent"}.`);
143
+ };
144
+ const restore = (name) => {
145
+ const was = pillsFromModel(model).find((p) => p.id === name);
146
+ if (!was)
147
+ return;
148
+ change(name, was);
149
+ say("field.restored", `${was.label} put back as it is saved.`, { field: name });
150
+ };
151
+ const save = async () => {
152
+ if (!draft || !onSave || problems.length > 0)
153
+ return;
154
+ setSaving(true);
155
+ try {
156
+ const saved = await onSave(draft, saveNote.trim() || `${changes.size} ${changes.size === 1 ? "change" : "changes"}`);
157
+ if (saved) {
158
+ setDraft(undefined);
159
+ setSaveNote("");
160
+ say("model.saved", `Saved as version ${saved.version}. Every report and explorer on this model now uses it.`, { model: saved.name, version: saved.version, changes: Object.fromEntries(changes) });
161
+ }
162
+ }
163
+ catch (error) {
164
+ setNote(messageOf(error));
165
+ }
166
+ finally {
167
+ setSaving(false);
168
+ }
169
+ };
170
+ const askBox = props.onAsk && (_jsxs("form", { className: "sf-semantic-ask", onSubmit: (e) => {
171
+ e.preventDefault();
172
+ sendAsk();
173
+ }, children: [_jsx("label", { htmlFor: `${id}-ask`, children: isNew ? `Tell ${props.askLabel ?? "the agent"} what this model should measure; it drafts the tables, joins, grain and fields for you to check.` : `Ask ${props.askLabel ?? "the agent"} to change this model.` }), _jsxs("span", { className: "sf-semantic-ask-row", children: [_jsx("input", { id: `${id}-ask`, className: "sf-input", placeholder: isNew ? "Order lines with their store and product, to measure revenue and refunds" : "Add margin as a share of revenue", value: ask, onChange: (e) => setAsk(e.target.value) }), _jsx("button", { type: "submit", className: "sf-button", "data-variant": "primary", disabled: !ask.trim(), children: "Ask" })] })] }));
174
+ const section = (kind) => {
175
+ const rows = [...pills.filter((p) => p.kind === kind), ...removed.filter((p) => p.kind === kind)];
176
+ return (_jsxs("section", { className: "sf-semantic-section", "aria-labelledby": `${id}-${kind}`, children: [_jsxs("h4", { id: `${id}-${kind}`, className: "sf-explore-heading", children: [_jsxs("span", { children: [KIND[kind].title, " ", _jsx("span", { className: "sf-semantic-count", children: pills.filter((p) => p.kind === kind).length })] }), onSave && (_jsx("button", { type: "button", className: "sf-explore-add", "aria-label": `Add a ${KIND[kind].one}`, onClick: () => setEditing({ pill: blank(kind), isNew: true }), children: "+" }))] }), _jsx("p", { className: "sf-explore-hint", children: KIND[kind].hint }), rows.length === 0 ? (_jsx("p", { className: "sf-explore-hint", children: "None yet." })) : (_jsxs("table", { className: "sf-semantic-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Label" }), _jsx("th", { scope: "col", children: "Name" }), _jsx("th", { scope: "col", children: kind === "derived" ? "Calculation" : "Definition" }), _jsx("th", { scope: "col", children: "Defined by" }), onSave && (_jsx("th", { scope: "col", children: _jsx("span", { className: "sf-a2-visually-hidden", children: "Controls" }) }))] }) }), _jsx("tbody", { children: rows.map((pill) => {
177
+ const state = changes.get(pill.id);
178
+ const gone = state === "removed";
179
+ return (_jsxs("tr", { className: CONTROLS_HOST, "data-change": state, children: [_jsxs("th", { scope: "row", children: [pill.label, state && _jsx("span", { className: "sf-semantic-change", children: CHANGE_WORDS[state] }), pill.description && _jsx("span", { className: "sf-semantic-description", children: pill.description })] }), _jsx("td", { children: _jsx("code", { children: pill.id }) }), _jsxs("td", { children: [_jsx("code", { children: definition(gone ? model : shown, pill) }), pill.format && _jsxs("span", { className: "sf-semantic-format", children: [" \u00B7 ", pill.format] })] }), _jsx("td", { children: fieldNamed(gone ? model : shown, pill.id)?.definedBy || "—" }), onSave && (_jsx("td", { children: gone ? (_jsx("button", { type: "button", className: "sf-button", onClick: () => restore(pill.id), children: "Put back" })) : (_jsx(ItemControls, { label: `${pill.label} controls`, controls: standardControls(pill.label, {
180
+ edit: () => setEditing({ pill, isNew: false }),
181
+ duplicate: () => setEditing({ pill: { ...pill, label: `${pill.label} copy`, by: editor }, isNew: true }),
182
+ remove: () => {
183
+ change(pill.id, undefined);
184
+ say("field.removed", `${pill.label} taken out of the draft. Save to remove it from the model.`, { field: pill.id });
185
+ },
186
+ }) })) }))] }, pill.id));
187
+ }) })] }))] }, kind));
188
+ };
189
+ return (_jsxs("div", { className: ["sf-semantic", props.className].filter(Boolean).join(" "), children: [_jsxs("header", { className: "sf-semantic-header", children: [isNew && onSave ? (_jsxs("div", { className: "sf-semantic-identity", children: [_jsx("h3", { className: "sf-semantic-title", children: "New model" }), _jsx("label", { htmlFor: `${id}-label`, children: "Name for people" }), _jsx("input", { id: `${id}-label`, className: "sf-input", placeholder: "Sales lines", value: shown.label, onChange: (e) => setPart({ label: e.target.value, ...(nameTouched ? {} : { name: modelName(e.target.value) }) }) }), _jsx("label", { htmlFor: `${id}-name`, children: "Name in calculations and files" }), _jsx("input", { id: `${id}-name`, className: "sf-input", placeholder: "sales_lines", value: shown.name, onChange: (e) => (setNameTouched(true), setPart({ name: e.target.value })) }), _jsx("label", { htmlFor: `${id}-about`, children: "What it is for" }), _jsx("input", { id: `${id}-about`, className: "sf-input", placeholder: "Revenue, cost and refunds by store and product.", value: shown.description, onChange: (e) => setPart({ description: e.target.value }) })] })) : (_jsxs(_Fragment, { children: [_jsx("h3", { className: "sf-semantic-title", children: shown.label || shown.name }), shown.description && _jsx("p", { className: "sf-semantic-description", children: shown.description })] })), _jsxs("p", { className: "sf-explore-hint", children: [shown.name ? _jsx("code", { children: shown.name }) : "Not named yet", " on ", model.sourceId, isNew ? " · not saved yet" : ` · version ${model.version}`, model.savedBy && ` · saved by ${model.savedBy}`, model.updatedAt && ` on ${model.updatedAt.slice(0, 10)}`] }), queryProblem && (_jsxs("p", { className: "sf-filter-problem", role: "alert", children: ["The query does not run: ", queryProblem] }))] }), isNew && onSave && built.length > 0 && !shown.dataset && (_jsxs("div", { className: "sf-semantic-actions sf-semantic-from-dataset", children: [_jsx("label", { htmlFor: `${id}-dataset`, children: "Start from a pipeline dataset" }), _jsxs("select", { id: `${id}-dataset`, className: "sf-input", value: datasetChoice, onChange: (e) => setDatasetChoice(e.target.value), children: [_jsx("option", { value: "", children: "Choose a dataset\u2026" }), built.map((p, pi) => (_jsx("optgroup", { label: p.summary?.name || p.summary?.id, children: p.datasets.map((d, di) => d.kind === DatasetKind.SOURCE ? null : (_jsxs("option", { value: `${pi}:${di}`, children: [d.name, d.grain ? ` · ${d.grain}` : "", d.builtAt ? "" : " · not built yet"] }, d.name))) }, p.summary?.id)))] }), _jsx("button", { type: "button", className: "sf-button", disabled: !datasetChoice, onClick: fromDataset, children: "Use this dataset" }), _jsx("span", { className: "sf-explore-hint", children: "Its grain and key are checked by the pipeline after every build; its columns become fields for you to check." })] })), _jsx(ModelLineage, { model: shown, pipelines: pipelines, onOpenDataset: props.onOpenDataset, onUseDataset: onSave
190
+ ? (standing) => {
191
+ keep(create(SemanticModelSchema, { ...shown, sourceId: shown.sourceId, sql: datasetSql({ name: standing.dataset, relation: standing.relation ?? "" }), grain: standing.grain || shown.grain, primaryKey: standing.primaryKey }));
192
+ say("rows.changed", `The grain and key are the dataset's again: ${standing.primaryKey.join(", ")}.`, { grain: standing.grain, primaryKey: standing.primaryKey });
193
+ }
194
+ : undefined }), isNew && askBox, _jsx(SemanticRows, { model: shown, columns: columns, editor: editor, dataSource: dataSource, building: props.building && !shown.dataset, onChange: onSave
195
+ ? (next, summary) => {
196
+ // Rows written or joined by hand are no longer the pipeline's dataset.
197
+ if (next.dataset && (next.tables.length > 0 || next.sql !== shown.sql))
198
+ next = create(SemanticModelSchema, { ...next, dataset: undefined });
199
+ keep(next);
200
+ if (summary)
201
+ say("rows.changed", summary, { grain: next.grain, primaryKey: next.primaryKey, tables: next.tables });
202
+ }
203
+ : undefined }), onSave && columns.length > 0 && shown.dimensions.length === 0 && shown.measures.length === 0 && (_jsxs("p", { className: "sf-semantic-actions", children: [_jsx("button", { type: "button", className: "sf-button", onClick: draftFields, children: "Draft fields from the columns" }), _jsx("span", { className: "sf-explore-hint", children: "Dimensions and measures from the columns' names and types, marked as generated, for you to check." })] })), draft && (_jsxs("div", { className: "sf-semantic-draft", role: "region", "aria-label": "Changes not saved", children: [_jsxs("p", { children: [_jsx("strong", { children: isNew ? "New model, not saved" : `${changes.size} ${changes.size === 1 ? "change" : "changes"} not saved` }), props.proposedBy ? `, proposed by ${props.proposedBy}. Read ${isNew ? "it" : "them"} before saving.` : ".", " ", isNew ? `${shown.dimensions.length} dimensions, ${shown.measures.length} measures, ${shown.metrics.length} metrics.` : [...changes].map(changeText).join(", ")] }), (problems.length > 0 || props.problem) && (_jsx("ul", { className: "sf-filter-problem", role: "alert", children: [...problems, ...(props.problem ? [props.problem] : [])].map((problem) => (_jsx("li", { children: problem }, problem))) })), onSave && (_jsxs("div", { className: "sf-semantic-actions", children: [_jsx("label", { htmlFor: `${id}-note`, className: "sf-a2-visually-hidden", children: "What changed" }), _jsx("input", { id: `${id}-note`, className: "sf-input", placeholder: "What changed, in a few words", value: saveNote, onChange: (e) => setSaveNote(e.target.value) }), _jsx("button", { type: "button", className: "sf-button", "data-variant": "primary", disabled: problems.length > 0 || saving, onClick: () => void save(), children: saving ? "Saving…" : `Save as version ${model.version + 1}` }), _jsx("button", { type: "button", className: "sf-button", onClick: () => {
204
+ setDraft(undefined);
205
+ say("draft.discarded", isNew ? "The new model was cleared, to start again." : `${changes.size} ${changes.size === 1 ? "change" : "changes"} dropped; the model is as saved.`);
206
+ }, children: isNew ? "Start again" : "Drop changes" })] }))] })), editing && (_jsx(PillEditor, { pill: editing.pill, all: pills, columns: columns, isNew: editing.isNew, onCancel: () => setEditing(undefined), onSave: (next) => {
207
+ change(editing.isNew ? next.id : editing.pill.id, next);
208
+ say(editing.isNew ? "field.added" : "field.changed", `${next.label} ${editing.isNew ? "added to" : "changed in"} the draft. Save to keep it.`, { field: next, ...(editing.isNew ? {} : { was: editing.pill }) });
209
+ setEditing(undefined);
210
+ }, onRemove: editing.isNew
211
+ ? undefined
212
+ : () => {
213
+ change(editing.pill.id, undefined);
214
+ say("field.removed", `${editing.pill.label} taken out of the draft. Save to remove it from the model.`, { field: editing.pill.id });
215
+ setEditing(undefined);
216
+ } }, `${editing.pill.id}-${editing.isNew}`)), ["attribute", "metric", "derived"].map(section), !isNew && askBox, _jsx("p", { className: "sf-explore-note", role: "status", children: note })] }));
217
+ }
218
+ /** The aggregate words the editor shows, by the contract's function. */
219
+ export const aggregateLabel = (fn) => AGGREGATE_WORDS[aggregateWord(fn) ?? ""] ?? "";
220
+ //# sourceMappingURL=SemanticModelEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SemanticModelEditor.js","sourceRoot":"","sources":["../../src/explore/SemanticModelEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAmC,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3L,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAqC,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAExJ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAoB,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAkDjD,MAAM,IAAI,GAAmE;IAC3E,SAAS,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,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,CAAC,IAlBF,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,OAAO,CAAC,KAAK,EAAE,CAoB1C,CACH,EACC,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,EAC/D,CAAC,KAAK,IAAI,MAAM,EACjB,YAAG,SAAS,EAAC,iBAAiB,EAAC,IAAI,EAAC,QAAQ,YACzC,IAAI,GACH,IACA,CACP,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAuC,EAAE,EAAE,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC","sourcesContent":["import { clone, create } from \"@bufbuild/protobuf\";\nimport { type DataSource, type Pipelines, aggregateWord, collect, datasetSql, draftSemanticFields, semanticModelFromDataset, semanticModelProblems, thePipeline } from \"@surfaces-ui/data\";\nimport { DatasetKind, DimensionKind, DimensionSchema, MeasureSchema, type Pipeline, type SemanticModel, SemanticModelSchema } from \"@surfaces-ui/proto\";\nimport type { Field } from \"apache-arrow\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { OnContext } from \"../controls/context.js\";\nimport { CONTROLS_HOST, ItemControls, standardControls } from \"../controls/ItemControls.js\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport { messageOf } from \"../data/useRowWindow.js\";\nimport { useOptionalPipelines } from \"../pipeline/PipelineView.js\";\nimport { piiHints } from \"../review/pii.js\";\nimport { ModelLineage } from \"./ModelLineage.js\";\nimport { PillEditor } from \"./Explorer.js\";\nimport type { Pill, PillKind } from \"./model.js\";\nimport { type FieldChange, fieldNamed, modelChanges, pillsFromModel, setModelField } from \"./semantic.js\";\nimport { SemanticRows } from \"./SemanticRows.js\";\n\nexport interface SemanticModelEditorProps {\n /**\n * The model as saved. A model of version 0 is not saved yet: the editor\n * creates it, asking for its name, what one row is and its key, and keeps\n * it as version 1 when a person saves.\n */\n model: SemanticModel;\n /**\n * Changes not saved yet: a person's edits, or what an agent proposes. Held\n * by the host when given; each change comes back through `onDraftChange`.\n * Nothing is kept until a person presses Save.\n */\n draft?: SemanticModel;\n defaultDraft?: SemanticModel;\n onDraftChange?(draft: SemanticModel | undefined): void;\n /** Who proposed the draft, when it was not the person looking at it: an agent's name. Shown above the changes. */\n proposedBy?: string;\n /** Keeps the draft as the model's next version. Left out, the model is shown and cannot be changed. Resolve to the saved model, or undefined when it was refused. */\n onSave?(draft: SemanticModel, note: string): Promise<SemanticModel | undefined> | SemanticModel | undefined | void;\n /** A problem the store reported on the last save, shown with the changes. */\n problem?: string;\n /** Name recorded on fields a person adds or changes. Defaults to \"you\". */\n editor?: string;\n /** Told what a person does here (a field added, changed or removed, the rows changed, the changes saved or dropped), for an agent's context. */\n onContext?: OnContext;\n /**\n * Hands a person's words to the host's agent with the draft as it stands,\n * so the agent can propose or redo it. The editor never calls a model.\n * Left out, there is no box to ask in.\n */\n onAsk?(text: string, draft: SemanticModel): void;\n /** Who `onAsk` reaches, as the box names it. Defaults to \"the agent\". */\n askLabel?: string;\n /** Open the join builder at once: a new model built from tables. */\n building?: boolean;\n dataSource?: DataSource;\n /**\n * Where pipeline datasets come from. Left out, the one from\n * `PipelinesProvider`. With one, a new model can start from a built\n * dataset (its grain, key and columns), and a model on a dataset shows\n * when it was built, how its checks went and what it reads.\n */\n pipelines?: Pipelines;\n /** Opens a model's dataset in the host's pipeline view. */\n onOpenDataset?(pipelineId: string, dataset: string): void;\n className?: string;\n}\n\nconst KIND: Record<PillKind, { title: string; one: string; hint: string }> = {\n attribute: { title: \"Dimensions\", one: \"dimension\", hint: \"Ways to break the rows down: a category, or a date grouped by month.\" },\n metric: { title: \"Measures\", one: \"measure\", hint: \"A column summarised: a sum, an average, a count.\" },\n derived: { title: \"Metrics\", one: \"metric\", hint: \"Arithmetic over measures, worked out by the database after summarising: a rate, a margin.\" },\n};\nconst AGGREGATE_WORDS: Record<string, string> = { sum: \"Sum\", avg: \"Average\", count: \"Count\", count_distinct: \"Distinct count\", min: \"Smallest\", max: \"Largest\", median: \"Median\", stddev: \"Standard deviation\", variance: \"Variance\" };\nconst CHANGE_WORDS: Record<FieldChange, string> = { added: \"Added\", changed: \"Changed\", removed: \"Removed\" };\n/** The parts of a model that are not fields, as a change list names them. */\nconst PART_WORDS: Record<string, string> = { \"(name)\": \"the name\", \"(label)\": \"the label\", \"(description)\": \"the description\", \"(sql)\": \"the query\", \"(grain)\": \"what one row is\", \"(primaryKey)\": \"the key\", \"(joins)\": \"the tables and joins\", \"(dataset)\": \"the pipeline dataset\" };\nconst changeText = ([name, kind]: [string, FieldChange]) => (PART_WORDS[name] ? `Changed ${PART_WORDS[name]}` : `${CHANGE_WORDS[kind]} ${name}`);\nconst modelName = (label: string) =>\n label\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^[^a-z]+|_+$/g, \"\")\n .slice(0, 64);\n\nfunction definition(model: SemanticModel, pill: Pill): string {\n if (pill.kind === \"attribute\") {\n const dimension = model.dimensions.find((d) => d.name === pill.id);\n return dimension?.kind === DimensionKind.TIME ? `${pill.column}, by ${pill.grain ?? \"month\"}` : (pill.column ?? \"\");\n }\n if (pill.kind === \"metric\") return pill.column ? `${AGGREGATE_WORDS[pill.aggregate ?? \"\"] ?? pill.aggregate} of ${pill.column}` : \"Count of rows\";\n return pill.expression ?? \"\";\n}\n\n/**\n * A semantic model, to read and to change: its query, and its dimensions,\n * measures and metrics with who defined each. Changes, a person's or an\n * agent's, are a draft marked field by field against what is saved, checked\n * as they are made, and kept only when a person saves them as the next\n * version. Every report and explorer on the model takes its fields from it.\n */\nexport function SemanticModelEditor(props: SemanticModelEditorProps) {\n const { model, onSave, editor = \"you\" } = props;\n const isNew = model.version === 0;\n const dataSource = useDataSource(props.dataSource);\n const id = useId();\n const [ownDraft, setOwnDraft] = useState<SemanticModel | undefined>(props.defaultDraft);\n const draft = props.draft !== undefined || props.onDraftChange ? props.draft : ownDraft;\n const shown = draft ?? model;\n const setDraft = (next: SemanticModel | undefined) => {\n setOwnDraft(next);\n props.onDraftChange?.(next);\n };\n const context = useRef(props.onContext);\n context.current = props.onContext;\n const [note, setNote] = useState(\"\");\n const say = (kind: string, summary: string, subject?: Record<string, unknown>) => {\n setNote(summary);\n context.current?.({ kind, summary, ...(subject ? { subject } : {}) });\n };\n\n const [columns, setColumns] = useState<Field[]>([]);\n const [queryProblem, setQueryProblem] = useState<string | undefined>();\n useEffect(() => {\n if (!shown.sql.trim() || !shown.sourceId) return setColumns([]), setQueryProblem(undefined);\n const controller = new AbortController();\n collect(dataSource.execute({ sourceId: shown.sourceId, query: { baseSql: shown.sql, page: { limit: 1 } } }, { signal: controller.signal }))\n .then((result) => !controller.signal.aborted && (setColumns(result.table.schema.fields), setQueryProblem(undefined)))\n .catch((error: unknown) => !controller.signal.aborted && setQueryProblem(messageOf(error)));\n return () => controller.abort();\n }, [dataSource, shown.sourceId, shown.sql]);\n\n const pipelines = useOptionalPipelines(props.pipelines);\n const [built, setBuilt] = useState<Pipeline[]>([]);\n const [datasetChoice, setDatasetChoice] = useState(\"\");\n useEffect(() => {\n if (!isNew || !onSave || !pipelines) return;\n const controller = new AbortController();\n const options = { signal: controller.signal };\n pipelines\n .listPipelines({}, options)\n .then((list) => Promise.all(list.pipelines.filter((p) => !model.sourceId || p.sourceId === model.sourceId).map((p) => pipelines.getPipeline({ id: p.id }, options).then((r) => r.pipeline))))\n .then((found) => !controller.signal.aborted && setBuilt(found.filter((p): p is Pipeline => !!p && p.datasets.some((d) => d.kind !== DatasetKind.SOURCE))))\n .catch(() => !controller.signal.aborted && setBuilt([]));\n return () => controller.abort();\n }, [pipelines, isNew, !!onSave, model.sourceId]); // eslint-disable-line react-hooks/exhaustive-deps\n const fromDataset = () => {\n const [pi, di] = datasetChoice.split(\":\").map(Number);\n const pipeline = built[pi ?? -1];\n const dataset = pipeline?.datasets[di ?? -1]?.name;\n const pipelineId = pipeline?.summary?.id ?? \"\";\n if (!pipeline || !dataset) return;\n const next = semanticModelFromDataset(pipeline, dataset, { ...(shown.name ? { name: shown.name } : {}), ...(shown.label ? { label: shown.label } : {}) });\n if (shown.description) next.description = shown.description;\n keep(next);\n setNameTouched(true);\n say(\"rows.changed\", `Started from the dataset ${dataset} of ${thePipeline(pipeline.summary?.name || pipelineId)}: its grain, key and ${next.dimensions.length + next.measures.length} fields from its columns, for you to check.`, { pipeline: pipelineId, dataset });\n };\n\n const pills = useMemo(() => pillsFromModel(shown), [shown]);\n const changes = useMemo(() => (draft ? modelChanges(model, draft) : new Map<string, FieldChange>()), [model, draft]);\n const removed = useMemo(() => pillsFromModel(model).filter((p) => changes.get(p.id) === \"removed\"), [model, changes]);\n const names = columns.map((c) => c.name);\n const problems = useMemo(() => {\n const found = draft ? semanticModelProblems(draft, { isNew }) : [];\n if (columns.length > 0) for (const p of pills) if (p.column && !names.includes(p.column)) found.push(`\"${p.id}\" names the column \"${p.column}\", which the query does not return.`);\n return found;\n }, [draft, pills, columns]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const [editing, setEditing] = useState<{ pill: Pill; isNew: boolean } | undefined>();\n const [saveNote, setSaveNote] = useState(\"\");\n const [saving, setSaving] = useState(false);\n const blank = (kind: PillKind): Pill => ({ id: \"\", kind, label: \"\", by: editor, ...(kind === \"metric\" ? { aggregate: \"sum\" as const, column: columns.find((c) => /Int|Float|Decimal/.test(String(c.type)))?.name } : kind === \"attribute\" ? { column: columns[0]?.name } : { expression: \"\", format: \"number\" as const }) });\n\n // A draft that comes back to what is saved is no draft; a new model's draft is kept, as it is all there is.\n const keep = (next: SemanticModel) => setDraft(!isNew && modelChanges(model, next).size === 0 ? undefined : next);\n const change = (name: string, pill: Pill | undefined) => keep(setModelField(shown, name, pill, editor));\n const setPart = (patch: Partial<Pick<SemanticModel, \"name\" | \"label\" | \"description\">>) => keep(create(SemanticModelSchema, { ...shown, ...patch }));\n const [nameTouched, setNameTouched] = useState(!isNew || !!model.name);\n const draftFields = () => {\n const personal = new Set(piiHints(columns.map((c) => c.name)).map((h) => h.column));\n const fields = draftSemanticFields(\n columns.map((c) => ({ name: c.name, type: String(c.type), personal: personal.has(c.name) })),\n { grain: shown.grain },\n );\n const next = clone(SemanticModelSchema, shown);\n next.dimensions = (fields.dimensions ?? []).map((d) => create(DimensionSchema, d));\n next.measures = (fields.measures ?? []).map((m) => create(MeasureSchema, m));\n keep(next);\n say(\"fields.drafted\", `Fields drafted from the query's ${columns.length} columns by name and type${personal.size ? `, leaving out ${personal.size} that may hold personal data` : \"\"}. Check them before saving.`);\n };\n const [ask, setAsk] = useState(\"\");\n const sendAsk = () => {\n const text = ask.trim();\n if (!text || !props.onAsk) return;\n props.onAsk(text, shown);\n setAsk(\"\");\n setNote(`Sent to ${props.askLabel ?? \"the agent\"}.`);\n };\n const restore = (name: string) => {\n const was = pillsFromModel(model).find((p) => p.id === name);\n if (!was) return;\n change(name, was);\n say(\"field.restored\", `${was.label} put back as it is saved.`, { field: name });\n };\n const save = async () => {\n if (!draft || !onSave || problems.length > 0) return;\n setSaving(true);\n try {\n const saved = await onSave(draft, saveNote.trim() || `${changes.size} ${changes.size === 1 ? \"change\" : \"changes\"}`);\n if (saved) {\n setDraft(undefined);\n setSaveNote(\"\");\n say(\"model.saved\", `Saved as version ${saved.version}. Every report and explorer on this model now uses it.`, { model: saved.name, version: saved.version, changes: Object.fromEntries(changes) });\n }\n } catch (error) {\n setNote(messageOf(error));\n } finally {\n setSaving(false);\n }\n };\n\n const askBox = props.onAsk && (\n <form\n className=\"sf-semantic-ask\"\n onSubmit={(e) => {\n e.preventDefault();\n sendAsk();\n }}\n >\n <label htmlFor={`${id}-ask`}>\n {isNew ? `Tell ${props.askLabel ?? \"the agent\"} what this model should measure; it drafts the tables, joins, grain and fields for you to check.` : `Ask ${props.askLabel ?? \"the agent\"} to change this model.`}\n </label>\n <span className=\"sf-semantic-ask-row\">\n <input id={`${id}-ask`} className=\"sf-input\" placeholder={isNew ? \"Order lines with their store and product, to measure revenue and refunds\" : \"Add margin as a share of revenue\"} value={ask} onChange={(e) => setAsk(e.target.value)} />\n <button type=\"submit\" className=\"sf-button\" data-variant=\"primary\" disabled={!ask.trim()}>\n Ask\n </button>\n </span>\n </form>\n );\n\n const section = (kind: PillKind) => {\n const rows = [...pills.filter((p) => p.kind === kind), ...removed.filter((p) => p.kind === kind)];\n return (\n <section key={kind} className=\"sf-semantic-section\" aria-labelledby={`${id}-${kind}`}>\n <h4 id={`${id}-${kind}`} className=\"sf-explore-heading\">\n <span>\n {KIND[kind].title} <span className=\"sf-semantic-count\">{pills.filter((p) => p.kind === kind).length}</span>\n </span>\n {onSave && (\n <button type=\"button\" className=\"sf-explore-add\" aria-label={`Add a ${KIND[kind].one}`} onClick={() => setEditing({ pill: blank(kind), isNew: true })}>\n +\n </button>\n )}\n </h4>\n <p className=\"sf-explore-hint\">{KIND[kind].hint}</p>\n {rows.length === 0 ? (\n <p className=\"sf-explore-hint\">None yet.</p>\n ) : (\n <table className=\"sf-semantic-table\">\n <thead>\n <tr>\n <th scope=\"col\">Label</th>\n <th scope=\"col\">Name</th>\n <th scope=\"col\">{kind === \"derived\" ? \"Calculation\" : \"Definition\"}</th>\n <th scope=\"col\">Defined by</th>\n {onSave && (\n <th scope=\"col\">\n <span className=\"sf-a2-visually-hidden\">Controls</span>\n </th>\n )}\n </tr>\n </thead>\n <tbody>\n {rows.map((pill) => {\n const state = changes.get(pill.id);\n const gone = state === \"removed\";\n return (\n <tr key={pill.id} className={CONTROLS_HOST} data-change={state}>\n <th scope=\"row\">\n {pill.label}\n {state && <span className=\"sf-semantic-change\">{CHANGE_WORDS[state]}</span>}\n {pill.description && <span className=\"sf-semantic-description\">{pill.description}</span>}\n </th>\n <td>\n <code>{pill.id}</code>\n </td>\n <td>\n <code>{definition(gone ? model : shown, pill)}</code>\n {pill.format && <span className=\"sf-semantic-format\"> · {pill.format}</span>}\n </td>\n <td>{fieldNamed(gone ? model : shown, pill.id)?.definedBy || \"—\"}</td>\n {onSave && (\n <td>\n {gone ? (\n <button type=\"button\" className=\"sf-button\" onClick={() => restore(pill.id)}>\n Put back\n </button>\n ) : (\n <ItemControls\n label={`${pill.label} controls`}\n controls={standardControls(pill.label, {\n edit: () => setEditing({ pill, isNew: false }),\n duplicate: () => setEditing({ pill: { ...pill, label: `${pill.label} copy`, by: editor }, isNew: true }),\n remove: () => {\n change(pill.id, undefined);\n say(\"field.removed\", `${pill.label} taken out of the draft. Save to remove it from the model.`, { field: pill.id });\n },\n })}\n />\n )}\n </td>\n )}\n </tr>\n );\n })}\n </tbody>\n </table>\n )}\n </section>\n );\n };\n\n return (\n <div className={[\"sf-semantic\", props.className].filter(Boolean).join(\" \")}>\n <header className=\"sf-semantic-header\">\n {isNew && onSave ? (\n <div className=\"sf-semantic-identity\">\n <h3 className=\"sf-semantic-title\">New model</h3>\n <label htmlFor={`${id}-label`}>Name for people</label>\n <input\n id={`${id}-label`}\n className=\"sf-input\"\n placeholder=\"Sales lines\"\n value={shown.label}\n onChange={(e) => setPart({ label: e.target.value, ...(nameTouched ? {} : { name: modelName(e.target.value) }) })}\n />\n <label htmlFor={`${id}-name`}>Name in calculations and files</label>\n <input\n id={`${id}-name`}\n className=\"sf-input\"\n placeholder=\"sales_lines\"\n value={shown.name}\n onChange={(e) => (setNameTouched(true), setPart({ name: e.target.value }))}\n />\n <label htmlFor={`${id}-about`}>What it is for</label>\n <input id={`${id}-about`} className=\"sf-input\" placeholder=\"Revenue, cost and refunds by store and product.\" value={shown.description} onChange={(e) => setPart({ description: e.target.value })} />\n </div>\n ) : (\n <>\n <h3 className=\"sf-semantic-title\">{shown.label || shown.name}</h3>\n {shown.description && <p className=\"sf-semantic-description\">{shown.description}</p>}\n </>\n )}\n <p className=\"sf-explore-hint\">\n {shown.name ? <code>{shown.name}</code> : \"Not named yet\"} on {model.sourceId}\n {isNew ? \" · not saved yet\" : ` · version ${model.version}`}\n {model.savedBy && ` · saved by ${model.savedBy}`}\n {model.updatedAt && ` on ${model.updatedAt.slice(0, 10)}`}\n </p>\n {queryProblem && (\n <p className=\"sf-filter-problem\" role=\"alert\">\n The query does not run: {queryProblem}\n </p>\n )}\n </header>\n\n {isNew && onSave && built.length > 0 && !shown.dataset && (\n <div className=\"sf-semantic-actions sf-semantic-from-dataset\">\n <label htmlFor={`${id}-dataset`}>Start from a pipeline dataset</label>\n <select id={`${id}-dataset`} className=\"sf-input\" value={datasetChoice} onChange={(e) => setDatasetChoice(e.target.value)}>\n <option value=\"\">Choose a dataset…</option>\n {built.map((p, pi) => (\n <optgroup key={p.summary?.id} label={p.summary?.name || p.summary?.id}>\n {p.datasets.map((d, di) =>\n d.kind === DatasetKind.SOURCE ? null : (\n <option key={d.name} value={`${pi}:${di}`}>\n {d.name}\n {d.grain ? ` · ${d.grain}` : \"\"}\n {d.builtAt ? \"\" : \" · not built yet\"}\n </option>\n ),\n )}\n </optgroup>\n ))}\n </select>\n <button type=\"button\" className=\"sf-button\" disabled={!datasetChoice} onClick={fromDataset}>\n Use this dataset\n </button>\n <span className=\"sf-explore-hint\">Its grain and key are checked by the pipeline after every build; its columns become fields for you to check.</span>\n </div>\n )}\n\n <ModelLineage\n model={shown}\n pipelines={pipelines}\n onOpenDataset={props.onOpenDataset}\n onUseDataset={\n onSave\n ? (standing) => {\n keep(create(SemanticModelSchema, { ...shown, sourceId: shown.sourceId, sql: datasetSql({ name: standing.dataset, relation: standing.relation ?? \"\" }), grain: standing.grain || shown.grain, primaryKey: standing.primaryKey }));\n say(\"rows.changed\", `The grain and key are the dataset's again: ${standing.primaryKey.join(\", \")}.`, { grain: standing.grain, primaryKey: standing.primaryKey });\n }\n : undefined\n }\n />\n\n {isNew && askBox}\n\n <SemanticRows\n model={shown}\n columns={columns}\n editor={editor}\n dataSource={dataSource}\n building={props.building && !shown.dataset}\n onChange={\n onSave\n ? (next, summary) => {\n // Rows written or joined by hand are no longer the pipeline's dataset.\n if (next.dataset && (next.tables.length > 0 || next.sql !== shown.sql)) next = create(SemanticModelSchema, { ...next, dataset: undefined });\n keep(next);\n if (summary) say(\"rows.changed\", summary, { grain: next.grain, primaryKey: next.primaryKey, tables: next.tables });\n }\n : undefined\n }\n />\n\n {onSave && columns.length > 0 && shown.dimensions.length === 0 && shown.measures.length === 0 && (\n <p className=\"sf-semantic-actions\">\n <button type=\"button\" className=\"sf-button\" onClick={draftFields}>\n Draft fields from the columns\n </button>\n <span className=\"sf-explore-hint\">Dimensions and measures from the columns' names and types, marked as generated, for you to check.</span>\n </p>\n )}\n\n {draft && (\n <div className=\"sf-semantic-draft\" role=\"region\" aria-label=\"Changes not saved\">\n <p>\n <strong>{isNew ? \"New model, not saved\" : `${changes.size} ${changes.size === 1 ? \"change\" : \"changes\"} not saved`}</strong>\n {props.proposedBy ? `, proposed by ${props.proposedBy}. Read ${isNew ? \"it\" : \"them\"} before saving.` : \".\"}{\" \"}\n {isNew ? `${shown.dimensions.length} dimensions, ${shown.measures.length} measures, ${shown.metrics.length} metrics.` : [...changes].map(changeText).join(\", \")}\n </p>\n {(problems.length > 0 || props.problem) && (\n <ul className=\"sf-filter-problem\" role=\"alert\">\n {[...problems, ...(props.problem ? [props.problem] : [])].map((problem) => (\n <li key={problem}>{problem}</li>\n ))}\n </ul>\n )}\n {onSave && (\n <div className=\"sf-semantic-actions\">\n <label htmlFor={`${id}-note`} className=\"sf-a2-visually-hidden\">\n What changed\n </label>\n <input id={`${id}-note`} className=\"sf-input\" placeholder=\"What changed, in a few words\" value={saveNote} onChange={(e) => setSaveNote(e.target.value)} />\n <button type=\"button\" className=\"sf-button\" data-variant=\"primary\" disabled={problems.length > 0 || saving} onClick={() => void save()}>\n {saving ? \"Saving…\" : `Save as version ${model.version + 1}`}\n </button>\n <button\n type=\"button\"\n className=\"sf-button\"\n onClick={() => {\n setDraft(undefined);\n say(\"draft.discarded\", isNew ? \"The new model was cleared, to start again.\" : `${changes.size} ${changes.size === 1 ? \"change\" : \"changes\"} dropped; the model is as saved.`);\n }}\n >\n {isNew ? \"Start again\" : \"Drop changes\"}\n </button>\n </div>\n )}\n </div>\n )}\n\n {editing && (\n <PillEditor\n key={`${editing.pill.id}-${editing.isNew}`}\n pill={editing.pill}\n all={pills}\n columns={columns}\n isNew={editing.isNew}\n onCancel={() => setEditing(undefined)}\n onSave={(next) => {\n change(editing.isNew ? next.id : editing.pill.id, next);\n say(editing.isNew ? \"field.added\" : \"field.changed\", `${next.label} ${editing.isNew ? \"added to\" : \"changed in\"} the draft. Save to keep it.`, { field: next, ...(editing.isNew ? {} : { was: editing.pill }) });\n setEditing(undefined);\n }}\n onRemove={\n editing.isNew\n ? undefined\n : () => {\n change(editing.pill.id, undefined);\n say(\"field.removed\", `${editing.pill.label} taken out of the draft. Save to remove it from the model.`, { field: editing.pill.id });\n setEditing(undefined);\n }\n }\n />\n )}\n {([\"attribute\", \"metric\", \"derived\"] as PillKind[]).map(section)}\n {!isNew && askBox}\n <p className=\"sf-explore-note\" role=\"status\">\n {note}\n </p>\n </div>\n );\n}\n\n/** The aggregate words the editor shows, by the contract's function. */\nexport const aggregateLabel = (fn: Parameters<typeof aggregateWord>[0]) => AGGREGATE_WORDS[aggregateWord(fn) ?? \"\"] ?? \"\";\n"]}
@@ -0,0 +1,42 @@
1
+ import { type DataSource } from "@surfaces-ui/data";
2
+ import { JoinType, type SemanticJoin, type SemanticModel } from "@surfaces-ui/proto";
3
+ import type { Field } from "apache-arrow";
4
+ import { type DataModel, type JoinKind, type ModelJoin, type ModelSql } from "../model/ModelDiagram.js";
5
+ export declare const INFERRED_BY = "inferred from names";
6
+ export declare const DECLARED_BY = "declared by the source";
7
+ /** A join kind as the contract stores it. */
8
+ export declare const joinTypeOf: (kind: JoinKind | undefined) => JoinType;
9
+ /** A stored join type as a kind; unspecified is an inner join, which is what models saved before join kinds ran. */
10
+ export declare const joinKindOf: (type: JoinType) => JoinKind;
11
+ /** A model's joins as the diagram draws them: a guess no one confirmed is "Inferred", a foreign key the source declares is "Declared". */
12
+ export declare function diagramJoins(joins: SemanticJoin[]): ModelJoin[];
13
+ /**
14
+ * The model's tables and joins from what the diagram holds, each join saying
15
+ * who made it (kept from before, or the person editing now), and its query:
16
+ * the diagram's own when given (it names every column, so it runs on every
17
+ * engine), generated without the columns otherwise. A guess no one has
18
+ * confirmed is kept on the model, marked, but left out of the query.
19
+ */
20
+ export declare function rowsFromDiagram(model: SemanticModel, diagram: DataModel, editor: string, query?: ModelSql): SemanticModel;
21
+ /** The query a model's tables and joins make without knowing their columns: from the first table, through every join but unconfirmed guesses. The diagram replaces it with one that names every column once it has read them. */
22
+ export declare function semanticSql(diagram: DataModel): {
23
+ sql: string;
24
+ unjoined: string[];
25
+ };
26
+ export interface SemanticRowsProps {
27
+ model: SemanticModel;
28
+ columns: Field[];
29
+ /** Called with every change; `summary` says it in words for the agent, and is left out while a person is still typing. Left out, the rows are shown and cannot be changed. */
30
+ onChange?(next: SemanticModel, summary?: string): void;
31
+ editor: string;
32
+ dataSource: DataSource;
33
+ /** A new model: the join builder is open even before it has a table. */
34
+ building?: boolean;
35
+ }
36
+ /**
37
+ * What one row of a model is and where the rows come from: the grain, the
38
+ * columns that make a row unique (checked by the engine on request), and
39
+ * the tables and joins the rows are built from, drawn in a ModelDiagram with
40
+ * the first table as where the rows come from, or the query as written.
41
+ */
42
+ export declare function SemanticRows(props: SemanticRowsProps): import("react").JSX.Element;