@malloy-publisher/sdk 0.9.13 → 0.9.15
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-BClN_PG6.cjs.js +154 -0
- package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
- package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
- package/dist/ServerProvider-e2369oom.cjs.js +1 -0
- package/dist/builder/index.cjs.js +80 -79
- package/dist/builder/index.es.js +7430 -6548
- package/dist/client/api.d.ts +30 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
- package/dist/components/Dashboard/DashboardView.d.ts +9 -2
- package/dist/components/Dashboard/index.d.ts +1 -1
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
- package/dist/components/Dashboard/useStuck.d.ts +18 -12
- package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
- package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
- package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
- package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
- package/dist/components/Report/Report.d.ts +7 -1
- package/dist/components/Report/ReportPage.d.ts +7 -0
- package/dist/components/Report/layoutRules.d.ts +45 -0
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
- package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
- package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/catalog.d.ts +23 -0
- package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
- package/dist/components/ReportBuilder/controls.d.ts +2 -2
- package/dist/components/ReportBuilder/document.d.ts +53 -5
- package/dist/components/ReportBuilder/imports.d.ts +7 -0
- package/dist/components/ReportBuilder/placement.d.ts +75 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +3 -1
- package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
- package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3328 -3287
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +127 -10
- package/src/components/Dashboard/DashboardTile.tsx +11 -1
- package/src/components/Dashboard/DashboardView.tsx +63 -10
- package/src/components/Dashboard/TileCard.tsx +6 -0
- package/src/components/Dashboard/index.ts +1 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
- package/src/components/Dashboard/tileHeight.spec.ts +72 -0
- package/src/components/Dashboard/useStuck.ts +76 -28
- package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
- package/src/components/Package/NewDocumentDialog.tsx +10 -11
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
- package/src/components/RenderedResult/RenderedResult.tsx +21 -6
- package/src/components/RenderedResult/ResultContainer.tsx +60 -7
- package/src/components/RenderedResult/ResultPanel.tsx +21 -1
- package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
- package/src/components/RenderedResult/chartPresentation.ts +166 -0
- package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
- package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
- package/src/components/RenderedResult/resultSizing.ts +65 -11
- package/src/components/Report/Report.spec.tsx +19 -0
- package/src/components/Report/Report.tsx +8 -1
- package/src/components/Report/ReportPage.tsx +13 -1
- package/src/components/Report/layoutRules.spec.ts +43 -3
- package/src/components/Report/layoutRules.ts +70 -0
- package/src/components/Report/tileOverflow.spec.tsx +162 -0
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
- package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
- package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
- package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
- package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
- package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
- package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
- package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
- package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
- package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
- package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
- package/src/components/ReportBuilder/TileFrame.tsx +251 -6
- package/src/components/ReportBuilder/TileMenu.tsx +259 -20
- package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
- package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
- package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
- package/src/components/ReportBuilder/catalog.ts +90 -37
- package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
- package/src/components/ReportBuilder/chartLine.ts +80 -2
- package/src/components/ReportBuilder/controls.ts +4 -3
- package/src/components/ReportBuilder/document.ts +65 -7
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
- package/src/components/ReportBuilder/imports.ts +1 -1
- package/src/components/ReportBuilder/invariants.spec.ts +18 -10
- package/src/components/ReportBuilder/layout.ts +3 -0
- package/src/components/ReportBuilder/placement.spec.ts +193 -0
- package/src/components/ReportBuilder/placement.ts +250 -0
- package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
- package/src/components/ReportBuilder/preview.spec.ts +151 -11
- package/src/components/ReportBuilder/preview.ts +203 -40
- package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
- package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
- package/src/components/ReportBuilder/readDocument.ts +194 -23
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +4 -0
- package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
- package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
- package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
- package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
- package/src/components/ReportBuilder/spliceDocument.ts +139 -52
- package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
- package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
- package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
- package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
- package/src/components/ReportBuilder/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileHeight.ts +149 -0
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/ReportBuilder/useTileResize.ts +16 -1
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/resolveTheme.spec.ts +72 -1
- package/src/theme/resolveTheme.ts +43 -0
- package/src/utils/blankQuoted.spec.ts +50 -0
- package/src/utils/blankQuoted.ts +32 -0
- package/src/utils/malloyText.ts +2 -1
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
|
@@ -536,10 +536,10 @@ describe("ReportBuilder: tiles added and removed", () => {
|
|
|
536
536
|
);
|
|
537
537
|
await waitFor(() => expect(written).toBeDefined());
|
|
538
538
|
expect(written).toContain(
|
|
539
|
-
'tiles=["a -> by_cat", "a -> by_brand", "a -> sales_by_state_tile"]',
|
|
539
|
+
'tiles=["a -> by_cat", "a -> by_brand", "a -> sales_by_state_tile" { colspan=6 }]',
|
|
540
540
|
);
|
|
541
541
|
expect(written).toContain(
|
|
542
|
-
'
|
|
542
|
+
'\n\n # label="Revenue by state"\n view: sales_by_state_tile is sales_by_state\n}',
|
|
543
543
|
);
|
|
544
544
|
});
|
|
545
545
|
|
|
@@ -619,6 +619,65 @@ describe("ReportBuilder: a tile's own settings", () => {
|
|
|
619
619
|
});
|
|
620
620
|
});
|
|
621
621
|
|
|
622
|
+
describe("ReportBuilder: a tile that names a query", () => {
|
|
623
|
+
const named = `## artifact { title="T" tiles=["by_carrier", "flights -> by_month"] }
|
|
624
|
+
import { flights } from '../flights.malloy'
|
|
625
|
+
|
|
626
|
+
query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
|
|
627
|
+
|
|
628
|
+
it("opens the report and shows the tile, with nothing on it to edit", async () => {
|
|
629
|
+
const document = await openDocument(named);
|
|
630
|
+
render(<ReportBuilder source={named} document={document} />);
|
|
631
|
+
// Titled as the reader titles it, from the query's name.
|
|
632
|
+
expect(
|
|
633
|
+
within(screen.getByLabelText("Tile by_carrier")).getByText(
|
|
634
|
+
"By carrier",
|
|
635
|
+
),
|
|
636
|
+
).toBeDefined();
|
|
637
|
+
// No title field on the tile, and a menu that says why. Its width and
|
|
638
|
+
// height are the report's, on its entry, so both edges are there.
|
|
639
|
+
fireEvent.click(screen.getByText("By carrier"));
|
|
640
|
+
expect(screen.queryByLabelText("Tile title")).toBeNull();
|
|
641
|
+
expect(
|
|
642
|
+
screen.queryByRole("separator", { name: "Width of by_carrier" }),
|
|
643
|
+
).not.toBeNull();
|
|
644
|
+
fireEvent.click(screen.getByLabelText("Settings for by_carrier"));
|
|
645
|
+
expect(
|
|
646
|
+
screen.getByText(
|
|
647
|
+
"It names a query, so its chart is set where that query is declared.",
|
|
648
|
+
),
|
|
649
|
+
).toBeDefined();
|
|
650
|
+
// The menu names what the tile runs: the query, with no empty source.
|
|
651
|
+
const menu = screen.getByRole("menu", {
|
|
652
|
+
name: "by_carrier",
|
|
653
|
+
hidden: true,
|
|
654
|
+
});
|
|
655
|
+
expect(within(menu).getByText("by_carrier")).toBeDefined();
|
|
656
|
+
expect(within(menu).queryByText(/→/)).toBeNull();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it("removes it from the list and saves the query untouched", async () => {
|
|
660
|
+
let written: string | undefined;
|
|
661
|
+
const document = await openDocument(named);
|
|
662
|
+
render(
|
|
663
|
+
<ReportBuilder
|
|
664
|
+
source={named}
|
|
665
|
+
document={document}
|
|
666
|
+
onSave={(next) => {
|
|
667
|
+
written = next;
|
|
668
|
+
}}
|
|
669
|
+
/>,
|
|
670
|
+
);
|
|
671
|
+
fireEvent.click(screen.getByLabelText("Remove by_carrier"));
|
|
672
|
+
fireEvent.click(
|
|
673
|
+
screen.getByRole("button", { name: "Save", hidden: true }),
|
|
674
|
+
);
|
|
675
|
+
await waitFor(() => expect(written).toBeDefined());
|
|
676
|
+
expect(written).toContain('tiles=["flights -> by_month"]');
|
|
677
|
+
expect(written).toContain("query: by_carrier is flights");
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
|
|
622
681
|
describe("ReportBuilder: widths and the page's own settings", () => {
|
|
623
682
|
it("steps a tile's width from the keyboard on its edge, one undo step each", async () => {
|
|
624
683
|
await mount();
|
|
@@ -638,6 +697,37 @@ describe("ReportBuilder: widths and the page's own settings", () => {
|
|
|
638
697
|
expect(itemStyleOf("by_cat")).toContain("grid-column: span 5");
|
|
639
698
|
});
|
|
640
699
|
|
|
700
|
+
it("steps a tile's height from the keyboard on its bottom edge, and fits it again on Delete", async () => {
|
|
701
|
+
await mount();
|
|
702
|
+
const edge = () =>
|
|
703
|
+
screen.getByRole("separator", { name: "Height of By category" });
|
|
704
|
+
expect(edge().getAttribute("aria-valuetext")).toBe("Auto height");
|
|
705
|
+
expect(itemStyleOf("by_cat")).not.toContain("height:");
|
|
706
|
+
fireEvent.keyDown(edge(), { key: "ArrowDown" });
|
|
707
|
+
// One row past the fewest a chart is offered (3).
|
|
708
|
+
expect(edge().getAttribute("aria-valuetext")).toBe("4 rows tall");
|
|
709
|
+
// Four 80px rows and the three gaps between them.
|
|
710
|
+
expect(itemStyleOf("by_cat")).toContain("height: 368px");
|
|
711
|
+
fireEvent.keyDown(edge(), { key: "End" });
|
|
712
|
+
expect(edge().getAttribute("aria-valuenow")).toBe("16");
|
|
713
|
+
fireEvent.keyDown(edge(), { key: "Delete" });
|
|
714
|
+
expect(edge().getAttribute("aria-valuetext")).toBe("Auto height");
|
|
715
|
+
fireEvent.click(button("Undo"));
|
|
716
|
+
expect(edge().getAttribute("aria-valuenow")).toBe("16");
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
it("lays out a tile the model owns: it has both edges", async () => {
|
|
720
|
+
const source = `## artifact { title="T" tiles=["orders -> by_brand"] } dashboard { columns=12 }\nimport { orders } from '../orders.malloy'`;
|
|
721
|
+
const document = await openDocument(source);
|
|
722
|
+
render(<ReportBuilder source={source} document={document} />);
|
|
723
|
+
expect(
|
|
724
|
+
screen.getByRole("separator", { name: "Width of by_brand" }),
|
|
725
|
+
).toBeDefined();
|
|
726
|
+
expect(
|
|
727
|
+
screen.getByRole("separator", { name: "Height of by_brand" }),
|
|
728
|
+
).toBeDefined();
|
|
729
|
+
});
|
|
730
|
+
|
|
641
731
|
it("sets a tile's width by dragging its right edge, not from its menu", async () => {
|
|
642
732
|
await mount();
|
|
643
733
|
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
@@ -741,6 +831,57 @@ source: a is scoped_orders extend {
|
|
|
741
831
|
);
|
|
742
832
|
});
|
|
743
833
|
|
|
834
|
+
const clickableItem = () =>
|
|
835
|
+
screen.getByRole("menuitem", {
|
|
836
|
+
name: /^Clickable cells/,
|
|
837
|
+
hidden: true,
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
it("says which clicks it sets up, and that none act while editing", async () => {
|
|
841
|
+
// The renderer reports clicks on table cells only, never on a bar, and
|
|
842
|
+
// the builder renders tiles without click handling, because a press there
|
|
843
|
+
// selects the tile. The window says both, so the setting does not look
|
|
844
|
+
// broken when a click in the builder does nothing.
|
|
845
|
+
const doc = await openDocument(WITH_DIMENSION);
|
|
846
|
+
render(<ReportBuilder source={WITH_DIMENSION} document={doc} />);
|
|
847
|
+
fireEvent.click(screen.getByLabelText("Settings for x"));
|
|
848
|
+
fireEvent.click(clickableItem());
|
|
849
|
+
const dialog = screen.getByRole("dialog", { hidden: true });
|
|
850
|
+
expect(dialog.textContent).toContain(
|
|
851
|
+
"A click on a table cell sets a filter to its value, on this report or on the one it opens.",
|
|
852
|
+
);
|
|
853
|
+
expect(dialog.textContent).toContain(
|
|
854
|
+
"Bars, lines and points on a chart do not respond to a click.",
|
|
855
|
+
);
|
|
856
|
+
expect(dialog.textContent).toContain(
|
|
857
|
+
"Clicks work in the report, not while you edit it.",
|
|
858
|
+
);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it("warns on a chart tile that its bars will not click", async () => {
|
|
862
|
+
const BAR = WITH_DIMENSION.replace(
|
|
863
|
+
" # colspan=6\n view: x",
|
|
864
|
+
" # colspan=6\n # bar_chart\n view: x",
|
|
865
|
+
);
|
|
866
|
+
expect(BAR).toContain("# bar_chart");
|
|
867
|
+
const doc = await openDocument(BAR);
|
|
868
|
+
render(<ReportBuilder source={BAR} document={doc} />);
|
|
869
|
+
fireEvent.click(screen.getByLabelText("Settings for x"));
|
|
870
|
+
expect(clickableItem().textContent).toContain(
|
|
871
|
+
"Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",
|
|
872
|
+
);
|
|
873
|
+
// Still offered: the tag is on the dimension, which a table tile on the
|
|
874
|
+
// same source can use.
|
|
875
|
+
expect(clickableItem().getAttribute("aria-disabled")).not.toBe("true");
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
it("adds no chart warning to a table tile", async () => {
|
|
879
|
+
const doc = await openDocument(WITH_DIMENSION);
|
|
880
|
+
render(<ReportBuilder source={WITH_DIMENSION} document={doc} />);
|
|
881
|
+
fireEvent.click(screen.getByLabelText("Settings for x"));
|
|
882
|
+
expect(clickableItem().textContent).toBe("Clickable cells…");
|
|
883
|
+
});
|
|
884
|
+
|
|
744
885
|
it("offers no Drill when the source declares no dimension here", async () => {
|
|
745
886
|
// A window whose only content is why its Apply is off is a dead end;
|
|
746
887
|
// the menu leaves the entry out instead.
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import { reportClasses } from "../../theme/classes";
|
|
5
5
|
import AddIcon from "@mui/icons-material/Add";
|
|
6
|
-
import { Alert, Button, Stack, Typography } from "@mui/material";
|
|
7
|
-
import { useMemo, useRef, useState, type ReactNode } from "react";
|
|
8
|
-
import {
|
|
6
|
+
import { Alert, Button, Stack, Typography, useMediaQuery } from "@mui/material";
|
|
7
|
+
import { useCallback, useMemo, useRef, useState, type ReactNode } from "react";
|
|
8
|
+
import {
|
|
9
|
+
isPlaced,
|
|
10
|
+
nudgedSpan,
|
|
11
|
+
useDefaultTileSpan,
|
|
12
|
+
} from "../Dashboard/DashboardGrid";
|
|
9
13
|
import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
|
|
10
14
|
import type { SavesTo } from "./documentSession";
|
|
11
15
|
import type { ReportEventHandler } from "../Report/telemetry";
|
|
@@ -22,11 +26,7 @@ import {
|
|
|
22
26
|
} from "./builderControls";
|
|
23
27
|
import { OpenDraftContext } from "./openDraft";
|
|
24
28
|
import type { PackageCatalog } from "./catalog";
|
|
25
|
-
import {
|
|
26
|
-
isQueryTile,
|
|
27
|
-
type DashboardDocument,
|
|
28
|
-
type QueryTile,
|
|
29
|
-
} from "./document";
|
|
29
|
+
import type { DashboardDocument, QueryTile } from "./document";
|
|
30
30
|
import { FilterStrip, type FixedFilter } from "./FilterStrip";
|
|
31
31
|
import { clockTime, type SaveStatusProps } from "./SaveStatus";
|
|
32
32
|
import { SELECTION_RING_PX } from "./TileFrame";
|
|
@@ -39,8 +39,10 @@ import type { SaveHandler } from "./useDocumentEditor";
|
|
|
39
39
|
import { useOpenDraftCommit } from "./useOpenDraftCommit";
|
|
40
40
|
import { useTileEditing } from "./useTileEditing";
|
|
41
41
|
import { useTileReorder } from "./useTileReorder";
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
42
|
+
import { settle } from "./placement";
|
|
43
|
+
import { useTileHeight } from "./useTileHeight";
|
|
44
|
+
import { useTileResize, widestFrom } from "./useTileResize";
|
|
45
|
+
import { layoutRules, withSpan } from "../Report/layoutRules";
|
|
44
46
|
import { ReportPage } from "../Report/ReportPage";
|
|
45
47
|
|
|
46
48
|
export type { BuilderGiven } from "./controls";
|
|
@@ -296,6 +298,17 @@ export function ReportBuilder({
|
|
|
296
298
|
?.split("/")
|
|
297
299
|
.at(-1)
|
|
298
300
|
?.replace(/\.malloy$/, "");
|
|
301
|
+
// Below `md` the grid is drawn as one column, as a phone shows it, so a
|
|
302
|
+
// tile's width and place do not show: moving and widening are off there.
|
|
303
|
+
// Assumed wide where the width cannot be asked (tests, server render).
|
|
304
|
+
// 900px is `md` in the default breakpoints, which the grid's own `sx`
|
|
305
|
+
// resolves against; written out so a host with no MUI theme still works.
|
|
306
|
+
const wide = useMediaQuery("(min-width:900px)", {
|
|
307
|
+
defaultMatches: true,
|
|
308
|
+
noSsr: true,
|
|
309
|
+
});
|
|
310
|
+
const arrange = !rules.widths || wide;
|
|
311
|
+
// On a grid a move is free placement; on a linear report it reorders.
|
|
299
312
|
const reorder = useTileReorder({
|
|
300
313
|
tiles: editor.document.tiles,
|
|
301
314
|
commit: (next) =>
|
|
@@ -303,7 +316,16 @@ export function ReportBuilder({
|
|
|
303
316
|
draft.tiles = next;
|
|
304
317
|
}),
|
|
305
318
|
onLanded: selectTile,
|
|
319
|
+
...(rules.widths && wide ? { placement: { columns, gridBox } } : {}),
|
|
306
320
|
});
|
|
321
|
+
// After a tile on a placed report changes size, whatever it now covers
|
|
322
|
+
// is pushed down; a report that flows has nothing to settle.
|
|
323
|
+
const placesTiles = rules.widths;
|
|
324
|
+
const place = useCallback(
|
|
325
|
+
(tiles: DashboardDocument["tiles"], index: number) =>
|
|
326
|
+
placesTiles && isPlaced(tiles) ? settle(tiles, columns, index) : tiles,
|
|
327
|
+
[placesTiles, columns],
|
|
328
|
+
);
|
|
307
329
|
const { dragging } = reorder;
|
|
308
330
|
// Dragging a tile's right edge sets its width, written once on release.
|
|
309
331
|
// A tile with no `# colspan` is drawn as the reader draws it, at least
|
|
@@ -328,7 +350,23 @@ export function ReportBuilder({
|
|
|
328
350
|
commit: (index, span) =>
|
|
329
351
|
editor.update((draft) => {
|
|
330
352
|
const tile = draft.tiles[index];
|
|
331
|
-
if (tile)
|
|
353
|
+
if (tile)
|
|
354
|
+
draft.tiles[index] = withSpan(tile, span, columns, defaultSpan);
|
|
355
|
+
draft.tiles = place(draft.tiles, index);
|
|
356
|
+
}),
|
|
357
|
+
});
|
|
358
|
+
// Dragging a tile's bottom edge sets its height in rows, the same way.
|
|
359
|
+
const sizing = useTileHeight({
|
|
360
|
+
tiles: editor.document.tiles,
|
|
361
|
+
gridBox,
|
|
362
|
+
onStart: selectTile,
|
|
363
|
+
commit: (index, rows) =>
|
|
364
|
+
editor.update((draft) => {
|
|
365
|
+
const tile = draft.tiles[index];
|
|
366
|
+
if (!tile) return;
|
|
367
|
+
if (rows === undefined) delete tile.rowspan;
|
|
368
|
+
else tile.rowspan = rows;
|
|
369
|
+
draft.tiles = place(draft.tiles, index);
|
|
332
370
|
}),
|
|
333
371
|
});
|
|
334
372
|
const tiles = useTileEditing({
|
|
@@ -371,26 +409,32 @@ export function ReportBuilder({
|
|
|
371
409
|
},
|
|
372
410
|
nudge: (delta: 1 | -1) => {
|
|
373
411
|
// The drag's keyboard sensor also reads the arrows, and a drop would write the drag-start width back.
|
|
374
|
-
if (dragging || selected === undefined || !rules.widths)
|
|
375
|
-
const tile = editor.document.tiles[selected];
|
|
376
|
-
if (
|
|
377
|
-
!tile ||
|
|
378
|
-
(isQueryTile(tile) && tile.declaration.kind === "inherited")
|
|
379
|
-
)
|
|
412
|
+
if (dragging || selected === undefined || !rules.widths || !arrange)
|
|
380
413
|
return;
|
|
414
|
+
// Any tile, an inherited one too: its width is on its entry.
|
|
415
|
+
const tile = editor.document.tiles[selected];
|
|
416
|
+
if (!tile) return;
|
|
381
417
|
const span = nudgedSpan(
|
|
382
418
|
tile.colspan ?? defaultSpan,
|
|
383
419
|
delta,
|
|
384
|
-
columns,
|
|
420
|
+
widestFrom(tile, columns),
|
|
385
421
|
);
|
|
386
422
|
if (span === (tile.colspan ?? defaultSpan)) return;
|
|
387
423
|
editor.update((draft) => {
|
|
388
|
-
draft.tiles[selected]
|
|
424
|
+
draft.tiles[selected] = withSpan(
|
|
425
|
+
draft.tiles[selected],
|
|
426
|
+
span,
|
|
427
|
+
columns,
|
|
428
|
+
defaultSpan,
|
|
429
|
+
);
|
|
430
|
+
draft.tiles = place(draft.tiles, selected);
|
|
389
431
|
});
|
|
390
432
|
},
|
|
391
433
|
}),
|
|
392
434
|
[
|
|
393
435
|
defaultSpan,
|
|
436
|
+
arrange,
|
|
437
|
+
place,
|
|
394
438
|
editor,
|
|
395
439
|
menu,
|
|
396
440
|
filterDialog,
|
|
@@ -618,10 +662,20 @@ export function ReportBuilder({
|
|
|
618
662
|
<Alert severity="warning">{editor.error}</Alert>
|
|
619
663
|
)}
|
|
620
664
|
|
|
665
|
+
{!arrange && (
|
|
666
|
+
<Alert severity="info">
|
|
667
|
+
This window is too narrow for the grid, so tiles stack in
|
|
668
|
+
one column, as on a phone. Widen it to move tiles or change
|
|
669
|
+
their width.
|
|
670
|
+
</Alert>
|
|
671
|
+
)}
|
|
621
672
|
<BuilderGrid
|
|
622
673
|
editor={editor}
|
|
674
|
+
arrange={arrange}
|
|
623
675
|
reorder={reorder}
|
|
624
676
|
resizing={resizing}
|
|
677
|
+
sizing={sizing}
|
|
678
|
+
place={place}
|
|
625
679
|
gridBox={gridBox}
|
|
626
680
|
defaultSpan={defaultSpan}
|
|
627
681
|
rules={rules}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import {
|
|
13
|
+
DocumentNotFoundError,
|
|
14
|
+
type DocumentLocator,
|
|
15
|
+
type DocumentStorage,
|
|
16
|
+
type Workspace,
|
|
17
|
+
} from "../DocumentStorage";
|
|
18
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Which charts a tile can take come from the report file's own compiled
|
|
22
|
+
* model, for the views it declares. That model is the package's file, so it
|
|
23
|
+
* speaks for the builder only while the builder is on that text: a host's
|
|
24
|
+
* record can declare a view of the same name with another shape.
|
|
25
|
+
*/
|
|
26
|
+
const file = (
|
|
27
|
+
body: string,
|
|
28
|
+
) => `## artifact { title="Overview" tiles=["a -> kpis"] }
|
|
29
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
30
|
+
|
|
31
|
+
source: a is scoped_orders extend {
|
|
32
|
+
# label="Key figures"
|
|
33
|
+
view: kpis is { ${body} }
|
|
34
|
+
}`;
|
|
35
|
+
const PACKAGE_FILE = file("aggregate: revenue, order_count");
|
|
36
|
+
const RECORD_FILE = file("group_by: carrier; aggregate: revenue");
|
|
37
|
+
|
|
38
|
+
const total = (name: string) => ({
|
|
39
|
+
kind: "dimension",
|
|
40
|
+
name,
|
|
41
|
+
type: { kind: "number_type" },
|
|
42
|
+
annotations: [{ value: '#(malloy) reference_id = "x" calculation\n' }],
|
|
43
|
+
});
|
|
44
|
+
// The package file's compile: `kpis` is two totals and nothing else.
|
|
45
|
+
const SERVED = {
|
|
46
|
+
modelPath: "dashboards/overview.malloy",
|
|
47
|
+
sourceText: PACKAGE_FILE,
|
|
48
|
+
sources: [{ name: "a", views: [{ name: "kpis" }] }],
|
|
49
|
+
sourceInfos: [
|
|
50
|
+
JSON.stringify({
|
|
51
|
+
name: "a",
|
|
52
|
+
schema: {
|
|
53
|
+
fields: [
|
|
54
|
+
{
|
|
55
|
+
kind: "view",
|
|
56
|
+
name: "kpis",
|
|
57
|
+
schema: { fields: [total("revenue"), total("order_count")] },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
mockServerProvider(
|
|
66
|
+
{
|
|
67
|
+
models: {
|
|
68
|
+
getModel: mock((_env: string, _pkg: string, path: string) =>
|
|
69
|
+
Promise.resolve({
|
|
70
|
+
data:
|
|
71
|
+
path === "dashboards/overview.malloy"
|
|
72
|
+
? SERVED
|
|
73
|
+
: { modelPath: path, sources: [], sourceInfos: [] },
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
executeQueryModel: mock(() => pending()),
|
|
77
|
+
listModels: mock(() => Promise.resolve({ data: [] })),
|
|
78
|
+
},
|
|
79
|
+
reports: {
|
|
80
|
+
getReport: mock(() =>
|
|
81
|
+
Promise.resolve({
|
|
82
|
+
data: {
|
|
83
|
+
path: "dashboards/overview.malloy",
|
|
84
|
+
givens: [],
|
|
85
|
+
tiles: [],
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
listReports: mock(() => Promise.resolve({ data: [] })),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{ mutable: true },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
96
|
+
|
|
97
|
+
beforeEach(() => clearCache());
|
|
98
|
+
|
|
99
|
+
/** A host store that is the record, holding one document. */
|
|
100
|
+
class RecordStorage implements DocumentStorage {
|
|
101
|
+
private readonly workspace: Workspace = {
|
|
102
|
+
name: "Branch",
|
|
103
|
+
writeable: true,
|
|
104
|
+
description: "Saved to the draft branch",
|
|
105
|
+
authoritative: true,
|
|
106
|
+
};
|
|
107
|
+
constructor(private readonly text: string) {}
|
|
108
|
+
async listWorkspaces(): Promise<Workspace[]> {
|
|
109
|
+
return [this.workspace];
|
|
110
|
+
}
|
|
111
|
+
async listDocuments(): Promise<DocumentLocator[]> {
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
workspace: this.workspace.name,
|
|
115
|
+
type: "grid",
|
|
116
|
+
path: "env/pkg/dashboards/overview.malloy",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
async getDocument(locator: DocumentLocator): Promise<string> {
|
|
121
|
+
if (locator.path !== "env/pkg/dashboards/overview.malloy")
|
|
122
|
+
throw new DocumentNotFoundError(`No dashboard at ${locator.path}`);
|
|
123
|
+
return this.text;
|
|
124
|
+
}
|
|
125
|
+
async saveDocument(): Promise<void> {}
|
|
126
|
+
async deleteDocument(): Promise<void> {}
|
|
127
|
+
async moveDocument(): Promise<void> {
|
|
128
|
+
throw new Error("not exercised");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const editor = (
|
|
133
|
+
<ReportEditor
|
|
134
|
+
environmentName="env"
|
|
135
|
+
packageName="pkg"
|
|
136
|
+
dashboardName="overview"
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
/** The Line choice in the open tile's Chart submenu. */
|
|
141
|
+
const lineChoice = async () => {
|
|
142
|
+
fireEvent.click(await screen.findByLabelText("Settings for Key figures"));
|
|
143
|
+
fireEvent.click(
|
|
144
|
+
screen.getByRole("menuitem", { name: /^Chart/, hidden: true }),
|
|
145
|
+
);
|
|
146
|
+
const menu = screen.getByRole("menu", { name: "Chart", hidden: true });
|
|
147
|
+
return within(menu)
|
|
148
|
+
.getAllByRole("menuitemradio", { hidden: true })
|
|
149
|
+
.find(
|
|
150
|
+
(item) =>
|
|
151
|
+
item.querySelector(".MuiListItemText-primary")?.textContent ===
|
|
152
|
+
"Line",
|
|
153
|
+
) as HTMLElement;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
describe("the chart choices of a view the report declares", () => {
|
|
157
|
+
it("follow the package's compile while the builder is on the package's file", async () => {
|
|
158
|
+
render(editor, { wrapper: serverWrapper });
|
|
159
|
+
const line = await lineChoice();
|
|
160
|
+
expect(line.getAttribute("aria-disabled")).toBe("true");
|
|
161
|
+
expect(line.textContent).toContain(
|
|
162
|
+
"This view has no field for the x-axis",
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("do not follow it on a record whose view of the same name has another shape", async () => {
|
|
167
|
+
render(
|
|
168
|
+
<DocumentStorageProvider
|
|
169
|
+
documentStorage={new RecordStorage(RECORD_FILE)}
|
|
170
|
+
>
|
|
171
|
+
{editor}
|
|
172
|
+
</DocumentStorageProvider>,
|
|
173
|
+
{ wrapper: serverWrapper },
|
|
174
|
+
);
|
|
175
|
+
const line = await lineChoice();
|
|
176
|
+
expect(line.getAttribute("aria-disabled")).not.toBe("true");
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -220,7 +220,7 @@ source: recalls_tiles is recalls extend {
|
|
|
220
220
|
],
|
|
221
221
|
};
|
|
222
222
|
|
|
223
|
-
it("can
|
|
223
|
+
it("can make the model filter's current value the report's default", async () => {
|
|
224
224
|
packageFile = RECALLS;
|
|
225
225
|
served = READS_MANUFACTURER;
|
|
226
226
|
open();
|
|
@@ -229,13 +229,11 @@ source: recalls_tiles is recalls extend {
|
|
|
229
229
|
);
|
|
230
230
|
fireEvent.click(
|
|
231
231
|
await screen.findByRole("button", {
|
|
232
|
-
name: "
|
|
232
|
+
name: "Make this the report's default",
|
|
233
233
|
}),
|
|
234
234
|
);
|
|
235
235
|
// The report now holds it: the popover says so, and Undo takes it back.
|
|
236
|
-
expect(
|
|
237
|
-
await screen.findByText("The report opens with this value."),
|
|
238
|
-
).toBeDefined();
|
|
236
|
+
expect(await screen.findByText("Report default")).toBeDefined();
|
|
239
237
|
expect(
|
|
240
238
|
(
|
|
241
239
|
screen.getByRole("button", {
|