@malloydata/malloy-explorer 0.0.331-dev260103000551 → 0.0.337-dev260213014950

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.
@@ -3,6 +3,13 @@ import * as Malloy from "@malloydata/malloy-interfaces";
3
3
  import type { DrillData } from "@malloydata/render";
4
4
  import { SearchValueMapResult } from "../hooks/useTopValues";
5
5
  import { ColorTheme } from "./primitives/colors.stylex";
6
+ import { SubmittedQuery } from "./ResultPanel/SubmittedQuery";
7
+ declare export interface MalloyExplorerDownloadProps {
8
+ source: Malloy.SourceInfo;
9
+ submittedQuery: SubmittedQuery;
10
+ name: string;
11
+ format: "json" | "csv";
12
+ }
6
13
  declare export interface MalloyExplorerProviderProps {
7
14
  source: Malloy.SourceInfo;
8
15
  query?: Malloy.Query | string;
@@ -14,6 +21,7 @@ declare export interface MalloyExplorerProviderProps {
14
21
  onDrill?: ($$param0$: DrillData) => void;
15
22
  theme?: ColorTheme;
16
23
  dark?: boolean;
24
+ onDownload?: ($$param0$: MalloyExplorerDownloadProps) => void;
17
25
  }
18
26
  declare export function MalloyExplorerProvider(
19
27
  $$param0$: MalloyExplorerProviderProps,
@@ -3480,7 +3480,8 @@ function MalloyExplorerProvider({
3480
3480
  topValues,
3481
3481
  onDrill,
3482
3482
  theme,
3483
- dark
3483
+ dark,
3484
+ onDownload
3484
3485
  }) {
3485
3486
  const rootQuery = useQueryBuilder(source, query);
3486
3487
  const updateQuery = React.useCallback(() => {
@@ -3508,6 +3509,7 @@ function MalloyExplorerProvider({
3508
3509
  rootQuery,
3509
3510
  setQuery: onQueryChange,
3510
3511
  onDrill,
3512
+ onDownload,
3511
3513
  query
3512
3514
  },
3513
3515
  children: /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, {
@@ -32339,7 +32341,7 @@ function Visualization({
32339
32341
  }) {
32340
32342
  const {
32341
32343
  tag
32342
- } = malloyTag.Tag.fromTagLines(annotations.map((annotation) => annotation.value));
32344
+ } = malloyTag.parseTag(annotations.map((annotation) => annotation.value));
32343
32345
  const renderer = tagToRenderer(tag) ?? "table";
32344
32346
  return /* @__PURE__ */ jsxRuntime.jsx(Token, {
32345
32347
  label: snakeToTitle(renderer),
@@ -36183,6 +36185,9 @@ class StubConnection extends connection$1.BaseConnection {
36183
36185
  this.name = "stub";
36184
36186
  this.dialectName = dialectName;
36185
36187
  }
36188
+ getDigest() {
36189
+ return "stub";
36190
+ }
36186
36191
  runSQL() {
36187
36192
  throw new Error("Stub connection cannot run SQL.");
36188
36193
  }
@@ -38569,14 +38574,26 @@ async function* dataIterator(result) {
38569
38574
  }
38570
38575
  function DownloadButton({
38571
38576
  name = "malloy",
38572
- result
38577
+ source,
38578
+ submittedQuery
38573
38579
  }) {
38580
+ var _a2;
38574
38581
  const [href, setHref] = React.useState("");
38575
38582
  const [fileName, setFileName] = React.useState("");
38576
38583
  const [format2, _setFormat] = React.useState("csv");
38584
+ const {
38585
+ onDownload
38586
+ } = React.useContext(QueryEditorContext);
38577
38587
  React.useEffect(() => {
38588
+ var _a3;
38589
+ if (onDownload) return;
38590
+ const result = (_a3 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _a3.result;
38591
+ if (!result) {
38592
+ setHref("");
38593
+ return;
38594
+ }
38578
38595
  const createBlob = async () => {
38579
- if (!(result == null ? void 0 : result.data)) {
38596
+ if (!(submittedQuery == null ? void 0 : submittedQuery.response)) {
38580
38597
  setHref("");
38581
38598
  return;
38582
38599
  }
@@ -38604,7 +38621,7 @@ function DownloadButton({
38604
38621
  setFileName(fileName2);
38605
38622
  };
38606
38623
  void createBlob();
38607
- }, [name, format2, result]);
38624
+ }, [name, format2, onDownload, submittedQuery]);
38608
38625
  React.useEffect(() => {
38609
38626
  return () => {
38610
38627
  if (href) {
@@ -38627,6 +38644,17 @@ function DownloadButton({
38627
38644
  children: "Download CSV"
38628
38645
  })]
38629
38646
  });
38647
+ } else if (onDownload && ((_a2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _a2.result)) {
38648
+ return /* @__PURE__ */ jsxRuntime.jsx(Button, {
38649
+ onClick: () => onDownload({
38650
+ source,
38651
+ submittedQuery,
38652
+ name,
38653
+ format: "csv"
38654
+ }),
38655
+ icon: "download",
38656
+ label: "Download CSV"
38657
+ });
38630
38658
  } else {
38631
38659
  return null;
38632
38660
  }
@@ -38697,7 +38725,7 @@ function ResultPanel({
38697
38725
  submittedQuery,
38698
38726
  options
38699
38727
  }) {
38700
- var _a2, _b2, _c2, _d;
38728
+ var _a2, _b2, _c2;
38701
38729
  const {
38702
38730
  theme
38703
38731
  } = React.useContext(ThemeContext);
@@ -38761,7 +38789,8 @@ function ResultPanel({
38761
38789
  text: clipboardText,
38762
38790
  label: "Copy Code"
38763
38791
  }), tab === Tab.RESULTS && /* @__PURE__ */ jsxRuntime.jsx(DownloadButton, {
38764
- result: (_b2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _b2.result
38792
+ source,
38793
+ submittedQuery
38765
38794
  })]
38766
38795
  }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
38767
38796
  ...{
@@ -38811,7 +38840,7 @@ function ResultPanel({
38811
38840
  ...{
38812
38841
  className: "mlywp4ipm mlyh8yej3 mly5yr21d mly9f619"
38813
38842
  },
38814
- children: ((_d = (_c2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _c2.result) == null ? void 0 : _d.sql) && /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, {
38843
+ children: ((_c2 = (_b2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _b2.result) == null ? void 0 : _c2.sql) && /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, {
38815
38844
  code: submittedQuery.response.result.sql,
38816
38845
  language: "sql"
38817
38846
  })