@malloy-publisher/sdk 0.12.1 → 0.12.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/README.md +79 -6
- package/dist/{RenderedResult-DrNhQ2_9.cjs.js → RenderedResult-C2arX5Zz.cjs.js} +1 -1
- package/dist/{RenderedResult-AyM-RQaA.es.js → RenderedResult-DqPvGZgL.es.js} +2 -2
- package/dist/ServerProvider-CqL6xzta.cjs.js +1 -0
- package/dist/{ServerProvider-a9Ki0QXO.es.js → ServerProvider-DRbZ6tLP.es.js} +1213 -1187
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +3 -3
- package/dist/client/api.d.ts +43 -13
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +28 -27
- package/dist/components/Model/ExplorerPage.d.ts +9 -0
- package/dist/components/Model/Model.d.ts +27 -11
- package/dist/components/ModelViewer/AccessChips.d.ts +34 -0
- package/dist/components/ModelViewer/EmptyRow.d.ts +23 -0
- package/dist/components/ModelViewer/Facts.d.ts +15 -0
- package/dist/components/ModelViewer/FieldGroup.d.ts +31 -0
- package/dist/components/ModelViewer/FieldRow.d.ts +69 -0
- package/dist/components/ModelViewer/GivenFacts.d.ts +21 -0
- package/dist/components/ModelViewer/HeaderBar.d.ts +75 -0
- package/dist/components/ModelViewer/InlineDoc.d.ts +13 -0
- package/dist/components/ModelViewer/ModelGivensSection.d.ts +32 -0
- package/dist/components/ModelViewer/ModelSection.d.ts +21 -0
- package/dist/components/ModelViewer/ModelViewer.d.ts +91 -0
- package/dist/components/ModelViewer/QueriesGroup.d.ts +15 -0
- package/dist/components/ModelViewer/RowGlyph.d.ts +27 -0
- package/dist/components/ModelViewer/RunResult.d.ts +46 -0
- package/dist/components/ModelViewer/SampleValues.d.ts +20 -0
- package/dist/components/ModelViewer/SchemaJoin.d.ts +51 -0
- package/dist/components/ModelViewer/SchemaView.d.ts +52 -0
- package/dist/components/ModelViewer/SegmentIcons.d.ts +70 -0
- package/dist/components/ModelViewer/SourcesDropdown.d.ts +53 -0
- package/dist/components/ModelViewer/SourcesNav.d.ts +25 -0
- package/dist/components/ModelViewer/StatusPill.d.ts +56 -0
- package/dist/components/ModelViewer/ValueChip.d.ts +17 -0
- package/dist/components/ModelViewer/ViewRow.d.ts +36 -0
- package/dist/components/ModelViewer/clickableBox.d.ts +29 -0
- package/dist/components/ModelViewer/codeDisplay.d.ts +44 -0
- package/dist/components/ModelViewer/docAnnotations.d.ts +90 -0
- package/dist/components/ModelViewer/explorerModel.d.ts +12 -0
- package/dist/components/ModelViewer/extensions.d.ts +94 -0
- package/dist/components/ModelViewer/fieldCode.d.ts +74 -0
- package/dist/components/ModelViewer/fieldEntities.d.ts +45 -0
- package/dist/components/ModelViewer/fieldExpansion.d.ts +41 -0
- package/dist/components/ModelViewer/givenUsage.d.ts +71 -0
- package/dist/components/ModelViewer/headerCard.d.ts +31 -0
- package/dist/components/ModelViewer/httpStatus.d.ts +4 -0
- package/dist/components/ModelViewer/icons.d.ts +31 -0
- package/dist/components/ModelViewer/index.d.ts +9 -0
- package/dist/components/ModelViewer/joinAccess.d.ts +52 -0
- package/dist/components/ModelViewer/malloyRunText.d.ts +22 -0
- package/dist/components/ModelViewer/malloyText.d.ts +21 -0
- package/dist/components/ModelViewer/modelGivens.d.ts +61 -0
- package/dist/components/ModelViewer/modelGivensContext.d.ts +9 -0
- package/dist/components/ModelViewer/modelHeaderPresentation.d.ts +28 -0
- package/dist/components/ModelViewer/modelTextDeclarations.d.ts +32 -0
- package/dist/components/ModelViewer/modelTextParse.d.ts +27 -0
- package/dist/components/ModelViewer/namedQueryCode.d.ts +12 -0
- package/dist/components/ModelViewer/offSurface.d.ts +54 -0
- package/dist/components/ModelViewer/rowLayers.d.ts +30 -0
- package/dist/components/ModelViewer/runGate.d.ts +49 -0
- package/dist/components/ModelViewer/schemaModel.d.ts +109 -0
- package/dist/components/ModelViewer/sectionOpenCommand.d.ts +45 -0
- package/dist/components/ModelViewer/sourceAccess.d.ts +67 -0
- package/dist/components/ModelViewer/sourceLineage.d.ts +14 -0
- package/dist/components/ModelViewer/sourcePicker.d.ts +66 -0
- package/dist/components/ModelViewer/surface.d.ts +47 -0
- package/dist/components/ModelViewer/text.d.ts +6 -0
- package/dist/components/ModelViewer/theme.d.ts +63 -0
- package/dist/components/ModelViewer/tokens.d.ts +52 -0
- package/dist/components/ModelViewer/ui.d.ts +48 -0
- package/dist/components/ModelViewer/useDimensionSamples.d.ts +76 -0
- package/dist/components/ModelViewer/useModelSources.d.ts +92 -0
- package/dist/components/ModelViewer/useRunQuery.d.ts +115 -0
- package/dist/components/ReportBuilder/loadMalloy.d.ts +4 -0
- package/dist/components/ServerProvider.d.ts +15 -1
- package/dist/components/filter/utils.d.ts +1 -1
- package/dist/components/given/GivenInput.d.ts +7 -1
- package/dist/components/given/GivensPanel.d.ts +3 -1
- package/dist/components/given/filterSummary.d.ts +6 -0
- package/dist/components/given/useGivenUrlParams.d.ts +11 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/modelPage.d.ts +36 -0
- package/dist/hooks/useDimensionalFilterRangeData.d.ts +9 -0
- package/dist/hooks/useSuggestOptions.d.ts +26 -2
- package/dist/index.cjs.js +47 -19
- package/dist/index.es.js +14281 -9879
- package/dist/useCompiledDocument--Z7vKZL5.cjs.js +143 -0
- package/dist/{useCompiledDocument-Utj2u8CG.es.js → useCompiledDocument-BnT2QpG0.es.js} +6975 -6893
- package/dist/utils/filterCondition.d.ts +14 -0
- package/dist/utils/malloyLiteral.d.ts +20 -1
- package/package.json +2 -2
- package/src/components/Model/ExplorerPage.tsx +269 -0
- package/src/components/Model/Model.tsx +66 -250
- package/src/components/Model/ModelExplorer.spec.tsx +64 -1
- package/src/components/ModelViewer/AccessChips.tsx +149 -0
- package/src/components/ModelViewer/EmptyRow.tsx +71 -0
- package/src/components/ModelViewer/Facts.tsx +46 -0
- package/src/components/ModelViewer/FieldGroup.tsx +137 -0
- package/src/components/ModelViewer/FieldRow.tsx +566 -0
- package/src/components/ModelViewer/GivenFacts.tsx +89 -0
- package/src/components/ModelViewer/HeaderBar.tsx +362 -0
- package/src/components/ModelViewer/InlineDoc.tsx +50 -0
- package/src/components/ModelViewer/ModelGivensSection.tsx +142 -0
- package/src/components/ModelViewer/ModelSection.tsx +98 -0
- package/src/components/ModelViewer/ModelViewer.spec.tsx +937 -0
- package/src/components/ModelViewer/ModelViewer.tsx +777 -0
- package/src/components/ModelViewer/QueriesGroup.tsx +107 -0
- package/src/components/ModelViewer/RowGlyph.tsx +138 -0
- package/src/components/ModelViewer/RunResult.tsx +298 -0
- package/src/components/ModelViewer/SampleValues.tsx +97 -0
- package/src/components/ModelViewer/SchemaJoin.tsx +258 -0
- package/src/components/ModelViewer/SchemaView.tsx +222 -0
- package/src/components/ModelViewer/SegmentIcons.tsx +129 -0
- package/src/components/ModelViewer/SourcesDropdown.tsx +265 -0
- package/src/components/ModelViewer/SourcesNav.tsx +75 -0
- package/src/components/ModelViewer/StatusPill.tsx +145 -0
- package/src/components/ModelViewer/ValueChip.tsx +39 -0
- package/src/components/ModelViewer/ViewRow.tsx +274 -0
- package/src/components/ModelViewer/clickableBox.ts +59 -0
- package/src/components/ModelViewer/codeDisplay.spec.ts +176 -0
- package/src/components/ModelViewer/codeDisplay.ts +118 -0
- package/src/components/ModelViewer/docAnnotations.spec.ts +181 -0
- package/src/components/ModelViewer/docAnnotations.ts +244 -0
- package/src/components/ModelViewer/docAnnotations.typeDetail.spec.ts +114 -0
- package/src/components/ModelViewer/explorerModel.spec.ts +43 -0
- package/src/components/ModelViewer/explorerModel.ts +31 -0
- package/src/components/ModelViewer/extensions.tsx +112 -0
- package/src/components/ModelViewer/fieldCode.spec.ts +168 -0
- package/src/components/ModelViewer/fieldCode.ts +118 -0
- package/src/components/ModelViewer/fieldEntities.ts +63 -0
- package/src/components/ModelViewer/fieldExpansion.spec.ts +116 -0
- package/src/components/ModelViewer/fieldExpansion.ts +95 -0
- package/src/components/ModelViewer/givenUsage.spec.ts +304 -0
- package/src/components/ModelViewer/givenUsage.ts +325 -0
- package/src/components/ModelViewer/headerCard.tsx +102 -0
- package/src/components/ModelViewer/httpStatus.ts +15 -0
- package/src/components/ModelViewer/icons.tsx +67 -0
- package/src/components/ModelViewer/index.ts +26 -0
- package/src/components/ModelViewer/joinAccess.spec.ts +95 -0
- package/src/components/ModelViewer/joinAccess.ts +54 -0
- package/src/components/ModelViewer/malloyRunText.spec.ts +48 -0
- package/src/components/ModelViewer/malloyRunText.ts +51 -0
- package/src/components/ModelViewer/malloyText.spec.ts +47 -0
- package/src/components/ModelViewer/malloyText.ts +77 -0
- package/src/components/ModelViewer/modelGivens.ts +228 -0
- package/src/components/ModelViewer/modelGivensContext.ts +13 -0
- package/src/components/ModelViewer/modelHeaderPresentation.spec.ts +31 -0
- package/src/components/ModelViewer/modelHeaderPresentation.ts +41 -0
- package/src/components/ModelViewer/modelTextDeclarations.spec.ts +336 -0
- package/src/components/ModelViewer/modelTextDeclarations.ts +228 -0
- package/src/components/ModelViewer/modelTextParse.ts +112 -0
- package/src/components/ModelViewer/namedQueryCode.spec.ts +58 -0
- package/src/components/ModelViewer/namedQueryCode.ts +26 -0
- package/src/components/ModelViewer/offSurface.tsx +124 -0
- package/src/components/ModelViewer/rowLayers.tsx +104 -0
- package/src/components/ModelViewer/runGate.spec.ts +219 -0
- package/src/components/ModelViewer/runGate.ts +145 -0
- package/src/components/ModelViewer/schemaModel.defaultSource.spec.ts +126 -0
- package/src/components/ModelViewer/schemaModel.queries.spec.ts +37 -0
- package/src/components/ModelViewer/schemaModel.ts +300 -0
- package/src/components/ModelViewer/sectionOpenCommand.tsx +125 -0
- package/src/components/ModelViewer/sourceAccess.spec.ts +130 -0
- package/src/components/ModelViewer/sourceAccess.ts +194 -0
- package/src/components/ModelViewer/sourceLineage.spec.ts +73 -0
- package/src/components/ModelViewer/sourceLineage.ts +38 -0
- package/src/components/ModelViewer/sourcePicker.spec.ts +294 -0
- package/src/components/ModelViewer/sourcePicker.ts +162 -0
- package/src/components/ModelViewer/surface.ts +51 -0
- package/src/components/ModelViewer/text.tsx +33 -0
- package/src/components/ModelViewer/theme.spec.ts +38 -0
- package/src/components/ModelViewer/theme.ts +58 -0
- package/src/components/ModelViewer/tokens.ts +87 -0
- package/src/components/ModelViewer/ui.tsx +201 -0
- package/src/components/ModelViewer/useDimensionSamples.spec.tsx +139 -0
- package/src/components/ModelViewer/useDimensionSamples.ts +220 -0
- package/src/components/ModelViewer/useModelSources.spec.ts +110 -0
- package/src/components/ModelViewer/useModelSources.ts +238 -0
- package/src/components/ModelViewer/useRunQuery.spec.ts +50 -0
- package/src/components/ModelViewer/useRunQuery.ts +223 -0
- package/src/components/ReportBuilder/emptyStart.spec.ts +8 -0
- package/src/components/ReportBuilder/loadMalloy.ts +8 -1
- package/src/components/ServerProvider.tsx +27 -3
- package/src/components/filter/utils.ts +4 -60
- package/src/components/given/FilterButton.tsx +4 -1
- package/src/components/given/GivenInput.tsx +8 -0
- package/src/components/given/GivensPanel.tsx +6 -1
- package/src/components/given/filterSummary.spec.ts +31 -1
- package/src/components/given/filterSummary.ts +41 -19
- package/src/components/given/useGivenUrlParams.spec.tsx +32 -0
- package/src/components/given/useGivenUrlParams.ts +49 -14
- package/src/components/index.ts +6 -1
- package/src/components/legacy/malloynb/Notebook.spec.tsx +38 -4
- package/src/components/legacy/malloynb/NotebookCell.tsx +8 -2
- package/src/components/modelPage.spec.ts +79 -0
- package/src/components/modelPage.ts +48 -0
- package/src/hooks/useDimensionFilters.ts +3 -58
- package/src/hooks/useDimensionFiltersQuery.ts +3 -58
- package/src/hooks/useDimensionalFilterRangeData.spec.ts +57 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +8 -63
- package/src/hooks/useSuggestOptions.dom.spec.ts +54 -1
- package/src/hooks/useSuggestOptions.spec.ts +71 -0
- package/src/hooks/useSuggestOptions.ts +102 -12
- package/src/utils/filterCondition.spec.ts +87 -0
- package/src/utils/filterCondition.ts +66 -0
- package/src/utils/malloyLiteral.spec.ts +53 -1
- package/src/utils/malloyLiteral.ts +47 -12
- package/dist/ServerProvider-BvD7PYZ7.cjs.js +0 -1
- package/dist/useCompiledDocument-CRhFBKv_.cjs.js +0 -142
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
5
|
+
import type { GivenRequest } from "./modelGivens";
|
|
6
|
+
import type { ShownRun } from "./RunResult";
|
|
7
|
+
import type { ExplorerField } from "./schemaModel";
|
|
8
|
+
import type { SampleValuesFetcher } from "./useDimensionSamples";
|
|
9
|
+
|
|
10
|
+
/** An open view's or named query's run, for a host's actions beside it. */
|
|
11
|
+
export interface RunActionContext {
|
|
12
|
+
kind: "view" | "query";
|
|
13
|
+
modelPath: string;
|
|
14
|
+
/** The source a view belongs to; "" for a named query. */
|
|
15
|
+
sourceName: string;
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The Malloy the row runs: the view or query by name, with no row limit of
|
|
19
|
+
* its own, so its rows are what the server's cap allows.
|
|
20
|
+
*/
|
|
21
|
+
query: string;
|
|
22
|
+
/** The given values the run sends (`QueryRequest.givens`), unset ones left out. */
|
|
23
|
+
givens?: GivenRequest;
|
|
24
|
+
/**
|
|
25
|
+
* The viewer's cache key for this run, so a host's refresh can invalidate
|
|
26
|
+
* it and a host's own run of the same query can share the entry.
|
|
27
|
+
*/
|
|
28
|
+
queryKey: readonly unknown[];
|
|
29
|
+
/** The result the card shows, once it has one. */
|
|
30
|
+
shown?: ShownRun;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A field row, for a host's additions to it. */
|
|
34
|
+
export interface FieldContext {
|
|
35
|
+
modelPath: string;
|
|
36
|
+
sourceName: string;
|
|
37
|
+
field: ExplorerField;
|
|
38
|
+
/** A joined source's field, shown inside a join on another source's page. */
|
|
39
|
+
joined: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The source on screen, or a source in the picker, for a host's additions to it. */
|
|
43
|
+
export interface SourceContext {
|
|
44
|
+
modelPath: string;
|
|
45
|
+
sourceName: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What a host adds to a source's line in the picker. */
|
|
49
|
+
export interface PickerSourceExtras {
|
|
50
|
+
/** A description where the source has no `#(doc)`, marked Generated. */
|
|
51
|
+
summary?: string;
|
|
52
|
+
/** Hold the description's line: the host is still reading its summaries. */
|
|
53
|
+
summaryPending?: boolean;
|
|
54
|
+
/** Chips after the source's name. */
|
|
55
|
+
status?: ReactNode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* What a host adds to the viewer without the viewer knowing what it is: the
|
|
60
|
+
* Publisher's own reads draw every row, and a host with more to say about a
|
|
61
|
+
* field (what it has built from it, an index of its values) or more to do with
|
|
62
|
+
* a result (download it) says and does it through these.
|
|
63
|
+
*
|
|
64
|
+
* **Experimental.** These slots are new, and no host has been built on them
|
|
65
|
+
* yet; they may change in a minor release until one has.
|
|
66
|
+
*/
|
|
67
|
+
export interface ModelViewerExtensions {
|
|
68
|
+
/** Actions beside an open view's or named query's Result | Code switch. */
|
|
69
|
+
renderRunActions?: (run: RunActionContext) => ReactNode;
|
|
70
|
+
/** A dimension's sample values, instead of the viewer's own query. */
|
|
71
|
+
fetchSamples?: SampleValuesFetcher;
|
|
72
|
+
/**
|
|
73
|
+
* The build of the values `fetchSamples` serves (an index's version, say):
|
|
74
|
+
* a new one is a new cache entry, so a row reopened after a rebuild never
|
|
75
|
+
* shows the values from before it.
|
|
76
|
+
*/
|
|
77
|
+
samplesGeneration?: string;
|
|
78
|
+
/** Chips a host adds to a field's line, after its own. */
|
|
79
|
+
renderFieldStatus?: (field: FieldContext) => ReactNode;
|
|
80
|
+
/** The row's one action, beside its chips (a Rebuild, say). */
|
|
81
|
+
renderFieldAction?: (field: FieldContext) => ReactNode;
|
|
82
|
+
/**
|
|
83
|
+
* What an open field row shows. `builtIn` is the viewer's own card (the
|
|
84
|
+
* field's code, a dimension's values, the givens it reads), undefined where
|
|
85
|
+
* the row has none. Return it to keep it, beside a card of your own or not;
|
|
86
|
+
* return something else to show that in its place; return null for nothing,
|
|
87
|
+
* and the row then doesn't open.
|
|
88
|
+
*/
|
|
89
|
+
renderFieldDetail?: (
|
|
90
|
+
field: FieldContext,
|
|
91
|
+
builtIn: ReactNode | undefined,
|
|
92
|
+
) => ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* Whether a view's or field's row is listed, for a host's narrowed view of
|
|
95
|
+
* a source (the fields it has built from, say). Each section's count is of
|
|
96
|
+
* the rows it lists. Absent, every row is.
|
|
97
|
+
*/
|
|
98
|
+
showField?: (field: FieldContext) => boolean;
|
|
99
|
+
/** A card under the source's header, for what only the host knows of it (where its data comes from, its build). */
|
|
100
|
+
renderSourceDetail?: (source: SourceContext) => ReactNode;
|
|
101
|
+
/** A host's summary and chips on a source's line in the picker. */
|
|
102
|
+
describePickerSource?: (
|
|
103
|
+
source: SourceContext,
|
|
104
|
+
) => PickerSourceExtras | undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const ModelViewerExtensionsContext =
|
|
108
|
+
createContext<ModelViewerExtensions>({});
|
|
109
|
+
|
|
110
|
+
export function useModelViewerExtensions(): ModelViewerExtensions {
|
|
111
|
+
return useContext(ModelViewerExtensionsContext);
|
|
112
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { makeGetFieldCode } from "./fieldCode";
|
|
6
|
+
import { groupEntitiesBySource, type FieldEntity } from "./fieldEntities";
|
|
7
|
+
|
|
8
|
+
const entity = (
|
|
9
|
+
over: Partial<FieldEntity> & Pick<FieldEntity, "name">,
|
|
10
|
+
): FieldEntity => ({
|
|
11
|
+
fieldType: "dimension",
|
|
12
|
+
...over,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("groupEntitiesBySource", () => {
|
|
16
|
+
it("keeps same-named fields of different sources apart", () => {
|
|
17
|
+
// The whole reason the map is not keyed by bare field name: a model that
|
|
18
|
+
// declares `aircraft` and `aircraft_models` has an `id` in each, and a
|
|
19
|
+
// flat map would render one source's definition on the other's field.
|
|
20
|
+
const bySource = groupEntitiesBySource([
|
|
21
|
+
entity({ name: "id", source: "aircraft", code: "-- aircraft id" }),
|
|
22
|
+
entity({ name: "id", source: "aircraft_models", code: "-- model id" }),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
expect(bySource.get("aircraft")?.get("id")?.code).toBe("-- aircraft id");
|
|
26
|
+
expect(bySource.get("aircraft_models")?.get("id")?.code).toBe(
|
|
27
|
+
"-- model id",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("drops entities with no declaring source rather than guessing one", () => {
|
|
32
|
+
// `source` is absent on artifacts predating its capture. Attributing such
|
|
33
|
+
// an entity to an arbitrary source would show the wrong code.
|
|
34
|
+
const bySource = groupEntitiesBySource([
|
|
35
|
+
entity({ name: "orphan", code: "x" }),
|
|
36
|
+
entity({ name: "kept", source: "s", code: "y" }),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
expect([...bySource.keys()]).toEqual(["s"]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("makeGetFieldCode", () => {
|
|
44
|
+
it("suppresses an inherited column's code and marks it inherited", () => {
|
|
45
|
+
// A column entity's stored slice is the SOURCE's declaring line, which
|
|
46
|
+
// reads as nonsense on the field — the row must say "inherited" instead.
|
|
47
|
+
const get = makeGetFieldCode({
|
|
48
|
+
entities: new Map([
|
|
49
|
+
[
|
|
50
|
+
"id",
|
|
51
|
+
entity({
|
|
52
|
+
name: "id",
|
|
53
|
+
source: "a",
|
|
54
|
+
fieldType: "column",
|
|
55
|
+
code: "duckdb.table('x')",
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
]),
|
|
59
|
+
loading: false,
|
|
60
|
+
error: false,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(get({ name: "id" })).toMatchObject({
|
|
64
|
+
code: undefined,
|
|
65
|
+
inherited: true,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns a declared field's code verbatim", () => {
|
|
70
|
+
const get = makeGetFieldCode({
|
|
71
|
+
entities: new Map([
|
|
72
|
+
["total", entity({ name: "total", source: "a", code: "sum(x)" })],
|
|
73
|
+
]),
|
|
74
|
+
loading: false,
|
|
75
|
+
error: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(get({ name: "total" })).toMatchObject({
|
|
79
|
+
code: "sum(x)",
|
|
80
|
+
inherited: false,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("never reports loading once the fetch has errored", () => {
|
|
85
|
+
// An error carries no evidence of absence; showing a spinner next to a
|
|
86
|
+
// failed fetch would read as "still coming".
|
|
87
|
+
const get = makeGetFieldCode({
|
|
88
|
+
entities: undefined,
|
|
89
|
+
loading: true,
|
|
90
|
+
error: true,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(get({ name: "anything" })).toMatchObject({
|
|
94
|
+
loading: false,
|
|
95
|
+
error: true,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("describes an inherited column from the table's generated descriptions", () => {
|
|
100
|
+
const get = makeGetFieldCode({
|
|
101
|
+
entities: new Map([
|
|
102
|
+
["id", entity({ name: "id", source: "a", fieldType: "column" })],
|
|
103
|
+
]),
|
|
104
|
+
loading: false,
|
|
105
|
+
error: false,
|
|
106
|
+
columnDescriptions: new Map([
|
|
107
|
+
["id", "Primary key of the orders table."],
|
|
108
|
+
]),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(get({ name: "id" }).columnDoc).toBe(
|
|
112
|
+
"Primary key of the orders table.",
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("withholds a column description from a field the model defines", () => {
|
|
117
|
+
// A same-named computed dimension is not that column: `state is
|
|
118
|
+
// upper(state_code)` would otherwise inherit the description of a
|
|
119
|
+
// `state` column it doesn't read.
|
|
120
|
+
const get = makeGetFieldCode({
|
|
121
|
+
entities: new Map([
|
|
122
|
+
[
|
|
123
|
+
"state",
|
|
124
|
+
entity({
|
|
125
|
+
name: "state",
|
|
126
|
+
source: "a",
|
|
127
|
+
code: "upper(state_code)",
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
]),
|
|
131
|
+
loading: false,
|
|
132
|
+
error: false,
|
|
133
|
+
columnDescriptions: new Map([["state", "Two-letter US state code."]]),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(get({ name: "state" }).columnDoc).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("gives a joined source's field the same shape as the active source's", () => {
|
|
140
|
+
// The parity this factory exists to guarantee: the joined section must
|
|
141
|
+
// not render a field differently from that source's own page.
|
|
142
|
+
const fields = new Map([
|
|
143
|
+
[
|
|
144
|
+
"manufacturer",
|
|
145
|
+
entity({
|
|
146
|
+
name: "manufacturer",
|
|
147
|
+
source: "aircraft_models",
|
|
148
|
+
fieldType: "column",
|
|
149
|
+
}),
|
|
150
|
+
],
|
|
151
|
+
]);
|
|
152
|
+
const asActive = makeGetFieldCode({
|
|
153
|
+
entities: fields,
|
|
154
|
+
loading: false,
|
|
155
|
+
error: false,
|
|
156
|
+
});
|
|
157
|
+
const asJoined = makeGetFieldCode({
|
|
158
|
+
entities: fields,
|
|
159
|
+
loading: false,
|
|
160
|
+
error: false,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const a = asActive({ name: "manufacturer" });
|
|
164
|
+
const b = asJoined({ name: "manufacturer" });
|
|
165
|
+
expect(a).toEqual(b);
|
|
166
|
+
expect(a.inherited).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { EntitiesByField, FieldEntity } from "./fieldEntities";
|
|
5
|
+
import type { TextDeclaration } from "./modelTextDeclarations";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Per-field Malloy-definition lookup, supplied by the owner (SchemaView) when
|
|
9
|
+
* code snippets are available for this row's source. `code` stays undefined
|
|
10
|
+
* while loading or when the field has no definition of its own (an inherited
|
|
11
|
+
* column).
|
|
12
|
+
*/
|
|
13
|
+
export interface FieldCodeLookup {
|
|
14
|
+
code?: string;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
/** The definitions read failed: kept distinct from "this field has no
|
|
17
|
+
* definition" (an error carries no evidence of absence), and the one
|
|
18
|
+
* absence the row still opens to report. */
|
|
19
|
+
error?: boolean;
|
|
20
|
+
/** The field is an inherited table column (entity `fieldType` "column"):
|
|
21
|
+
* its stored code is the SOURCE's declaring line, which reads as nonsense
|
|
22
|
+
* for the field, so it's suppressed. Such a row doesn't open; without a
|
|
23
|
+
* description it says "inherited" beside its type instead. */
|
|
24
|
+
inherited?: boolean;
|
|
25
|
+
/** For an inherited column, where it comes from: the table expression a
|
|
26
|
+
* table column is read from (`fromTable`), or the passthrough line of the
|
|
27
|
+
* query source it is an output of. Shown as its Code in place of a
|
|
28
|
+
* definition of its own. */
|
|
29
|
+
inheritedFrom?: { code: string; fromTable: boolean };
|
|
30
|
+
/** For an inherited column: a host's description of that warehouse column,
|
|
31
|
+
* so a passthrough dimension the modeler never documented still says what
|
|
32
|
+
* it holds. Never set for a defined field. */
|
|
33
|
+
columnDoc?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds the per-field code lookup for ONE source's fields.
|
|
38
|
+
*
|
|
39
|
+
* Shared by the active source and by each joined source rendered inline: a
|
|
40
|
+
* joined source is the same source seen from another page, so its fields must
|
|
41
|
+
* offer the same definition/"inherited" affordance. Keeping one factory is what
|
|
42
|
+
* makes that identical rather than merely similar.
|
|
43
|
+
*
|
|
44
|
+
* `entities` must be the fields of the source that DECLARES these fields —
|
|
45
|
+
* for a join, the target source's map, not the host's. Field names are only
|
|
46
|
+
* unique within a source, so passing the wrong map silently renders another
|
|
47
|
+
* source's definition on a same-named field.
|
|
48
|
+
*/
|
|
49
|
+
export function makeGetFieldCode(params: {
|
|
50
|
+
entities: EntitiesByField | undefined;
|
|
51
|
+
loading: boolean;
|
|
52
|
+
error: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Generated descriptions of the base TABLE's columns (column name → text),
|
|
55
|
+
* for the table this source reads. Only ever applied to inherited columns —
|
|
56
|
+
* a field with a Malloy definition is the modeler's expression, and its name
|
|
57
|
+
* colliding with a warehouse column's says nothing about what it computes.
|
|
58
|
+
*
|
|
59
|
+
* Must be the table behind THESE entities. A joined source reads its own
|
|
60
|
+
* table, so the host's map would describe the wrong columns — SchemaJoin
|
|
61
|
+
* passes none.
|
|
62
|
+
*/
|
|
63
|
+
columnDescriptions?: ReadonlyMap<string, string>;
|
|
64
|
+
/**
|
|
65
|
+
* The same source's declarations read from the model file's text
|
|
66
|
+
* (`fieldDeclarations`), for a field the entities don't carry: without a
|
|
67
|
+
* host's entities, every field's code comes from here. Used only once the entities read has settled with no entity for the
|
|
68
|
+
* field, and only for a declaration of the field's own kind.
|
|
69
|
+
*/
|
|
70
|
+
declarations?: ReadonlyMap<string, TextDeclaration>;
|
|
71
|
+
/** The model file is still being parsed for `declarations`. */
|
|
72
|
+
declarationsLoading?: boolean;
|
|
73
|
+
}): (field: { name: string; kind?: string }) => FieldCodeLookup {
|
|
74
|
+
const {
|
|
75
|
+
entities,
|
|
76
|
+
loading,
|
|
77
|
+
error,
|
|
78
|
+
columnDescriptions,
|
|
79
|
+
declarations,
|
|
80
|
+
declarationsLoading,
|
|
81
|
+
} = params;
|
|
82
|
+
return (field) => {
|
|
83
|
+
const entity: FieldEntity | undefined = entities?.get(field.name);
|
|
84
|
+
const declared = declarations?.get(field.name);
|
|
85
|
+
if (!entity && !loading && declared && declared.kind === field.kind) {
|
|
86
|
+
return {
|
|
87
|
+
code: declared.code,
|
|
88
|
+
loading: false,
|
|
89
|
+
error: false,
|
|
90
|
+
inherited: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (!entity && !loading && !error && declarationsLoading) {
|
|
94
|
+
return { loading: true, error: false, inherited: false };
|
|
95
|
+
}
|
|
96
|
+
// An inherited table column's stored code slice is the SOURCE's
|
|
97
|
+
// declaring line (e.g. `duckdb.table('…')`) — misleading as a field
|
|
98
|
+
// definition, so it's suppressed and the row says "inherited".
|
|
99
|
+
const inherited = entity?.fieldType === "column";
|
|
100
|
+
return {
|
|
101
|
+
code: inherited ? undefined : (entity?.code ?? undefined),
|
|
102
|
+
// Where an inherited column comes from, shown in its place: a table's
|
|
103
|
+
// column carries the source's table expression (and the table itself);
|
|
104
|
+
// a query source's passthrough carries its own line (`category`).
|
|
105
|
+
inheritedFrom:
|
|
106
|
+
inherited && entity?.code
|
|
107
|
+
? {
|
|
108
|
+
code: entity.code,
|
|
109
|
+
fromTable: !!entity.table || entity.code !== field.name,
|
|
110
|
+
}
|
|
111
|
+
: undefined,
|
|
112
|
+
loading: !error && loading,
|
|
113
|
+
error,
|
|
114
|
+
inherited,
|
|
115
|
+
columnDoc: inherited ? columnDescriptions?.get(field.name) : undefined,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a host knows about a model's fields beyond what the compiled model says.
|
|
6
|
+
*
|
|
7
|
+
* The viewer's own reads give it every field's name, type and annotations, and
|
|
8
|
+
* the model file's text gives it the code of whatever the file declares. A host
|
|
9
|
+
* with a fuller record of the model (an index of every field the model compiles,
|
|
10
|
+
* say) can pass that record as entities, and the viewer then shows what only it
|
|
11
|
+
* knows: an inherited table column's origin, the table a source reads, a join's
|
|
12
|
+
* target source and its declaration.
|
|
13
|
+
*/
|
|
14
|
+
export interface FieldEntity {
|
|
15
|
+
/** The field's name within its declaring source. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** The source that declares the field. An entity without one is dropped:
|
|
18
|
+
* field names are unique only within a source. */
|
|
19
|
+
source?: string | null;
|
|
20
|
+
/** `dimension`, `measure`, `view`, `join`, or `column` for a table column the
|
|
21
|
+
* source passes through unchanged. */
|
|
22
|
+
fieldType?: string | null;
|
|
23
|
+
/** The Malloy that defines the field, verbatim. */
|
|
24
|
+
code?: string | null;
|
|
25
|
+
/** The table the declaring source reads, when it reads one. */
|
|
26
|
+
table?: FieldEntityTable | null;
|
|
27
|
+
/** For a join, the source it joins: the alias can differ from its name. */
|
|
28
|
+
joinTarget?: { modelPath: string; sourceName: string } | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FieldEntityTable {
|
|
32
|
+
connectionName: string;
|
|
33
|
+
catalogName?: string | null;
|
|
34
|
+
schemaName?: string | null;
|
|
35
|
+
tableName: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One source's fields, keyed by field name. */
|
|
39
|
+
export type EntitiesByField = ReadonlyMap<string, FieldEntity>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Every source declared by one model file, keyed by SOURCE name, never a flat
|
|
43
|
+
* field map: `aircraft` and `aircraft_models` can both declare `id`, and a flat
|
|
44
|
+
* map would show one source's definition on the other's field.
|
|
45
|
+
*/
|
|
46
|
+
export type EntitiesBySource = ReadonlyMap<string, EntitiesByField>;
|
|
47
|
+
|
|
48
|
+
/** A model's entities grouped by declaring source; one with no source is dropped rather than guessed. */
|
|
49
|
+
export function groupEntitiesBySource(
|
|
50
|
+
entities: ReadonlyArray<FieldEntity>,
|
|
51
|
+
): EntitiesBySource {
|
|
52
|
+
const bySource = new Map<string, Map<string, FieldEntity>>();
|
|
53
|
+
for (const entity of entities) {
|
|
54
|
+
if (!entity.source) continue;
|
|
55
|
+
let fields = bySource.get(entity.source);
|
|
56
|
+
if (!fields) {
|
|
57
|
+
fields = new Map();
|
|
58
|
+
bySource.set(entity.source, fields);
|
|
59
|
+
}
|
|
60
|
+
fields.set(entity.name, entity);
|
|
61
|
+
}
|
|
62
|
+
return bySource;
|
|
63
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
expandableFirst,
|
|
7
|
+
hasDefinitionToShow,
|
|
8
|
+
isFieldExpandable,
|
|
9
|
+
} from "./fieldExpansion";
|
|
10
|
+
import type { FieldCodeLookup } from "./FieldRow";
|
|
11
|
+
import type { ExplorerField } from "./schemaModel";
|
|
12
|
+
|
|
13
|
+
const dimension = (name: string, indexed = false): ExplorerField => ({
|
|
14
|
+
name,
|
|
15
|
+
kind: "dimension",
|
|
16
|
+
indexed,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const lookup = (over: Partial<FieldCodeLookup> = {}): FieldCodeLookup => ({
|
|
20
|
+
loading: false,
|
|
21
|
+
...over,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("hasDefinitionToShow", () => {
|
|
25
|
+
it("is true for code, while loading, and on error", () => {
|
|
26
|
+
expect(hasDefinitionToShow(lookup({ code: "sum(x)" }))).toBe(true);
|
|
27
|
+
// Unknown yet — better a chevron that arrives late than one that vanishes
|
|
28
|
+
// under the pointer.
|
|
29
|
+
expect(hasDefinitionToShow(lookup({ loading: true }))).toBe(true);
|
|
30
|
+
// A fact about the pane, not about the field.
|
|
31
|
+
expect(hasDefinitionToShow(lookup({ error: true }))).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("is false for an inherited column and for no lookup at all", () => {
|
|
35
|
+
expect(hasDefinitionToShow(lookup({ inherited: true }))).toBe(false);
|
|
36
|
+
expect(hasDefinitionToShow(undefined)).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("isFieldExpandable", () => {
|
|
41
|
+
it("keeps an indexed dimension expandable without a definition", () => {
|
|
42
|
+
// Its sample values live in the expansion and nowhere else.
|
|
43
|
+
expect(
|
|
44
|
+
isFieldExpandable(
|
|
45
|
+
dimension("state", true),
|
|
46
|
+
lookup({ inherited: true }),
|
|
47
|
+
),
|
|
48
|
+
).toBe(true);
|
|
49
|
+
expect(
|
|
50
|
+
isFieldExpandable(dimension("state"), lookup({ inherited: true })),
|
|
51
|
+
).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("expandableFirst", () => {
|
|
56
|
+
const getFieldCode = (field: ExplorerField) =>
|
|
57
|
+
field.name.startsWith("defined")
|
|
58
|
+
? lookup({ code: "1" })
|
|
59
|
+
: lookup({ inherited: true });
|
|
60
|
+
|
|
61
|
+
it("hoists expandable fields, each block keeping declaration order", () => {
|
|
62
|
+
const items = [
|
|
63
|
+
dimension("inherited_a"),
|
|
64
|
+
dimension("defined_x"),
|
|
65
|
+
dimension("inherited_b"),
|
|
66
|
+
dimension("defined_y"),
|
|
67
|
+
];
|
|
68
|
+
expect(expandableFirst(items, getFieldCode).map((f) => f.name)).toEqual([
|
|
69
|
+
"defined_x",
|
|
70
|
+
"defined_y",
|
|
71
|
+
"inherited_a",
|
|
72
|
+
"inherited_b",
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns the SAME array when there is nothing to reorder", () => {
|
|
77
|
+
// Identity matters: a fresh array on every render would remount the rows,
|
|
78
|
+
// closing whatever the reader had expanded.
|
|
79
|
+
const allDefined = [dimension("defined_x"), dimension("defined_y")];
|
|
80
|
+
expect(expandableFirst(allDefined, getFieldCode)).toBe(allDefined);
|
|
81
|
+
const noneDefined = [dimension("inherited_a"), dimension("inherited_b")];
|
|
82
|
+
expect(expandableFirst(noneDefined, getFieldCode)).toBe(noneDefined);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("holds declaration order while the definitions read is in flight", () => {
|
|
86
|
+
// The churn this prevents: if `loading` counted as expandable, EVERY row
|
|
87
|
+
// would hoist, the group would paint in declaration order anyway, and
|
|
88
|
+
// then re-sort under the reader once the read landed and the inherited
|
|
89
|
+
// columns dropped to the tail. Same order as the settled-empty case, but
|
|
90
|
+
// reached deliberately.
|
|
91
|
+
// One indexed row is what makes this bite: with `loading` counted as
|
|
92
|
+
// expandable EVERY row hoists, `rest` is empty, and the identity
|
|
93
|
+
// short-circuit hands back declaration order by accident. With it not
|
|
94
|
+
// counted, the indexed row hoists alone — so if the read were allowed to
|
|
95
|
+
// decide order, THIS is the order that would later be disturbed.
|
|
96
|
+
const items = [
|
|
97
|
+
dimension("inherited_a"),
|
|
98
|
+
dimension("state", true),
|
|
99
|
+
dimension("inherited_b"),
|
|
100
|
+
];
|
|
101
|
+
const loadingCode = () => lookup({ loading: true });
|
|
102
|
+
expect(expandableFirst(items, loadingCode).map((f) => f.name)).toEqual([
|
|
103
|
+
"state",
|
|
104
|
+
"inherited_a",
|
|
105
|
+
"inherited_b",
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("sorts once the read lands", () => {
|
|
110
|
+
const items = [dimension("inherited_a"), dimension("defined_x")];
|
|
111
|
+
expect(expandableFirst(items, getFieldCode).map((f) => f.name)).toEqual([
|
|
112
|
+
"defined_x",
|
|
113
|
+
"inherited_a",
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a field row opens to — the one rule behind both whether the row is a
|
|
6
|
+
* button (FieldRow) and the order fields appear in (FieldGroup). Kept in a pure
|
|
7
|
+
* module so those two can't drift: a row that opens to nothing, or an
|
|
8
|
+
* "expandable first" sort that hoists rows with no expansion, are the same bug
|
|
9
|
+
* seen from either side.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { FieldCodeLookup } from "./fieldCode";
|
|
13
|
+
import type { ExplorerField } from "./schemaModel";
|
|
14
|
+
|
|
15
|
+
/** A dimension whose VALUES are in the search index (`#(index)`), so the row can
|
|
16
|
+
* show sample values — content in its own right, with or without a definition. */
|
|
17
|
+
export function isIndexedDimension(field: ExplorerField): boolean {
|
|
18
|
+
return field.kind === "dimension" && field.indexed === true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether the expansion has a definition section to draw. True while the fetch
|
|
23
|
+
* is in flight (the answer isn't known yet, and a row that opens late is
|
|
24
|
+
* better than one that vanishes under the pointer) and true on failure, which
|
|
25
|
+
* is a fact about the pane worth surfacing rather than reading as "no
|
|
26
|
+
* definition". False for an inherited table column — its story is told on the
|
|
27
|
+
* row's hover instead.
|
|
28
|
+
*/
|
|
29
|
+
export function hasDefinitionToShow(
|
|
30
|
+
fieldCode: FieldCodeLookup | undefined,
|
|
31
|
+
): boolean {
|
|
32
|
+
return (
|
|
33
|
+
!!fieldCode &&
|
|
34
|
+
(fieldCode.loading ||
|
|
35
|
+
!!fieldCode.code ||
|
|
36
|
+
!!fieldCode.inheritedFrom ||
|
|
37
|
+
!!fieldCode.error)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isFieldExpandable(
|
|
42
|
+
field: ExplorerField,
|
|
43
|
+
fieldCode: FieldCodeLookup | undefined,
|
|
44
|
+
): boolean {
|
|
45
|
+
return hasDefinitionToShow(fieldCode) || isIndexedDimension(field);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Expandable fields first, each block keeping the model's declaration order.
|
|
50
|
+
*
|
|
51
|
+
* A group of a table-backed source's dimensions is mostly passthrough columns,
|
|
52
|
+
* and the handful the modeler actually wrote were scattered among them — the
|
|
53
|
+
* interesting rows found by hunting for the ones that open. Hoisting them puts the
|
|
54
|
+
* source's own work at the top of the group and leaves the inherited columns as
|
|
55
|
+
* the tail they are.
|
|
56
|
+
*
|
|
57
|
+
* **The row and the order answer "loading" differently, on purpose.**
|
|
58
|
+
* `isFieldExpandable` is optimistic while the definitions read is in flight —
|
|
59
|
+
* a row that becomes openable late beats one that stops being so under the pointer. Order
|
|
60
|
+
* cannot be optimistic the same way: taking `loading` as expandable puts EVERY
|
|
61
|
+
* field in the hoisted block, so `rest` is empty, the identity short-circuit
|
|
62
|
+
* below returns the list unsorted, and the group then re-sorts under the reader
|
|
63
|
+
* when the read lands. So ordering asks a stricter question — is this field
|
|
64
|
+
* expandable *on what is known now*.
|
|
65
|
+
*
|
|
66
|
+
* **This narrows the reorder; it does not remove it.** A row is knowable at
|
|
67
|
+
* first paint only through `isIndexedDimension`, which reads `field.indexed`
|
|
68
|
+
* off the compiled schema. A plain written measure still hoists when its
|
|
69
|
+
* definition's read lands (the model text's parse, or a host's entities),
|
|
70
|
+
* because written-vs-inherited is only known from that read. Removing the rest
|
|
71
|
+
* needs the compiled schema to say what a field is.
|
|
72
|
+
*/
|
|
73
|
+
export function expandableFirst(
|
|
74
|
+
items: ExplorerField[],
|
|
75
|
+
getFieldCode: (field: ExplorerField) => FieldCodeLookup | undefined,
|
|
76
|
+
): ExplorerField[] {
|
|
77
|
+
const expandable: ExplorerField[] = [];
|
|
78
|
+
const rest: ExplorerField[] = [];
|
|
79
|
+
for (const field of items) {
|
|
80
|
+
const fieldCode = getFieldCode(field);
|
|
81
|
+
// `loading` is the one input that would flip this row's answer when the
|
|
82
|
+
// read lands, so it does not count here.
|
|
83
|
+
const knownExpandable =
|
|
84
|
+
(!!fieldCode &&
|
|
85
|
+
!fieldCode.loading &&
|
|
86
|
+
(!!fieldCode.code || !!fieldCode.error)) ||
|
|
87
|
+
isIndexedDimension(field);
|
|
88
|
+
(knownExpandable ? expandable : rest).push(field);
|
|
89
|
+
}
|
|
90
|
+
// Nothing to reorder — return the original array so React sees the same
|
|
91
|
+
// reference and the rows don't remount on every parent render.
|
|
92
|
+
return rest.length === 0 || expandable.length === 0
|
|
93
|
+
? items
|
|
94
|
+
: [...expandable, ...rest];
|
|
95
|
+
}
|