@malloydata/malloy-explorer 0.0.295-dev250710213205 → 0.0.299-dev250804170242

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.
Files changed (51) hide show
  1. package/@flowtypes/components/MalloyExplorerProvider.flow.js +1 -1
  2. package/dist/cjs/index.cjs +448 -285
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/esm/index.js +415 -252
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/types/components/FieldToken.d.ts +5 -1
  7. package/dist/types/components/MalloyExplorerProvider.d.ts +1 -1
  8. package/dist/types/components/QueryPanel/AddMenu/AddAggregate.d.ts +1 -3
  9. package/dist/types/components/QueryPanel/AddMenu/AddEmptyNest.d.ts +1 -3
  10. package/dist/types/components/QueryPanel/AddMenu/AddGroupBy.d.ts +1 -3
  11. package/dist/types/components/QueryPanel/AddMenu/AddLimit.d.ts +1 -3
  12. package/dist/types/components/QueryPanel/AddMenu/AddMenu.d.ts +1 -3
  13. package/dist/types/components/QueryPanel/AddMenu/AddOrderBy.d.ts +1 -3
  14. package/dist/types/components/QueryPanel/AddMenu/AddView.d.ts +1 -3
  15. package/dist/types/components/QueryPanel/AddMenu/AddWhere.d.ts +0 -2
  16. package/dist/types/components/QueryPanel/Operations.d.ts +2 -3
  17. package/dist/types/components/QueryPanel/Parameters.d.ts +3 -3
  18. package/dist/types/components/QueryPanel/Query.d.ts +3 -4
  19. package/dist/types/components/QueryPanel/Source.d.ts +3 -3
  20. package/dist/types/components/QueryPanel/View.d.ts +2 -3
  21. package/dist/types/components/QueryPanel/ViewDefinition.d.ts +2 -3
  22. package/dist/types/components/QueryPanel/Visualization.d.ts +1 -2
  23. package/dist/types/components/QueryPanel/VizEditor/VizEditor.d.ts +1 -2
  24. package/dist/types/components/QueryPanel/VizEditor/VizEditorDialog.d.ts +1 -2
  25. package/dist/types/components/QueryPanel/VizEditor/VizEditorPopover.d.ts +1 -2
  26. package/dist/types/components/QueryPanel/VizEditor/styles.d.ts +3 -0
  27. package/dist/types/components/QueryPanel/VizEditor/utils.d.ts +3 -0
  28. package/dist/types/components/QueryPanel/operations/AggregateOperations.d.ts +3 -4
  29. package/dist/types/components/QueryPanel/operations/DrillOperations.d.ts +1 -2
  30. package/dist/types/components/QueryPanel/operations/FilterOperations.d.ts +2 -3
  31. package/dist/types/components/QueryPanel/operations/GroupByOperations.d.ts +2 -3
  32. package/dist/types/components/QueryPanel/operations/LimitOperation.d.ts +2 -3
  33. package/dist/types/components/QueryPanel/operations/NestOperation.d.ts +3 -5
  34. package/dist/types/components/QueryPanel/operations/OperationActionTitle.d.ts +0 -2
  35. package/dist/types/components/QueryPanel/operations/OrderByOperations.d.ts +2 -3
  36. package/dist/types/components/QueryPanel/operations/RenameDialog.d.ts +3 -4
  37. package/dist/types/components/QueryPanel/operations/SortableOperations.d.ts +3 -4
  38. package/dist/types/components/SourcePanel/FieldGroupList.d.ts +3 -1
  39. package/dist/types/components/SourcePanel/FieldTokenWithActions.d.ts +3 -2
  40. package/dist/types/components/SourcePanel/SearchResultList.d.ts +3 -1
  41. package/dist/types/components/SourcePanel/hooks/useOperations.d.ts +0 -4
  42. package/dist/types/components/primitives/DropdownMenu.d.ts +1 -1
  43. package/dist/types/components/utils/axis.d.ts +10 -0
  44. package/dist/types/components/utils/icon.d.ts +3 -3
  45. package/dist/types/components/utils/segment.d.ts +1 -0
  46. package/dist/types/contexts/QueryEditorContext.d.ts +1 -10
  47. package/dist/types/hooks/useQueryBuilder.d.ts +2 -2
  48. package/dist/types/hooks/useQueryUpdate.d.ts +10 -0
  49. package/dist/types/hooks/useTopValues.d.ts +18 -0
  50. package/jest.config.ts +1 -1
  51. package/package.json +8 -8
package/dist/esm/index.js CHANGED
@@ -15,9 +15,8 @@ var __superGet = (cls, obj, key2) => __reflectGet(__getProtoOf(cls), key2, obj);
15
15
  var _a, _b, _captureMap, _compiled, _pattern, _nameMap, _strategy, __EmulatedRegExp_instances, execCore_fn, _c;
16
16
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
17
17
  import * as React from "react";
18
- import React__default, { useLayoutEffect, useEffect, useMemo, useState, useRef, createElement, useContext, useCallback, createContext, memo, useReducer } from "react";
19
- import * as QB from "@malloydata/malloy-query-builder";
20
- import { ASTArrowQueryDefinition, ASTArrowViewDefinition, ASTSegmentViewDefinition, ASTNestViewOperation, ASTRefinementViewDefinition, ASTFilterWithLiteralEquality, ASTAnnotation, ASTOrderByViewOperation, ASTGroupByViewOperation, ASTAggregateViewOperation, ASTLimitViewOperation, ASTTimeTruncationExpression, ASTFilterWithFilterString, ASTReferenceExpression, ASTWhereViewOperation, ASTHavingViewOperation, ASTDrillViewOperation, ASTQuery } from "@malloydata/malloy-query-builder";
18
+ import React__default, { useLayoutEffect, useEffect, useMemo, createContext, useContext, useCallback, useState, useRef, createElement, memo, useReducer } from "react";
19
+ import { ASTQuery, ASTArrowQueryDefinition, ASTArrowViewDefinition, ASTSegmentViewDefinition, ASTNestViewOperation, ASTRefinementViewDefinition, ASTFilterWithLiteralEquality, ASTAnnotation, ASTOrderByViewOperation, ASTGroupByViewOperation, ASTAggregateViewOperation, ASTLimitViewOperation, ASTCalculateViewOperation, ASTTimeTruncationExpression, ASTFilterWithFilterString, ASTReferenceExpression, ASTWhereViewOperation, ASTHavingViewOperation, ASTDrillViewOperation, ASTReferenceQueryArrowSource } from "@malloydata/malloy-query-builder";
21
20
  import { Tag } from "@malloydata/malloy-tag";
22
21
  import { MalloyRenderer, isCoreVizPluginInstance } from "@malloydata/render";
23
22
  import { TemporalFilterExpression, BooleanFilterExpression, NumberFilterExpression, StringFilterExpression } from "@malloydata/malloy-filter";
@@ -3311,11 +3310,14 @@ var Root3$1 = Tooltip;
3311
3310
  var Trigger$4 = TooltipTrigger;
3312
3311
  var Portal$4 = TooltipPortal;
3313
3312
  var Content2$4 = TooltipContent;
