@malloy-publisher/sdk 0.9.1 → 0.9.3
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.
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-DwB0-9Yx.es.js} +219 -210
- package/dist/RenderedResult-hKjFEqaN.cjs.js +141 -0
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-CcSrGaRN.es.js} +1473 -1326
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +143 -58
- package/dist/builder/index.es.js +12179 -9318
- package/dist/builder-entry.d.ts +5 -1
- package/dist/client/api.d.ts +247 -56
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +94 -88
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +38 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +21 -2
- package/dist/components/Dashboard/DashboardView.d.ts +71 -0
- package/dist/components/Dashboard/TileCard.d.ts +30 -5
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +5 -1
- package/dist/components/Dashboard/telemetry.d.ts +16 -3
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +15 -9
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +23 -15
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +56 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +44 -5
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +8 -4
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +10 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +51 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +12 -6
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -18
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +6 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +16 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +15 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +86 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +19 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +6 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +17 -1
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +5 -1
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +3 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9041 -7002
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CA0LZ1xL.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{Dashboard-H1kJlDFo.es.js → useCompiledDocument-BU6d8FPp.es.js} +17904 -19057
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/dist/utils/clock.d.ts +2 -0
- package/dist/utils/malloyText.d.ts +104 -0
- package/package.json +20 -11
- package/src/builder-entry.ts +36 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +29 -280
- package/src/components/Dashboard/DashboardGrid.tsx +87 -8
- package/src/components/Dashboard/DashboardTile.spec.tsx +121 -2
- package/src/components/Dashboard/DashboardTile.tsx +121 -30
- package/src/components/Dashboard/DashboardView.spec.tsx +368 -0
- package/src/components/Dashboard/DashboardView.tsx +428 -0
- package/src/components/Dashboard/RowsDialog.tsx +4 -3
- package/src/components/Dashboard/TileCard.tsx +60 -11
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +13 -1
- package/src/components/Dashboard/telemetry.ts +17 -5
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +124 -138
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +111 -80
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +156 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +183 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +373 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +105 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +117 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +146 -108
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +179 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +330 -512
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +55 -25
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +142 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +39 -13
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +9 -26
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +102 -25
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +252 -780
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +23 -11
- package/src/components/DashboardBuilder/FilterStrip.tsx +130 -70
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +182 -0
- package/src/components/DashboardBuilder/InlineText.tsx +112 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +31 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +302 -163
- package/src/components/DashboardBuilder/TileMenu.tsx +125 -97
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +46 -0
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -44
- package/src/components/DashboardBuilder/catalog.ts +61 -57
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +258 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyTree.ts +159 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +174 -26
- package/src/components/DashboardBuilder/readDocument.ts +137 -45
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +52 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +89 -0
- package/src/components/DashboardBuilder/sortable.tsx +11 -10
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +768 -131
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +253 -0
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +760 -0
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +250 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +255 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +45 -9
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +57 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +30 -5
- package/src/components/DashboardBuilder/useTileResize.ts +31 -8
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +72 -29
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +186 -0
- package/src/components/Package/Package.create.spec.tsx +401 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +396 -177
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +14 -1
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +23 -8
- package/src/components/RenderedResult/ResultContainer.tsx +51 -13
- package/src/components/RenderedResult/ResultPanel.tsx +24 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +5 -11
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +3 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +23 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +112 -0
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +48 -0
- package/src/utils/malloyText.ts +368 -0
- package/src/utils/queryClient.ts +8 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -15
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -20
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -64
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -122
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -168
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- package/src/components/DashboardBuilder/malloyText.ts +0 -214
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import { Alert, Box, Button, Stack, Typography } from "@mui/material";
|
|
4
|
+
import { Alert, Button, Stack } from "@mui/material";
|
|
6
5
|
import { useQueryClient } from "@tanstack/react-query";
|
|
7
|
-
import { useCallback,
|
|
6
|
+
import { useCallback, useRef } from "react";
|
|
7
|
+
import type { Given } from "../../client";
|
|
8
|
+
import type { HostGivenValue } from "../../hooks/givenValue";
|
|
8
9
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
9
10
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
type DashboardEvent,
|
|
14
|
-
type DashboardEventHandler,
|
|
15
|
-
} from "../Dashboard/telemetry";
|
|
16
|
-
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
17
|
-
import { parseResourceUri } from "../../utils/formatting";
|
|
18
|
-
import {
|
|
19
|
-
isDocumentNotFound,
|
|
20
|
-
useOptionalDocumentStorage,
|
|
21
|
-
type DocumentLocator,
|
|
22
|
-
type Workspace,
|
|
23
|
-
} from "../DocumentStorage";
|
|
24
|
-
import { GivensPanel } from "../given";
|
|
25
|
-
import { SecondaryButton } from "../buttons";
|
|
26
|
-
import { DashboardBar } from "../Dashboard/DashboardBar";
|
|
11
|
+
import type { BuilderEvent } from "./telemetry";
|
|
12
|
+
import { now } from "../../utils/clock";
|
|
13
|
+
import { useOptionalDocumentStorage } from "../DocumentStorage";
|
|
27
14
|
import { Loading } from "../Loading";
|
|
28
|
-
import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
29
15
|
import { useServer } from "../ServerProvider";
|
|
16
|
+
import type { DocumentKind } from "./document";
|
|
30
17
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} from "./
|
|
35
|
-
import {
|
|
36
|
-
import
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import { sha256Hex } from "../../utils/sha256";
|
|
18
|
+
resolveEditorTarget,
|
|
19
|
+
saveCaption,
|
|
20
|
+
withWorkspace,
|
|
21
|
+
} from "./documentSession";
|
|
22
|
+
import { EditorSurface } from "./EditorSurface";
|
|
23
|
+
import { useHostCopy } from "./useHostCopy";
|
|
24
|
+
import { useOpenedDocument } from "./useOpenedDocument";
|
|
25
|
+
import { useSaveChannel } from "./useSaveChannel";
|
|
40
26
|
|
|
41
27
|
/**
|
|
42
28
|
* The builder, opened on a package dashboard, with everything a host has to
|
|
@@ -75,13 +61,23 @@ export type DashboardEditorProps = (
|
|
|
75
61
|
dashboardName: string;
|
|
76
62
|
}
|
|
77
63
|
) & {
|
|
78
|
-
/** Leave the editor: the host's "Done editing". Absent, no such button. */
|
|
79
|
-
onExit?: () => void;
|
|
80
64
|
/**
|
|
81
65
|
* What the editor does — opened, saved, refused — for the host to log or
|
|
82
|
-
* count; see `DashboardEvent`.
|
|
66
|
+
* count; see `DashboardEvent`. A notebook reports `NotebookEvent`s instead.
|
|
67
|
+
*/
|
|
68
|
+
onEvent?: (event: BuilderEvent) => void;
|
|
69
|
+
/**
|
|
70
|
+
* What the document is to the host: its storage locator and event names.
|
|
71
|
+
* Default `dashboard`. A notebook is a dashboard with one column, and is
|
|
72
|
+
* read with the authoring flag and served through the notebook endpoint.
|
|
83
73
|
*/
|
|
84
|
-
|
|
74
|
+
kind?: DocumentKind;
|
|
75
|
+
/**
|
|
76
|
+
* The document's file within the package, when it is not where its kind
|
|
77
|
+
* puts a new one (`dashboards/<slug>.malloy`, `notebooks/<slug>.malloy`):
|
|
78
|
+
* the kind comes from the file's own tag, so a document may sit in either.
|
|
79
|
+
*/
|
|
80
|
+
path?: string;
|
|
85
81
|
/**
|
|
86
82
|
* Whether there are edits the record does not have, on every change and
|
|
87
83
|
* whenever the editor opens a document.
|
|
@@ -91,55 +87,62 @@ export type DashboardEditorProps = (
|
|
|
91
87
|
* without this a host cannot tell whether leaving costs anything.
|
|
92
88
|
*/
|
|
93
89
|
onDirtyChange?: (dirty: boolean) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Leave the editor: opted into, it draws Close after Save, which asks first
|
|
92
|
+
* when edits are unsaved. A host with a way out of its own (the Console's
|
|
93
|
+
* header View) leaves it unset and guards with `onDirtyChange`.
|
|
94
|
+
*/
|
|
95
|
+
onExit?: () => void;
|
|
96
|
+
/** Edit a document held as text; see {@link TextSourceOptions}. */
|
|
97
|
+
textSource?: TextSourceOptions;
|
|
94
98
|
};
|
|
95
99
|
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Open a document the host keeps as TEXT, rather than a file in a package.
|
|
102
|
+
*
|
|
103
|
+
* The text comes from the host's authoritative {@link DocumentStorage} and is
|
|
104
|
+
* compiled by the server, as the viewer, on top of `modelPath`: the model whose
|
|
105
|
+
* sources the document may name. The manifest is that compile's `document`, and
|
|
106
|
+
* every tile, cell and control option runs as the document's definitions
|
|
107
|
+
* followed by one `run:`, so each viewer sees what their own identity allows.
|
|
108
|
+
* The document carries no `import`, `##!` or `given:`, so "Add filter" is off
|
|
109
|
+
* and only the model's givens can be bound.
|
|
110
|
+
*/
|
|
111
|
+
export interface TextSourceOptions {
|
|
112
|
+
/** The model the text is compiled and run on top of. */
|
|
113
|
+
modelPath: string;
|
|
114
|
+
/** Givens the host sets itself: no control is shown for them. */
|
|
115
|
+
hiddenGivens?: readonly string[];
|
|
116
|
+
/** The values for the givens the host sets: sent with the compile and with each tile that reads one. */
|
|
117
|
+
givens?: Record<string, HostGivenValue>;
|
|
118
|
+
}
|
|
107
119
|
|
|
108
120
|
export function DashboardEditor(props: DashboardEditorProps) {
|
|
109
|
-
const {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"resourceUri" in props
|
|
127
|
-
? (parsed?.environmentName ?? "")
|
|
128
|
-
: props.environmentName;
|
|
129
|
-
const packageName =
|
|
130
|
-
"resourceUri" in props ? (parsed?.packageName ?? "") : props.packageName;
|
|
121
|
+
const {
|
|
122
|
+
onEvent,
|
|
123
|
+
onDirtyChange,
|
|
124
|
+
onExit,
|
|
125
|
+
kind = "dashboard",
|
|
126
|
+
path,
|
|
127
|
+
textSource,
|
|
128
|
+
} = props;
|
|
129
|
+
const notebook = kind === "notebook";
|
|
130
|
+
const textHeld = textSource !== undefined;
|
|
131
|
+
// Degraded, not thrown, on a bad URI: a throw in a render body takes the host's whole tree down.
|
|
132
|
+
const {
|
|
133
|
+
environmentName,
|
|
134
|
+
packageName,
|
|
135
|
+
versionId,
|
|
136
|
+
namesBoth: uriNamesBoth,
|
|
137
|
+
} = resolveEditorTarget(props);
|
|
131
138
|
const dashboardName =
|
|
132
139
|
"resourceUri" in props ? props.dashboard : props.dashboardName;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const uriNamesBoth =
|
|
138
|
-
"resourceUri" in props
|
|
139
|
-
? !!parsed?.environmentName && !!parsed?.packageName
|
|
140
|
-
: true;
|
|
140
|
+
const noun = notebook ? "notebook" : "dashboard";
|
|
141
|
+
const refusedEvent = notebook
|
|
142
|
+
? ("notebook.open_refused" as const)
|
|
143
|
+
: ("dashboard.open_refused" as const);
|
|
141
144
|
|
|
142
|
-
const { apiClients, mutable } = useServer();
|
|
145
|
+
const { apiClients, mutable, isLoadingStatus } = useServer();
|
|
143
146
|
const queryClient = useQueryClient();
|
|
144
147
|
// When the editor was asked for — or the reader chose what to open — so
|
|
145
148
|
// "opened" can say how long it took. Read through refs by the open effect,
|
|
@@ -150,7 +153,8 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
150
153
|
const onDirtyChangeRef = useRef(onDirtyChange);
|
|
151
154
|
onDirtyChangeRef.current = onDirtyChange;
|
|
152
155
|
const storage = useOptionalDocumentStorage()?.documentStorage;
|
|
153
|
-
const
|
|
156
|
+
const legacyFormat = notebook && /\.malloynb$/i.test(dashboardName);
|
|
157
|
+
const modelPath = path ?? `${kind}s/${dashboardName}.malloy`;
|
|
154
158
|
|
|
155
159
|
// The file as the package has it. `sourceText` rides on the compiled model.
|
|
156
160
|
const modelQuery = useQueryWithApiError({
|
|
@@ -160,460 +164,208 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
160
164
|
packageName,
|
|
161
165
|
modelPath,
|
|
162
166
|
versionId,
|
|
167
|
+
notebook,
|
|
163
168
|
],
|
|
169
|
+
// A curated package otherwise withholds the text of a notebook reading an off-surface source.
|
|
164
170
|
queryFn: () =>
|
|
165
171
|
apiClients.models.getModel(
|
|
166
172
|
environmentName,
|
|
167
173
|
packageName,
|
|
168
174
|
modelPath,
|
|
169
175
|
versionId,
|
|
176
|
+
notebook ? true : undefined,
|
|
170
177
|
),
|
|
171
|
-
enabled: uriNamesBoth,
|
|
178
|
+
enabled: uriNamesBoth && !legacyFormat && !textHeld,
|
|
172
179
|
});
|
|
173
180
|
const packageText = (
|
|
174
181
|
modelQuery.data?.data as { sourceText?: string } | undefined
|
|
175
182
|
)?.sourceText;
|
|
176
183
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// The package file as it stood when the editor last opened a document. The
|
|
262
|
-
// base a save is spliced against is the package's, which is NOT the text
|
|
263
|
-
// the builder holds: a resumed copy was opened from the store, and a
|
|
264
|
-
// version held back while the reader keeps editing has moved the fetch
|
|
265
|
-
// past the file the reader is answering for.
|
|
266
|
-
const packageBaseRef = useRef<string | undefined>(undefined);
|
|
267
|
-
// What this editor last wrote into the package, and the fetch it was
|
|
268
|
-
// written on top of. The write is in the file before the fetch behind
|
|
269
|
-
// `packageText` catches up, so until a fetch actually lands `packageText`
|
|
270
|
-
// is the text the save replaced rather than a version to open. Tied to the
|
|
271
|
-
// fetch and not to the text, so the NEXT fetch speaks for the file whether
|
|
272
|
-
// it carries this editor's write or someone else's.
|
|
273
|
-
const [wrote, setWrote] = useState<
|
|
274
|
-
{ text: string; onFetch: number } | undefined
|
|
275
|
-
>(undefined);
|
|
276
|
-
const fetchedAt = modelQuery.dataUpdatedAt;
|
|
277
|
-
const fetchedAtRef = useRef(fetchedAt);
|
|
278
|
-
fetchedAtRef.current = fetchedAt;
|
|
279
|
-
const packageNow =
|
|
280
|
-
wrote !== undefined && wrote.onFetch === fetchedAt
|
|
281
|
-
? wrote.text
|
|
282
|
-
: packageText;
|
|
283
|
-
const packageNowRef = useRef(packageNow);
|
|
284
|
-
packageNowRef.current = packageNow;
|
|
285
|
-
const latest = fromDraft ? draft : packageNow;
|
|
286
|
-
|
|
287
|
-
// Whether the builder holds edits the record does not have, and the version
|
|
288
|
-
// being held back because of them.
|
|
289
|
-
const [dirty, setDirty] = useState(false);
|
|
290
|
-
const [accepted, setAccepted] = useState<string | undefined>(undefined);
|
|
291
|
-
// The text on this channel the editor has already reckoned with: what it
|
|
292
|
-
// opened, and what it wrote. Compared against the CHANNEL rather than
|
|
293
|
-
// against the builder, because the two diverge legitimately — a copy saved
|
|
294
|
-
// beside the package leaves the builder ahead of a package that has not
|
|
295
|
-
// moved, and reading that as an incoming version would offer a reader
|
|
296
|
-
// their own work back forever.
|
|
297
|
-
const [seen, setSeen] = useState<string | undefined>(undefined);
|
|
298
|
-
const incoming = latest !== undefined && latest !== seen;
|
|
299
|
-
// What the builder is on. A save does not remount it, so this follows the
|
|
300
|
-
// save rather than the text the builder was opened with.
|
|
301
|
-
const current = opened?.source;
|
|
302
|
-
const holding =
|
|
303
|
-
incoming && dirty && current !== undefined && latest !== accepted;
|
|
304
|
-
const opening = holding ? current : incoming ? latest : (current ?? latest);
|
|
305
|
-
const held = holding ? latest : undefined;
|
|
306
|
-
|
|
307
|
-
// Read by the open effect so it keeps its single dependency: the guard must
|
|
308
|
-
// not re-run the effect when what it compares against changes.
|
|
309
|
-
const openedSourceRef = useRef(current);
|
|
310
|
-
openedSourceRef.current = current;
|
|
311
|
-
const latestRef = useRef(latest);
|
|
312
|
-
latestRef.current = latest;
|
|
313
|
-
const fromRef = useRef<"package" | "draft" | "record">("package");
|
|
314
|
-
fromRef.current = fromDraft
|
|
315
|
-
? authoritative
|
|
316
|
-
? "record"
|
|
317
|
-
: "draft"
|
|
318
|
-
: "package";
|
|
319
|
-
useEffect(() => {
|
|
320
|
-
// Not until the storage answer is in. Opening on the package file while
|
|
321
|
-
// the editor still has no idea whether the host keeps the record would
|
|
322
|
-
// open the wrong document, and report an open of it.
|
|
323
|
-
if (opening === undefined || !draftChecked || blockedOnRecord) return;
|
|
324
|
-
if (opening === openedSourceRef.current) return;
|
|
325
|
-
let stale = false;
|
|
326
|
-
const packageAtOpen = packageNowRef.current;
|
|
327
|
-
const latestAtOpen = latestRef.current;
|
|
328
|
-
void readDashboardDocument(opening).then((result) => {
|
|
329
|
-
if (stale) return;
|
|
330
|
-
if (readFailed(result)) {
|
|
331
|
-
const reason = result.line
|
|
332
|
-
? `${result.reason} (line ${result.line})`
|
|
333
|
-
: result.reason;
|
|
334
|
-
setOpenError(reason);
|
|
335
|
-
onEventRef.current?.({ type: "dashboard.open_refused", reason });
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
setOpenError(undefined);
|
|
339
|
-
// A different document is open, so what this editor wrote before is
|
|
340
|
-
// no longer the base anything is spliced against; the package file
|
|
341
|
-
// the reader is now answering for is the one current at this open.
|
|
342
|
-
savedHashRef.current = undefined;
|
|
343
|
-
packageBaseRef.current = packageAtOpen;
|
|
344
|
-
setWrote(undefined);
|
|
345
|
-
setAccepted(undefined);
|
|
346
|
-
setSeen(latestAtOpen);
|
|
347
|
-
setOpened((previous) => ({
|
|
348
|
-
source: opening,
|
|
349
|
-
document: result.document,
|
|
350
|
-
generation: (previous?.generation ?? 0) + 1,
|
|
351
|
-
}));
|
|
352
|
-
onEventRef.current?.({
|
|
353
|
-
type: "dashboard.opened",
|
|
354
|
-
from: fromRef.current,
|
|
355
|
-
tiles: result.document.tiles.length,
|
|
356
|
-
durationMs: now() - startedAt.current,
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
return () => {
|
|
360
|
-
stale = true;
|
|
361
|
-
};
|
|
362
|
-
}, [opening, draftChecked, blockedOnRecord]);
|
|
363
|
-
|
|
364
|
-
const locator =
|
|
365
|
-
workspace === undefined
|
|
366
|
-
? undefined
|
|
367
|
-
: dashboardLocator(
|
|
368
|
-
workspace.name,
|
|
369
|
-
environmentName,
|
|
370
|
-
packageName,
|
|
371
|
-
modelPath,
|
|
372
|
-
);
|
|
373
|
-
// Into the host's store: the record when the host says so, and otherwise a
|
|
374
|
-
// copy kept beside the package.
|
|
375
|
-
const saveToStorage = useCallback(
|
|
376
|
-
async (source: string) => {
|
|
377
|
-
if (!storage || !locator)
|
|
378
|
-
throw new Error(
|
|
379
|
-
"This host keeps no documents, so there is nowhere to save.",
|
|
380
|
-
);
|
|
381
|
-
await storage.saveDocument(locator, source);
|
|
382
|
-
// The builder keeps its history and its text; what it holds is now
|
|
383
|
-
// this, not the text it was opened with.
|
|
384
|
-
setOpened((previous) => previous && { ...previous, source });
|
|
385
|
-
setDraft(source);
|
|
386
|
-
// Whenever the copy IS the channel — the record, or a copy the reader
|
|
387
|
-
// resumed — the write moved that channel, and its own text is not an
|
|
388
|
-
// incoming version. A copy written while the package is what is open
|
|
389
|
-
// leaves the package where it was, so nothing there has moved.
|
|
390
|
-
if (authoritative || resume === true) setSeen(source);
|
|
391
|
-
// Saving without choosing is choosing the package file.
|
|
392
|
-
if (!authoritative) setResume((chosen) => chosen ?? false);
|
|
393
|
-
},
|
|
394
|
-
[storage, locator, authoritative, resume],
|
|
395
|
-
);
|
|
396
|
-
// A supersede that did not happen, left where a reader can see it: the copy
|
|
397
|
-
// is still there and will be offered again on the next visit.
|
|
398
|
-
const [supersedeFailure, setSupersedeFailure] = useState<string | undefined>(
|
|
399
|
-
undefined,
|
|
400
|
-
);
|
|
401
|
-
// Into the package itself, when the server takes writes: compile-checked,
|
|
402
|
-
// written atomically and reloaded there, refused if the file changed since
|
|
403
|
-
// it was opened. A copy of the same file kept beside it is superseded by it.
|
|
404
|
-
const saveToPackage = useCallback(
|
|
405
|
-
async (source: string) => {
|
|
406
|
-
// The hash of the package file this editor opened against, never of
|
|
407
|
-
// the latest fetch. A version held back while the reader keeps
|
|
408
|
-
// editing moves the fetch past that file, and a hash taken from it
|
|
409
|
-
// would match, be accepted, and overwrite the change the reader was
|
|
410
|
-
// just told about.
|
|
411
|
-
const base = packageBaseRef.current;
|
|
412
|
-
const expectedHash =
|
|
413
|
-
savedHashRef.current ??
|
|
414
|
-
(base === undefined ? undefined : await sha256Hex(base));
|
|
415
|
-
if (expectedHash === undefined)
|
|
416
|
-
throw new Error("The package file is still loading; try again.");
|
|
417
|
-
let result;
|
|
418
|
-
try {
|
|
419
|
-
result = await apiClients.models.updateModelSource(
|
|
420
|
-
environmentName,
|
|
421
|
-
packageName,
|
|
422
|
-
modelPath,
|
|
423
|
-
{ source, expectedHash },
|
|
424
|
-
);
|
|
425
|
-
} catch (error) {
|
|
426
|
-
// A refused write usually means the file moved. Fetch it, so the
|
|
427
|
-
// reader is offered that version rather than left re-saving
|
|
428
|
-
// against a base the server will go on rejecting.
|
|
429
|
-
void queryClient.invalidateQueries({
|
|
430
|
-
queryKey: [
|
|
431
|
-
"dashboard-editor-model",
|
|
432
|
-
environmentName,
|
|
433
|
-
packageName,
|
|
434
|
-
modelPath,
|
|
435
|
-
versionId,
|
|
436
|
-
],
|
|
437
|
-
});
|
|
438
|
-
throw new Error(apiErrorMessage(error));
|
|
439
|
-
}
|
|
440
|
-
setOpened((previous) => previous && { ...previous, source });
|
|
441
|
-
setWrote({ text: source, onFetch: fetchedAtRef.current });
|
|
442
|
-
setSeen(source);
|
|
443
|
-
savedHashRef.current = result.data.contentHash;
|
|
444
|
-
setSupersedeFailure(undefined);
|
|
445
|
-
if (storage && locator) {
|
|
446
|
-
try {
|
|
447
|
-
await storage.deleteDocument(locator);
|
|
448
|
-
setDraft(undefined);
|
|
449
|
-
setOffered(false);
|
|
450
|
-
} catch (error) {
|
|
451
|
-
// Only absence means the copy is gone. Any other rejection
|
|
452
|
-
// leaves it there, so the state must keep saying so.
|
|
453
|
-
if (isDocumentNotFound(error)) {
|
|
454
|
-
setDraft(undefined);
|
|
455
|
-
setOffered(false);
|
|
456
|
-
} else setSupersedeFailure(storageErrorMessage(error));
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
// The package is what is open now, even if the copy beside it
|
|
460
|
-
// survived the supersede: reading the channel off a stale copy would
|
|
461
|
-
// put the builder back on the text this save replaced.
|
|
462
|
-
setResume(false);
|
|
463
|
-
// The package changed: the file, the manifest the live view reads,
|
|
464
|
-
// the package's dashboards list, and the dashboard the reader sees.
|
|
465
|
-
await queryClient.invalidateQueries({
|
|
466
|
-
queryKey: [
|
|
467
|
-
"dashboard-editor-model",
|
|
468
|
-
environmentName,
|
|
469
|
-
packageName,
|
|
470
|
-
modelPath,
|
|
471
|
-
versionId,
|
|
472
|
-
],
|
|
473
|
-
});
|
|
474
|
-
for (const key of [
|
|
475
|
-
"dashboard-editor-manifest",
|
|
476
|
-
"dashboards",
|
|
477
|
-
"dashboard",
|
|
478
|
-
])
|
|
479
|
-
void queryClient.invalidateQueries({ queryKey: [key] });
|
|
480
|
-
},
|
|
481
|
-
[
|
|
482
|
-
apiClients,
|
|
483
|
-
environmentName,
|
|
484
|
-
packageName,
|
|
485
|
-
modelPath,
|
|
486
|
-
versionId,
|
|
487
|
-
storage,
|
|
488
|
-
locator,
|
|
489
|
-
queryClient,
|
|
490
|
-
],
|
|
491
|
-
);
|
|
492
|
-
// `authoritative` wins outright rather than breaking a tie: a host whose
|
|
493
|
-
// store is the record may well sit on a server that reports itself
|
|
494
|
-
// writable, and writing the package there would edit a deploy of the
|
|
495
|
-
// record instead of the record.
|
|
496
|
-
const savesTo = authoritative ? "host" : mutable ? "package" : "browser";
|
|
497
|
-
const canWriteWorkspace = workspace?.writeable === true;
|
|
498
|
-
// A version is an immutable checkpoint, and `updateModelSource` cannot be
|
|
499
|
-
// told to write against one (the server answers 501). Without this guard,
|
|
500
|
-
// `expectedHash` would be the hash of the pinned text, the server would
|
|
501
|
-
// refuse every save against the current file, and the catch would refetch
|
|
502
|
-
// the same pinned text, so the "changed since you opened it" banner would
|
|
503
|
-
// never fire either: a dead end with no way out. Storage-backed saves are
|
|
504
|
-
// unaffected, since they never touch the package's compare-and-swap.
|
|
505
|
-
const pinnedPackageSave = versionId !== undefined && savesTo === "package";
|
|
506
|
-
const writer = authoritative
|
|
507
|
-
? storage && locator && canWriteWorkspace
|
|
508
|
-
? saveToStorage
|
|
509
|
-
: undefined
|
|
510
|
-
: pinnedPackageSave
|
|
511
|
-
? undefined
|
|
512
|
-
: mutable
|
|
513
|
-
? saveToPackage
|
|
514
|
-
: storage && locator && canWriteWorkspace
|
|
515
|
-
? saveToStorage
|
|
516
|
-
: undefined;
|
|
517
|
-
// A copy that could not be read is not a copy that is not there. Saving on
|
|
518
|
-
// that belief is what rewinds the record, so Save is off until a reader can
|
|
519
|
-
// be told what actually happened.
|
|
520
|
-
const save = readFailure === undefined ? writer : undefined;
|
|
184
|
+
const {
|
|
185
|
+
workspace,
|
|
186
|
+
draft,
|
|
187
|
+
setDraft,
|
|
188
|
+
draftChecked,
|
|
189
|
+
offered,
|
|
190
|
+
setOffered,
|
|
191
|
+
readFailure,
|
|
192
|
+
} = useHostCopy({
|
|
193
|
+
storage,
|
|
194
|
+
kind,
|
|
195
|
+
notebook,
|
|
196
|
+
environmentName,
|
|
197
|
+
packageName,
|
|
198
|
+
modelPath,
|
|
199
|
+
});
|
|
200
|
+
const {
|
|
201
|
+
authoritative,
|
|
202
|
+
blockedOnRecord,
|
|
203
|
+
resume,
|
|
204
|
+
setResume,
|
|
205
|
+
fromDraft,
|
|
206
|
+
opened,
|
|
207
|
+
setOpened,
|
|
208
|
+
openError,
|
|
209
|
+
savedHashRef,
|
|
210
|
+
packageBaseRef,
|
|
211
|
+
setWrote,
|
|
212
|
+
fetchedAtRef,
|
|
213
|
+
setDirty,
|
|
214
|
+
setSeen,
|
|
215
|
+
held,
|
|
216
|
+
choose,
|
|
217
|
+
acceptHeld,
|
|
218
|
+
} = useOpenedDocument({
|
|
219
|
+
workspace,
|
|
220
|
+
draft,
|
|
221
|
+
draftChecked,
|
|
222
|
+
readFailure,
|
|
223
|
+
packageText,
|
|
224
|
+
fetchedAt: modelQuery.dataUpdatedAt,
|
|
225
|
+
packageSettled: modelQuery.isSuccess && !modelQuery.isFetching,
|
|
226
|
+
modelPath,
|
|
227
|
+
notebook,
|
|
228
|
+
noun,
|
|
229
|
+
refusedEvent,
|
|
230
|
+
legacyFormat,
|
|
231
|
+
textHeld,
|
|
232
|
+
startedAt,
|
|
233
|
+
onEventRef,
|
|
234
|
+
});
|
|
235
|
+
const {
|
|
236
|
+
save,
|
|
237
|
+
savesTo,
|
|
238
|
+
writer,
|
|
239
|
+
pinnedPackageSave,
|
|
240
|
+
takesWrites,
|
|
241
|
+
supersedeFailure,
|
|
242
|
+
} = useSaveChannel({
|
|
243
|
+
storage,
|
|
244
|
+
workspace,
|
|
245
|
+
kind,
|
|
246
|
+
notebook,
|
|
247
|
+
environmentName,
|
|
248
|
+
packageName,
|
|
249
|
+
modelPath,
|
|
250
|
+
versionId,
|
|
251
|
+
apiClients,
|
|
252
|
+
queryClient,
|
|
253
|
+
mutable,
|
|
254
|
+
textHeld,
|
|
255
|
+
readFailure,
|
|
256
|
+
authoritative,
|
|
257
|
+
resume,
|
|
258
|
+
setResume,
|
|
259
|
+
setOpened,
|
|
260
|
+
setDraft,
|
|
261
|
+
setOffered,
|
|
262
|
+
setSeen,
|
|
263
|
+
setWrote,
|
|
264
|
+
savedHashRef,
|
|
265
|
+
packageBaseRef,
|
|
266
|
+
fetchedAtRef,
|
|
267
|
+
});
|
|
521
268
|
const workspaceName = workspace?.name;
|
|
522
269
|
const reportEvent = useCallback(
|
|
523
|
-
(event:
|
|
524
|
-
|
|
525
|
-
// package was not taken by one, and naming it there would say the
|
|
526
|
-
// record moved somewhere it did not.
|
|
527
|
-
onEventRef.current?.(
|
|
528
|
-
event.type === "dashboard.saved" &&
|
|
529
|
-
event.where !== "package" &&
|
|
530
|
-
workspaceName !== undefined
|
|
531
|
-
? { ...event, workspace: workspaceName }
|
|
532
|
-
: event,
|
|
533
|
-
);
|
|
270
|
+
(event: BuilderEvent) => {
|
|
271
|
+
onEventRef.current?.(withWorkspace(event, workspaceName));
|
|
534
272
|
},
|
|
535
273
|
[workspaceName],
|
|
536
274
|
);
|
|
537
275
|
// Stable: the builder fires this from an effect that depends on it.
|
|
538
|
-
const reportDirty = useCallback(
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
276
|
+
const reportDirty = useCallback(
|
|
277
|
+
(value: boolean) => {
|
|
278
|
+
setDirty(value);
|
|
279
|
+
onDirtyChangeRef.current?.(value);
|
|
280
|
+
},
|
|
281
|
+
[setDirty],
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const saveLabel =
|
|
285
|
+
savesTo === "host" && workspace?.description
|
|
286
|
+
? workspace.description
|
|
287
|
+
: undefined;
|
|
288
|
+
const caption =
|
|
289
|
+
!authoritative && !textHeld && mutable === undefined
|
|
290
|
+
? isLoadingStatus
|
|
291
|
+
? "Checking whether this server takes writes."
|
|
292
|
+
: "This server did not say whether it takes writes, so Save is off."
|
|
293
|
+
: saveCaption({
|
|
294
|
+
authoritative,
|
|
295
|
+
mutable: takesWrites,
|
|
296
|
+
pinnedPackageSave,
|
|
297
|
+
...(workspace ? { workspace } : {}),
|
|
298
|
+
...(readFailure !== undefined ? { readFailure } : {}),
|
|
299
|
+
...(versionId !== undefined ? { versionId } : {}),
|
|
300
|
+
});
|
|
301
|
+
// The description is already the Save caption, so the note does not repeat it.
|
|
302
|
+
const note = caption === saveLabel ? "" : caption;
|
|
553
303
|
|
|
554
304
|
// After every hook, so the hook order does not depend on the URI. Same
|
|
555
305
|
// reasoning as `Dashboard`'s own check.
|
|
556
306
|
if (!uriNamesBoth && "resourceUri" in props)
|
|
557
307
|
return (
|
|
558
308
|
<Alert severity="error" sx={{ m: 2 }}>
|
|
559
|
-
A
|
|
309
|
+
A {noun} resource URI must name an environment and a package.
|
|
560
310
|
Received: {props.resourceUri}
|
|
561
311
|
</Alert>
|
|
562
312
|
);
|
|
563
|
-
if (
|
|
313
|
+
if (openError)
|
|
314
|
+
return (
|
|
315
|
+
<Alert severity="error" sx={{ m: 2 }}>
|
|
316
|
+
This {noun} cannot be opened in the builder: {openError}
|
|
317
|
+
</Alert>
|
|
318
|
+
);
|
|
319
|
+
// Only before an open: after one, a failed refetch is a banner above the builder so unsaved edits survive it.
|
|
320
|
+
if (modelQuery.isError && !opened)
|
|
564
321
|
return (
|
|
565
322
|
<ApiErrorDisplay
|
|
566
323
|
error={modelQuery.error}
|
|
567
|
-
context=
|
|
324
|
+
context={`Opening the ${noun}`}
|
|
568
325
|
/>
|
|
569
326
|
);
|
|
570
|
-
if (!packageText || !draftChecked)
|
|
571
|
-
|
|
572
|
-
// shape: the reader's view had a bar in this spot, and a spinner where
|
|
573
|
-
// the bar was made the switch look like a page reload.
|
|
574
|
-
return (
|
|
575
|
-
<Stack sx={{ gap: 2 }}>
|
|
576
|
-
<DashboardBar />
|
|
577
|
-
<Loading text="Opening the dashboard…" />
|
|
578
|
-
</Stack>
|
|
579
|
-
);
|
|
327
|
+
if (!opened && (!(textHeld || packageText) || !draftChecked))
|
|
328
|
+
return <Loading text={`Opening the ${noun}…`} />;
|
|
580
329
|
// Where the host's copy IS the document, a copy that could not be read
|
|
581
330
|
// leaves nothing safe to edit: the package file is a deploy of the record,
|
|
582
331
|
// so opening it and arming Save would publish it over the record.
|
|
583
332
|
if (blockedOnRecord)
|
|
584
333
|
return (
|
|
585
334
|
<Alert severity="error" sx={{ m: 2 }}>
|
|
586
|
-
This
|
|
335
|
+
This {noun} cannot be opened: {readFailure}
|
|
587
336
|
</Alert>
|
|
588
337
|
);
|
|
589
|
-
if (openError)
|
|
590
|
-
return (
|
|
591
|
-
<Alert severity="error" sx={{ m: 2 }}>
|
|
592
|
-
This dashboard cannot be opened in the builder: {openError}
|
|
593
|
-
</Alert>
|
|
594
|
-
);
|
|
595
|
-
|
|
596
338
|
const draftDiffers = draft !== undefined && draft !== packageText;
|
|
597
339
|
return (
|
|
598
340
|
<Stack sx={{ gap: 2 }}>
|
|
599
|
-
{
|
|
600
|
-
<Alert
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
<Stack direction="row" sx={{ gap: 1 }}>
|
|
604
|
-
<Button size="small" onClick={() => choose(true)}>
|
|
605
|
-
Resume
|
|
606
|
-
</Button>
|
|
607
|
-
<Button size="small" onClick={() => choose(false)}>
|
|
608
|
-
Start from the package
|
|
609
|
-
</Button>
|
|
610
|
-
</Stack>
|
|
611
|
-
}
|
|
612
|
-
>
|
|
613
|
-
You have edits to this dashboard saved in this browser that the
|
|
614
|
-
package does not have.
|
|
341
|
+
{modelQuery.isError && (
|
|
342
|
+
<Alert severity="warning">
|
|
343
|
+
The {noun} could not be re-read from the server:{" "}
|
|
344
|
+
{modelQuery.error?.message}. Your edits are still here.
|
|
615
345
|
</Alert>
|
|
616
346
|
)}
|
|
347
|
+
{!notebook &&
|
|
348
|
+
!authoritative &&
|
|
349
|
+
offered &&
|
|
350
|
+
draftDiffers &&
|
|
351
|
+
resume === undefined && (
|
|
352
|
+
<Alert
|
|
353
|
+
severity="info"
|
|
354
|
+
action={
|
|
355
|
+
<Stack direction="row" sx={{ gap: 1 }}>
|
|
356
|
+
<Button size="small" onClick={() => choose(true)}>
|
|
357
|
+
Resume
|
|
358
|
+
</Button>
|
|
359
|
+
<Button size="small" onClick={() => choose(false)}>
|
|
360
|
+
Start from the package
|
|
361
|
+
</Button>
|
|
362
|
+
</Stack>
|
|
363
|
+
}
|
|
364
|
+
>
|
|
365
|
+
You have edits to this dashboard saved in this browser that
|
|
366
|
+
the package does not have.
|
|
367
|
+
</Alert>
|
|
368
|
+
)}
|
|
617
369
|
{held !== undefined && (
|
|
618
370
|
<Alert
|
|
619
371
|
severity="warning"
|
|
@@ -638,314 +390,34 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
638
390
|
</Alert>
|
|
639
391
|
)}
|
|
640
392
|
{opened && (
|
|
641
|
-
<
|
|
393
|
+
<EditorSurface
|
|
642
394
|
key={opened.generation}
|
|
395
|
+
kind={kind}
|
|
643
396
|
environmentName={environmentName}
|
|
644
397
|
packageName={packageName}
|
|
645
398
|
modelPath={modelPath}
|
|
399
|
+
{...(textSource ? { textSource } : {})}
|
|
646
400
|
slug={dashboardName}
|
|
401
|
+
modelGivens={
|
|
402
|
+
(modelQuery.data?.data as { givens?: Given[] } | undefined)
|
|
403
|
+
?.givens
|
|
404
|
+
}
|
|
647
405
|
{...(versionId !== undefined ? { versionId } : {})}
|
|
648
406
|
opened={opened}
|
|
407
|
+
{...(fromDraft &&
|
|
408
|
+
writer === "package" &&
|
|
409
|
+
opened.packageText !== undefined
|
|
410
|
+
? { replaces: opened.packageText }
|
|
411
|
+
: {})}
|
|
649
412
|
onSave={save}
|
|
650
413
|
onDirtyChange={reportDirty}
|
|
414
|
+
{...(onExit ? { onExit } : {})}
|
|
651
415
|
savesTo={savesTo}
|
|
416
|
+
{...(saveLabel ? { saveLabel } : {})}
|
|
652
417
|
{...(onEvent ? { onEvent: reportEvent } : {})}
|
|
653
|
-
|
|
654
|
-
onExit && (
|
|
655
|
-
<SecondaryButton
|
|
656
|
-
label="Done editing"
|
|
657
|
-
icon={<CheckIcon />}
|
|
658
|
-
onClick={onExit}
|
|
659
|
-
/>
|
|
660
|
-
)
|
|
661
|
-
}
|
|
662
|
-
note={caption({
|
|
663
|
-
authoritative,
|
|
664
|
-
mutable,
|
|
665
|
-
pinnedPackageSave,
|
|
666
|
-
...(workspace ? { workspace } : {}),
|
|
667
|
-
...(readFailure !== undefined ? { readFailure } : {}),
|
|
668
|
-
...(versionId !== undefined ? { versionId } : {}),
|
|
669
|
-
})}
|
|
418
|
+
note={note}
|
|
670
419
|
/>
|
|
671
420
|
)}
|
|
672
421
|
</Stack>
|
|
673
422
|
);
|
|
674
423
|
}
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* What the toolbar says about where Save goes, in the backend's own words
|
|
678
|
-
* wherever it has any: a workspace carries a `description` precisely so the
|
|
679
|
-
* editor does not have to guess, and "this browser" is one host's answer
|
|
680
|
-
* rather than the interface's.
|
|
681
|
-
*/
|
|
682
|
-
function caption({
|
|
683
|
-
authoritative,
|
|
684
|
-
mutable,
|
|
685
|
-
pinnedPackageSave,
|
|
686
|
-
workspace,
|
|
687
|
-
readFailure,
|
|
688
|
-
versionId,
|
|
689
|
-
}: {
|
|
690
|
-
authoritative: boolean;
|
|
691
|
-
mutable: boolean;
|
|
692
|
-
pinnedPackageSave: boolean;
|
|
693
|
-
workspace?: Workspace;
|
|
694
|
-
readFailure?: string;
|
|
695
|
-
versionId?: string;
|
|
696
|
-
}): string {
|
|
697
|
-
if (readFailure !== undefined)
|
|
698
|
-
return `The saved copy could not be read, so Save is off: ${readFailure}`;
|
|
699
|
-
if (authoritative && workspace)
|
|
700
|
-
return workspace.writeable
|
|
701
|
-
? workspace.description
|
|
702
|
-
: `${workspace.description}: you cannot save into it.`;
|
|
703
|
-
if (pinnedPackageSave)
|
|
704
|
-
return `Reading version ${versionId}: a version is a fixed point in history, so Save is off.`;
|
|
705
|
-
if (mutable) return "Save writes the file into the package.";
|
|
706
|
-
if (workspace)
|
|
707
|
-
return `${workspace.description}: this server does not take writes.`;
|
|
708
|
-
return "This server does not take writes.";
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* The builder under a real control row, with the controls driving the tiles,
|
|
713
|
-
* both following the LIVE document rather than the saved file.
|
|
714
|
-
*
|
|
715
|
-
* Owns the given values for the same reason the reader's `Dashboard` does: the
|
|
716
|
-
* bar and the tiles have to read one set of values, so whatever holds them has
|
|
717
|
-
* to sit above both. The manifest supplies what the file cannot say about the
|
|
718
|
-
* model's own givens, and the set of givens the server can be sent; a control
|
|
719
|
-
* declared here and not yet in the package is written into each tile's query as
|
|
720
|
-
* a literal, so it works the moment it is added.
|
|
721
|
-
*/
|
|
722
|
-
function Surface({
|
|
723
|
-
environmentName,
|
|
724
|
-
packageName,
|
|
725
|
-
modelPath,
|
|
726
|
-
slug,
|
|
727
|
-
versionId,
|
|
728
|
-
opened,
|
|
729
|
-
onSave,
|
|
730
|
-
onDirtyChange,
|
|
731
|
-
onEvent,
|
|
732
|
-
savesTo,
|
|
733
|
-
toolbar,
|
|
734
|
-
note,
|
|
735
|
-
}: {
|
|
736
|
-
environmentName: string;
|
|
737
|
-
packageName: string;
|
|
738
|
-
modelPath: string;
|
|
739
|
-
slug: string;
|
|
740
|
-
versionId?: string;
|
|
741
|
-
opened: { source: string; document: DashboardDocument; generation: number };
|
|
742
|
-
onSave?: (source: string) => Promise<void>;
|
|
743
|
-
onDirtyChange: (dirty: boolean) => void;
|
|
744
|
-
onEvent?: DashboardEventHandler;
|
|
745
|
-
savesTo: "package" | "browser" | "host";
|
|
746
|
-
toolbar: React.ReactNode;
|
|
747
|
-
note: string;
|
|
748
|
-
}) {
|
|
749
|
-
const { apiClients } = useServer();
|
|
750
|
-
|
|
751
|
-
const { data, isSuccess } = useQueryWithApiError({
|
|
752
|
-
queryKey: [
|
|
753
|
-
"dashboard-editor-manifest",
|
|
754
|
-
environmentName,
|
|
755
|
-
packageName,
|
|
756
|
-
slug,
|
|
757
|
-
versionId,
|
|
758
|
-
],
|
|
759
|
-
queryFn: () =>
|
|
760
|
-
apiClients.dashboards.getDashboard(
|
|
761
|
-
environmentName,
|
|
762
|
-
packageName,
|
|
763
|
-
slug,
|
|
764
|
-
versionId,
|
|
765
|
-
),
|
|
766
|
-
});
|
|
767
|
-
const manifest = data?.data;
|
|
768
|
-
|
|
769
|
-
// The package's other dashboards, by slug: where a clicked cell can go.
|
|
770
|
-
const { data: dashboardList } = useQueryWithApiError({
|
|
771
|
-
queryKey: [
|
|
772
|
-
"dashboard-editor-dashboards",
|
|
773
|
-
environmentName,
|
|
774
|
-
packageName,
|
|
775
|
-
versionId,
|
|
776
|
-
],
|
|
777
|
-
queryFn: () =>
|
|
778
|
-
apiClients.dashboards.listDashboards(
|
|
779
|
-
environmentName,
|
|
780
|
-
packageName,
|
|
781
|
-
versionId,
|
|
782
|
-
),
|
|
783
|
-
});
|
|
784
|
-
const otherDashboards = useMemo(
|
|
785
|
-
() =>
|
|
786
|
-
(dashboardList?.data ?? [])
|
|
787
|
-
.map((d) => d.name)
|
|
788
|
-
.filter((name): name is string => !!name && name !== slug),
|
|
789
|
-
[dashboardList, slug],
|
|
790
|
-
);
|
|
791
|
-
|
|
792
|
-
// The catalog: what the package publishes, limited to what this file can
|
|
793
|
-
// see. A tile runs against this file and may read only the package surface,
|
|
794
|
-
// so offering a source from any other file would offer a tile that 404s.
|
|
795
|
-
// Files off the surface are not readable anyway (their model GET is 404).
|
|
796
|
-
const imports = useMemo(() => {
|
|
797
|
-
const dir = modelPath.slice(0, modelPath.lastIndexOf("/") + 1);
|
|
798
|
-
return opened.document.imports.map((imported) => ({
|
|
799
|
-
...imported,
|
|
800
|
-
path: new URL(
|
|
801
|
-
imported.from,
|
|
802
|
-
`https://malloy.invalid/${dir}`,
|
|
803
|
-
).pathname.slice(1),
|
|
804
|
-
}));
|
|
805
|
-
}, [opened.document.imports, modelPath]);
|
|
806
|
-
const { data: catalog } = useQueryWithApiError<PackageCatalog>({
|
|
807
|
-
queryKey: [
|
|
808
|
-
"dashboard-editor-catalog",
|
|
809
|
-
environmentName,
|
|
810
|
-
packageName,
|
|
811
|
-
...imports.map((i) => i.path),
|
|
812
|
-
versionId,
|
|
813
|
-
],
|
|
814
|
-
queryFn: async () => {
|
|
815
|
-
const listed = (
|
|
816
|
-
await apiClients.models.listModels(
|
|
817
|
-
environmentName,
|
|
818
|
-
packageName,
|
|
819
|
-
versionId,
|
|
820
|
-
)
|
|
821
|
-
).data.filter((m) => m.path && !m.error);
|
|
822
|
-
// One model that fails to load (a reload racing this fetch, say)
|
|
823
|
-
// costs the catalog that model's sources, not every suggestion.
|
|
824
|
-
const settled = await Promise.allSettled(
|
|
825
|
-
listed.map((m) =>
|
|
826
|
-
apiClients.models
|
|
827
|
-
.getModel(environmentName, packageName, m.path!, versionId)
|
|
828
|
-
.then((response) => response.data),
|
|
829
|
-
),
|
|
830
|
-
);
|
|
831
|
-
const models = settled.flatMap((result) =>
|
|
832
|
-
result.status === "fulfilled" ? [result.value] : [],
|
|
833
|
-
);
|
|
834
|
-
return visibleToDashboard(buildCatalog(models), imports, models);
|
|
835
|
-
},
|
|
836
|
-
enabled: imports.length > 0,
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
const [doc, setDoc] = useState(opened.document);
|
|
840
|
-
useEffect(() => setDoc(opened.document), [opened.document]);
|
|
841
|
-
const modelSpecs = useMemo(() => manifest?.givens ?? [], [manifest]);
|
|
842
|
-
const runnable = useMemo(
|
|
843
|
-
() =>
|
|
844
|
-
new Set(
|
|
845
|
-
modelSpecs
|
|
846
|
-
.map((spec) => spec.name)
|
|
847
|
-
.filter((name): name is string => name !== undefined),
|
|
848
|
-
),
|
|
849
|
-
[modelSpecs],
|
|
850
|
-
);
|
|
851
|
-
const specs = useMemo(
|
|
852
|
-
() => previewGivens(doc, modelSpecs),
|
|
853
|
-
[doc, modelSpecs],
|
|
854
|
-
);
|
|
855
|
-
const { declaredTypes, applied, panel } = useDocumentControls({
|
|
856
|
-
specs,
|
|
857
|
-
loaded: isSuccess,
|
|
858
|
-
startingValues: manifest?.startingGivens,
|
|
859
|
-
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${slug}/edit`,
|
|
860
|
-
autorun: manifest?.autorun !== false,
|
|
861
|
-
environmentName,
|
|
862
|
-
packageName,
|
|
863
|
-
modelPath: manifest?.path,
|
|
864
|
-
versionId,
|
|
865
|
-
documentName: slug,
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
const renderTile = useMemo(
|
|
869
|
-
() =>
|
|
870
|
-
function LiveTile(tile: DashboardDocument["tiles"][number]) {
|
|
871
|
-
const query = previewTileQuery(doc, tile, runnable, applied);
|
|
872
|
-
return (
|
|
873
|
-
<DashboardTile
|
|
874
|
-
environmentName={environmentName}
|
|
875
|
-
packageName={packageName}
|
|
876
|
-
versionId={versionId}
|
|
877
|
-
modelPath={modelPath}
|
|
878
|
-
tile={query.expression}
|
|
879
|
-
label={
|
|
880
|
-
tile.label ?? tileTitle(`${tile.source} -> ${tile.name}`)
|
|
881
|
-
}
|
|
882
|
-
subtitle={tile.subtitle}
|
|
883
|
-
borderless={tile.borderless}
|
|
884
|
-
givens={applied}
|
|
885
|
-
declaredTypes={declaredTypes}
|
|
886
|
-
givenNames={query.givenNames}
|
|
887
|
-
height={TILE_MAX_HEIGHT}
|
|
888
|
-
/>
|
|
889
|
-
);
|
|
890
|
-
},
|
|
891
|
-
[
|
|
892
|
-
doc,
|
|
893
|
-
runnable,
|
|
894
|
-
environmentName,
|
|
895
|
-
packageName,
|
|
896
|
-
versionId,
|
|
897
|
-
modelPath,
|
|
898
|
-
applied,
|
|
899
|
-
declaredTypes,
|
|
900
|
-
],
|
|
901
|
-
);
|
|
902
|
-
|
|
903
|
-
return (
|
|
904
|
-
<Stack sx={{ gap: 1 }}>
|
|
905
|
-
<DashboardBuilder
|
|
906
|
-
source={opened.source}
|
|
907
|
-
document={opened.document}
|
|
908
|
-
renderTile={renderTile}
|
|
909
|
-
givens={specs
|
|
910
|
-
.filter((spec) => spec.name !== undefined)
|
|
911
|
-
.map((spec) => ({
|
|
912
|
-
name: spec.name as string,
|
|
913
|
-
...(spec.label ? { label: spec.label } : {}),
|
|
914
|
-
...(spec.type ? { type: spec.type } : {}),
|
|
915
|
-
...(spec.suggest?.dimension
|
|
916
|
-
? { field: spec.suggest.dimension }
|
|
917
|
-
: {}),
|
|
918
|
-
}))}
|
|
919
|
-
onChange={setDoc}
|
|
920
|
-
onDirtyChange={onDirtyChange}
|
|
921
|
-
{...(catalog ? { catalog } : {})}
|
|
922
|
-
dashboards={otherDashboards}
|
|
923
|
-
{...(onEvent ? { onEvent } : {})}
|
|
924
|
-
toolbar={toolbar}
|
|
925
|
-
controls={
|
|
926
|
-
isSuccess ? <GivensPanel {...panel} layout="bar" /> : undefined
|
|
927
|
-
}
|
|
928
|
-
{...(onSave ? { onSave } : {})}
|
|
929
|
-
savesTo={savesTo}
|
|
930
|
-
/>
|
|
931
|
-
<Box sx={{ px: 0.5 }}>
|
|
932
|
-
<Typography variant="caption" sx={{ opacity: 0.7 }}>
|
|
933
|
-
{note}
|
|
934
|
-
</Typography>
|
|
935
|
-
</Box>
|
|
936
|
-
</Stack>
|
|
937
|
-
);
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
/** What a storage backend said went wrong, for a reader who has to act on it. */
|
|
941
|
-
function storageErrorMessage(error: unknown): string {
|
|
942
|
-
return error instanceof Error ? error.message : String(error);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/** The server's own reason for a refused write, when it gave one. */
|
|
946
|
-
function apiErrorMessage(error: unknown): string {
|
|
947
|
-
const data = (error as { response?: { data?: { message?: string } } })
|
|
948
|
-
.response?.data;
|
|
949
|
-
if (data?.message) return data.message;
|
|
950
|
-
return error instanceof Error ? error.message : String(error);
|
|
951
|
-
}
|