@malloydata/malloy-explorer 0.0.331-dev260103000551 → 0.0.331-dev260122023015

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/esm/index.js CHANGED
@@ -3463,7 +3463,8 @@ function MalloyExplorerProvider({
3463
3463
  topValues,
3464
3464
  onDrill,
3465
3465
  theme,
3466
- dark
3466
+ dark,
3467
+ onDownload
3467
3468
  }) {
3468
3469
  const rootQuery = useQueryBuilder(source, query);
3469
3470
  const updateQuery = useCallback(() => {
@@ -3491,6 +3492,7 @@ function MalloyExplorerProvider({
3491
3492
  rootQuery,
3492
3493
  setQuery: onQueryChange,
3493
3494
  onDrill,
3495
+ onDownload,
3494
3496
  query
3495
3497
  },
3496
3498
  children: /* @__PURE__ */ jsx(ThemeContext.Provider, {
@@ -38552,14 +38554,26 @@ async function* dataIterator(result) {
38552
38554
  }
38553
38555
  function DownloadButton({
38554
38556
  name = "malloy",
38555
- result
38557
+ source,
38558
+ submittedQuery
38556
38559
  }) {
38560
+ var _a2;
38557
38561
  const [href, setHref] = useState("");
38558
38562
  const [fileName, setFileName] = useState("");
38559
38563
  const [format2, _setFormat] = useState("csv");
38564
+ const {
38565
+ onDownload
38566
+ } = useContext(QueryEditorContext);
38560
38567
  useEffect(() => {
38568
+ var _a3;
38569
+ if (onDownload) return;
38570
+ const result = (_a3 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _a3.result;
38571
+ if (!result) {
38572
+ setHref("");
38573
+ return;
38574
+ }
38561
38575
  const createBlob = async () => {
38562
- if (!(result == null ? void 0 : result.data)) {
38576
+ if (!(submittedQuery == null ? void 0 : submittedQuery.response)) {
38563
38577
  setHref("");
38564
38578
  return;
38565
38579
  }
@@ -38587,7 +38601,7 @@ function DownloadButton({
38587
38601
  setFileName(fileName2);
38588
38602
  };
38589
38603
  void createBlob();
38590
- }, [name, format2, result]);
38604
+ }, [name, format2, onDownload, submittedQuery]);
38591
38605
  useEffect(() => {
38592
38606
  return () => {
38593
38607
  if (href) {
@@ -38610,6 +38624,17 @@ function DownloadButton({
38610
38624
  children: "Download CSV"
38611
38625
  })]
38612
38626
  });
38627
+ } else if (onDownload && ((_a2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _a2.result)) {
38628
+ return /* @__PURE__ */ jsx(Button, {
38629
+ onClick: () => onDownload({
38630
+ source,
38631
+ submittedQuery,
38632
+ name,
38633
+ format: "csv"
38634
+ }),
38635
+ icon: "download",
38636
+ label: "Download CSV"
38637
+ });
38613
38638
  } else {
38614
38639
  return null;
38615
38640
  }
@@ -38680,7 +38705,7 @@ function ResultPanel({
38680
38705
  submittedQuery,
38681
38706
  options
38682
38707
  }) {
38683
- var _a2, _b2, _c2, _d;
38708
+ var _a2, _b2, _c2;
38684
38709
  const {
38685
38710
  theme
38686
38711
  } = useContext(ThemeContext);
@@ -38744,7 +38769,8 @@ function ResultPanel({
38744
38769
  text: clipboardText,
38745
38770
  label: "Copy Code"
38746
38771
  }), tab === Tab.RESULTS && /* @__PURE__ */ jsx(DownloadButton, {
38747
- result: (_b2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _b2.result
38772
+ source,
38773
+ submittedQuery
38748
38774
  })]
38749
38775
  }), /* @__PURE__ */ jsxs("div", {
38750
38776
  ...{
@@ -38794,7 +38820,7 @@ function ResultPanel({
38794
38820
  ...{
38795
38821
  className: "mlywp4ipm mlyh8yej3 mly5yr21d mly9f619"
38796
38822
  },
38797
- children: ((_d = (_c2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _c2.result) == null ? void 0 : _d.sql) && /* @__PURE__ */ jsx(CodeBlock, {
38823
+ children: ((_c2 = (_b2 = submittedQuery == null ? void 0 : submittedQuery.response) == null ? void 0 : _b2.result) == null ? void 0 : _c2.sql) && /* @__PURE__ */ jsx(CodeBlock, {
38798
38824
  code: submittedQuery.response.result.sql,
38799
38825
  language: "sql"
38800
38826
  })