3314
- const QueryEditorContext = /* @__PURE__ */ React.createContext({});
3313
+ const QueryEditorContext = /* @__PURE__ */ React.createContext({
3314
+ setQuery: () => {
3315
+ }
3316
+ });
3315
3317
  function useQueryBuilder(source, query) {
3316
3318
  return useMemo(() => {
3317
3319
  if (source) {
3318
- return new QB.ASTQuery({
3320
+ return new ASTQuery({
3319
3321
  query,
3320
3322
  source
3321
3323
  });
@@ -3399,10 +3401,29 @@ const findNestView = (currentView, remainingPath) => {
3399
3401
  }
3400
3402
  return null;
3401
3403
  };
3404
+ const UpdateQueryContext = /* @__PURE__ */ createContext({
3405
+ updateQuery: () => {
3406
+ console.warn("Missing <MalloyExplorerProvider>");
3407
+ }
3408
+ });
3409
+ function useUpdateQuery() {
3410
+ const {
3411
+ updateQuery
3412
+ } = useContext(UpdateQueryContext);
3413
+ return updateQuery;
3414
+ }
3415
+ const TopValuesContext = /* @__PURE__ */ createContext({});
3416
+ function useTopValues() {
3417
+ const {
3418
+ topValues
3419
+ } = useContext(TopValuesContext);
3420
+ return topValues;
3421
+ }
3402
3422
  function MalloyExplorerProvider({
3403
3423
  source,
3404
3424
  query,
3405
- onQueryChange,
3425
+ onQueryChange = () => {
3426
+ },
3406
3427
  focusedNestViewPath,
3407
3428
  onFocusedNestViewPathChange,
3408
3429
  children,
@@ -3410,20 +3431,32 @@ function MalloyExplorerProvider({
3410
3431
  onDrill
3411
3432
  }) {
3412
3433
  const rootQuery = useQueryBuilder(source, query);
3434
+ const updateQuery = useCallback(() => {
3435
+ onQueryChange == null ? void 0 : onQueryChange(rootQuery == null ? void 0 : rootQuery.build());
3436
+ }, [onQueryChange, rootQuery]);
3413
3437
  return /* @__PURE__ */ jsx(TooltipProvider, {
3414
3438
  children: /* @__PURE__ */ jsx(MalloyQueryFocusProvider, {
3415
3439
  rootQuery,
3416
3440
  focusedNestViewPath,
3417
3441
  onFocusedNestViewPathChange,
3418
- children: /* @__PURE__ */ jsx(QueryEditorContext.Provider, {
3442
+ children: /* @__PURE__ */ jsx(UpdateQueryContext.Provider, {
3419
3443
  value: {
3420
- source,
3421
- rootQuery,
3422
- setQuery: onQueryChange,
3423
- topValues,
3424
- onDrill
3444
+ updateQuery
3425
3445
  },
3426
- children
3446
+ children: /* @__PURE__ */ jsx(TopValuesContext.Provider, {
3447
+ value: {
3448
+ topValues
3449
+ },
3450
+ children: /* @__PURE__ */ jsx(QueryEditorContext.Provider, {
3451
+ value: {
3452
+ source,
3453
+ rootQuery,
3454
+ setQuery: onQueryChange,
3455
+ onDrill
3456
+ },
3457
+ children
3458
+ })
3459
+ })
3427
3460
  })
3428
3461
  })
3429
3462
  });
@@ -25986,9 +26019,9 @@ function QueryActionBar({
25986
26019
  children: [/* @__PURE__ */ jsx(Button, {
25987
26020
  onClick: () => {
25988
26021
  focusMainView();
25989
- setQuery == null ? void 0 : setQuery(void 0);
26022
+ setQuery(void 0);
25990
26023
  },
25991
- isDisabled: !rootQuery || (rootQuery == null ? void 0 : rootQuery.isEmpty()),
26024
+ isDisabled: !rootQuery || rootQuery.isEmpty(),
25992
26025
  label: "Clear",
25993
26026
  variant: "flat",
25994
26027
  size: "compact"
@@ -26198,6 +26231,7 @@ function fieldToIcon(field) {
26198
26231
  break;
26199
26232
  case "dimension":
26200
26233
  case "measure":
26234
+ case "calculate":
26201
26235
  icon = atomicTypeToIcon(field.type.kind);
26202
26236
  break;
26203
26237
  case "join":
@@ -26209,8 +26243,7 @@ function fieldToIcon(field) {
26209
26243
  function relationshipToIcon(relationship) {
26210
26244
  return relationshipMap[relationship];
26211
26245
  }
26212
- function viewToVisualizationIcon(view) {
26213
- const currentTag = view.getTag();
26246
+ function tagToVisualization(currentTag) {
26214
26247
  const currentRenderer = tagToRenderer(currentTag) ?? "table";
26215
26248
  return `viz_${currentRenderer}`;
26216
26249
  }
@@ -26230,6 +26263,7 @@ const fieldKindMap = {
26230
26263
  view: "purple",
26231
26264
  dimension: "cyan",
26232
26265
  measure: "green",
26266
+ calculate: "green",
26233
26267
  join: void 0
26234
26268
  };
26235
26269
  const relationshipMap = {
@@ -26239,6 +26273,7 @@ const relationshipMap = {
26239
26273
  };
26240
26274
  function FieldToken({
26241
26275
  field,
26276
+ additionalSiblings,
26242
26277
  hoverActions,
26243
26278
  hoverActionsVisible,
26244
26279
  ...props2
@@ -26263,7 +26298,7 @@ function FieldToken({
26263
26298
  color: fieldKindToColor(field.kind),
26264
26299
  icon: fieldToIcon(field),
26265
26300
  ...props2
26266
- }), hoverActions && /* @__PURE__ */ jsx("div", {
26301
+ }), additionalSiblings, hoverActions && /* @__PURE__ */ jsx("div", {
26267
26302
  ...{
26268
26303
  className: "mly1vsucm1 mly2lah0s"
26269
26304
  },
@@ -30599,6 +30634,12 @@ const styles$s = {
30599
30634
  justifyContent: "mly1rfj78v",
30600
30635
  $$css: true
30601
30636
  },
30637
+ nest: {
30638
+ gridColumn: "mly623te4",
30639
+ gridColumnStart: null,
30640
+ gridColumnEnd: null,
30641
+ $$css: true
30642
+ },
30602
30643
  heading: {
30603
30644
  gridColumn: "mly623te4",
30604
30645
  gridColumnStart: null,
@@ -31111,6 +31152,20 @@ const colorVariants = {
31111
31152
  $$css: true
31112
31153
  }
31113
31154
  };
31155
+ function setAtPath(current, path, value) {
31156
+ const newCurrent = {
31157
+ ...current
31158
+ };
31159
+ let target = newCurrent;
31160
+ for (let i2 = 0; i2 < path.length - 1; i2++) {
31161
+ if (typeof target[path[i2]] !== "object") {
31162
+ target[path[i2]] = {};
31163
+ }
31164
+ target = target[path[i2]];
31165
+ }
31166
+ target[path[path.length - 1]] = value;
31167
+ return newCurrent;
31168
+ }
31114
31169
  function OneOfEditor({
31115
31170
  view,
31116
31171
  name,
@@ -31156,6 +31211,15 @@ function OneOfEditor({
31156
31211
  current,
31157
31212
  option: subOption
31158
31213
  }, key2);
31214
+ case "object":
31215
+ return /* @__PURE__ */ jsx(OneOfObjectEditor, {
31216
+ view,
31217
+ name,
31218
+ path,
31219
+ updateCurrent,
31220
+ current,
31221
+ option: subOption
31222
+ }, key2);
31159
31223
  }
31160
31224
  return null;
31161
31225
  })]
@@ -31265,7 +31329,7 @@ function OneOfNumberEditor({
31265
31329
  valueAsNumber
31266
31330
  }
31267
31331
  }) => {
31268
- setValue(value);
31332
+ setValue(valueAsNumber);
31269
31333
  updateCurrent(path, valueAsNumber);
31270
31334
  },
31271
31335
  ..._stylex.props(styles$s.input)
@@ -31304,6 +31368,48 @@ function OneOfArrayEditor({
31304
31368
  }), /* @__PURE__ */ jsx("div", {})]
31305
31369
  });
31306
31370
  }
31371
+ function OneOfObjectEditor({
31372
+ path,
31373
+ current,
31374
+ option: option2,
31375
+ updateCurrent,
31376
+ view
31377
+ }) {
31378
+ const isObject2 = current != null && typeof current === "object" && !Array.isArray(current);
31379
+ const [objectValue, setObjectValue] = useState(isObject2 ? current : {});
31380
+ return /* @__PURE__ */ jsxs(Fragment, {
31381
+ children: [/* @__PURE__ */ jsx("div", {
31382
+ ..._stylex.props(styles$s.left),
31383
+ children: /* @__PURE__ */ jsx("input", {
31384
+ type: "radio",
31385
+ checked: isObject2,
31386
+ onChange: ({
31387
+ target: {
31388
+ checked
31389
+ }
31390
+ }) => {
31391
+ if (checked) {
31392
+ updateCurrent(path, objectValue);
31393
+ }
31394
+ }
31395
+ })
31396
+ }), /* @__PURE__ */ jsx("div", {
31397
+ ..._stylex.props(styles$s.nest, styles$s.editorGrid),
31398
+ children: /* @__PURE__ */ jsx(ObjectEditor, {
31399
+ current: objectValue,
31400
+ updateCurrent: (path2, value) => {
31401
+ const [_2, ...subPath] = path2;
31402
+ setObjectValue(setAtPath(objectValue, subPath, value));
31403
+ updateCurrent(path2, value);
31404
+ },
31405
+ view,
31406
+ name: "",
31407
+ path,
31408
+ option: option2
31409
+ })
31410
+ })]
31411
+ });
31412
+ }
31307
31413
  function ArrayEditor({
31308
31414
  name,
31309
31415
  path,
@@ -31334,6 +31440,7 @@ function NumberEditor$1({
31334
31440
  option: option2,
31335
31441
  updateCurrent
31336
31442
  }) {
31443
+ const [value, setValue] = React.useState(current ?? option2.minimum);
31337
31444
  return /* @__PURE__ */ jsxs(Fragment, {
31338
31445
  children: [/* @__PURE__ */ jsx("div", {
31339
31446
  ..._stylex.props(styles$s.left, styles$s.label),
@@ -31341,7 +31448,7 @@ function NumberEditor$1({
31341
31448
  children: [option2.title ?? name, ":"]
31342
31449
  })
31343
31450
  }), /* @__PURE__ */ jsx("input", {
31344
- value: current,
31451
+ value,
31345
31452
  type: "number",
31346
31453
  min: option2.minimum,
31347
31454
  max: option2.maximum,
@@ -31350,6 +31457,7 @@ function NumberEditor$1({
31350
31457
  valueAsNumber
31351
31458
  }
31352
31459
  }) => {
31460
+ setValue(valueAsNumber);
31353
31461
  updateCurrent(path, valueAsNumber);
31354
31462
  },
31355
31463
  ..._stylex.props(styles$s.input)
@@ -31548,11 +31656,12 @@ function ObjectEditor({
31548
31656
  option: option2,
31549
31657
  updateCurrent
31550
31658
  }) {
31551
- const [isExpanded, setIsExpanded] = useState(path.length === 0);
31659
+ const [isExpanded, setIsExpanded] = useState(path.length === 0 || !name);
31552
31660
  return /* @__PURE__ */ jsxs(Fragment, {
31553
31661
  children: [name ? /* @__PURE__ */ jsxs(Fragment, {
31554
31662
  children: [/* @__PURE__ */ jsxs("div", {
31555
31663
  ..._stylex.props(styles$s.label, styles$s.heading),
31664
+ onClick: () => setIsExpanded(!isExpanded),
31556
31665
  children: [/* @__PURE__ */ jsx("label", {
31557
31666
  children: option2.title ?? name
31558
31667
  }), option2.description ? /* @__PURE__ */ jsx(InfoHover, {
@@ -31644,31 +31753,20 @@ function ObjectEditor({
31644
31753
  });
31645
31754
  }
31646
31755
  function VizEditor({
31647
- rootQuery,
31648
31756
  view,
31649
31757
  plugin,
31650
31758
  setOpen
31651
31759
  }) {
31652
- const {
31653
- setQuery
31654
- } = useContext(QueryEditorContext);
31760
+ const updateQuery = useUpdateQuery();
31655
31761
  const [current, setCurrent] = useState(plugin.getSettings());
31656
- console.info("RendererEditor current settings:", current);
31657
31762
  const schema = plugin.getSchema();
31658
31763
  const updateCurrent = (path, value) => {
31659
- const newCurrent = {
31660
- ...current
31661
- };
31662
- let target = newCurrent;
31663
- for (let i2 = 0; i2 < path.length - 1; i2++) {
31664
- if (!(path[i2] in target)) {
31665
- target[path[i2]] = {};
31666
- }
31667
- target = target[path[i2]];
31668
- }
31669
- target[path[path.length - 1]] = value;
31764
+ const newCurrent = setAtPath(current, path, value);
31670
31765
  setCurrent(newCurrent);
31671
31766
  };
31767
+ React.useEffect(() => {
31768
+ console.info("RendererEditor current settings:", current);
31769
+ }, [current]);
31672
31770
  return /* @__PURE__ */ jsxs("div", {
31673
31771
  ..._stylex.props(styles$s.editor),
31674
31772
  children: [/* @__PURE__ */ jsx("div", {
@@ -31703,7 +31801,7 @@ function VizEditor({
31703
31801
  view.getOrAddAnnotations().add(new ASTAnnotation({
31704
31802
  value
31705
31803
  }));
31706
- setQuery == null ? void 0 : setQuery(rootQuery.build());
31804
+ updateQuery();
31707
31805
  setOpen(false);
31708
31806
  },
31709
31807
  customStyle: styles$s.editorCell
@@ -31916,7 +32014,6 @@ const dialogStyles = {
31916
32014
  }
31917
32015
  };
31918
32016
  function VizEditorDialog({
31919
- rootQuery,
31920
32017
  plugin,
31921
32018
  view,
31922
32019
  customStyle,
@@ -31946,7 +32043,6 @@ function VizEditorDialog({
31946
32043
  ..._stylex.props(dialogStyles.displayNone),
31947
32044
  children: "Edit visualization parameters"
31948
32045
  }), /* @__PURE__ */ jsx(VizEditor, {
31949
- rootQuery,
31950
32046
  view,
31951
32047
  plugin,
31952
32048
  setOpen
@@ -31965,12 +32061,9 @@ const styles$p = {
31965
32061
  }
31966
32062
  };
31967
32063
  function Visualization$1({
31968
- rootQuery,
31969
32064
  view
31970
32065
  }) {
31971
- const {
31972
- setQuery
31973
- } = useContext(QueryEditorContext);
32066
+ const updateQuery = useUpdateQuery();
31974
32067
  const renderer = useMemo(() => new MalloyRenderer(), []);
31975
32068
  const [currentRenderer, setCurrentRenderer] = useState("table");
31976
32069
  const [plugin, setPlugin] = useState();
@@ -32015,7 +32108,7 @@ function Visualization$1({
32015
32108
  }, [renderer, view, tag]);
32016
32109
  const updateViz = (renderer2) => {
32017
32110
  view.setTagProperty(["viz"], renderer2, RENDERER_PREFIX);
32018
- setQuery == null ? void 0 : setQuery(rootQuery.build());
32111
+ updateQuery();
32019
32112
  };
32020
32113
  const items = VIZ_RENDERERS.map((viz) => ({
32021
32114
  icon: /* @__PURE__ */ jsx(Icon, {
@@ -32054,7 +32147,6 @@ function Visualization$1({
32054
32147
  }), /* @__PURE__ */ jsx(VizEditorDialog, {
32055
32148
  open,
32056
32149
  setOpen,
32057
- rootQuery,
32058
32150
  plugin,
32059
32151
  view
32060
32152
  })]
@@ -32197,9 +32289,7 @@ function TopValuesTable({
32197
32289
  field,
32198
32290
  path
32199
32291
  }) {
32200
- const {
32201
- topValues
32202
- } = useContext(QueryEditorContext);
32292
+ const topValues = useTopValues();
32203
32293
  const fieldPath = [...path, field.name].join(".");
32204
32294
  const fieldTopValues = topValues == null ? void 0 : topValues.find((entry) => entry.fieldName === fieldPath);
32205
32295
  if (!fieldTopValues) {
@@ -32572,9 +32662,7 @@ function BooleanFilterCore({
32572
32662
  });
32573
32663
  }
32574
32664
  function useSearch(searchTerm, fieldPath) {
32575
- const {
32576
- topValues
32577
- } = useContext(QueryEditorContext);
32665
+ const topValues = useTopValues();
32578
32666
  if (topValues && searchTerm) {
32579
32667
  let searchValues = topValues;
32580
32668
  if (fieldPath) {
@@ -33976,6 +34064,42 @@ const styles$g = {
33976
34064
  $$css: true
33977
34065
  }
33978
34066
  };
34067
+ const getPrimaryAxis = (view) => {
34068
+ const schema = view.getOutputSchema();
34069
+ return getPrimaryAxisFromSchema(schema);
34070
+ };
34071
+ const getPrimaryAxisFromSchema = (schema) => {
34072
+ let primaryAxisField = void 0;
34073
+ primaryAxisField = findAxisFieldByAnnotation(schema.fields) || findAxisFieldByType(schema.fields) || findDefaultAxisField(schema.fields);
34074
+ return primaryAxisField;
34075
+ };
34076
+ const findAxisFieldByAnnotation = (fields) => {
34077
+ return fields.find((field) => {
34078
+ if (field.kind === "dimension" && field.annotations && field.annotations.find((annotation) => annotation.value === "# x")) {
34079
+ return true;
34080
+ }
34081
+ return false;
34082
+ });
34083
+ };
34084
+ const findAxisFieldByType = (fields) => {
34085
+ return fields.find((field) => {
34086
+ if (field.kind === "dimension") {
34087
+ const dimension = field;
34088
+ if (dimension.type.kind === "date_type" || dimension.type.kind === "timestamp_type") {
34089
+ return true;
34090
+ }
34091
+ }
34092
+ return false;
34093
+ });
34094
+ };
34095
+ const findDefaultAxisField = (fields) => {
34096
+ return fields.find((field) => {
34097
+ if (field.kind === "dimension") {
34098
+ return true;
34099
+ }
34100
+ return false;
34101
+ });
34102
+ };
33979
34103
  function toFullName(path, name) {
33980
34104
  return [...path || [], name].join(".");
33981
34105
  }
@@ -34054,6 +34178,34 @@ function addGroupBy(view, field, path) {
34054
34178
  segment.addTimestampGroupBy(field.name, path, "second");
34055
34179
  } else {
34056
34180
  segment.addGroupBy(field.name, path, rename);
34181
+ recomputePartitionByAndPrimaryAxis(segment);
34182
+ }
34183
+ }
34184
+ function recomputePartitionByAndPrimaryAxis(segment) {
34185
+ var _a2;
34186
+ const primaryAxis = getPrimaryAxisFromSchema(segment.getOutputSchema());
34187
+ const groupBys = segment.operations.items.filter((op) => op.kind === "group_by");
34188
+ const movingAverages = segment.operations.items.filter((op) => op.kind === "calculate" && op.expression.kind === "moving_average");
34189
+ const canSmooth = primaryAxis !== null && (primaryAxis == null ? void 0 : primaryAxis.kind) === "dimension" && (primaryAxis.type.kind === "timestamp_type" || primaryAxis.type.kind === "date_type");
34190
+ if (!canSmooth) {
34191
+ movingAverages.forEach((operation) => {
34192
+ operation.delete();
34193
+ segment.addAggregate(operation.getFieldInfo().name);
34194
+ });
34195
+ } else {
34196
+ const nonPrimaryGroupByNames = groupBys.filter((gb) => gb.name !== primaryAxis.name);
34197
+ movingAverages.forEach((operation) => {
34198
+ operation.expression.edit();
34199
+ operation.expression.setPartitionFields(nonPrimaryGroupByNames.map((gb) => gb.field.getReference()).filter((ref) => !!ref));
34200
+ });
34201
+ const primaryTimeAxisOperation = groupBys.find((gb) => gb.name === primaryAxis.name);
34202
+ if (primaryTimeAxisOperation) {
34203
+ const expression = (_a2 = primaryTimeAxisOperation.field) == null ? void 0 : _a2.expression;
34204
+ if (expression && expression.kind === "time_truncation") {
34205
+ const truncationExpression = primaryTimeAxisOperation.field.expression;
34206
+ truncationExpression.truncation = "day";
34207
+ }
34208
+ }
34057
34209
  }
34058
34210
  }
34059
34211
  function addAggregate(view, field, path) {
@@ -34165,16 +34317,13 @@ function OperationActionTitle({
34165
34317
  });
34166
34318
  }
34167
34319
  function RenameDialog({
34168
- rootQuery,
34169
34320
  view,
34170
34321
  target,
34171
34322
  open,
34172
34323
  setOpen
34173
34324
  }) {
34174
34325
  const [name, setName] = useState("");
34175
- const {
34176
- setQuery
34177
- } = useContext(QueryEditorContext);
34326
+ const updateQuery = useUpdateQuery();
34178
34327
  useEffect(() => {
34179
34328
  if (target) {
34180
34329
  setName(target.name);
@@ -34184,8 +34333,9 @@ function RenameDialog({
34184
34333
  return null;
34185
34334
  }
34186
34335
  const onRename = () => {
34336
+ target.edit();
34187
34337
  target.name = name;
34188
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34338
+ updateQuery();
34189
34339
  setOpen(false);
34190
34340
  };
34191
34341
  const {
@@ -34248,15 +34398,12 @@ function RenameDialog({
34248
34398
  });
34249
34399
  }
34250
34400
  function SortableOperations({
34251
- rootQuery,
34252
34401
  segment,
34253
34402
  view,
34254
34403
  operations,
34255
34404
  kind
34256
34405
  }) {
34257
- const {
34258
- setQuery
34259
- } = useContext(QueryEditorContext);
34406
+ const updateQuery = useUpdateQuery();
34260
34407
  const sensors = useSensors(useSensor(PointerSensor));
34261
34408
  const items = useMemo(() => {
34262
34409
  return operations.map((operation) => ({
@@ -34278,7 +34425,7 @@ function SortableOperations({
34278
34425
  const oldIndex = names.indexOf(active.id);
34279
34426
  const newIndex = names.indexOf(over.id);
34280
34427
  segment.reorderFields(arrayMove(names, oldIndex, newIndex));
34281
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34428
+ updateQuery();
34282
34429
  }
34283
34430
  }
34284
34431
  const {
@@ -34290,7 +34437,7 @@ function SortableOperations({
34290
34437
  types: ["dimension"],
34291
34438
  onClick: (field, path) => {
34292
34439
  addGroupBy(view, field, path);
34293
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34440
+ updateQuery();
34294
34441
  }
34295
34442
  } : {
34296
34443
  title: "aggregate",
@@ -34298,12 +34445,11 @@ function SortableOperations({
34298
34445
  types: ["measure"],
34299
34446
  onClick: (field, path) => {
34300
34447
  addAggregate(view, field, path);
34301
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34448
+ updateQuery();
34302
34449
  }
34303
34450
  };
34304
34451
  return /* @__PURE__ */ jsxs("div", {
34305
34452
  children: [/* @__PURE__ */ jsx(OperationActionTitle, {
34306
- rootQuery,
34307
34453
  view,
34308
34454
  fields,
34309
34455
  ...props2
@@ -34316,7 +34462,6 @@ function SortableOperations({
34316
34462
  children: /* @__PURE__ */ jsx(SortableContext, {
34317
34463
  items,
34318
34464
  children: items.map((item) => /* @__PURE__ */ jsx(SortableOperation, {
34319
- rootQuery,
34320
34465
  id: item.id,
34321
34466
  color: kind === "group_by" ? "cyan" : "green",
34322
34467
  view,
@@ -34329,18 +34474,16 @@ function SortableOperations({
34329
34474
  }
34330
34475
  const NULL_PATH = [];
34331
34476
  function SortableOperation({
34332
- rootQuery,
34333
34477
  id,
34334
34478
  view,
34335
34479
  operation,
34336
34480
  color
34337
34481
  }) {
34338
34482
  var _a2;
34339
- const {
34340
- setQuery
34341
- } = useContext(QueryEditorContext);
34483
+ const updateQuery = useUpdateQuery();
34342
34484
  const fieldInfo = operation.getFieldInfo();
34343
- const path = ((_a2 = operation.field.getReference()) == null ? void 0 : _a2.path) ?? NULL_PATH;
34485
+ const field = operation instanceof ASTCalculateViewOperation ? null : operation.field;
34486
+ const path = operation instanceof ASTCalculateViewOperation ? operation.expression.node.field_reference.path ?? NULL_PATH : ((_a2 = operation.field.getReference()) == null ? void 0 : _a2.path) ?? NULL_PATH;
34344
34487
  const {
34345
34488
  attributes,
34346
34489
  listeners,
@@ -34360,6 +34503,18 @@ function SortableOperation({
34360
34503
  transform: CSS$1.Transform.toString(transform2),
34361
34504
  transition
34362
34505
  };
34506
+ const primaryAxis = useMemo(() => {
34507
+ return getPrimaryAxis(view);
34508
+ }, [view]);
34509
+ const canSmooth = operation.kind === "aggregate" && primaryAxis !== null && (primaryAxis == null ? void 0 : primaryAxis.kind) === "dimension" && (primaryAxis.type.kind === "timestamp_type" || primaryAxis.type.kind === "date_type");
34510
+ const enableSmoothing = useCallback((operation2) => {
34511
+ if (!canSmooth) {
34512
+ return;
34513
+ }
34514
+ operation2.convertToCalculateMovingAverage(operation2.name + "_smoothed", 7);
34515
+ recomputePartitionByAndPrimaryAxis(view.getOrAddDefaultSegment());
34516
+ updateQuery();
34517
+ }, [canSmooth, updateQuery, view]);
34363
34518
  const hoverActions = useMemo(() => {
34364
34519
  return /* @__PURE__ */ jsxs(Fragment, {
34365
34520
  children: [/* @__PURE__ */ jsx(DropdownMenu, {
@@ -34370,7 +34525,14 @@ function SortableOperation({
34370
34525
  tooltip: "More Actions"
34371
34526
  }),
34372
34527
  onOpenChange: setHoverActionsVisible,
34373
- children: [/* @__PURE__ */ jsx(DropdownMenuItem, {
34528
+ children: [canSmooth ? /* @__PURE__ */ jsx(DropdownMenuItem, {
34529
+ label: "Add smoothing",
34530
+ onClick: () => {
34531
+ if (operation instanceof ASTAggregateViewOperation) {
34532
+ enableSmoothing(operation);
34533
+ }
34534
+ }
34535
+ }, "smoothing") : null, /* @__PURE__ */ jsx(DropdownMenuItem, {
34374
34536
  label: "Rename",
34375
34537
  onClick: () => {
34376
34538
  setRenameTarget(operation);
@@ -34380,12 +34542,21 @@ function SortableOperation({
34380
34542
  }, [...path, fieldInfo.name].join(".")), /* @__PURE__ */ jsx(ClearButton, {
34381
34543
  onClick: () => {
34382
34544
  operation.delete();
34383
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34545
+ recomputePartitionByAndPrimaryAxis(view.getOrAddDefaultSegment());
34546
+ updateQuery();
34384
34547
  }
34385
34548
  })]
34386
34549
  });
34387
- }, [fieldInfo, operation, path, rootQuery, setQuery]);
34388
- const granular = granularityMenuItems(fieldInfo, operation.field);
34550
+ }, [canSmooth, enableSmoothing, fieldInfo.name, operation, path, updateQuery, view]);
34551
+ const hasSmoothedField = useMemo(() => {
34552
+ return view.getOrAddDefaultSegment().operations.items.some((operation2) => {
34553
+ return operation2.kind === "calculate";
34554
+ });
34555
+ }, [view]);
34556
+ const granular = granularityMenuItems(fieldInfo, field);
34557
+ if (hasSmoothedField && granular && operation.name === (primaryAxis == null ? void 0 : primaryAxis.name)) {
34558
+ granular.options = granular.options.filter((option2) => option2.value === "day");
34559
+ }
34389
34560
  let icon = "orderBy";
34390
34561
  if (fieldInfo.kind === "dimension" || fieldInfo.kind === "measure") {
34391
34562
  icon = atomicTypeToIcon(fieldInfo.type.kind);
@@ -34394,7 +34565,7 @@ function SortableOperation({
34394
34565
  id,
34395
34566
  ref: setNodeRef,
34396
34567
  style,
34397
- children: [granular ? /* @__PURE__ */ jsxs("div", {
34568
+ children: [field && granular ? /* @__PURE__ */ jsxs("div", {
34398
34569
  ...{
34399
34570
  0: {
34400
34571
  className: "mly78zum5 mly6s0dn4 mly1nhvcw1 mly1jnr06f mly11ogjb6 mly1g9of4s"
@@ -34417,8 +34588,8 @@ function SortableOperation({
34417
34588
  color,
34418
34589
  value: granular.value,
34419
34590
  onChange: (granulation) => {
34420
- if (operation.field.expression instanceof ASTTimeTruncationExpression) operation.field.expression.truncation = granulation;
34421
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34591
+ if (field.expression instanceof ASTTimeTruncationExpression) field.expression.truncation = granulation;
34592
+ updateQuery();
34422
34593
  },
34423
34594
  items: granular.options
34424
34595
  })]
@@ -34428,7 +34599,7 @@ function SortableOperation({
34428
34599
  },
34429
34600
  children: hoverActions
34430
34601
  })]
34431
- }) : /* @__PURE__ */ jsx(FieldToken, {
34602
+ }) : operation instanceof ASTCalculateViewOperation ? /* @__PURE__ */ jsx(FieldToken, {
34432
34603
  field: fieldInfo,
34433
34604
  color,
34434
34605
  hoverActionsVisible,
@@ -34445,9 +34616,67 @@ function SortableOperation({
34445
34616
  dragProps: {
34446
34617
  attributes,
34447
34618
  listeners
34448
- }
34619
+ },
34620
+ additionalSiblings: /* @__PURE__ */ jsx(SelectorToken, {
34621
+ color,
34622
+ value: "" + (operation.expression.node.rows_preceding ?? 7),
34623
+ onChange: (value) => {
34624
+ if (value === "1") {
34625
+ view.getOrAddDefaultSegment().operations.add(new ASTAggregateViewOperation({
34626
+ kind: "aggregate",
34627
+ field: {
34628
+ expression: {
34629
+ kind: "field_reference",
34630
+ name: operation.expression.node.field_reference.name
34631
+ }
34632
+ }
34633
+ }));
34634
+ operation.delete();
34635
+ updateQuery();
34636
+ } else {
34637
+ operation.expression.edit();
34638
+ operation.expression.rowsPreceding = parseInt(value, 10);
34639
+ updateQuery();
34640
+ }
34641
+ },
34642
+ items: [{
34643
+ label: "7d",
34644
+ value: "7"
34645
+ }, {
34646
+ label: "14d",
34647
+ value: "14"
34648
+ }, {
34649
+ label: "28d",
34650
+ value: "28"
34651
+ }, {
34652
+ label: "30d",
34653
+ value: "30"
34654
+ }, {
34655
+ label: "Remove smoothing",
34656
+ value: "1"
34657
+ }]
34658
+ })
34659
+ }) : /* @__PURE__ */ jsx(Fragment, {
34660
+ children: /* @__PURE__ */ jsx(FieldToken, {
34661
+ field: fieldInfo,
34662
+ color,
34663
+ hoverActionsVisible,
34664
+ hoverActions,
34665
+ tooltip: /* @__PURE__ */ jsx(FieldHoverCard, {
34666
+ field: fieldInfo,
34667
+ path
34668
+ }),
34669
+ tooltipProps: {
34670
+ side: "right",
34671
+ align: "start",
34672
+ alignOffset: 28
34673
+ },
34674
+ dragProps: {
34675
+ attributes,
34676
+ listeners
34677
+ }
34678
+ })
34449
34679
  }), /* @__PURE__ */ jsx(RenameDialog, {
34450
- rootQuery,
34451
34680
  view,
34452
34681
  target: renameTarget,
34453
34682
  open: renameOpen,
@@ -34458,7 +34687,7 @@ function SortableOperation({
34458
34687
  const DateGranulation = ["day", "week", "month", "quarter", "year"];
34459
34688
  const TimestampGranulation = ["second", "minute", "hour", "day", "week", "month", "quarter", "year"];
34460
34689
  function granularityMenuItems(fieldInfo, field) {
34461
- if (fieldInfo.kind !== "dimension" || !(field.expression instanceof ASTTimeTruncationExpression)) {
34690
+ if (!field || fieldInfo.kind !== "dimension" || !(field.expression instanceof ASTTimeTruncationExpression)) {
34462
34691
  return null;
34463
34692
  }
34464
34693
  if (fieldInfo.type.kind === "timestamp_type") {
@@ -34488,13 +34717,11 @@ const customStyles = {
34488
34717
  }
34489
34718
  };
34490
34719
  function GroupByOperations({
34491
- rootQuery,
34492
34720
  segment,
34493
34721
  view,
34494
34722
  groupBys
34495
34723
  }) {
34496
34724
  return /* @__PURE__ */ jsx(SortableOperations, {
34497
- rootQuery,
34498
34725
  segment,
34499
34726
  view,
34500
34727
  operations: groupBys,
@@ -34737,12 +34964,9 @@ function displayTimeFromMoment(momentObj) {
34737
34964
  return momentObj.moment;
34738
34965
  }
34739
34966
  function FilterOperations({
34740
- rootQuery,
34741
34967
  filters
34742
34968
  }) {
34743
- const {
34744
- setQuery
34745
- } = useContext(QueryEditorContext);
34969
+ const updateQuery = useUpdateQuery();
34746
34970
  if (filters.length === 0) {
34747
34971
  return null;
34748
34972
  }
@@ -34758,13 +34982,12 @@ function FilterOperations({
34758
34982
  children: ["Invalid filter", /* @__PURE__ */ jsx(ClearButton, {
34759
34983
  onClick: () => {
34760
34984
  filterOperation.delete();
34761
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34985
+ updateQuery();
34762
34986
  }
34763
34987
  })]
34764
34988
  }),
34765
34989
  children: /* @__PURE__ */ jsx(SingleFilterOperation, {
34766
- filterOperation,
34767
- rootQuery
34990
+ filterOperation
34768
34991
  })
34769
34992
  }, key2);
34770
34993
  })
@@ -34772,18 +34995,15 @@ function FilterOperations({
34772
34995
  });
34773
34996
  }
34774
34997
  function SingleFilterOperation({
34775
- rootQuery,
34776
34998
  filterOperation
34777
34999
  }) {
34778
- const {
34779
- setQuery
34780
- } = useContext(QueryEditorContext);
35000
+ const updateQuery = useUpdateQuery();
34781
35001
  const setFilter = useCallback((filter2) => {
34782
35002
  if (filterOperation.filter instanceof ASTFilterWithFilterString) {
34783
35003
  filterOperation.filter.setFilter(filter2);
34784
35004
  }
34785
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34786
- }, [filterOperation.filter, rootQuery, setQuery]);
35005
+ updateQuery();
35006
+ }, [filterOperation.filter, updateQuery]);
34787
35007
  const {
34788
35008
  filter
34789
35009
  } = filterOperation;
@@ -34827,19 +35047,16 @@ function SingleFilterOperation({
34827
35047
  children: /* @__PURE__ */ jsx(ClearButton, {
34828
35048
  onClick: () => {
34829
35049
  filterOperation.delete();
34830
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35050
+ updateQuery();
34831
35051
  }
34832
35052
  })
34833
35053
  })]
34834
35054
  });
34835
35055
  }
34836
35056
  function LimitOperation({
34837
- rootQuery,
34838
35057
  limit
34839
35058
  }) {
34840
- const {
34841
- setQuery
34842
- } = useContext(QueryEditorContext);
35059
+ const updateQuery = useUpdateQuery();
34843
35060
  if (!limit) {
34844
35061
  return null;
34845
35062
  }
@@ -34854,7 +35071,7 @@ function LimitOperation({
34854
35071
  value: limit.limit,
34855
35072
  onChange: (value) => {
34856
35073
  limit.limit = value;
34857
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35074
+ updateQuery();
34858
35075
  },
34859
35076
  errorMessage: limit.limit < 0 ? "Limit must be positive" : void 0
34860
35077
  }), /* @__PURE__ */ jsx("div", {
@@ -34862,7 +35079,7 @@ function LimitOperation({
34862
35079
  children: /* @__PURE__ */ jsx(ClearButton, {
34863
35080
  onClick: () => {
34864
35081
  limit.delete();
34865
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35082
+ updateQuery();
34866
35083
  }
34867
35084
  })
34868
35085
  })]
@@ -34870,13 +35087,11 @@ function LimitOperation({
34870
35087
  });
34871
35088
  }
34872
35089
  function AggregateOperations({
34873
- rootQuery,
34874
35090
  segment,
34875
35091
  view,
34876
35092
  aggregates
34877
35093
  }) {
34878
35094
  return /* @__PURE__ */ jsx(SortableOperations, {
34879
- rootQuery,
34880
35095
  segment,
34881
35096
  view,
34882
35097
  operations: aggregates,
@@ -34884,12 +35099,9 @@ function AggregateOperations({
34884
35099
  });
34885
35100
  }
34886
35101
  function OrderByOperations({
34887
- rootQuery,
34888
35102
  orderBys
34889
35103
  }) {
34890
- const {
34891
- setQuery
34892
- } = useContext(QueryEditorContext);
35104
+ const updateQuery = useUpdateQuery();
34893
35105
  if (orderBys.length === 0) {
34894
35106
  return null;
34895
35107
  }
@@ -34929,7 +35141,7 @@ function OrderByOperations({
34929
35141
  value: orderBy.direction ?? "asc",
34930
35142
  onChange: (direction) => {
34931
35143
  orderBy.direction = direction;
34932
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35144
+ updateQuery();
34933
35145
  }
34934
35146
  })]
34935
35147
  }), /* @__PURE__ */ jsx("div", {
@@ -34937,7 +35149,7 @@ function OrderByOperations({
34937
35149
  children: /* @__PURE__ */ jsx(ClearButton, {
34938
35150
  onClick: () => {
34939
35151
  orderBy.delete();
34940
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35152
+ updateQuery();
34941
35153
  }
34942
35154
  })
34943
35155
  })]
@@ -34947,7 +35159,6 @@ function OrderByOperations({
34947
35159
  });
34948
35160
  }
34949
35161
  function View({
34950
- rootQuery,
34951
35162
  view
34952
35163
  }) {
34953
35164
  return /* @__PURE__ */ jsxs("div", {
@@ -34957,10 +35168,8 @@ function View({
34957
35168
  gap: 8
34958
35169
  },
34959
35170
  children: [/* @__PURE__ */ jsx(Visualization$1, {
34960
- rootQuery,
34961
35171
  view
34962
35172
  }), /* @__PURE__ */ jsx(ViewDefinition, {
34963
- rootQuery,
34964
35173
  view,
34965
35174
  viewDef: view.definition
34966
35175
  })]
@@ -35025,12 +35234,9 @@ const styles$f = {
35025
35234
  }
35026
35235
  };
35027
35236
  function AddLimit({
35028
- rootQuery,
35029
35237
  view
35030
35238
  }) {
35031
- const {
35032
- setQuery
35033
- } = useContext(QueryEditorContext);
35239
+ const updateQuery = useUpdateQuery();
35034
35240
  const segment = getSegmentIfPresent(view);
35035
35241
  const hasLimit = segment ? segmentHasLimit(segment) : false;
35036
35242
  return /* @__PURE__ */ jsx(AddItem, {
@@ -35042,17 +35248,14 @@ function AddLimit({
35042
35248
  onClick: () => {
35043
35249
  const segment2 = view.getOrAddDefaultSegment();
35044
35250
  segment2.setLimit(10);
35045
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35251
+ updateQuery();
35046
35252
  }
35047
35253
  });
35048
35254
  }
35049
35255
  function AddEmptyNest({
35050
- rootQuery,
35051
35256
  view
35052
35257
  }) {
35053
- const {
35054
- setQuery
35055
- } = useContext(QueryEditorContext);
35258
+ const updateQuery = useUpdateQuery();
35056
35259
  return /* @__PURE__ */ jsx(AddItem, {
35057
35260
  icon: /* @__PURE__ */ jsx(Icon, {
35058
35261
  name: "nest"
@@ -35062,7 +35265,7 @@ function AddEmptyNest({
35062
35265
  const segment = view.getOrAddDefaultSegment();
35063
35266
  const nestNo = segmentNestNo(segment, `Nest`);
35064
35267
  segment.addEmptyNest(nestNo > 1 ? `Nest ${nestNo}` : `Nest`);
35065
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35268
+ updateQuery();
35066
35269
  }
35067
35270
  });
35068
35271
  }
@@ -35094,13 +35297,10 @@ const styles$e = {
35094
35297
  }
35095
35298
  };
35096
35299
  function AddOrderBy({
35097
- rootQuery,
35098
35300
  view,
35099
35301
  search
35100
35302
  }) {
35101
- const {
35102
- setQuery
35103
- } = useContext(QueryEditorContext);
35303
+ const updateQuery = useUpdateQuery();
35104
35304
  const outputSchemaFields = view.getOutputSchema().fields;
35105
35305
  const segment = getSegmentIfPresent(view);
35106
35306
  const fields = useMemo(() => outputSchemaFields.filter((field) => field.kind === "dimension").filter((field) => ORDERABLE_TYPES$1.includes(field.type.kind)).filter((field) => segment ? !segmentHasOrderBy(segment, field.name) : true), [outputSchemaFields, segment]);
@@ -35112,7 +35312,7 @@ function AddOrderBy({
35112
35312
  types: ["dimension"],
35113
35313
  onAddOperation: (field) => {
35114
35314
  addOrderBy(view, field);
35115
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35315
+ updateQuery();
35116
35316
  },
35117
35317
  disabledMessage: "There must be at least one field in the output to order by.",
35118
35318
  search
@@ -35120,13 +35320,10 @@ function AddOrderBy({
35120
35320
  }
35121
35321
  const ORDERABLE_TYPES$1 = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
35122
35322
  function AddGroupBy({
35123
- rootQuery,
35124
35323
  view,
35125
35324
  search
35126
35325
  }) {
35127
- const {
35128
- setQuery
35129
- } = useContext(QueryEditorContext);
35326
+ const updateQuery = useUpdateQuery();
35130
35327
  const {
35131
35328
  fields
35132
35329
  } = getInputSchemaFromViewParent(view);
@@ -35143,19 +35340,16 @@ function AddGroupBy({
35143
35340
  filter,
35144
35341
  onAddOperation: (field, path) => {
35145
35342
  addGroupBy(view, field, path);
35146
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35343
+ updateQuery();
35147
35344
  },
35148
35345
  search
35149
35346
  });
35150
35347
  }
35151
35348
  function AddAggregate({
35152
- rootQuery,
35153
35349
  view,
35154
35350
  search
35155
35351
  }) {
35156
- const {
35157
- setQuery
35158
- } = useContext(QueryEditorContext);
35352
+ const updateQuery = useUpdateQuery();
35159
35353
  const {
35160
35354
  fields
35161
35355
  } = getInputSchemaFromViewParent(view);
@@ -35172,7 +35366,7 @@ function AddAggregate({
35172
35366
  filter,
35173
35367
  onAddOperation: (field, path) => {
35174
35368
  addAggregate(view, field, path);
35175
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35369
+ updateQuery();
35176
35370
  },
35177
35371
  search
35178
35372
  });
@@ -35181,10 +35375,7 @@ function AddWhere({
35181
35375
  view,
35182
35376
  search
35183
35377
  }) {
35184
- const {
35185
- rootQuery,
35186
- setQuery
35187
- } = React.useContext(QueryEditorContext);
35378
+ const updateQuery = useUpdateQuery();
35188
35379
  const {
35189
35380
  fields
35190
35381
  } = getInputSchemaFromViewParent(view);
@@ -35198,7 +35389,7 @@ function AddWhere({
35198
35389
  onAddOperation: (field, path, filter) => {
35199
35390
  if (filter && (field.kind === "dimension" || field.kind === "measure")) {
35200
35391
  addFilter(view, field, path, filter);
35201
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
35392
+ updateQuery();
35202
35393
  }
35203
35394
  },
35204
35395
  isFilterOperation: true,
@@ -35207,15 +35398,18 @@ function AddWhere({
35207
35398
  }
35208
35399
  const FILTERABLE_TYPES$1 = /* @__PURE__ */ new Set(["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"]);
35209
35400
  function AddView({
35210
- rootQuery,
35211
35401
  view,
35212
35402
  search
35213
35403
  }) {
35214
35404
  const {
35215
- setQuery
35405
+ rootQuery
35216
35406
  } = useContext(QueryEditorContext);
35407
+ const updateQuery = useUpdateQuery();
35217
35408
  const allFields = getInputSchemaFromViewParent(view).fields;
35218
35409
  const fields = useMemo(() => allFields.filter((field) => field.kind === "view" && !isIndexView(field)), [allFields]);
35410
+ if (!rootQuery) {
35411
+ return null;
35412
+ }
35219
35413
  return /* @__PURE__ */ jsx(AddFieldItem, {
35220
35414
  label: "Add view",
35221
35415
  icon: "view",
@@ -35229,20 +35423,17 @@ function AddView({
35229
35423
  } else {
35230
35424
  addNest(view, field);
35231
35425
  }
35232
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35426
+ updateQuery();
35233
35427
  },
35234
35428
  search
35235
35429
  });
35236
35430
  }
35237
35431
  function AddMenu({
35238
- rootQuery,
35239
35432
  view
35240
35433
  }) {
35241
35434
  const [open, setOpen] = useState(false);
35242
35435
  const [active, setActive] = useState("");
35243
- const {
35244
- setQuery
35245
- } = useContext(QueryEditorContext);
35436
+ const updateQuery = useUpdateQuery();
35246
35437
  const [search, setSearch] = useState("");
35247
35438
  const segment = getSegmentIfPresent(view);
35248
35439
  const toggleActive = (toggle) => {
@@ -35306,7 +35497,7 @@ function AddMenu({
35306
35497
  } else {
35307
35498
  addNest(view, field);
35308
35499
  }
35309
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35500
+ updateQuery();
35310
35501
  },
35311
35502
  search
35312
35503
  }), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(ValueList, {
@@ -35322,7 +35513,7 @@ function AddMenu({
35322
35513
  values: [value.fieldValue ?? "∅"]
35323
35514
  }
35324
35515
  });
35325
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35516
+ updateQuery();
35326
35517
  }
35327
35518
  })]
35328
35519
  }) : /* @__PURE__ */ jsxs("div", {
@@ -35359,7 +35550,6 @@ function AddMenu({
35359
35550
  onClick: () => toggleActive("view"),
35360
35551
  open: active === "view"
35361
35552
  }), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(AddLimit, {
35362
- rootQuery,
35363
35553
  view
35364
35554
  }), /* @__PURE__ */ jsx(AddItem, {
35365
35555
  icon: /* @__PURE__ */ jsx(Icon, {
@@ -35369,7 +35559,6 @@ function AddMenu({
35369
35559
  onClick: () => toggleActive("order_by"),
35370
35560
  open: active === "order_by"
35371
35561
  }), /* @__PURE__ */ jsx(AddEmptyNest, {
35372
- rootQuery,
35373
35562
  view
35374
35563
  })]
35375
35564
  }), /* @__PURE__ */ jsxs("div", {
@@ -35378,23 +35567,18 @@ function AddMenu({
35378
35567
  overflowY: "auto"
35379
35568
  },
35380
35569
  children: [active === "group_by" && /* @__PURE__ */ jsx(AddGroupBy, {
35381
- rootQuery,
35382
35570
  view,
35383
35571
  search
35384
35572
  }), active === "aggregate" && /* @__PURE__ */ jsx(AddAggregate, {
35385
- rootQuery,
35386
35573
  view,
35387
35574
  search
35388
35575
  }), active === "where" && /* @__PURE__ */ jsx(AddWhere, {
35389
- rootQuery,
35390
35576
  view,
35391
35577
  search
35392
35578
  }), active === "view" && /* @__PURE__ */ jsx(AddView, {
35393
- rootQuery,
35394
35579
  view,
35395
35580
  search
35396
35581
  }), active === "order_by" && /* @__PURE__ */ jsx(AddOrderBy, {
35397
- rootQuery,
35398
35582
  view,
35399
35583
  search
35400
35584
  })]
@@ -35440,7 +35624,6 @@ function FocusableView({
35440
35624
  });
35441
35625
  }
35442
35626
  function NestOperations({
35443
- rootQuery,
35444
35627
  view,
35445
35628
  nests
35446
35629
  }) {
@@ -35450,20 +35633,16 @@ function NestOperations({
35450
35633
  return /* @__PURE__ */ jsx("div", {
35451
35634
  ..._stylex.props(styles$u.tokenContainer),
35452
35635
  children: nests.map((nest) => /* @__PURE__ */ jsx(NestOperation, {
35453
- rootQuery,
35454
35636
  view,
35455
35637
  nest
35456
35638
  }, nest.name))
35457
35639
  });
35458
35640
  }
35459
35641
  function NestOperation({
35460
- rootQuery,
35461
35642
  view,
35462
35643
  nest
35463
35644
  }) {
35464
- const {
35465
- setQuery
35466
- } = useContext(QueryEditorContext);
35645
+ const updateQuery = useUpdateQuery();
35467
35646
  const [renameOpen, setRenameOpen] = useState(false);
35468
35647
  const parentNestViewPath = useContext(NestViewPathContext);
35469
35648
  const {
@@ -35484,7 +35663,7 @@ function NestOperation({
35484
35663
  onClick: () => {
35485
35664
  focusNestView([...parentNestViewPath]);
35486
35665
  nest2.delete();
35487
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35666
+ updateQuery();
35488
35667
  }
35489
35668
  }), /* @__PURE__ */ jsx(DropdownMenuItem, {
35490
35669
  label: "Rename",
@@ -35493,7 +35672,6 @@ function NestOperation({
35493
35672
  }
35494
35673
  })]
35495
35674
  }), /* @__PURE__ */ jsx(AddMenu, {
35496
- rootQuery,
35497
35675
  view: nest2.view
35498
35676
  })]
35499
35677
  });
@@ -35505,17 +35683,15 @@ function NestOperation({
35505
35683
  },
35506
35684
  children: [/* @__PURE__ */ jsx(CollapsiblePanel, {
35507
35685
  title: nest.name,
35508
- icon: viewToVisualizationIcon(nest.view),
35686
+ icon: tagToVisualization(nest.view.getTag()),
35509
35687
  defaultOpen: true,
35510
35688
  controls: getControls(nest),
35511
35689
  collapsedControls: getControls(nest),
35512
35690
  isFocused: isNestViewFocused([...parentNestViewPath, nest.name]),
35513
35691
  children: /* @__PURE__ */ jsx(View, {
35514
- rootQuery,
35515
35692
  view: nest.view
35516
35693
  })
35517
35694
  }), /* @__PURE__ */ jsx(RenameDialog, {
35518
- rootQuery,
35519
35695
  view,
35520
35696
  target: nest,
35521
35697
  open: renameOpen,
@@ -35525,7 +35701,6 @@ function NestOperation({
35525
35701
  });
35526
35702
  }
35527
35703
  function Operations({
35528
- rootQuery,
35529
35704
  view,
35530
35705
  viewDef
35531
35706
  }) {
@@ -35543,7 +35718,7 @@ function Operations({
35543
35718
  segment.operations.items.forEach((operation) => {
35544
35719
  if (operation instanceof ASTGroupByViewOperation) {
35545
35720
  groupBys.push(operation);
35546
- } else if (operation instanceof ASTAggregateViewOperation) {
35721
+ } else if (operation instanceof ASTAggregateViewOperation || operation instanceof ASTCalculateViewOperation) {
35547
35722
  aggregates.push(operation);
35548
35723
  } else if (operation instanceof ASTWhereViewOperation) {
35549
35724
  filters.push(operation);
@@ -35564,66 +35739,53 @@ function Operations({
35564
35739
  className: "mly1tpqehw mly10lvyaf"
35565
35740
  },
35566
35741
  children: [/* @__PURE__ */ jsx(GroupByOperations, {
35567
- rootQuery,
35568
35742
  segment,
35569
35743
  view,
35570
35744
  groupBys
35571
35745
  }), /* @__PURE__ */ jsx(AggregateOperations, {
35572
- rootQuery,
35573
35746
  segment,
35574
35747
  view,
35575
35748
  aggregates
35576
35749
  }), /* @__PURE__ */ jsx(DrillOperations, {
35577
- rootQuery,
35578
35750
  drills
35579
35751
  }), /* @__PURE__ */ jsx(FilterOperations, {
35580
- rootQuery,
35581
35752
  filters
35582
35753
  }), /* @__PURE__ */ jsx(OrderByOperations, {
35583
- rootQuery,
35584
35754
  orderBys
35585
35755
  }), /* @__PURE__ */ jsx(NestOperations, {
35586
- rootQuery,
35587
35756
  view,
35588
35757
  nests
35589
35758
  }), /* @__PURE__ */ jsx(LimitOperation, {
35590
- rootQuery,
35591
35759
  limit
35592
35760
  })]
35593
35761
  });
35594
35762
  }
35595
35763
  function ViewDefinition({
35596
- rootQuery,
35597
35764
  view,
35598
35765
  viewDef
35599
35766
  }) {
35600
35767
  if (viewDef instanceof ASTArrowViewDefinition) {
35601
35768
  return /* @__PURE__ */ jsx(ViewDefinition, {
35602
- rootQuery,
35603
35769
  view,
35604
35770
  viewDef: viewDef.view
35605
35771
  });
35606
35772
  } else if (viewDef instanceof ASTRefinementViewDefinition) {
35607
35773
  return /* @__PURE__ */ jsxs("div", {
35608
35774
  children: [/* @__PURE__ */ jsx(ViewDefinition, {
35609
- rootQuery,
35610
35775
  view,
35611
35776
  viewDef: viewDef.base
35612
35777
  }), /* @__PURE__ */ jsx(ViewDefinition, {
35613
- rootQuery,
35614
35778
  view,
35615
35779
  viewDef: viewDef.refinement
35616
35780
  })]
35617
35781
  });
35618
35782
  } else if (viewDef instanceof ASTSegmentViewDefinition) {
35619
35783
  return /* @__PURE__ */ jsx(Operations, {
35620
- rootQuery,
35621
35784
  view,
35622
35785
  viewDef
35623
35786
  });
35624
35787
  } else {
35625
35788
  return /* @__PURE__ */ jsx(CollapsingView, {
35626
- rootQuery,
35627
35789
  viewDef
35628
35790
  });
35629
35791
  }
@@ -35692,14 +35854,21 @@ const styles$c = {
35692
35854
  }
35693
35855
  };
35694
35856
  function Query({
35695
- rootQuery,
35696
- query,
35697
- setQuery
35857
+ definition
35698
35858
  }) {
35699
35859
  const {
35700
35860
  focusMainView,
35701
35861
  isMainViewFocused
35702
35862
  } = useQueryFocus();
35863
+ const {
35864
+ rootQuery,
35865
+ setQuery
35866
+ } = useContext(QueryEditorContext);
35867
+ const updateQuery = useUpdateQuery();
35868
+ if (!rootQuery) {
35869
+ return null;
35870
+ }
35871
+ const isEmpty = rootQuery.isEmpty();
35703
35872
  return /* @__PURE__ */ jsx(FocusableView, {
35704
35873
  children: /* @__PURE__ */ jsxs(CollapsiblePanel, {
35705
35874
  title: "Main query",
@@ -35718,44 +35887,41 @@ function Query({
35718
35887
  label: "Clear query",
35719
35888
  onClick: () => {
35720
35889
  focusMainView();
35721
- setQuery == null ? void 0 : setQuery(void 0);
35890
+ setQuery(void 0);
35722
35891
  },
35723
- disabled: rootQuery.isEmpty()
35892
+ disabled: isEmpty
35724
35893
  }), /* @__PURE__ */ jsx(DropdownMenuItem, {
35725
35894
  icon: "nest",
35726
35895
  label: "Nest query",
35727
35896
  onClick: () => {
35728
- if (rootQuery.definition instanceof ASTArrowQueryDefinition) {
35729
- rootQuery.definition.view.convertToNest("Nest");
35897
+ if (definition instanceof ASTArrowQueryDefinition) {
35898
+ definition.view.convertToNest("Nest");
35730
35899
  }
35731
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35900
+ updateQuery();
35732
35901
  },
35733
- disabled: rootQuery.isEmpty() || !(rootQuery.definition instanceof ASTArrowQueryDefinition)
35902
+ disabled: isEmpty || !(definition instanceof ASTArrowQueryDefinition)
35734
35903
  })]
35735
35904
  }) : /* @__PURE__ */ jsx(Fragment, {})
35736
- }), query.definition instanceof ASTArrowQueryDefinition ? /* @__PURE__ */ jsx(AddMenu, {
35737
- rootQuery,
35738
- view: query.definition
35905
+ }), definition instanceof ASTArrowQueryDefinition ? /* @__PURE__ */ jsx(AddMenu, {
35906
+ view: definition
35739
35907
  }) : null]
35740
35908
  }),
35741
35909
  collapsedControls: /* @__PURE__ */ jsx(Icon, {
35742
- name: viewToVisualizationIcon(query)
35910
+ name: tagToVisualization(rootQuery.getTag())
35743
35911
  }),
35744
- children: [query.definition instanceof ASTArrowQueryDefinition ? /* @__PURE__ */ jsxs("div", {
35912
+ children: [definition instanceof ASTArrowQueryDefinition ? /* @__PURE__ */ jsxs("div", {
35745
35913
  style: {
35746
35914
  display: "flex",
35747
35915
  flexDirection: "column",
35748
35916
  gap: 8
35749
35917
  },
35750
- children: [!query.isEmpty() && /* @__PURE__ */ jsx(Visualization$1, {
35751
- rootQuery,
35752
- view: query
35918
+ children: [!isEmpty && /* @__PURE__ */ jsx(Visualization$1, {
35919
+ view: rootQuery
35753
35920
  }), /* @__PURE__ */ jsx(ViewDefinition, {
35754
- rootQuery,
35755
- view: query.definition,
35756
- viewDef: query.definition.view
35921
+ view: definition,
35922
+ viewDef: definition.view
35757
35923
  })]
35758
- }) : null, query.isEmpty() ? /* @__PURE__ */ jsx("div", {
35924
+ }) : null, isEmpty ? /* @__PURE__ */ jsx("div", {
35759
35925
  ...{
35760
35926
  className: "mly78zum5 mlyl56j7k mly6s0dn4 mlyng8ra"
35761
35927
  },
@@ -35777,9 +35943,9 @@ function Query({
35777
35943
  });
35778
35944
  }
35779
35945
  function Source({
35780
- rootQuery
35946
+ definition
35781
35947
  }) {
35782
- if (rootQuery.definition instanceof ASTArrowQueryDefinition) {
35948
+ if (definition instanceof ASTArrowQueryDefinition) {
35783
35949
  return /* @__PURE__ */ jsx("div", {
35784
35950
  ..._stylex.props(styles$u.queryCard, styles$b.content),
35785
35951
  children: /* @__PURE__ */ jsxs("div", {
@@ -35790,7 +35956,7 @@ function Source({
35790
35956
  ...{
35791
35957
  className: "mlyb3r6kr mlylyipyv mly117nqv4"
35792
35958
  },
35793
- children: rootQuery.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource().name
35959
+ children: definition.source.getSourceInfo().name
35794
35960
  })]
35795
35961
  })
35796
35962
  });
@@ -36127,13 +36293,13 @@ function LiteralValueEditor({
36127
36293
  }
36128
36294
  }
36129
36295
  function Parameters({
36130
- rootQuery
36296
+ definition
36131
36297
  }) {
36132
- const {
36133
- setQuery
36134
- } = useContext(QueryEditorContext);
36135
- if (rootQuery.definition instanceof ASTArrowQueryDefinition) {
36136
- const source = rootQuery.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource();
36298
+ const updateQuery = useUpdateQuery();
36299
+ if (definition instanceof ASTArrowQueryDefinition && definition.source instanceof ASTReferenceQueryArrowSource) {
36300
+ const {
36301
+ source
36302
+ } = definition;
36137
36303
  const sourceParameters = source.getSourceParameters();
36138
36304
  if (!sourceParameters || sourceParameters.length === 0) {
36139
36305
  return null;
@@ -36156,7 +36322,7 @@ function Parameters({
36156
36322
  value: ((_a2 = source.tryGetParameter(parameter.name)) == null ? void 0 : _a2.parameter.value) ?? parameter.default_value,
36157
36323
  setValue: (value) => {
36158
36324
  source.setParameter(parameter.name, value);
36159
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36325
+ updateQuery();
36160
36326
  }
36161
36327
  })]
36162
36328
  }, parameter.name);
@@ -36174,23 +36340,23 @@ const styles$9 = {
36174
36340
  };
36175
36341
  function QueryEditor() {
36176
36342
  const {
36177
- rootQuery,
36178
- setQuery
36343
+ rootQuery
36179
36344
  } = useContext(QueryEditorContext);
36180
36345
  if (!rootQuery) {
36181
36346
  console.error("Missing <MalloyExplorerProvider>");
36182
36347
  return null;
36183
36348
  }
36349
+ const {
36350
+ definition
36351
+ } = rootQuery;
36184
36352
  return /* @__PURE__ */ jsxs("div", {
36185
36353
  ..._stylex.props(fontStyles.body, styles$8.main),
36186
36354
  children: [/* @__PURE__ */ jsx(Source, {
36187
- rootQuery
36355
+ definition
36188
36356
  }), /* @__PURE__ */ jsx(Parameters, {
36189
- rootQuery
36357
+ definition
36190
36358
  }), /* @__PURE__ */ jsx(Query, {
36191
- rootQuery,
36192
- query: rootQuery,
36193
- setQuery
36359
+ definition
36194
36360
  })]
36195
36361
  });
36196
36362
  }
@@ -36733,7 +36899,7 @@ function RenderedResult({
36733
36899
  query: stableQuery,
36734
36900
  source
36735
36901
  });
36736
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36902
+ setQuery(rootQuery.build());
36737
36903
  },
36738
36904
  tableConfig: {
36739
36905
  enableDrill: true
@@ -37314,27 +37480,21 @@ function useOperations(view, field, path) {
37314
37480
  return "";
37315
37481
  }, [matchingFieldItem, view, path, field.name, fullName]);
37316
37482
  return {
37317
- isGroupByAllowed: !groupByDisabledReason,
37318
37483
  groupByDisabledReason,
37319
- isAggregateAllowed: !aggregateDisabledReason,
37320
37484
  aggregateDisabledReason,
37321
- isFilterAllowed: !filterDisabledReason,
37322
37485
  filterDisabledReason,
37323
- isOrderByAllowed: !orderByDisabledReason,
37324
37486
  orderByDisabledReason
37325
37487
  };
37326
37488
  }
37327
37489
  const FILTERABLE_TYPES = ["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"];
37328
37490
  const ORDERABLE_TYPES = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
37329
37491
  function FieldTokenWithActions({
37492
+ rootQuery,
37330
37493
  field,
37331
37494
  path,
37332
37495
  viewDef
37333
37496
  }) {
37334
- const {
37335
- rootQuery,
37336
- setQuery
37337
- } = React__default.useContext(QueryEditorContext);
37497
+ const updateQuery = useUpdateQuery();
37338
37498
  const {
37339
37499
  focusedNestView
37340
37500
  } = useQueryFocus();
@@ -37358,19 +37518,19 @@ function FieldTokenWithActions({
37358
37518
  } else if (operation === "filter" && !filterDisabledReason && filter) {
37359
37519
  addFilter(view, field, path, filter);
37360
37520
  }
37361
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37521
+ updateQuery();
37362
37522
  }
37363
37523
  };
37364
37524
  const handleSetView = () => {
37365
- if (field.kind === "view" && (rootQuery == null ? void 0 : rootQuery.isEmpty())) {
37366
- rootQuery == null ? void 0 : rootQuery.setView(field.name);
37367
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37525
+ if (field.kind === "view" && rootQuery.isEmpty()) {
37526
+ rootQuery.setView(field.name);
37527
+ updateQuery();
37368
37528
  }
37369
37529
  };
37370
37530
  const handleAddView = () => {
37371
37531
  if (field.kind === "view") {
37372
37532
  addNest(view, field);
37373
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37533
+ updateQuery();
37374
37534
  }
37375
37535
  };
37376
37536
  return /* @__PURE__ */ jsx(FieldToken, {
@@ -37378,9 +37538,9 @@ function FieldTokenWithActions({
37378
37538
  hoverActions: field.kind === "view" ? /* @__PURE__ */ jsxs(Fragment, {
37379
37539
  children: [/* @__PURE__ */ jsx(ActionButton, {
37380
37540
  icon: "insert",
37381
- disabled: !(rootQuery == null ? void 0 : rootQuery.isEmpty()),
37541
+ disabled: !rootQuery.isEmpty(),
37382
37542
  onClick: handleSetView,
37383
- tooltip: !(rootQuery == null ? void 0 : rootQuery.isEmpty()) ? "Can only add a view to an empty query." : "Add view",
37543
+ tooltip: !rootQuery.isEmpty() ? "Can only add a view to an empty query." : "Add view",
37384
37544
  onTooltipOpenChange: setIsTooltipOpen
37385
37545
  }), /* @__PURE__ */ jsx(ActionButton, {
37386
37546
  icon: "nest",
@@ -37446,7 +37606,7 @@ function FieldTokenWithActions({
37446
37606
  })]
37447
37607
  }) : null,
37448
37608
  onClick: field.kind === "dimension" && !groupByDisabledReason ? () => handleAddOperationAction("groupBy") : field.kind === "measure" && !aggregateDisabledReason ? () => handleAddOperationAction("aggregate") : field.kind === "view" ? () => {
37449
- if (rootQuery == null ? void 0 : rootQuery.isEmpty()) {
37609
+ if (rootQuery.isEmpty()) {
37450
37610
  handleSetView();
37451
37611
  } else {
37452
37612
  handleAddView();
@@ -37490,6 +37650,7 @@ function ActionButton({
37490
37650
  }
37491
37651
  const FIELD_KIND_ORDER = ["dimension", "measure", "view"];
37492
37652
  function SearchResultList({
37653
+ rootQuery,
37493
37654
  source,
37494
37655
  items
37495
37656
  }) {
@@ -37499,10 +37660,7 @@ function SearchResultList({
37499
37660
  items: groupFieldItemsByPath(source, group.items)
37500
37661
  }));
37501
37662
  }, [source, items]);
37502
- const {
37503
- rootQuery
37504
- } = React.useContext(QueryEditorContext);
37505
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37663
+ const viewDef = rootQuery.definition;
37506
37664
  if (!(viewDef instanceof ASTArrowQueryDefinition)) {
37507
37665
  return null;
37508
37666
  }
@@ -37539,6 +37697,7 @@ function SearchResultList({
37539
37697
  field,
37540
37698
  path
37541
37699
  }) => /* @__PURE__ */ jsx(FieldTokenWithActions, {
37700
+ rootQuery,
37542
37701
  field,
37543
37702
  path,
37544
37703
  viewDef
@@ -37565,6 +37724,7 @@ const getSublabelFromPath = (source, path) => {
37565
37724
  return path.length > 0 ? `joined to ${[...path.slice(0, -1), source.name].join(" > ")}` : void 0;
37566
37725
  };
37567
37726
  function FieldGroupList({
37727
+ rootQuery,
37568
37728
  source,
37569
37729
  fieldItems,
37570
37730
  fieldGroupType
@@ -37584,10 +37744,7 @@ function FieldGroupList({
37584
37744
  group
37585
37745
  }) => group === fieldGroupType)) == null ? void 0 : _a2.items) ?? [];
37586
37746
  }, [fieldGroupsByKindByPath, fieldGroupType]);
37587
- const {
37588
- rootQuery
37589
- } = React.useContext(QueryEditorContext);
37590
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37747
+ const viewDef = rootQuery.definition;
37591
37748
  if (!(viewDef instanceof ASTArrowQueryDefinition)) {
37592
37749
  return null;
37593
37750
  }
@@ -37604,6 +37761,7 @@ function FieldGroupList({
37604
37761
  field,
37605
37762
  path
37606
37763
  }) => /* @__PURE__ */ jsx(FieldTokenWithActions, {
37764
+ rootQuery,
37607
37765
  field,
37608
37766
  path,
37609
37767
  viewDef
@@ -37616,7 +37774,8 @@ function SourcePanel({
37616
37774
  onRefresh
37617
37775
  }) {
37618
37776
  const {
37619
- source
37777
+ source,
37778
+ rootQuery
37620
37779
  } = React.useContext(QueryEditorContext);
37621
37780
  const [searchQuery, setSearchQuery] = React.useState("");
37622
37781
  const {
@@ -37639,7 +37798,7 @@ function SourcePanel({
37639
37798
  return [];
37640
37799
  }, [fieldItems, searchQuery]);
37641
37800
  const isSearchActive = !!searchQuery;
37642
- if (!source) {
37801
+ if (!source || !rootQuery) {
37643
37802
  return null;
37644
37803
  }
37645
37804
  return /* @__PURE__ */ jsxs("div", {
@@ -37694,6 +37853,7 @@ function SourcePanel({
37694
37853
  className: "mly78zum5 mlydt5ytf mlyysyzu8 mly1iyjqo2"
37695
37854
  },
37696
37855
  children: isSearchActive ? /* @__PURE__ */ jsx(SearchResultList, {
37856
+ rootQuery,
37697
37857
  source,
37698
37858
  items: searchResultItems
37699
37859
  }) : /* @__PURE__ */ jsxs(AccordionList, {
@@ -37710,6 +37870,7 @@ function SourcePanel({
37710
37870
  color: "cyan"
37711
37871
  }),
37712
37872
  children: /* @__PURE__ */ jsx(FieldGroupList, {
37873
+ rootQuery,
37713
37874
  source,
37714
37875
  fieldItems,
37715
37876
  fieldGroupType: "dimension"
@@ -37726,6 +37887,7 @@ function SourcePanel({
37726
37887
  color: "green"
37727
37888
  }),
37728
37889
  children: /* @__PURE__ */ jsx(FieldGroupList, {
37890
+ rootQuery,
37729
37891
  source,
37730
37892
  fieldItems,
37731
37893
  fieldGroupType: "measure"
@@ -37742,6 +37904,7 @@ function SourcePanel({
37742
37904
  color: "purple"
37743
37905
  }),
37744
37906
  children: /* @__PURE__ */ jsx(FieldGroupList, {
37907
+ rootQuery,
37745
37908
  source,
37746
37909
  fieldItems,
37747
37910
  fieldGroupType: "view"