@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
package/src/hooks/index.ts
CHANGED
|
@@ -43,6 +43,10 @@ export {
|
|
|
43
43
|
type UseGivensStateResult,
|
|
44
44
|
} from "./useGivensState";
|
|
45
45
|
export { useSuggestOptions } from "./useSuggestOptions";
|
|
46
|
+
export {
|
|
47
|
+
useCompiledDocument,
|
|
48
|
+
type CompiledDocumentSpec,
|
|
49
|
+
} from "./useCompiledDocument";
|
|
46
50
|
|
|
47
51
|
// One query, and one control row, as every surface asks for them
|
|
48
52
|
export {
|
|
@@ -56,3 +60,6 @@ export {
|
|
|
56
60
|
type DocumentControls,
|
|
57
61
|
type UseDocumentControlsOptions,
|
|
58
62
|
} from "./useDocumentControls";
|
|
63
|
+
|
|
64
|
+
// Below the 600px breakpoint, where the editors step aside
|
|
65
|
+
export { isNarrowScreen, useNarrowScreen } from "./useNarrowScreen";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
serverWrapper,
|
|
10
|
+
} from "../../test/serverProvider";
|
|
11
|
+
|
|
12
|
+
const compileModelSource = mock(
|
|
13
|
+
(
|
|
14
|
+
_env: string,
|
|
15
|
+
_pkg: string,
|
|
16
|
+
_path: string,
|
|
17
|
+
_body: { source?: string; scope?: string; givens?: object },
|
|
18
|
+
) => Promise.resolve({ data: { status: "success", problems: [] } }),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
mockServerProvider({ models: { compileModelSource } });
|
|
22
|
+
|
|
23
|
+
const { useCompiledDocument } = await import("./useCompiledDocument");
|
|
24
|
+
|
|
25
|
+
const SOURCE = '## artifact { tiles=["orders_secured -> by_status"] }\n';
|
|
26
|
+
|
|
27
|
+
const render = (givens?: Record<string, unknown>) =>
|
|
28
|
+
renderHook(
|
|
29
|
+
() =>
|
|
30
|
+
useCompiledDocument({
|
|
31
|
+
environmentName: "env",
|
|
32
|
+
packageName: "pkg",
|
|
33
|
+
modelPath: "index.malloy",
|
|
34
|
+
source: SOURCE,
|
|
35
|
+
givens,
|
|
36
|
+
}),
|
|
37
|
+
{ wrapper: serverWrapper },
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const bodyOfLastCall = () => compileModelSource.mock.calls.at(-1)?.[3];
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
clearCache();
|
|
44
|
+
compileModelSource.mockClear();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("useCompiledDocument: the givens a gate reads", () => {
|
|
48
|
+
it("sends no givens key when the host sets none", async () => {
|
|
49
|
+
const { result } = render();
|
|
50
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
51
|
+
expect(bodyOfLastCall()).toEqual({ source: SOURCE, scope: "append" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("sends a list-valued given as the list, which a `$TENANTS`-style gate reads", async () => {
|
|
55
|
+
const { result } = render({ TENANTS: ["acme", "globex"] });
|
|
56
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
57
|
+
expect(bodyOfLastCall()).toEqual({
|
|
58
|
+
source: SOURCE,
|
|
59
|
+
scope: "append",
|
|
60
|
+
givens: { TENANTS: ["acme", "globex"] },
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("compiles again when a given's value changes, so a stale restricted verdict is not reused", async () => {
|
|
65
|
+
const { result, rerender } = renderHook(
|
|
66
|
+
({ givens }: { givens: Record<string, unknown> }) =>
|
|
67
|
+
useCompiledDocument({
|
|
68
|
+
environmentName: "env",
|
|
69
|
+
packageName: "pkg",
|
|
70
|
+
modelPath: "index.malloy",
|
|
71
|
+
source: SOURCE,
|
|
72
|
+
givens,
|
|
73
|
+
}),
|
|
74
|
+
{
|
|
75
|
+
wrapper: serverWrapper,
|
|
76
|
+
initialProps: { givens: { TENANTS: ["acme"] } },
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
80
|
+
rerender({ givens: { TENANTS: ["acme", "globex"] } });
|
|
81
|
+
await waitFor(() => expect(compileModelSource).toHaveBeenCalledTimes(2));
|
|
82
|
+
expect(bodyOfLastCall()?.givens).toEqual({
|
|
83
|
+
TENANTS: ["acme", "globex"],
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { CompiledDocument, CompileResult } from "../client";
|
|
5
|
+
import { useServer } from "../components/ServerProvider";
|
|
6
|
+
import { useQueryWithApiError } from "./useQueryWithApiError";
|
|
7
|
+
|
|
8
|
+
export interface CompiledDocumentSpec {
|
|
9
|
+
environmentName: string;
|
|
10
|
+
packageName: string;
|
|
11
|
+
/** The model the text is compiled on top of: what it may name is what this model offers the viewer. */
|
|
12
|
+
modelPath: string;
|
|
13
|
+
source: string;
|
|
14
|
+
/** The values the host sets for the givens a source's gate reads; a gate sent none of its givens denies, so every tile would come back `restricted`. */
|
|
15
|
+
givens?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The document a text compiles to, read for the viewer who asks: the manifest
|
|
20
|
+
* and cells the server would serve, with the tiles and cells that viewer may
|
|
21
|
+
* not read marked `restricted`. Compile-only; nothing runs.
|
|
22
|
+
*/
|
|
23
|
+
export function useCompiledDocument(
|
|
24
|
+
spec: CompiledDocumentSpec,
|
|
25
|
+
{ enabled = true }: { enabled?: boolean } = {},
|
|
26
|
+
) {
|
|
27
|
+
const { apiClients } = useServer();
|
|
28
|
+
return useQueryWithApiError<{
|
|
29
|
+
document?: CompiledDocument;
|
|
30
|
+
result: CompileResult;
|
|
31
|
+
}>({
|
|
32
|
+
queryKey: [
|
|
33
|
+
"compiled-document",
|
|
34
|
+
spec.environmentName,
|
|
35
|
+
spec.packageName,
|
|
36
|
+
spec.modelPath,
|
|
37
|
+
spec.source,
|
|
38
|
+
spec.givens ?? null,
|
|
39
|
+
],
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
const result = (
|
|
42
|
+
await apiClients.models.compileModelSource(
|
|
43
|
+
spec.environmentName,
|
|
44
|
+
spec.packageName,
|
|
45
|
+
spec.modelPath,
|
|
46
|
+
{
|
|
47
|
+
source: spec.source,
|
|
48
|
+
scope: "append",
|
|
49
|
+
...(spec.givens && Object.keys(spec.givens).length > 0
|
|
50
|
+
? { givens: spec.givens }
|
|
51
|
+
: {}),
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
).data;
|
|
55
|
+
return { document: result.document, result };
|
|
56
|
+
},
|
|
57
|
+
enabled,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -698,7 +698,7 @@ export function useDimensionalFilterRangeData(
|
|
|
698
698
|
versionId,
|
|
699
699
|
activeFilters,
|
|
700
700
|
],
|
|
701
|
-
queryFn: async () => {
|
|
701
|
+
queryFn: async ({ signal }) => {
|
|
702
702
|
if (!shouldExecuteQuery) {
|
|
703
703
|
// Return empty map if no query needed (using composite keys)
|
|
704
704
|
const emptyMap = new Map<string, DimensionValue[]>();
|
|
@@ -721,6 +721,8 @@ export function useDimensionalFilterRangeData(
|
|
|
721
721
|
versionId: versionId,
|
|
722
722
|
bypassFilters: true,
|
|
723
723
|
},
|
|
724
|
+
undefined,
|
|
725
|
+
{ signal },
|
|
724
726
|
);
|
|
725
727
|
return {
|
|
726
728
|
config,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { useCallback, useMemo } from "react";
|
|
5
5
|
import type { Given } from "../client";
|
|
6
|
+
import type { HostGivenValue } from "./givenValue";
|
|
6
7
|
import { useDrillSelf } from "../components/drill/useDrillSelf";
|
|
7
8
|
import type { GivensPanelProps } from "../components/given/GivensPanel";
|
|
8
9
|
import { useGivensState, type UseGivensStateResult } from "./useGivensState";
|
|
@@ -63,6 +64,10 @@ export interface UseDocumentControlsOptions {
|
|
|
63
64
|
versionId?: string;
|
|
64
65
|
/** How the document names itself in a refused-drill warning. */
|
|
65
66
|
documentName: string;
|
|
67
|
+
/** Text-source mode: the document's definitions, which a suggest runs after as the viewer's own text. */
|
|
68
|
+
preamble?: string;
|
|
69
|
+
/** Givens the host sets with no control, so a suggest over a source they gate still carries them. */
|
|
70
|
+
hostGivens?: Readonly<Record<string, HostGivenValue>>;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
export interface DocumentControls extends UseGivensStateResult {
|
|
@@ -92,6 +97,8 @@ export function useDocumentControls({
|
|
|
92
97
|
modelPath,
|
|
93
98
|
versionId,
|
|
94
99
|
documentName,
|
|
100
|
+
preamble,
|
|
101
|
+
hostGivens,
|
|
95
102
|
}: UseDocumentControlsOptions): DocumentControls {
|
|
96
103
|
const declaredTypes = useMemo(
|
|
97
104
|
() =>
|
|
@@ -136,7 +143,12 @@ export function useDocumentControls({
|
|
|
136
143
|
specs,
|
|
137
144
|
versionId,
|
|
138
145
|
// So a suggest over a gated or scoped source carries the givens it needs.
|
|
139
|
-
{
|
|
146
|
+
{
|
|
147
|
+
values: state.applied,
|
|
148
|
+
declaredTypes,
|
|
149
|
+
...(hostGivens ? { host: hostGivens } : {}),
|
|
150
|
+
},
|
|
151
|
+
preamble,
|
|
140
152
|
);
|
|
141
153
|
|
|
142
154
|
const { canSelf, onSelf } = useDrillSelf({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useMediaQuery } from "@mui/material";
|
|
5
|
+
|
|
6
|
+
// MUI's `sm` breakpoint is 600px.
|
|
7
|
+
const NARROW = "(max-width:599.95px)";
|
|
8
|
+
|
|
9
|
+
/** Whether the viewport is below 600px, live; `noSsr` so the first render already knows. */
|
|
10
|
+
export function useNarrowScreen(): boolean {
|
|
11
|
+
return useMediaQuery(NARROW, { noSsr: true });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The same question answered once, for a view that must not change under someone mid-task. */
|
|
15
|
+
export function isNarrowScreen(): boolean {
|
|
16
|
+
return (
|
|
17
|
+
typeof window !== "undefined" &&
|
|
18
|
+
typeof window.matchMedia === "function" &&
|
|
19
|
+
window.matchMedia(NARROW).matches
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, it } from "bun:test";
|
|
5
|
+
import { act, render, screen } from "@testing-library/react";
|
|
6
|
+
import { useNearViewport } from "./useNearViewport";
|
|
7
|
+
|
|
8
|
+
function Probe() {
|
|
9
|
+
const [ref, near] = useNearViewport<HTMLDivElement>();
|
|
10
|
+
return <div ref={ref}>{near ? "near" : "far"}</div>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let callbacks: IntersectionObserverCallback[] = [];
|
|
14
|
+
let options: Array<IntersectionObserverInit | undefined> = [];
|
|
15
|
+
let disconnects = 0;
|
|
16
|
+
class FakeObserver {
|
|
17
|
+
private callback: IntersectionObserverCallback;
|
|
18
|
+
constructor(
|
|
19
|
+
callback: IntersectionObserverCallback,
|
|
20
|
+
init?: IntersectionObserverInit,
|
|
21
|
+
) {
|
|
22
|
+
this.callback = callback;
|
|
23
|
+
options.push(init);
|
|
24
|
+
}
|
|
25
|
+
observe() {
|
|
26
|
+
callbacks.push(this.callback);
|
|
27
|
+
}
|
|
28
|
+
disconnect() {
|
|
29
|
+
disconnects += 1;
|
|
30
|
+
}
|
|
31
|
+
unobserve() {}
|
|
32
|
+
takeRecords() {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const report = (isIntersecting: boolean) =>
|
|
37
|
+
act(() =>
|
|
38
|
+
callbacks.forEach((callback) =>
|
|
39
|
+
callback(
|
|
40
|
+
[{ isIntersecting } as IntersectionObserverEntry],
|
|
41
|
+
{} as IntersectionObserver,
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// happy-dom's own, put back after each spec: @dnd-kit elsewhere needs one.
|
|
47
|
+
const original = globalThis.IntersectionObserver;
|
|
48
|
+
const install = (observer: unknown) => {
|
|
49
|
+
(globalThis as { IntersectionObserver?: unknown }).IntersectionObserver =
|
|
50
|
+
observer;
|
|
51
|
+
};
|
|
52
|
+
// Somewhere far below the fold, for an element the observer has to report.
|
|
53
|
+
const placeFarBelow = () =>
|
|
54
|
+
Object.assign(HTMLElement.prototype, {
|
|
55
|
+
getBoundingClientRect: () => ({ top: 10_000, bottom: 10_400 }) as DOMRect,
|
|
56
|
+
});
|
|
57
|
+
const originalRect = HTMLElement.prototype.getBoundingClientRect;
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
install(original);
|
|
61
|
+
HTMLElement.prototype.getBoundingClientRect = originalRect;
|
|
62
|
+
callbacks = [];
|
|
63
|
+
options = [];
|
|
64
|
+
disconnects = 0;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("is open where there is no IntersectionObserver to ask", () => {
|
|
68
|
+
install(undefined);
|
|
69
|
+
render(<Probe />);
|
|
70
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("is open at once for an element that mounts near the viewport", () => {
|
|
74
|
+
install(FakeObserver);
|
|
75
|
+
render(<Probe />);
|
|
76
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
77
|
+
expect(callbacks).toHaveLength(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("opens once the element comes within the margin, and stays open", () => {
|
|
81
|
+
install(FakeObserver);
|
|
82
|
+
placeFarBelow();
|
|
83
|
+
render(<Probe />);
|
|
84
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
85
|
+
expect(options[0]?.rootMargin).toBe("600px 0px");
|
|
86
|
+
|
|
87
|
+
report(false);
|
|
88
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
89
|
+
|
|
90
|
+
report(true);
|
|
91
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
92
|
+
expect(disconnects).toBeGreaterThan(0);
|
|
93
|
+
|
|
94
|
+
// Scrolled away again: what has run stays run.
|
|
95
|
+
report(false);
|
|
96
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("measures against the box that scrolls the page, not the window", () => {
|
|
100
|
+
install(FakeObserver);
|
|
101
|
+
// The scroller is on screen; the tile is far down inside it.
|
|
102
|
+
Object.assign(HTMLElement.prototype, {
|
|
103
|
+
getBoundingClientRect(this: HTMLElement) {
|
|
104
|
+
return (
|
|
105
|
+
this.dataset.scroller
|
|
106
|
+
? { top: 0, bottom: 400 }
|
|
107
|
+
: { top: 10_000, bottom: 10_400 }
|
|
108
|
+
) as DOMRect;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const scrollHeight = Object.getOwnPropertyDescriptor(
|
|
112
|
+
HTMLElement.prototype,
|
|
113
|
+
"scrollHeight",
|
|
114
|
+
);
|
|
115
|
+
Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
|
|
116
|
+
configurable: true,
|
|
117
|
+
get() {
|
|
118
|
+
return (this as HTMLElement).dataset.scroller ? 5000 : 0;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
render(
|
|
123
|
+
<div data-scroller="yes" style={{ overflowY: "auto", height: 400 }}>
|
|
124
|
+
<Probe />
|
|
125
|
+
</div>,
|
|
126
|
+
);
|
|
127
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
128
|
+
expect(
|
|
129
|
+
(options[0]?.root as HTMLElement | undefined)?.dataset.scroller,
|
|
130
|
+
).toBe("yes");
|
|
131
|
+
} finally {
|
|
132
|
+
if (scrollHeight)
|
|
133
|
+
Object.defineProperty(
|
|
134
|
+
HTMLElement.prototype,
|
|
135
|
+
"scrollHeight",
|
|
136
|
+
scrollHeight,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("opens for printing, which lays the whole page out at once", () => {
|
|
142
|
+
install(FakeObserver);
|
|
143
|
+
placeFarBelow();
|
|
144
|
+
render(<Probe />);
|
|
145
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
146
|
+
act(() => {
|
|
147
|
+
window.dispatchEvent(new Event("beforeprint"));
|
|
148
|
+
});
|
|
149
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
150
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
/** How far above or below the viewport an element counts as near, in pixels: a screen or so of scroll. */
|
|
7
|
+
export const NEAR_VIEWPORT_MARGIN_PX = 600;
|
|
8
|
+
|
|
9
|
+
const observerUnavailable = () => typeof IntersectionObserver === "undefined";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The element that scrolls `node`, or null for the viewport. A host that
|
|
13
|
+
* scrolls its page inside a box (the Console does) clips a tile by that box,
|
|
14
|
+
* so a margin on the viewport would never be reached: the look-ahead has to be
|
|
15
|
+
* measured on the box itself.
|
|
16
|
+
*/
|
|
17
|
+
function scrollRootOf(node: Element): Element | null {
|
|
18
|
+
for (let at = node.parentElement; at; at = at.parentElement) {
|
|
19
|
+
const { overflowY } = getComputedStyle(at);
|
|
20
|
+
if (
|
|
21
|
+
(overflowY === "auto" || overflowY === "scroll") &&
|
|
22
|
+
at.scrollHeight > at.clientHeight
|
|
23
|
+
)
|
|
24
|
+
return at;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether an element has come near the viewport, latched: once true it stays
|
|
31
|
+
* true, so scrolling a tile away again never takes back what it has run.
|
|
32
|
+
*
|
|
33
|
+
* Returns a callback ref for the element and the flag. Where there is no
|
|
34
|
+
* `IntersectionObserver` (server rendering, a test DOM) the flag starts true,
|
|
35
|
+
* so gating on it never leaves something waiting for an observer that will not
|
|
36
|
+
* come.
|
|
37
|
+
*
|
|
38
|
+
* For work that costs: a dashboard tile's query runs against a warehouse that
|
|
39
|
+
* bills for it, and a long dashboard used to run every tile on mount, however
|
|
40
|
+
* far below the fold.
|
|
41
|
+
*/
|
|
42
|
+
export function useNearViewport<T extends Element = HTMLElement>(
|
|
43
|
+
marginPx: number = NEAR_VIEWPORT_MARGIN_PX,
|
|
44
|
+
): [ref: (node: T | null) => void, near: boolean] {
|
|
45
|
+
const [near, setNear] = useState(observerUnavailable);
|
|
46
|
+
const nearRef = useRef(near);
|
|
47
|
+
const observerRef = useRef<IntersectionObserver | null>(null);
|
|
48
|
+
|
|
49
|
+
const ref = useCallback(
|
|
50
|
+
(node: T | null) => {
|
|
51
|
+
observerRef.current?.disconnect();
|
|
52
|
+
observerRef.current = null;
|
|
53
|
+
if (!node || nearRef.current || observerUnavailable()) return;
|
|
54
|
+
// Already near when it mounts, as everything above the fold is: open
|
|
55
|
+
// now, in the commit that attached it, rather than a frame later when
|
|
56
|
+
// the observer first reports.
|
|
57
|
+
const rect = node.getBoundingClientRect();
|
|
58
|
+
const root = scrollRootOf(node);
|
|
59
|
+
const bounds = root?.getBoundingClientRect() ?? {
|
|
60
|
+
top: 0,
|
|
61
|
+
bottom: window.innerHeight || document.documentElement.clientHeight,
|
|
62
|
+
};
|
|
63
|
+
if (
|
|
64
|
+
rect.bottom >= bounds.top - marginPx &&
|
|
65
|
+
rect.top <= bounds.bottom + marginPx
|
|
66
|
+
) {
|
|
67
|
+
nearRef.current = true;
|
|
68
|
+
setNear(true);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const observer = new IntersectionObserver(
|
|
72
|
+
(entries) => {
|
|
73
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
74
|
+
nearRef.current = true;
|
|
75
|
+
observer.disconnect();
|
|
76
|
+
setNear(true);
|
|
77
|
+
},
|
|
78
|
+
{ root, rootMargin: `${marginPx}px 0px` },
|
|
79
|
+
);
|
|
80
|
+
observer.observe(node);
|
|
81
|
+
observerRef.current = observer;
|
|
82
|
+
},
|
|
83
|
+
[marginPx],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
useEffect(() => () => observerRef.current?.disconnect(), []);
|
|
87
|
+
|
|
88
|
+
// Printing lays out the whole page at once with nobody scrolling: every
|
|
89
|
+
// tile has to have run by then.
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (near || typeof window === "undefined") return;
|
|
92
|
+
const open = () => {
|
|
93
|
+
nearRef.current = true;
|
|
94
|
+
observerRef.current?.disconnect();
|
|
95
|
+
setNear(true);
|
|
96
|
+
};
|
|
97
|
+
window.addEventListener("beforeprint", open);
|
|
98
|
+
return () => window.removeEventListener("beforeprint", open);
|
|
99
|
+
}, [near]);
|
|
100
|
+
|
|
101
|
+
return [ref, near];
|
|
102
|
+
}
|
|
@@ -53,6 +53,22 @@ export function queryResultKey(spec: QueryRequestSpec): QueryKey {
|
|
|
53
53
|
];
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** Every cached result of one model, for invalidating after the model is saved. */
|
|
57
|
+
export function modelResultsKey(
|
|
58
|
+
spec: Pick<
|
|
59
|
+
QueryRequestSpec,
|
|
60
|
+
"environmentName" | "packageName" | "versionId" | "modelPath"
|
|
61
|
+
>,
|
|
62
|
+
): QueryKey {
|
|
63
|
+
return [
|
|
64
|
+
"queryResult",
|
|
65
|
+
spec.environmentName,
|
|
66
|
+
spec.packageName,
|
|
67
|
+
spec.versionId,
|
|
68
|
+
spec.modelPath,
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
56
72
|
export function useQueryResult(
|
|
57
73
|
spec: QueryRequestSpec,
|
|
58
74
|
{ enabled = true }: { enabled?: boolean } = {},
|
|
@@ -60,7 +76,11 @@ export function useQueryResult(
|
|
|
60
76
|
const { apiClients } = useServer();
|
|
61
77
|
return useQueryWithApiError({
|
|
62
78
|
queryKey: queryResultKey(spec),
|
|
63
|
-
|
|
79
|
+
// The signal cancels a run the page no longer wants: a tile whose givens
|
|
80
|
+
// changed under it, or one that unmounted. react-query reverts a
|
|
81
|
+
// cancelled query to its previous state rather than to an error, so an
|
|
82
|
+
// abort never reaches `ResultPanel`'s failed state.
|
|
83
|
+
queryFn: ({ signal }) =>
|
|
64
84
|
apiClients.models.executeQueryModel(
|
|
65
85
|
spec.environmentName,
|
|
66
86
|
spec.packageName,
|
|
@@ -72,6 +92,8 @@ export function useQueryResult(
|
|
|
72
92
|
givens: spec.givens,
|
|
73
93
|
versionId: spec.versionId,
|
|
74
94
|
},
|
|
95
|
+
undefined,
|
|
96
|
+
{ signal },
|
|
75
97
|
),
|
|
76
98
|
enabled,
|
|
77
99
|
...CHART_RESULT_QUERY_OPTIONS,
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
type QueryFunctionContext,
|
|
6
|
+
type QueryKey,
|
|
5
7
|
useMutation,
|
|
6
8
|
UseMutationOptions,
|
|
7
9
|
UseMutationResult,
|
|
@@ -17,7 +19,12 @@ import { globalQueryClient } from "../utils/queryClient";
|
|
|
17
19
|
export { globalQueryClient };
|
|
18
20
|
export function useQueryWithApiError<TData = unknown, TError = ApiError>(
|
|
19
21
|
options: Omit<UseQueryOptions<TData, TError>, "throwOnError" | "retry"> & {
|
|
20
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Receives react-query's context. Pass its `signal` into the request
|
|
24
|
+
* (axios takes it as `{ signal }`) so a query superseded by a key change,
|
|
25
|
+
* or abandoned by an unmount, is cancelled rather than left to finish.
|
|
26
|
+
*/
|
|
27
|
+
queryFn: (context: QueryFunctionContext<QueryKey>) => Promise<TData>;
|
|
21
28
|
},
|
|
22
29
|
): UseQueryResult<TData, TError> {
|
|
23
30
|
const { server } = useServer();
|
|
@@ -25,9 +32,9 @@ export function useQueryWithApiError<TData = unknown, TError = ApiError>(
|
|
|
25
32
|
...options,
|
|
26
33
|
// Add in the server to the query key so that we can have a per-server caches.
|
|
27
34
|
queryKey: [...options.queryKey, server],
|
|
28
|
-
queryFn: async () => {
|
|
35
|
+
queryFn: async (context) => {
|
|
29
36
|
try {
|
|
30
|
-
return await options.queryFn();
|
|
37
|
+
return await options.queryFn(context);
|
|
31
38
|
} catch (err) {
|
|
32
39
|
// Standardized error handling for axios errors
|
|
33
40
|
if (err && typeof err === "object" && "response" in err) {
|
|
@@ -37,7 +37,7 @@ export function useRawQueryData({
|
|
|
37
37
|
sourceName,
|
|
38
38
|
queryName,
|
|
39
39
|
],
|
|
40
|
-
queryFn: () =>
|
|
40
|
+
queryFn: ({ signal }) =>
|
|
41
41
|
apiClients.models.executeQueryModel(
|
|
42
42
|
environmentName,
|
|
43
43
|
packageName,
|
|
@@ -48,6 +48,8 @@ export function useRawQueryData({
|
|
|
48
48
|
queryName: queryName,
|
|
49
49
|
versionId: versionId,
|
|
50
50
|
},
|
|
51
|
+
undefined,
|
|
52
|
+
{ signal },
|
|
51
53
|
),
|
|
52
54
|
enabled,
|
|
53
55
|
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { act, renderHook } from "@testing-library/react";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, jest } from "bun:test";
|
|
6
|
+
import { useSettled } from "./useSettled";
|
|
7
|
+
|
|
8
|
+
// Bun runs it; its typings do not declare it.
|
|
9
|
+
const advance = (ms: number) =>
|
|
10
|
+
(
|
|
11
|
+
jest as unknown as { advanceTimersByTime(ms: number): void }
|
|
12
|
+
).advanceTimersByTime(ms);
|
|
13
|
+
|
|
14
|
+
describe("useSettled", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.useFakeTimers();
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
jest.useRealTimers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("returns the first value at once and a changed one only after it has stayed put", () => {
|
|
23
|
+
const view = renderHook(({ value }) => useSettled(value, 400), {
|
|
24
|
+
initialProps: { value: "a" },
|
|
25
|
+
});
|
|
26
|
+
expect(view.result.current).toBe("a");
|
|
27
|
+
|
|
28
|
+
// A burst of changes, each inside the window of the last, never settles.
|
|
29
|
+
for (const value of ["b", "bc", "bcd"]) {
|
|
30
|
+
view.rerender({ value });
|
|
31
|
+
act(() => {
|
|
32
|
+
advance(399);
|
|
33
|
+
});
|
|
34
|
+
expect(view.result.current).toBe("a");
|
|
35
|
+
}
|
|
36
|
+
act(() => {
|
|
37
|
+
advance(1);
|
|
38
|
+
});
|
|
39
|
+
expect(view.result.current).toBe("bcd");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How long a changed parameter has to stay changed before the notebook runs.
|
|
8
|
+
*
|
|
9
|
+
* Aborting the superseded run is not enough on its own: an abort cancels the
|
|
10
|
+
* HTTP request, but the cells already dispatched have reached the server and go
|
|
11
|
+
* on compiling and running against the customer's warehouse, and their answers
|
|
12
|
+
* are then thrown away. So autorun on a text control put one wave of doomed
|
|
13
|
+
* queries on that warehouse per keystroke. `origin/main` bounded the load by
|
|
14
|
+
* refusing to start a second run at all, which dropped the newest values;
|
|
15
|
+
* waiting for the value to settle bounds it without making that trade.
|
|
16
|
+
*/
|
|
17
|
+
export const GIVEN_SETTLE_MS = 400;
|
|
18
|
+
|
|
19
|
+
/** `value`, once it has stayed the same for `ms`; the first value is returned at once. */
|
|
20
|
+
export function useSettled<T>(value: T, ms: number): T {
|
|
21
|
+
const [settled, setSettled] = useState(value);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const timer = setTimeout(() => setSettled(value), ms);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}, [value, ms]);
|
|
26
|
+
return settled;
|
|
27
|
+
}
|