@vizzly/dashboard 0.15.0-dev-65c3e5d7491389a56cc8409b046f92683dd4725f → 0.15.0-dev-0618e6a45c18ec7cb9032ac19523c62e7bdeccaf

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.
@@ -14,6 +14,7 @@ import ReactDOM, { createPortal } from 'react-dom';
14
14
  import Fuse from 'fuse.js';
15
15
  import { CheckIcon, QuestionMarkCircleIcon, BadgeCheckIcon, DotsVerticalIcon, CloudIcon, SelectorIcon, ChevronUpIcon, ChevronDownIcon, DotsHorizontalIcon, ChevronLeftIcon, ChevronRightIcon, MinusSmIcon, PlusSmIcon } from '@heroicons/react/solid';
16
16
  import { VariableIcon, HashtagIcon, CalendarIcon, SearchIcon } from '@heroicons/react/outline';
17
+ import crypto from 'crypto';
17
18
  import moment$1 from 'moment';
18
19
  import { usePopper } from 'react-popper';
19
20
  import 'react-dates-17/initialize';
@@ -15622,7 +15623,7 @@ var DashboardBehaviourContext = /*#__PURE__*/React__default.createContext( /*#__
15622
15623
  setOverrideDeveloperInfo: noOp
15623
15624
  }));
15624
15625
  var DashboardBehaviourContextProvider = function DashboardBehaviourContextProvider(props) {
15625
- var _props$dashboardBehav, _props$dashboardBehav2, _props$dashboardBehav3, _props$dashboardBehav4, _props$dashboardBehav5;
15626
+ var _props$dashboardBehav, _props$dashboardBehav2, _props$dashboardBehav3, _props$dashboardBehav4, _props$dashboardBehav5, _props$dashboardBehav6;
15626
15627
  var _useFeatureTogglesSet = useFeatureTogglesSetup(props.mode, (_props$dashboardBehav = props.dashboardBehaviour) == null ? void 0 : _props$dashboardBehav.featureToggles, (_props$dashboardBehav2 = props.dashboardBehaviour) == null ? void 0 : _props$dashboardBehav2.queryEngineConfig, (_props$dashboardBehav3 = props.dashboardBehaviour) == null ? void 0 : _props$dashboardBehav3.scope, props.id),
15627
15628
  featureToggles = _useFeatureTogglesSet.featureToggles;
15628
15629
  var textOverride = props.textOverride || defaultText;
@@ -15654,7 +15655,8 @@ var DashboardBehaviourContextProvider = function DashboardBehaviourContextProvid
15654
15655
  id: props.id,
15655
15656
  featureToggles: featureToggles,
15656
15657
  valueAlias: props.valueAlias,
15657
- variables: props.variables
15658
+ variables: props.variables,
15659
+ updateDashboardHash: (_props$dashboardBehav6 = props.dashboardBehaviour) == null ? void 0 : _props$dashboardBehav6.updateDashboardHash
15658
15660
  }),
15659
15661
  children: props.children
15660
15662
  });
@@ -23664,7 +23666,9 @@ var DashboardContextProvider = function DashboardContextProvider(props) {
23664
23666
  var dashboard = props.dashboard,
23665
23667
  children = props.children,
23666
23668
  trackEvent = props.trackEvent,
23667
- componentEditor = props.componentEditor;
23669
+ componentEditor = props.componentEditor,
23670
+ onDashboardUpdate = props.onDashboardUpdate,
23671
+ dashboardHash = props.dashboardHash;
23668
23672
  var _useDashboardReducer = useDashboardReducer({
23669
23673
  componentEditor: componentEditor ? componentEditor : null,
23670
23674
  dashboard: dashboard ? mergeAPIIntoStoredTheme(dashboard, props.theme) : dashboard
@@ -23672,8 +23676,21 @@ var DashboardContextProvider = function DashboardContextProvider(props) {
23672
23676
  state = _useDashboardReducer[0],
23673
23677
  dispatch = _useDashboardReducer[1];
23674
23678
  useEffect(function () {
23675
- (props == null ? void 0 : props.onDashboardUpdate) && (props == null ? void 0 : props.onDashboardUpdate(state.dashboard));
23676
- }, [JSON.stringify(state.dashboard)]);
23679
+ if (!onDashboardUpdate) return;
23680
+ if (!dashboardHash) {
23681
+ onDashboardUpdate(state.dashboard, {
23682
+ hasUnsavedChanges: false
23683
+ });
23684
+ return;
23685
+ }
23686
+ var definition = toSaveableDefinition(state.dashboard);
23687
+ var serializedDefinition = JSON.stringify(definition);
23688
+ var newHash = crypto.createHash('md5').update(serializedDefinition).digest('hex');
23689
+ var hasUnsavedChanges = dashboardHash !== newHash;
23690
+ onDashboardUpdate(state.dashboard, {
23691
+ hasUnsavedChanges: hasUnsavedChanges
23692
+ });
23693
+ }, [JSON.stringify(state.dashboard), dashboardHash, onDashboardUpdate]);
23677
23694
  var trackEventFallback = function trackEventFallback() {};
23678
23695
  return jsx(DashboardContext.Provider, {
23679
23696
  value: _extends({}, state, {
@@ -41386,7 +41403,8 @@ var AdminTools = function AdminTools(props) {
41386
41403
  onSave = _useDashboardBehaviou.onSave,
41387
41404
  queryEngineConfig = _useDashboardBehaviou.queryEngineConfig,
41388
41405
  onOpenConfigManagerUi = _useDashboardBehaviou.onOpenConfigManagerUi,
41389
- disableToolbar = _useDashboardBehaviou.disableToolbar;
41406
+ disableToolbar = _useDashboardBehaviou.disableToolbar,
41407
+ updateDashboardHash = _useDashboardBehaviou.updateDashboardHash;
41390
41408
  var saveableDashboard = toSaveableDefinition(dashboard);
41391
41409
  var supportsConfigManagerUi = supportsFeature(queryEngineConfig, 'configManagerUi') && onOpenConfigManagerUi;
41392
41410
  useEffect(function () {
@@ -41427,6 +41445,7 @@ var AdminTools = function AdminTools(props) {
41427
41445
  if (data.save) {
41428
41446
  logDebug('Received from VizzlyState, `save()`');
41429
41447
  doSave();
41448
+ updateDashboardHash && updateDashboardHash(dashboard);
41430
41449
  }
41431
41450
  }, undefined, [dashboard]);
41432
41451
  if (disableToolbar) return null;
@@ -67772,10 +67791,11 @@ function useGoalLine(initialGoalLine, onAddingGoalLine) {
67772
67791
  });
67773
67792
  }
67774
67793
  var isDisabled$2 = function isDisabled(state) {
67775
- var _goalLineSchema$valid = goalLineSchema().validate(state),
67794
+ var _goalLineSchema$valid = goalLineSchema().validate(state, {
67795
+ presence: 'required'
67796
+ }),
67776
67797
  error = _goalLineSchema$valid.error;
67777
- if (error) return true;
67778
- return false;
67798
+ return !!error;
67779
67799
  };
67780
67800
 
67781
67801
  var GoalLineModal = function GoalLineModal(props) {
@@ -69738,7 +69758,8 @@ var StudioContexts = function StudioContexts(props) {
69738
69758
  trackEvent: props.trackEvent,
69739
69759
  dashboard: props.dashboard,
69740
69760
  componentEditor: props.componentEditor,
69741
- onDashboardUpdate: props.onDashboardUpdate,
69761
+ onDashboardUpdate: props.dashboardBehaviour.onDashboardUpdate,
69762
+ dashboardHash: props.dashboardHash,
69742
69763
  saving: props.saving,
69743
69764
  runQueriesCallback: function runQueriesCallback(queries, params) {
69744
69765
  var _props$identityConfig;
@@ -73553,848 +73574,74 @@ var EditorView$1 = function EditorView(props) {
73553
73574
  });
73554
73575
  };
73555
73576
 
73556
- var GlobalContext = /*#__PURE__*/createContext(undefined);
73557
-
73558
- var getDefaultParentDashboardId = function getDefaultParentDashboardId(parentDashboardId, parentDashboardIdOnDashboardAccessToken, dashboards) {
73559
- if (parentDashboardId) {
73560
- var parentDashboard = find$1(dashboards, parentDashboardId);
73561
- if (!(parentDashboard != null && parentDashboard.parentDashboardId)) {
73562
- return parentDashboardId;
73563
- } else {
73564
- throw '[Vizzly] `parentDashboardId` value must specify an ID for a parent dashboard.';
73565
- }
73566
- }
73567
- var parentDashboards = getParentDashboards(dashboards);
73568
- var programmaticDashboardId = checkAndReturnProgrammaticDashboardId(parentDashboards);
73569
- if (programmaticDashboardId) return programmaticDashboardId;
73570
- return parentDashboardIdOnDashboardAccessToken || getFirstCreated(parentDashboards).id;
73571
- };
73572
-
73573
- var getStrategy = function getStrategy(vizzly, requestedEndUserParentDashboardId, requestedEndUserDashboardId, isEditor) {
73574
- if (!('dashboards' in vizzly)) return undefined;
73575
- if (vizzly.loading || vizzly.error) return undefined;
73576
- logDebug('Loading dashboard strategy, with props;', {
73577
- dashboardId: requestedEndUserDashboardId,
73578
- parentDashboardId: requestedEndUserParentDashboardId
73579
- });
73580
- // This is a temporary fix for the issue where the dashboard is not loaded due to multiple hooks.
73581
- var checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks = isEditor && vizzly.dashboards.length === 0;
73582
- if (checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks) return undefined;
73583
- var defaultParentDashboardId = getDefaultParentDashboardId(requestedEndUserParentDashboardId, vizzly.identityConfig.dashboardAccess.dashboardId, vizzly.dashboards);
73584
- if (vizzly.accessType == 'admin') {
73585
- logDebug('Admin access found, so we will show the parent dashboard.', defaultParentDashboardId);
73586
- var dashboardId = defaultParentDashboardId;
73587
- // If the user wants a specific dashboard, then fetch the parent dashboard of it.
73588
- if (requestedEndUserDashboardId) {
73589
- var foundRequestedChildDashboard = vizzly.dashboards.find(function (dashboard) {
73590
- return dashboard.id == requestedEndUserDashboardId;
73591
- });
73592
- if (foundRequestedChildDashboard != null && foundRequestedChildDashboard.parentDashboardId) {
73593
- logDebug('A child dashboard was provided whilst in admin mode. Therefore the parent of the given child will be shown to administer.', foundRequestedChildDashboard.parentDashboardId);
73594
- dashboardId = foundRequestedChildDashboard.parentDashboardId;
73595
- }
73596
- }
73597
- logDebug('Admin access found, so we will show the parent dashboard.', dashboardId);
73598
- return {
73599
- type: 'exact',
73600
- dashboardId: dashboardId
73601
- };
73602
- }
73603
- if (requestedEndUserDashboardId) {
73604
- logDebug('Strategy will be to show dashboard', requestedEndUserDashboardId);
73605
- return {
73606
- type: 'exact',
73607
- dashboardId: requestedEndUserDashboardId
73608
- };
73609
- }
73610
- var childDashboards = vizzly.dashboards.filter(function (d) {
73611
- var isChildDashboard = d.parentDashboardId != null;
73612
- var hasNotRequestedEndUserParentDashboardId = requestedEndUserParentDashboardId === undefined;
73613
- var isChildOfRequestedParent = hasNotRequestedEndUserParentDashboardId || d.parentDashboardId === requestedEndUserParentDashboardId;
73614
- return isChildDashboard && isChildOfRequestedParent;
73615
- });
73616
- // Exactly one child dashboard for the user & in read-only mode so someone else is managing the dashboard with the same userReference.
73617
- // We will show that one dashboard to allow for a common SaaS environment where
73618
- // multiple users share the same userReference, but some of those users have `read_write` access and other users have read access.
73619
- // Those with `read` access should see the dashboard managed by those other users...
73620
- if (childDashboards.length === 1 && vizzly.identityConfig.dashboardAccess.scope == 'read') {
73621
- logDebug('Strategy will be to show read-only view of the only child dashboard. If you wish to render a read-only view of the parent dashboard, please make sure the `dashboardId` property matches the `parentDashboardId` property.', defaultParentDashboardId);
73622
- return {
73623
- type: 'exact',
73624
- dashboardId: vizzly.dashboards.find(function (d) {
73625
- return d.parentDashboardId != null;
73626
- }).id
73627
- };
73628
- }
73629
- // No specific dashboard requested, but dashboard access token only grants 'read' access.
73630
- if (vizzly.identityConfig.dashboardAccess.scope == 'read' && defaultParentDashboardId) {
73631
- logDebug('Strategy will be to return read-only view of the parent dashboard.', defaultParentDashboardId);
73632
- return {
73633
- type: 'exact',
73634
- dashboardId: defaultParentDashboardId
73635
- };
73636
- }
73637
- var dashboardIdSetInIdentityConfig = vizzly.identityConfig.dashboardAccess.dashboardId;
73638
- if (dashboardIdSetInIdentityConfig) {
73639
- var _vizzly$identityConfi, _vizzly$identityConfi2;
73640
- logDebug('Strategy will be to show a child of the parent dashboard determined by the identity config', (_vizzly$identityConfi = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi.dashboardId);
73641
- return {
73642
- type: 'instantCopyOf',
73643
- parentDashboardId: (_vizzly$identityConfi2 = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi2.dashboardId
73644
- };
73645
- } else {
73646
- logDebug('Strategy will be to show a child of the parent dashboard', defaultParentDashboardId);
73647
- return {
73648
- type: 'instantCopyOf',
73649
- parentDashboardId: defaultParentDashboardId
73650
- };
73651
- }
73652
- };
73653
-
73654
- var Mode;
73655
- (function (Mode) {
73656
- Mode["Admin"] = "admin";
73657
- Mode["EndUser"] = "endUser";
73658
- })(Mode || (Mode = {}));
73659
- var Scope;
73660
- (function (Scope) {
73661
- Scope["Read"] = "read";
73662
- Scope["ReadWrite"] = "read_write";
73663
- })(Scope || (Scope = {}));
73664
-
73665
- /*
73666
- Currently, we just replicate the same behaviour as what we used to have on the API.
73667
- */
73668
- var runStrategy = /*#__PURE__*/function () {
73669
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(strategy, vizzly) {
73670
- var currentDashboard, scope, _parentDashboard$perm, parentDashboard, hasParentDashboardWritePermission, dashboardCopies, mostRecentlyUpdatedChildDashboard, created;
73577
+ var getParentDashboards$1 = function getParentDashboards(httpClient) {
73578
+ return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
73579
+ var _yield$httpClient, status, body;
73671
73580
  return _regeneratorRuntime().wrap(function _callee$(_context) {
73672
73581
  while (1) switch (_context.prev = _context.next) {
73673
73582
  case 0:
73674
- if (!(strategy.type == 'exact')) {
73675
- _context.next = 9;
73676
- break;
73677
- }
73678
- currentDashboard = vizzly.dashboards.find(function (d) {
73679
- return d.id === strategy.dashboardId;
73680
- });
73681
- if (currentDashboard.permission) {
73682
- _context.next = 4;
73683
- break;
73684
- }
73685
- throw '';
73686
- case 4:
73687
- scope = currentDashboard.permission.scope;
73688
- logDebug('A specific dashboard has been requested. This will be rendered with', scope, 'scope.', strategy.dashboardId);
73689
- return _context.abrupt("return", {
73690
- dashboardId: strategy.dashboardId,
73691
- mode: scope === 'read_write' && currentDashboard.parentDashboardId === null ? Mode.Admin : Mode.EndUser,
73692
- scope: scope
73693
- });
73694
- case 9:
73695
- if (!(strategy.type == 'instantCopyOf')) {
73696
- _context.next = 29;
73697
- break;
73698
- }
73699
- // If the user has write access to the parent dashboard, then we return that dashboard ID, with mode=admin
73700
- parentDashboard = vizzly.dashboards.find(function (d) {
73701
- return d.id === strategy.parentDashboardId;
73702
- });
73703
- hasParentDashboardWritePermission = ((_parentDashboard$perm = parentDashboard.permission) == null ? void 0 : _parentDashboard$perm.scope) === 'read_write';
73704
- if (!hasParentDashboardWritePermission) {
73705
- _context.next = 15;
73706
- break;
73707
- }
73708
- logDebug('Write access to the parent dashboard has been found, so this dashboard will be shown with admin access.', strategy.parentDashboardId);
73709
- return _context.abrupt("return", {
73710
- dashboardId: strategy.parentDashboardId,
73711
- mode: Mode.Admin,
73712
- scope: Scope.ReadWrite
73713
- });
73714
- case 15:
73715
- dashboardCopies = getCopiesOfParentDashboard(strategy.parentDashboardId, vizzly.dashboards);
73716
- mostRecentlyUpdatedChildDashboard = takeMostRecentlyUpdated(dashboardCopies);
73717
- if (!mostRecentlyUpdatedChildDashboard) {
73718
- _context.next = 20;
73719
- break;
73720
- }
73721
- logDebug('An existing child dashboard exists of the parent dashboard. As no specific dashboardId was provided, we will render the most recently updated child dashboard', mostRecentlyUpdatedChildDashboard.id);
73722
- return _context.abrupt("return", {
73723
- dashboardId: mostRecentlyUpdatedChildDashboard.id,
73724
- mode: Mode.EndUser,
73725
- scope: mostRecentlyUpdatedChildDashboard.permission.scope
73726
- });
73727
- case 20:
73728
- logDebug('No previous child dashboard has been created on behalf of the current user for the parent dashboard', parentDashboard.id, '. Creating a child copy of the parent.');
73729
- _context.next = 23;
73730
- return vizzly.createDashboard({
73731
- parentDashboardId: parentDashboard.id,
73732
- definition: toSaveableDefinition(parentDashboard),
73733
- metadata: {}
73583
+ _context.next = 2;
73584
+ return httpClient({
73585
+ path: "/api/v2/parent-dashboards",
73586
+ method: 'get'
73734
73587
  });
73735
- case 23:
73736
- created = _context.sent;
73737
- if (created) {
73738
- _context.next = 26;
73588
+ case 2:
73589
+ _yield$httpClient = _context.sent;
73590
+ status = _yield$httpClient.status;
73591
+ body = _yield$httpClient.body;
73592
+ if (!(status == 200)) {
73593
+ _context.next = 7;
73739
73594
  break;
73740
73595
  }
73741
- throw 'Failed to create first child dashboard for the user.';
73742
- case 26:
73743
- return _context.abrupt("return", {
73744
- dashboardId: created.id,
73745
- scope: Scope.ReadWrite,
73746
- mode: Mode.EndUser
73747
- });
73748
- case 29:
73749
- throw "Unsupported strategy";
73750
- case 30:
73596
+ return _context.abrupt("return", body.dashboards.map(function (rawDashboard) {
73597
+ return {
73598
+ id: rawDashboard.id,
73599
+ created_at: rawDashboard.created_at,
73600
+ updated_at: rawDashboard.updated_at,
73601
+ webhook_id: rawDashboard.webhook_id
73602
+ };
73603
+ }));
73604
+ case 7:
73605
+ return _context.abrupt("return", undefined);
73606
+ case 8:
73751
73607
  case "end":
73752
73608
  return _context.stop();
73753
73609
  }
73754
73610
  }, _callee);
73755
73611
  }));
73756
- return function runStrategy(_x, _x2) {
73757
- return _ref.apply(this, arguments);
73758
- };
73759
- }();
73760
-
73761
- /*
73762
- Stores which dashboard is the currently active one...
73763
- */
73764
- var useDashboardStrategy = function useDashboardStrategy(strategy, vizzly, programmaticDashboard) {
73765
- var _useState = useState(),
73766
- state = _useState[0],
73767
- setState = _useState[1];
73768
- useEffect(function () {
73769
- var doWork = /*#__PURE__*/function () {
73770
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
73771
- var _yield$runStrategy, mode, dashboardId, scope;
73772
- return _regeneratorRuntime().wrap(function _callee$(_context) {
73773
- while (1) switch (_context.prev = _context.next) {
73774
- case 0:
73775
- if ('dashboards' in vizzly) {
73776
- _context.next = 2;
73777
- break;
73778
- }
73779
- return _context.abrupt("return");
73780
- case 2:
73781
- if (strategy) {
73782
- _context.next = 4;
73783
- break;
73784
- }
73785
- return _context.abrupt("return");
73786
- case 4:
73787
- if (!vizzly.loading) {
73788
- _context.next = 6;
73789
- break;
73790
- }
73791
- return _context.abrupt("return");
73792
- case 6:
73793
- _context.next = 8;
73794
- return runStrategy(strategy, vizzly);
73795
- case 8:
73796
- _yield$runStrategy = _context.sent;
73797
- mode = _yield$runStrategy.mode;
73798
- dashboardId = _yield$runStrategy.dashboardId;
73799
- scope = _yield$runStrategy.scope;
73800
- if (dashboardId != (state == null ? void 0 : state.dashboardId)) setState({
73801
- mode: mode,
73802
- dashboardId: dashboardId,
73803
- scope: scope
73804
- });
73805
- case 13:
73806
- case "end":
73807
- return _context.stop();
73808
- }
73809
- }, _callee);
73810
- }));
73811
- return function doWork() {
73812
- return _ref.apply(this, arguments);
73813
- };
73814
- }();
73815
- doWork();
73816
- }, [JSON.stringify({
73817
- strategy: strategy,
73818
- loading: vizzly.loading
73819
- })]);
73820
- if (!('dashboards' in vizzly)) return null;
73821
- if (!state) return null;
73822
- if (vizzly.loading) return null;
73823
- var dashboard = vizzly.dashboards.find(function (dash) {
73824
- return dash.id == state.dashboardId;
73825
- }) || null;
73826
- return {
73827
- mode: state.mode,
73828
- dashboard: dashboard,
73829
- scope: state.scope,
73830
- isProgrammaticParent: !!programmaticDashboard
73831
- };
73832
73612
  };
73833
73613
 
73834
- var NoDataSetResolved = /*#__PURE__*/function (_Error) {
73835
- function NoDataSetResolved() {
73836
- var _this;
73837
- _this = _Error.call(this, 'At least one data set must be built for the Vizzly dashboard to render.') || this;
73838
- _this.name = 'NoDataSetResolved';
73839
- return _this;
73840
- }
73841
- _inheritsLoose(NoDataSetResolved, _Error);
73842
- return NoDataSetResolved;
73843
- }( /*#__PURE__*/_wrapNativeSuper(Error));
73844
-
73845
- var useVizzly = function useVizzly(properties, options) {
73846
- var _useState = useState({
73847
- loading: true,
73848
- error: undefined,
73849
- dashboards: [],
73850
- globalLibraries: []
73851
- }),
73852
- state = _useState[0],
73853
- setState = _useState[1];
73854
- var vizzlyRef = useRef();
73855
- var vizzly = vizzlyRef.current;
73856
- useEffect(function () {
73857
- var abortController = new AbortController();
73858
- var doWork = /*#__PURE__*/function () {
73859
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
73860
- var _yield$Promise$all, globalLibraries, dashboards;
73861
- return _regeneratorRuntime().wrap(function _callee$(_context) {
73862
- while (1) switch (_context.prev = _context.next) {
73863
- case 0:
73864
- _context.prev = 0;
73865
- _context.next = 3;
73866
- return Vizzly$1.load(properties, {
73867
- apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
73868
- });
73869
- case 3:
73870
- vizzlyRef.current = _context.sent;
73871
- _context.next = 6;
73872
- return Promise.all([vizzlyRef.current.getGlobalLibraries({
73873
- abortController: abortController
73874
- }), vizzlyRef.current.getDashboards({
73875
- abortController: abortController
73876
- })]);
73877
- case 6:
73878
- _yield$Promise$all = _context.sent;
73879
- globalLibraries = _yield$Promise$all[0];
73880
- dashboards = _yield$Promise$all[1];
73881
- setState({
73882
- loading: false,
73883
- error: undefined,
73884
- dashboards: dashboards,
73885
- globalLibraries: globalLibraries
73886
- });
73887
- _context.next = 16;
73888
- break;
73889
- case 12:
73890
- _context.prev = 12;
73891
- _context.t0 = _context["catch"](0);
73892
- logError('Error loading Vizzly', _context.t0);
73893
- setState({
73894
- loading: false,
73895
- error: _context.t0,
73896
- dashboards: [].concat(state.dashboards),
73897
- globalLibraries: [].concat(state.globalLibraries)
73898
- });
73899
- case 16:
73900
- case "end":
73901
- return _context.stop();
73902
- }
73903
- }, _callee, null, [[0, 12]]);
73904
- }));
73905
- return function doWork() {
73906
- return _ref.apply(this, arguments);
73907
- };
73908
- }();
73909
- doWork();
73910
- return function () {
73911
- return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
73912
- };
73913
- }, []);
73914
- var refetch = /*#__PURE__*/function () {
73915
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
73916
- var abortController, doWork;
73917
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
73918
- while (1) switch (_context3.prev = _context3.next) {
73919
- case 0:
73920
- abortController = new AbortController();
73921
- doWork = /*#__PURE__*/function () {
73922
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73923
- var _yield$Promise$all2, globalLibraries, dashboards;
73924
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
73925
- while (1) switch (_context2.prev = _context2.next) {
73926
- case 0:
73927
- _context2.prev = 0;
73928
- _context2.next = 3;
73929
- return Vizzly$1.load(properties, {
73930
- apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
73931
- });
73932
- case 3:
73933
- vizzlyRef.current = _context2.sent;
73934
- _context2.next = 6;
73935
- return Promise.all([vizzlyRef.current.getGlobalLibraries({
73936
- abortController: abortController
73937
- }), vizzlyRef.current.getDashboards({
73938
- abortController: abortController
73939
- })]);
73940
- case 6:
73941
- _yield$Promise$all2 = _context2.sent;
73942
- globalLibraries = _yield$Promise$all2[0];
73943
- dashboards = _yield$Promise$all2[1];
73944
- setState({
73945
- loading: false,
73946
- error: undefined,
73947
- dashboards: dashboards,
73948
- globalLibraries: globalLibraries
73949
- });
73950
- _context2.next = 16;
73951
- break;
73952
- case 12:
73953
- _context2.prev = 12;
73954
- _context2.t0 = _context2["catch"](0);
73955
- logError('Error loading Vizzly', _context2.t0);
73956
- setState({
73957
- loading: false,
73958
- error: _context2.t0,
73959
- dashboards: [].concat(state.dashboards),
73960
- globalLibraries: [].concat(state.globalLibraries)
73961
- });
73962
- case 16:
73963
- case "end":
73964
- return _context2.stop();
73965
- }
73966
- }, _callee2, null, [[0, 12]]);
73967
- }));
73968
- return function doWork() {
73969
- return _ref3.apply(this, arguments);
73970
- };
73971
- }();
73972
- doWork();
73973
- return _context3.abrupt("return", function () {
73974
- return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
73975
- });
73976
- case 4:
73977
- case "end":
73978
- return _context3.stop();
73979
- }
73980
- }, _callee3);
73981
- }));
73982
- return function refetch() {
73983
- return _ref2.apply(this, arguments);
73984
- };
73985
- }();
73986
- var createDashboard = /*#__PURE__*/function () {
73987
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
73988
- var createdDashboard;
73989
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
73990
- while (1) switch (_context4.prev = _context4.next) {
73614
+ // If cronSchedule is `null`, then it means the scheduled
73615
+ // report is deleted.
73616
+ var saveScheduledReport = function saveScheduledReport(httpClient) {
73617
+ return /*#__PURE__*/function () {
73618
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
73619
+ var _yield$httpClient, status;
73620
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
73621
+ while (1) switch (_context.prev = _context.next) {
73991
73622
  case 0:
73992
- if (!vizzly) {
73993
- _context4.next = 15;
73994
- break;
73995
- }
73996
- _context4.prev = 1;
73997
- _context4.next = 4;
73998
- return vizzly.createDashboard({
73999
- definition: params.definition,
74000
- // permissions: params.permissions,
74001
- parentDashboardId: params.parentDashboardId,
74002
- metadata: params.metadata || params.meta,
74003
- abortSignal: params.abortSignal
73623
+ _context.next = 2;
73624
+ return httpClient({
73625
+ path: '/api/scheduled-report',
73626
+ method: 'post',
73627
+ body: {
73628
+ cronSchedule: params.cronSchedule,
73629
+ dashboardAccessToken: params.dashboardAccessToken,
73630
+ scheduledReportId: params.scheduledReportId
73631
+ }
74004
73632
  });
74005
- case 4:
74006
- createdDashboard = _context4.sent;
74007
- setState(_extends({}, state, {
74008
- dashboards: [].concat(state.dashboards, [createdDashboard])
74009
- }));
74010
- return _context4.abrupt("return", createdDashboard);
74011
- case 9:
74012
- _context4.prev = 9;
74013
- _context4.t0 = _context4["catch"](1);
74014
- logError(_context4.t0);
74015
- return _context4.abrupt("return", null);
74016
- case 13:
74017
- _context4.next = 16;
74018
- break;
74019
- case 15:
74020
- throw 'Unable to create a dashboard when vizzly has not been loaded.';
74021
- case 16:
73633
+ case 2:
73634
+ _yield$httpClient = _context.sent;
73635
+ status = _yield$httpClient.status;
73636
+ return _context.abrupt("return", status == 200);
73637
+ case 5:
74022
73638
  case "end":
74023
- return _context4.stop();
73639
+ return _context.stop();
74024
73640
  }
74025
- }, _callee4, null, [[1, 9]]);
73641
+ }, _callee);
74026
73642
  }));
74027
- return function createDashboard(_x) {
74028
- return _ref4.apply(this, arguments);
74029
- };
74030
- }();
74031
- useEffect(function () {
74032
- var abortController = new AbortController();
74033
- var doWork = /*#__PURE__*/function () {
74034
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
74035
- var _yield$Promise$all3, globalLibraries;
74036
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
74037
- while (1) switch (_context5.prev = _context5.next) {
74038
- case 0:
74039
- _context5.prev = 0;
74040
- _context5.next = 3;
74041
- return Vizzly$1.load(properties, {
74042
- apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
74043
- });
74044
- case 3:
74045
- vizzlyRef.current = _context5.sent;
74046
- _context5.next = 6;
74047
- return Promise.all([vizzlyRef.current.getGlobalLibraries({
74048
- abortController: abortController
74049
- })]);
74050
- case 6:
74051
- _yield$Promise$all3 = _context5.sent;
74052
- globalLibraries = _yield$Promise$all3[0];
74053
- setState(_extends({}, state, {
74054
- globalLibraries: globalLibraries
74055
- }));
74056
- _context5.next = 15;
74057
- break;
74058
- case 11:
74059
- _context5.prev = 11;
74060
- _context5.t0 = _context5["catch"](0);
74061
- logError('Error loading Vizzly', _context5.t0);
74062
- setState({
74063
- loading: false,
74064
- error: _context5.t0,
74065
- dashboards: [].concat(state.dashboards),
74066
- globalLibraries: [].concat(state.globalLibraries)
74067
- });
74068
- case 15:
74069
- case "end":
74070
- return _context5.stop();
74071
- }
74072
- }, _callee5, null, [[0, 11]]);
74073
- }));
74074
- return function doWork() {
74075
- return _ref5.apply(this, arguments);
74076
- };
74077
- }();
74078
- if (vizzly) {
74079
- var unsubscribe = Vizzly$1.subscription(function (eventBus) {
74080
- if (eventBus.data.action === 'newViewsInGlobalLibrary') {
74081
- doWork();
74082
- }
74083
- });
74084
- return function () {
74085
- return unsubscribe();
74086
- };
74087
- }
74088
- return function () {
74089
- return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
74090
- };
74091
- }, [vizzly]);
74092
- var updateDashboard = /*#__PURE__*/function () {
74093
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
74094
- var updatedDashboard, dashboards;
74095
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
74096
- while (1) switch (_context6.prev = _context6.next) {
74097
- case 0:
74098
- if (!vizzly) {
74099
- _context6.next = 20;
74100
- break;
74101
- }
74102
- setState(_extends({}, state, {
74103
- saving: SavingState.InProgress
74104
- }));
74105
- _context6.prev = 2;
74106
- _context6.next = 5;
74107
- return vizzly.updateDashboard({
74108
- dashboardId: params.dashboardId,
74109
- definition: params.definition,
74110
- deleted: params.deleted,
74111
- metadata: params.metadata || params.meta,
74112
- abortSignal: params.abortSignal,
74113
- name: params.name
74114
- });
74115
- case 5:
74116
- updatedDashboard = _context6.sent;
74117
- _context6.next = 8;
74118
- return vizzly.getDashboards();
74119
- case 8:
74120
- dashboards = _context6.sent;
74121
- setState(function (prevState) {
74122
- return _extends({}, prevState, {
74123
- dashboards: dashboards,
74124
- saving: SavingState.Saved
74125
- });
74126
- });
74127
- setTimeout(function () {
74128
- setState(_extends({}, state, {
74129
- saving: SavingState.Undefined
74130
- }));
74131
- }, 500);
74132
- return _context6.abrupt("return", updatedDashboard);
74133
- case 14:
74134
- _context6.prev = 14;
74135
- _context6.t0 = _context6["catch"](2);
74136
- logError('Error updating dashboard', _context6.t0);
74137
- return _context6.abrupt("return", null);
74138
- case 18:
74139
- _context6.next = 21;
74140
- break;
74141
- case 20:
74142
- throw 'Unable to update a dashboard when vizzly has not been loaded.';
74143
- case 21:
74144
- case "end":
74145
- return _context6.stop();
74146
- }
74147
- }, _callee6, null, [[2, 14]]);
74148
- }));
74149
- return function updateDashboard(_x2) {
74150
- return _ref6.apply(this, arguments);
74151
- };
74152
- }();
74153
-
74154
- // Are these needed?
74155
- var updateScheduledReport = function updateScheduledReport(dashboardAccessToken, reportId, newCron) {
74156
- if (vizzly) {
74157
- return vizzly.updateScheduledReport(dashboardAccessToken, reportId, newCron);
74158
- }
74159
- throw 'vizzly not set';
74160
- };
74161
- var getScheduledReports = function getScheduledReports(dashboardAccessToken) {
74162
- if (vizzly) {
74163
- return vizzly.getScheduledReports(dashboardAccessToken);
74164
- }
74165
- throw 'vizzly not set';
74166
- };
74167
- logDebug('useVizzly state.', state);
74168
- if (!vizzly || !!state.error || state.loading) {
74169
- return _extends({}, state, {
74170
- loading: true,
74171
- createDashboard: null,
74172
- identityConfig: null,
74173
- updateDashboard: null,
74174
- queryEngineConfig: null,
74175
- accessType: null,
74176
- refetch: null,
74177
- getScheduledReports: null,
74178
- updateScheduledReport: null
74179
- });
74180
- }
74181
- var identityConfig = vizzly.getIdentityConfig();
74182
- return _extends({}, state, {
74183
- loading: false,
74184
- identityConfig: identityConfig,
74185
- createDashboard: createDashboard,
74186
- updateDashboard: updateDashboard,
74187
- queryEngineConfig: vizzly.getViewConfiguration().queryEngineConfig,
74188
- accessType: !!identityConfig.dashboardAdminOverride ? 'admin' : identityConfig.dashboardAccess.accessType,
74189
- filterDashboards: Vizzly$1.filterDashboards,
74190
- refetch: refetch,
74191
- updateScheduledReport: updateScheduledReport,
74192
- getScheduledReports: getScheduledReports
74193
- });
74194
- };
74195
-
74196
- var useScheduledReports = function useScheduledReports(params, dashboardAccessToken) {
74197
- var _useState = useState([]),
74198
- reports = _useState[0],
74199
- setReports = _useState[1];
74200
- useEffect(function () {
74201
- var doWork = /*#__PURE__*/function () {
74202
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
74203
- var _yield$params$getSche, _reports;
74204
- return _regeneratorRuntime().wrap(function _callee$(_context) {
74205
- while (1) switch (_context.prev = _context.next) {
74206
- case 0:
74207
- if (!(params.getScheduledReports && dashboardAccessToken)) {
74208
- _context.next = 6;
74209
- break;
74210
- }
74211
- _context.next = 3;
74212
- return params.getScheduledReports(dashboardAccessToken);
74213
- case 3:
74214
- _yield$params$getSche = _context.sent;
74215
- _reports = _yield$params$getSche.reports;
74216
- setReports(_reports);
74217
- case 6:
74218
- case "end":
74219
- return _context.stop();
74220
- }
74221
- }, _callee);
74222
- }));
74223
- return function doWork() {
74224
- return _ref.apply(this, arguments);
74225
- };
74226
- }();
74227
- doWork();
74228
- }, [JSON.stringify({
74229
- dashboardAccessToken: dashboardAccessToken,
74230
- loadingVizzly: params
74231
- })]);
74232
- var updateScheduledReport = /*#__PURE__*/function () {
74233
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(reportId, newCron) {
74234
- var updatedReport, newReports, uniqueNewReports;
74235
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
74236
- while (1) switch (_context2.prev = _context2.next) {
74237
- case 0:
74238
- if (!(params.updateScheduledReport && dashboardAccessToken)) {
74239
- _context2.next = 7;
74240
- break;
74241
- }
74242
- _context2.next = 3;
74243
- return params.updateScheduledReport(dashboardAccessToken, reportId, newCron);
74244
- case 3:
74245
- updatedReport = _context2.sent;
74246
- if (updatedReport === true) {
74247
- // Remove the deleted report...
74248
- setReports([].concat(reports).filter(function (r) {
74249
- return r.id != reportId;
74250
- }));
74251
- } else if (updatedReport) {
74252
- // Upsert the report
74253
- newReports = [].concat(reports, [updatedReport.report]).map(function (r) {
74254
- return r.id == reportId ? updatedReport.report : r;
74255
- });
74256
- uniqueNewReports = uniqBy(newReports, function (r) {
74257
- return r.id;
74258
- });
74259
- setReports(uniqueNewReports);
74260
- }
74261
- _context2.next = 8;
74262
- break;
74263
- case 7:
74264
- console.warn('Function to update scheduled report not loaded.');
74265
- case 8:
74266
- case "end":
74267
- return _context2.stop();
74268
- }
74269
- }, _callee2);
74270
- }));
74271
- return function updateScheduledReport(_x, _x2) {
74272
- return _ref2.apply(this, arguments);
74273
- };
74274
- }();
74275
- return {
74276
- reports: reports,
74277
- getScheduledReports: params.getScheduledReports,
74278
- updateScheduledReport: updateScheduledReport
74279
- };
74280
- };
74281
-
74282
- /*
74283
- A context for managing the dashboard session.
74284
- */
74285
- var STILL_LOADING = null;
74286
- var useSessionContext = function useSessionContext(params) {
74287
- var _loadedStrategy$dashb, _loadedStrategy$dashb2;
74288
- var vizzly = useVizzly({
74289
- queryEngine: params.queryEngine,
74290
- identity: params.identityCallback,
74291
- dataSets: params.loadDataSetsCallback,
74292
- programmaticDashboard: params.programmaticDashboard
74293
- }, {
74294
- apiHost: params.apiConfig.host
74295
- });
74296
- var loadedStrategy = useDashboardStrategy(getStrategy(vizzly, params.parentDashboardId, params.dashboardId, params.isEditor), vizzly, params.programmaticDashboard);
74297
- var _useScheduledReports = useScheduledReports(vizzly, loadedStrategy == null || (_loadedStrategy$dashb = loadedStrategy.dashboard) == null || (_loadedStrategy$dashb = _loadedStrategy$dashb.permission) == null ? void 0 : _loadedStrategy$dashb.token),
74298
- reports = _useScheduledReports.reports,
74299
- updateScheduledReport = _useScheduledReports.updateScheduledReport;
74300
- if (!vizzly) return STILL_LOADING;
74301
- if ('error' in vizzly && vizzly.error) return {
74302
- error: vizzly.error
74303
- };
74304
- if ('loading' in vizzly && vizzly.loading) return STILL_LOADING;
74305
- if (!('dashboards' in vizzly)) return STILL_LOADING;
74306
- var identityConfig = vizzly.identityConfig,
74307
- queryEngineConfig = vizzly.queryEngineConfig;
74308
- if (!loadedStrategy) return null;
74309
- if (((loadedStrategy == null || (_loadedStrategy$dashb2 = loadedStrategy.dashboard) == null ? void 0 : _loadedStrategy$dashb2.dataSets) || []).length === 0) {
74310
- return {
74311
- error: new NoDataSetResolved()
74312
- };
74313
- }
74314
- var providedValues = {
74315
- vizzly: vizzly,
74316
- scope: loadedStrategy.scope,
74317
- queryEngineConfig: queryEngineConfig,
74318
- dashboard: loadedStrategy.dashboard,
74319
- identityConfig: identityConfig,
74320
- mode: loadedStrategy.mode,
74321
- vizzlyApiConfig: params.apiConfig,
74322
- isProgrammaticParent: loadedStrategy.isProgrammaticParent,
74323
- globalLibraries: vizzly.globalLibraries,
74324
- reports: reports,
74325
- updateScheduledReport: updateScheduledReport
74326
- };
74327
- return providedValues;
74328
- };
74329
-
74330
- var getParentDashboards$1 = function getParentDashboards(httpClient) {
74331
- return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
74332
- var _yield$httpClient, status, body;
74333
- return _regeneratorRuntime().wrap(function _callee$(_context) {
74334
- while (1) switch (_context.prev = _context.next) {
74335
- case 0:
74336
- _context.next = 2;
74337
- return httpClient({
74338
- path: "/api/v2/parent-dashboards",
74339
- method: 'get'
74340
- });
74341
- case 2:
74342
- _yield$httpClient = _context.sent;
74343
- status = _yield$httpClient.status;
74344
- body = _yield$httpClient.body;
74345
- if (!(status == 200)) {
74346
- _context.next = 7;
74347
- break;
74348
- }
74349
- return _context.abrupt("return", body.dashboards.map(function (rawDashboard) {
74350
- return {
74351
- id: rawDashboard.id,
74352
- created_at: rawDashboard.created_at,
74353
- updated_at: rawDashboard.updated_at,
74354
- webhook_id: rawDashboard.webhook_id
74355
- };
74356
- }));
74357
- case 7:
74358
- return _context.abrupt("return", undefined);
74359
- case 8:
74360
- case "end":
74361
- return _context.stop();
74362
- }
74363
- }, _callee);
74364
- }));
74365
- };
74366
-
74367
- // If cronSchedule is `null`, then it means the scheduled
74368
- // report is deleted.
74369
- var saveScheduledReport = function saveScheduledReport(httpClient) {
74370
- return /*#__PURE__*/function () {
74371
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
74372
- var _yield$httpClient, status;
74373
- return _regeneratorRuntime().wrap(function _callee$(_context) {
74374
- while (1) switch (_context.prev = _context.next) {
74375
- case 0:
74376
- _context.next = 2;
74377
- return httpClient({
74378
- path: '/api/scheduled-report',
74379
- method: 'post',
74380
- body: {
74381
- cronSchedule: params.cronSchedule,
74382
- dashboardAccessToken: params.dashboardAccessToken,
74383
- scheduledReportId: params.scheduledReportId
74384
- }
74385
- });
74386
- case 2:
74387
- _yield$httpClient = _context.sent;
74388
- status = _yield$httpClient.status;
74389
- return _context.abrupt("return", status == 200);
74390
- case 5:
74391
- case "end":
74392
- return _context.stop();
74393
- }
74394
- }, _callee);
74395
- }));
74396
- return function (_x) {
74397
- return _ref.apply(this, arguments);
73643
+ return function (_x) {
73644
+ return _ref.apply(this, arguments);
74398
73645
  };
74399
73646
  }();
74400
73647
  };
@@ -75134,6 +74381,28 @@ var api = function api(config) {
75134
74381
  };
75135
74382
  };
75136
74383
 
74384
+ var buildQueryEngineSignInUrl = function buildQueryEngineSignInUrl(queryEngineEndpoint, queryEngineAccessToken) {
74385
+ if (!queryEngineAccessToken) return '';
74386
+ var authToken = queryEngineAccessToken;
74387
+ authToken = encode(JSON.stringify({
74388
+ queryEngineAccessToken: queryEngineAccessToken,
74389
+ projectAccessToken: undefined
74390
+ }));
74391
+ var endpoint = buildPath(getHostFromQueryEngineEndpoint(queryEngineEndpoint), "/sign-in#" + authToken);
74392
+ return endpoint;
74393
+ };
74394
+
74395
+ var FailedToSaveError = /*#__PURE__*/function (_Error) {
74396
+ function FailedToSaveError(message) {
74397
+ var _this;
74398
+ _this = _Error.call(this, "Failed to save dashboard.") || this;
74399
+ _this.message = message;
74400
+ return _this;
74401
+ }
74402
+ _inheritsLoose(FailedToSaveError, _Error);
74403
+ return FailedToSaveError;
74404
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
74405
+
75137
74406
  var StatusLine = function StatusLine(props) {
75138
74407
  return jsx("div", {
75139
74408
  children: jsxs("span", {
@@ -75604,6 +74873,17 @@ var InvalidIdentityFunctionNotice = function InvalidIdentityFunctionNotice(props
75604
74873
  // />
75605
74874
  // );
75606
74875
 
74876
+ var NoDataSetResolved = /*#__PURE__*/function (_Error) {
74877
+ function NoDataSetResolved() {
74878
+ var _this;
74879
+ _this = _Error.call(this, 'At least one data set must be built for the Vizzly dashboard to render.') || this;
74880
+ _this.name = 'NoDataSetResolved';
74881
+ return _this;
74882
+ }
74883
+ _inheritsLoose(NoDataSetResolved, _Error);
74884
+ return NoDataSetResolved;
74885
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
74886
+
75607
74887
  var SetupError = function SetupError(props) {
75608
74888
  logError(props.error);
75609
74889
  var renderedError = jsx("p", {
@@ -75665,15 +74945,765 @@ var SetupError = function SetupError(props) {
75665
74945
  });
75666
74946
  };
75667
74947
 
75668
- var buildQueryEngineSignInUrl = function buildQueryEngineSignInUrl(queryEngineEndpoint, queryEngineAccessToken) {
75669
- if (!queryEngineAccessToken) return '';
75670
- var authToken = queryEngineAccessToken;
75671
- authToken = encode(JSON.stringify({
75672
- queryEngineAccessToken: queryEngineAccessToken,
75673
- projectAccessToken: undefined
74948
+ var getDefaultParentDashboardId = function getDefaultParentDashboardId(parentDashboardId, parentDashboardIdOnDashboardAccessToken, dashboards) {
74949
+ if (parentDashboardId) {
74950
+ var parentDashboard = find$1(dashboards, parentDashboardId);
74951
+ if (!(parentDashboard != null && parentDashboard.parentDashboardId)) {
74952
+ return parentDashboardId;
74953
+ } else {
74954
+ throw '[Vizzly] `parentDashboardId` value must specify an ID for a parent dashboard.';
74955
+ }
74956
+ }
74957
+ var parentDashboards = getParentDashboards(dashboards);
74958
+ var programmaticDashboardId = checkAndReturnProgrammaticDashboardId(parentDashboards);
74959
+ if (programmaticDashboardId) return programmaticDashboardId;
74960
+ return parentDashboardIdOnDashboardAccessToken || getFirstCreated(parentDashboards).id;
74961
+ };
74962
+
74963
+ var getStrategy = function getStrategy(vizzly, requestedEndUserParentDashboardId, requestedEndUserDashboardId, isEditor) {
74964
+ if (!('dashboards' in vizzly)) return undefined;
74965
+ if (vizzly.loading || vizzly.error) return undefined;
74966
+ logDebug('Loading dashboard strategy, with props;', {
74967
+ dashboardId: requestedEndUserDashboardId,
74968
+ parentDashboardId: requestedEndUserParentDashboardId
74969
+ });
74970
+ // This is a temporary fix for the issue where the dashboard is not loaded due to multiple hooks.
74971
+ var checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks = isEditor && vizzly.dashboards.length === 0;
74972
+ if (checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks) return undefined;
74973
+ var defaultParentDashboardId = getDefaultParentDashboardId(requestedEndUserParentDashboardId, vizzly.identityConfig.dashboardAccess.dashboardId, vizzly.dashboards);
74974
+ if (vizzly.accessType == 'admin') {
74975
+ logDebug('Admin access found, so we will show the parent dashboard.', defaultParentDashboardId);
74976
+ var dashboardId = defaultParentDashboardId;
74977
+ // If the user wants a specific dashboard, then fetch the parent dashboard of it.
74978
+ if (requestedEndUserDashboardId) {
74979
+ var foundRequestedChildDashboard = vizzly.dashboards.find(function (dashboard) {
74980
+ return dashboard.id == requestedEndUserDashboardId;
74981
+ });
74982
+ if (foundRequestedChildDashboard != null && foundRequestedChildDashboard.parentDashboardId) {
74983
+ logDebug('A child dashboard was provided whilst in admin mode. Therefore the parent of the given child will be shown to administer.', foundRequestedChildDashboard.parentDashboardId);
74984
+ dashboardId = foundRequestedChildDashboard.parentDashboardId;
74985
+ }
74986
+ }
74987
+ logDebug('Admin access found, so we will show the parent dashboard.', dashboardId);
74988
+ return {
74989
+ type: 'exact',
74990
+ dashboardId: dashboardId
74991
+ };
74992
+ }
74993
+ if (requestedEndUserDashboardId) {
74994
+ logDebug('Strategy will be to show dashboard', requestedEndUserDashboardId);
74995
+ return {
74996
+ type: 'exact',
74997
+ dashboardId: requestedEndUserDashboardId
74998
+ };
74999
+ }
75000
+ var childDashboards = vizzly.dashboards.filter(function (d) {
75001
+ var isChildDashboard = d.parentDashboardId != null;
75002
+ var hasNotRequestedEndUserParentDashboardId = requestedEndUserParentDashboardId === undefined;
75003
+ var isChildOfRequestedParent = hasNotRequestedEndUserParentDashboardId || d.parentDashboardId === requestedEndUserParentDashboardId;
75004
+ return isChildDashboard && isChildOfRequestedParent;
75005
+ });
75006
+ // Exactly one child dashboard for the user & in read-only mode so someone else is managing the dashboard with the same userReference.
75007
+ // We will show that one dashboard to allow for a common SaaS environment where
75008
+ // multiple users share the same userReference, but some of those users have `read_write` access and other users have read access.
75009
+ // Those with `read` access should see the dashboard managed by those other users...
75010
+ if (childDashboards.length === 1 && vizzly.identityConfig.dashboardAccess.scope == 'read') {
75011
+ logDebug('Strategy will be to show read-only view of the only child dashboard. If you wish to render a read-only view of the parent dashboard, please make sure the `dashboardId` property matches the `parentDashboardId` property.', defaultParentDashboardId);
75012
+ return {
75013
+ type: 'exact',
75014
+ dashboardId: vizzly.dashboards.find(function (d) {
75015
+ return d.parentDashboardId != null;
75016
+ }).id
75017
+ };
75018
+ }
75019
+ // No specific dashboard requested, but dashboard access token only grants 'read' access.
75020
+ if (vizzly.identityConfig.dashboardAccess.scope == 'read' && defaultParentDashboardId) {
75021
+ logDebug('Strategy will be to return read-only view of the parent dashboard.', defaultParentDashboardId);
75022
+ return {
75023
+ type: 'exact',
75024
+ dashboardId: defaultParentDashboardId
75025
+ };
75026
+ }
75027
+ var dashboardIdSetInIdentityConfig = vizzly.identityConfig.dashboardAccess.dashboardId;
75028
+ if (dashboardIdSetInIdentityConfig) {
75029
+ var _vizzly$identityConfi, _vizzly$identityConfi2;
75030
+ logDebug('Strategy will be to show a child of the parent dashboard determined by the identity config', (_vizzly$identityConfi = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi.dashboardId);
75031
+ return {
75032
+ type: 'instantCopyOf',
75033
+ parentDashboardId: (_vizzly$identityConfi2 = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi2.dashboardId
75034
+ };
75035
+ } else {
75036
+ logDebug('Strategy will be to show a child of the parent dashboard', defaultParentDashboardId);
75037
+ return {
75038
+ type: 'instantCopyOf',
75039
+ parentDashboardId: defaultParentDashboardId
75040
+ };
75041
+ }
75042
+ };
75043
+
75044
+ var Mode;
75045
+ (function (Mode) {
75046
+ Mode["Admin"] = "admin";
75047
+ Mode["EndUser"] = "endUser";
75048
+ })(Mode || (Mode = {}));
75049
+ var Scope;
75050
+ (function (Scope) {
75051
+ Scope["Read"] = "read";
75052
+ Scope["ReadWrite"] = "read_write";
75053
+ })(Scope || (Scope = {}));
75054
+
75055
+ /*
75056
+ Currently, we just replicate the same behaviour as what we used to have on the API.
75057
+ */
75058
+ var runStrategy = /*#__PURE__*/function () {
75059
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(strategy, vizzly) {
75060
+ var currentDashboard, scope, _parentDashboard$perm, parentDashboard, hasParentDashboardWritePermission, dashboardCopies, mostRecentlyUpdatedChildDashboard, created;
75061
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75062
+ while (1) switch (_context.prev = _context.next) {
75063
+ case 0:
75064
+ if (!(strategy.type == 'exact')) {
75065
+ _context.next = 9;
75066
+ break;
75067
+ }
75068
+ currentDashboard = vizzly.dashboards.find(function (d) {
75069
+ return d.id === strategy.dashboardId;
75070
+ });
75071
+ if (currentDashboard.permission) {
75072
+ _context.next = 4;
75073
+ break;
75074
+ }
75075
+ throw '';
75076
+ case 4:
75077
+ scope = currentDashboard.permission.scope;
75078
+ logDebug('A specific dashboard has been requested. This will be rendered with', scope, 'scope.', strategy.dashboardId);
75079
+ return _context.abrupt("return", {
75080
+ dashboardId: strategy.dashboardId,
75081
+ mode: scope === 'read_write' && currentDashboard.parentDashboardId === null ? Mode.Admin : Mode.EndUser,
75082
+ scope: scope
75083
+ });
75084
+ case 9:
75085
+ if (!(strategy.type == 'instantCopyOf')) {
75086
+ _context.next = 29;
75087
+ break;
75088
+ }
75089
+ // If the user has write access to the parent dashboard, then we return that dashboard ID, with mode=admin
75090
+ parentDashboard = vizzly.dashboards.find(function (d) {
75091
+ return d.id === strategy.parentDashboardId;
75092
+ });
75093
+ hasParentDashboardWritePermission = ((_parentDashboard$perm = parentDashboard.permission) == null ? void 0 : _parentDashboard$perm.scope) === 'read_write';
75094
+ if (!hasParentDashboardWritePermission) {
75095
+ _context.next = 15;
75096
+ break;
75097
+ }
75098
+ logDebug('Write access to the parent dashboard has been found, so this dashboard will be shown with admin access.', strategy.parentDashboardId);
75099
+ return _context.abrupt("return", {
75100
+ dashboardId: strategy.parentDashboardId,
75101
+ mode: Mode.Admin,
75102
+ scope: Scope.ReadWrite
75103
+ });
75104
+ case 15:
75105
+ dashboardCopies = getCopiesOfParentDashboard(strategy.parentDashboardId, vizzly.dashboards);
75106
+ mostRecentlyUpdatedChildDashboard = takeMostRecentlyUpdated(dashboardCopies);
75107
+ if (!mostRecentlyUpdatedChildDashboard) {
75108
+ _context.next = 20;
75109
+ break;
75110
+ }
75111
+ logDebug('An existing child dashboard exists of the parent dashboard. As no specific dashboardId was provided, we will render the most recently updated child dashboard', mostRecentlyUpdatedChildDashboard.id);
75112
+ return _context.abrupt("return", {
75113
+ dashboardId: mostRecentlyUpdatedChildDashboard.id,
75114
+ mode: Mode.EndUser,
75115
+ scope: mostRecentlyUpdatedChildDashboard.permission.scope
75116
+ });
75117
+ case 20:
75118
+ logDebug('No previous child dashboard has been created on behalf of the current user for the parent dashboard', parentDashboard.id, '. Creating a child copy of the parent.');
75119
+ _context.next = 23;
75120
+ return vizzly.createDashboard({
75121
+ parentDashboardId: parentDashboard.id,
75122
+ definition: toSaveableDefinition(parentDashboard),
75123
+ metadata: {}
75124
+ });
75125
+ case 23:
75126
+ created = _context.sent;
75127
+ if (created) {
75128
+ _context.next = 26;
75129
+ break;
75130
+ }
75131
+ throw 'Failed to create first child dashboard for the user.';
75132
+ case 26:
75133
+ return _context.abrupt("return", {
75134
+ dashboardId: created.id,
75135
+ scope: Scope.ReadWrite,
75136
+ mode: Mode.EndUser
75137
+ });
75138
+ case 29:
75139
+ throw "Unsupported strategy";
75140
+ case 30:
75141
+ case "end":
75142
+ return _context.stop();
75143
+ }
75144
+ }, _callee);
75674
75145
  }));
75675
- var endpoint = buildPath(getHostFromQueryEngineEndpoint(queryEngineEndpoint), "/sign-in#" + authToken);
75676
- return endpoint;
75146
+ return function runStrategy(_x, _x2) {
75147
+ return _ref.apply(this, arguments);
75148
+ };
75149
+ }();
75150
+
75151
+ /*
75152
+ Stores which dashboard is the currently active one...
75153
+ */
75154
+ var useDashboardStrategy = function useDashboardStrategy(strategy, vizzly, programmaticDashboard) {
75155
+ var _useState = useState(),
75156
+ state = _useState[0],
75157
+ setState = _useState[1];
75158
+ useEffect(function () {
75159
+ var doWork = /*#__PURE__*/function () {
75160
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
75161
+ var _yield$runStrategy, mode, dashboardId, scope;
75162
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75163
+ while (1) switch (_context.prev = _context.next) {
75164
+ case 0:
75165
+ if ('dashboards' in vizzly) {
75166
+ _context.next = 2;
75167
+ break;
75168
+ }
75169
+ return _context.abrupt("return");
75170
+ case 2:
75171
+ if (strategy) {
75172
+ _context.next = 4;
75173
+ break;
75174
+ }
75175
+ return _context.abrupt("return");
75176
+ case 4:
75177
+ if (!vizzly.loading) {
75178
+ _context.next = 6;
75179
+ break;
75180
+ }
75181
+ return _context.abrupt("return");
75182
+ case 6:
75183
+ _context.next = 8;
75184
+ return runStrategy(strategy, vizzly);
75185
+ case 8:
75186
+ _yield$runStrategy = _context.sent;
75187
+ mode = _yield$runStrategy.mode;
75188
+ dashboardId = _yield$runStrategy.dashboardId;
75189
+ scope = _yield$runStrategy.scope;
75190
+ if (dashboardId != (state == null ? void 0 : state.dashboardId)) setState({
75191
+ mode: mode,
75192
+ dashboardId: dashboardId,
75193
+ scope: scope
75194
+ });
75195
+ case 13:
75196
+ case "end":
75197
+ return _context.stop();
75198
+ }
75199
+ }, _callee);
75200
+ }));
75201
+ return function doWork() {
75202
+ return _ref.apply(this, arguments);
75203
+ };
75204
+ }();
75205
+ doWork();
75206
+ }, [JSON.stringify({
75207
+ strategy: strategy,
75208
+ loading: vizzly.loading
75209
+ })]);
75210
+ if (!('dashboards' in vizzly)) return null;
75211
+ if (!state) return null;
75212
+ if (vizzly.loading) return null;
75213
+ var dashboard = vizzly.dashboards.find(function (dash) {
75214
+ return dash.id == state.dashboardId;
75215
+ }) || null;
75216
+ return {
75217
+ mode: state.mode,
75218
+ dashboard: dashboard,
75219
+ scope: state.scope,
75220
+ isProgrammaticParent: !!programmaticDashboard
75221
+ };
75222
+ };
75223
+
75224
+ var useVizzly = function useVizzly(properties, options) {
75225
+ var _useState = useState({
75226
+ loading: true,
75227
+ error: undefined,
75228
+ dashboards: [],
75229
+ globalLibraries: []
75230
+ }),
75231
+ state = _useState[0],
75232
+ setState = _useState[1];
75233
+ var vizzlyRef = useRef();
75234
+ var vizzly = vizzlyRef.current;
75235
+ useEffect(function () {
75236
+ var abortController = new AbortController();
75237
+ var doWork = /*#__PURE__*/function () {
75238
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
75239
+ var _yield$Promise$all, globalLibraries, dashboards;
75240
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75241
+ while (1) switch (_context.prev = _context.next) {
75242
+ case 0:
75243
+ _context.prev = 0;
75244
+ _context.next = 3;
75245
+ return Vizzly$1.load(properties, {
75246
+ apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
75247
+ });
75248
+ case 3:
75249
+ vizzlyRef.current = _context.sent;
75250
+ _context.next = 6;
75251
+ return Promise.all([vizzlyRef.current.getGlobalLibraries({
75252
+ abortController: abortController
75253
+ }), vizzlyRef.current.getDashboards({
75254
+ abortController: abortController
75255
+ })]);
75256
+ case 6:
75257
+ _yield$Promise$all = _context.sent;
75258
+ globalLibraries = _yield$Promise$all[0];
75259
+ dashboards = _yield$Promise$all[1];
75260
+ setState({
75261
+ loading: false,
75262
+ error: undefined,
75263
+ dashboards: dashboards,
75264
+ globalLibraries: globalLibraries
75265
+ });
75266
+ _context.next = 16;
75267
+ break;
75268
+ case 12:
75269
+ _context.prev = 12;
75270
+ _context.t0 = _context["catch"](0);
75271
+ logError('Error loading Vizzly', _context.t0);
75272
+ setState({
75273
+ loading: false,
75274
+ error: _context.t0,
75275
+ dashboards: [].concat(state.dashboards),
75276
+ globalLibraries: [].concat(state.globalLibraries)
75277
+ });
75278
+ case 16:
75279
+ case "end":
75280
+ return _context.stop();
75281
+ }
75282
+ }, _callee, null, [[0, 12]]);
75283
+ }));
75284
+ return function doWork() {
75285
+ return _ref.apply(this, arguments);
75286
+ };
75287
+ }();
75288
+ doWork();
75289
+ return function () {
75290
+ return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
75291
+ };
75292
+ }, []);
75293
+ var refetch = /*#__PURE__*/function () {
75294
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
75295
+ var abortController, doWork;
75296
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
75297
+ while (1) switch (_context3.prev = _context3.next) {
75298
+ case 0:
75299
+ abortController = new AbortController();
75300
+ doWork = /*#__PURE__*/function () {
75301
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
75302
+ var _yield$Promise$all2, globalLibraries, dashboards;
75303
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
75304
+ while (1) switch (_context2.prev = _context2.next) {
75305
+ case 0:
75306
+ _context2.prev = 0;
75307
+ _context2.next = 3;
75308
+ return Vizzly$1.load(properties, {
75309
+ apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
75310
+ });
75311
+ case 3:
75312
+ vizzlyRef.current = _context2.sent;
75313
+ _context2.next = 6;
75314
+ return Promise.all([vizzlyRef.current.getGlobalLibraries({
75315
+ abortController: abortController
75316
+ }), vizzlyRef.current.getDashboards({
75317
+ abortController: abortController
75318
+ })]);
75319
+ case 6:
75320
+ _yield$Promise$all2 = _context2.sent;
75321
+ globalLibraries = _yield$Promise$all2[0];
75322
+ dashboards = _yield$Promise$all2[1];
75323
+ setState({
75324
+ loading: false,
75325
+ error: undefined,
75326
+ dashboards: dashboards,
75327
+ globalLibraries: globalLibraries
75328
+ });
75329
+ _context2.next = 16;
75330
+ break;
75331
+ case 12:
75332
+ _context2.prev = 12;
75333
+ _context2.t0 = _context2["catch"](0);
75334
+ logError('Error loading Vizzly', _context2.t0);
75335
+ setState({
75336
+ loading: false,
75337
+ error: _context2.t0,
75338
+ dashboards: [].concat(state.dashboards),
75339
+ globalLibraries: [].concat(state.globalLibraries)
75340
+ });
75341
+ case 16:
75342
+ case "end":
75343
+ return _context2.stop();
75344
+ }
75345
+ }, _callee2, null, [[0, 12]]);
75346
+ }));
75347
+ return function doWork() {
75348
+ return _ref3.apply(this, arguments);
75349
+ };
75350
+ }();
75351
+ doWork();
75352
+ return _context3.abrupt("return", function () {
75353
+ return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
75354
+ });
75355
+ case 4:
75356
+ case "end":
75357
+ return _context3.stop();
75358
+ }
75359
+ }, _callee3);
75360
+ }));
75361
+ return function refetch() {
75362
+ return _ref2.apply(this, arguments);
75363
+ };
75364
+ }();
75365
+ var createDashboard = /*#__PURE__*/function () {
75366
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
75367
+ var createdDashboard;
75368
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
75369
+ while (1) switch (_context4.prev = _context4.next) {
75370
+ case 0:
75371
+ if (!vizzly) {
75372
+ _context4.next = 15;
75373
+ break;
75374
+ }
75375
+ _context4.prev = 1;
75376
+ _context4.next = 4;
75377
+ return vizzly.createDashboard({
75378
+ definition: params.definition,
75379
+ // permissions: params.permissions,
75380
+ parentDashboardId: params.parentDashboardId,
75381
+ metadata: params.metadata || params.meta,
75382
+ abortSignal: params.abortSignal
75383
+ });
75384
+ case 4:
75385
+ createdDashboard = _context4.sent;
75386
+ setState(_extends({}, state, {
75387
+ dashboards: [].concat(state.dashboards, [createdDashboard])
75388
+ }));
75389
+ return _context4.abrupt("return", createdDashboard);
75390
+ case 9:
75391
+ _context4.prev = 9;
75392
+ _context4.t0 = _context4["catch"](1);
75393
+ logError(_context4.t0);
75394
+ return _context4.abrupt("return", null);
75395
+ case 13:
75396
+ _context4.next = 16;
75397
+ break;
75398
+ case 15:
75399
+ throw 'Unable to create a dashboard when vizzly has not been loaded.';
75400
+ case 16:
75401
+ case "end":
75402
+ return _context4.stop();
75403
+ }
75404
+ }, _callee4, null, [[1, 9]]);
75405
+ }));
75406
+ return function createDashboard(_x) {
75407
+ return _ref4.apply(this, arguments);
75408
+ };
75409
+ }();
75410
+ useEffect(function () {
75411
+ var abortController = new AbortController();
75412
+ var doWork = /*#__PURE__*/function () {
75413
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
75414
+ var _yield$Promise$all3, globalLibraries;
75415
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
75416
+ while (1) switch (_context5.prev = _context5.next) {
75417
+ case 0:
75418
+ _context5.prev = 0;
75419
+ _context5.next = 3;
75420
+ return Vizzly$1.load(properties, {
75421
+ apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
75422
+ });
75423
+ case 3:
75424
+ vizzlyRef.current = _context5.sent;
75425
+ _context5.next = 6;
75426
+ return Promise.all([vizzlyRef.current.getGlobalLibraries({
75427
+ abortController: abortController
75428
+ })]);
75429
+ case 6:
75430
+ _yield$Promise$all3 = _context5.sent;
75431
+ globalLibraries = _yield$Promise$all3[0];
75432
+ setState(_extends({}, state, {
75433
+ globalLibraries: globalLibraries
75434
+ }));
75435
+ _context5.next = 15;
75436
+ break;
75437
+ case 11:
75438
+ _context5.prev = 11;
75439
+ _context5.t0 = _context5["catch"](0);
75440
+ logError('Error loading Vizzly', _context5.t0);
75441
+ setState({
75442
+ loading: false,
75443
+ error: _context5.t0,
75444
+ dashboards: [].concat(state.dashboards),
75445
+ globalLibraries: [].concat(state.globalLibraries)
75446
+ });
75447
+ case 15:
75448
+ case "end":
75449
+ return _context5.stop();
75450
+ }
75451
+ }, _callee5, null, [[0, 11]]);
75452
+ }));
75453
+ return function doWork() {
75454
+ return _ref5.apply(this, arguments);
75455
+ };
75456
+ }();
75457
+ if (vizzly) {
75458
+ var unsubscribe = Vizzly$1.subscription(function (eventBus) {
75459
+ if (eventBus.data.action === 'newViewsInGlobalLibrary') {
75460
+ doWork();
75461
+ }
75462
+ });
75463
+ return function () {
75464
+ return unsubscribe();
75465
+ };
75466
+ }
75467
+ return function () {
75468
+ return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
75469
+ };
75470
+ }, [vizzly]);
75471
+ var updateDashboard = /*#__PURE__*/function () {
75472
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
75473
+ var updatedDashboard, dashboards;
75474
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
75475
+ while (1) switch (_context6.prev = _context6.next) {
75476
+ case 0:
75477
+ if (!vizzly) {
75478
+ _context6.next = 20;
75479
+ break;
75480
+ }
75481
+ setState(_extends({}, state, {
75482
+ saving: SavingState.InProgress
75483
+ }));
75484
+ _context6.prev = 2;
75485
+ _context6.next = 5;
75486
+ return vizzly.updateDashboard({
75487
+ dashboardId: params.dashboardId,
75488
+ definition: params.definition,
75489
+ deleted: params.deleted,
75490
+ metadata: params.metadata || params.meta,
75491
+ abortSignal: params.abortSignal,
75492
+ name: params.name
75493
+ });
75494
+ case 5:
75495
+ updatedDashboard = _context6.sent;
75496
+ _context6.next = 8;
75497
+ return vizzly.getDashboards();
75498
+ case 8:
75499
+ dashboards = _context6.sent;
75500
+ setState(function (prevState) {
75501
+ return _extends({}, prevState, {
75502
+ dashboards: dashboards,
75503
+ saving: SavingState.Saved
75504
+ });
75505
+ });
75506
+ setTimeout(function () {
75507
+ setState(_extends({}, state, {
75508
+ saving: SavingState.Undefined
75509
+ }));
75510
+ }, 500);
75511
+ return _context6.abrupt("return", updatedDashboard);
75512
+ case 14:
75513
+ _context6.prev = 14;
75514
+ _context6.t0 = _context6["catch"](2);
75515
+ logError('Error updating dashboard', _context6.t0);
75516
+ return _context6.abrupt("return", null);
75517
+ case 18:
75518
+ _context6.next = 21;
75519
+ break;
75520
+ case 20:
75521
+ throw 'Unable to update a dashboard when vizzly has not been loaded.';
75522
+ case 21:
75523
+ case "end":
75524
+ return _context6.stop();
75525
+ }
75526
+ }, _callee6, null, [[2, 14]]);
75527
+ }));
75528
+ return function updateDashboard(_x2) {
75529
+ return _ref6.apply(this, arguments);
75530
+ };
75531
+ }();
75532
+
75533
+ // Are these needed?
75534
+ var updateScheduledReport = function updateScheduledReport(dashboardAccessToken, reportId, newCron) {
75535
+ if (vizzly) {
75536
+ return vizzly.updateScheduledReport(dashboardAccessToken, reportId, newCron);
75537
+ }
75538
+ throw 'vizzly not set';
75539
+ };
75540
+ var getScheduledReports = function getScheduledReports(dashboardAccessToken) {
75541
+ if (vizzly) {
75542
+ return vizzly.getScheduledReports(dashboardAccessToken);
75543
+ }
75544
+ throw 'vizzly not set';
75545
+ };
75546
+ logDebug('useVizzly state.', state);
75547
+ if (!vizzly || !!state.error || state.loading) {
75548
+ return _extends({}, state, {
75549
+ loading: true,
75550
+ createDashboard: null,
75551
+ identityConfig: null,
75552
+ updateDashboard: null,
75553
+ queryEngineConfig: null,
75554
+ accessType: null,
75555
+ refetch: null,
75556
+ getScheduledReports: null,
75557
+ updateScheduledReport: null
75558
+ });
75559
+ }
75560
+ var identityConfig = vizzly.getIdentityConfig();
75561
+ return _extends({}, state, {
75562
+ loading: false,
75563
+ identityConfig: identityConfig,
75564
+ createDashboard: createDashboard,
75565
+ updateDashboard: updateDashboard,
75566
+ queryEngineConfig: vizzly.getViewConfiguration().queryEngineConfig,
75567
+ accessType: !!identityConfig.dashboardAdminOverride ? 'admin' : identityConfig.dashboardAccess.accessType,
75568
+ filterDashboards: Vizzly$1.filterDashboards,
75569
+ refetch: refetch,
75570
+ updateScheduledReport: updateScheduledReport,
75571
+ getScheduledReports: getScheduledReports
75572
+ });
75573
+ };
75574
+
75575
+ var useScheduledReports = function useScheduledReports(params, dashboardAccessToken) {
75576
+ var _useState = useState([]),
75577
+ reports = _useState[0],
75578
+ setReports = _useState[1];
75579
+ useEffect(function () {
75580
+ var doWork = /*#__PURE__*/function () {
75581
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
75582
+ var _yield$params$getSche, _reports;
75583
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75584
+ while (1) switch (_context.prev = _context.next) {
75585
+ case 0:
75586
+ if (!(params.getScheduledReports && dashboardAccessToken)) {
75587
+ _context.next = 6;
75588
+ break;
75589
+ }
75590
+ _context.next = 3;
75591
+ return params.getScheduledReports(dashboardAccessToken);
75592
+ case 3:
75593
+ _yield$params$getSche = _context.sent;
75594
+ _reports = _yield$params$getSche.reports;
75595
+ setReports(_reports);
75596
+ case 6:
75597
+ case "end":
75598
+ return _context.stop();
75599
+ }
75600
+ }, _callee);
75601
+ }));
75602
+ return function doWork() {
75603
+ return _ref.apply(this, arguments);
75604
+ };
75605
+ }();
75606
+ doWork();
75607
+ }, [JSON.stringify({
75608
+ dashboardAccessToken: dashboardAccessToken,
75609
+ loadingVizzly: params
75610
+ })]);
75611
+ var updateScheduledReport = /*#__PURE__*/function () {
75612
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(reportId, newCron) {
75613
+ var updatedReport, newReports, uniqueNewReports;
75614
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
75615
+ while (1) switch (_context2.prev = _context2.next) {
75616
+ case 0:
75617
+ if (!(params.updateScheduledReport && dashboardAccessToken)) {
75618
+ _context2.next = 7;
75619
+ break;
75620
+ }
75621
+ _context2.next = 3;
75622
+ return params.updateScheduledReport(dashboardAccessToken, reportId, newCron);
75623
+ case 3:
75624
+ updatedReport = _context2.sent;
75625
+ if (updatedReport === true) {
75626
+ // Remove the deleted report...
75627
+ setReports([].concat(reports).filter(function (r) {
75628
+ return r.id != reportId;
75629
+ }));
75630
+ } else if (updatedReport) {
75631
+ // Upsert the report
75632
+ newReports = [].concat(reports, [updatedReport.report]).map(function (r) {
75633
+ return r.id == reportId ? updatedReport.report : r;
75634
+ });
75635
+ uniqueNewReports = uniqBy(newReports, function (r) {
75636
+ return r.id;
75637
+ });
75638
+ setReports(uniqueNewReports);
75639
+ }
75640
+ _context2.next = 8;
75641
+ break;
75642
+ case 7:
75643
+ console.warn('Function to update scheduled report not loaded.');
75644
+ case 8:
75645
+ case "end":
75646
+ return _context2.stop();
75647
+ }
75648
+ }, _callee2);
75649
+ }));
75650
+ return function updateScheduledReport(_x, _x2) {
75651
+ return _ref2.apply(this, arguments);
75652
+ };
75653
+ }();
75654
+ return {
75655
+ reports: reports,
75656
+ getScheduledReports: params.getScheduledReports,
75657
+ updateScheduledReport: updateScheduledReport
75658
+ };
75659
+ };
75660
+
75661
+ /*
75662
+ A context for managing the dashboard session.
75663
+ */
75664
+ var STILL_LOADING = null;
75665
+ var useSessionContext = function useSessionContext(params) {
75666
+ var _loadedStrategy$dashb, _loadedStrategy$dashb2;
75667
+ var vizzly = useVizzly({
75668
+ queryEngine: params.queryEngine,
75669
+ identity: params.identityCallback,
75670
+ dataSets: params.loadDataSetsCallback,
75671
+ programmaticDashboard: params.programmaticDashboard
75672
+ }, {
75673
+ apiHost: params.apiConfig.host
75674
+ });
75675
+ var loadedStrategy = useDashboardStrategy(getStrategy(vizzly, params.parentDashboardId, params.dashboardId, params.isEditor), vizzly, params.programmaticDashboard);
75676
+ var _useScheduledReports = useScheduledReports(vizzly, loadedStrategy == null || (_loadedStrategy$dashb = loadedStrategy.dashboard) == null || (_loadedStrategy$dashb = _loadedStrategy$dashb.permission) == null ? void 0 : _loadedStrategy$dashb.token),
75677
+ reports = _useScheduledReports.reports,
75678
+ updateScheduledReport = _useScheduledReports.updateScheduledReport;
75679
+ if (!vizzly) return STILL_LOADING;
75680
+ if ('error' in vizzly && vizzly.error) return {
75681
+ error: vizzly.error
75682
+ };
75683
+ if ('loading' in vizzly && vizzly.loading) return STILL_LOADING;
75684
+ if (!('dashboards' in vizzly)) return STILL_LOADING;
75685
+ var identityConfig = vizzly.identityConfig,
75686
+ queryEngineConfig = vizzly.queryEngineConfig;
75687
+ if (!loadedStrategy) return null;
75688
+ if (((loadedStrategy == null || (_loadedStrategy$dashb2 = loadedStrategy.dashboard) == null ? void 0 : _loadedStrategy$dashb2.dataSets) || []).length === 0) {
75689
+ return {
75690
+ error: new NoDataSetResolved()
75691
+ };
75692
+ }
75693
+ var providedValues = {
75694
+ vizzly: vizzly,
75695
+ scope: loadedStrategy.scope,
75696
+ queryEngineConfig: queryEngineConfig,
75697
+ dashboard: loadedStrategy.dashboard,
75698
+ identityConfig: identityConfig,
75699
+ mode: loadedStrategy.mode,
75700
+ vizzlyApiConfig: params.apiConfig,
75701
+ isProgrammaticParent: loadedStrategy.isProgrammaticParent,
75702
+ globalLibraries: vizzly.globalLibraries,
75703
+ reports: reports,
75704
+ updateScheduledReport: updateScheduledReport
75705
+ };
75706
+ return providedValues;
75677
75707
  };
75678
75708
 
75679
75709
  var buildImplementationMeta = function buildImplementationMeta(props) {
@@ -75695,7 +75725,9 @@ var buildImplementationMeta = function buildImplementationMeta(props) {
75695
75725
  };
75696
75726
  };
75697
75727
 
75698
- var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, onDashboardLoad) {
75728
+ var GlobalContext = /*#__PURE__*/createContext(undefined);
75729
+
75730
+ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, onDashboardLoad, updateDashboardHash) {
75699
75731
  var _session$dashboard2;
75700
75732
  useEffect(function () {
75701
75733
  var _session$dashboard;
@@ -75706,6 +75738,7 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
75706
75738
  scope: session.scope,
75707
75739
  dataSets: session.dashboard.dataSets
75708
75740
  });
75741
+ updateDashboardHash(session.dashboard);
75709
75742
  }
75710
75743
  }, [JSON.stringify({
75711
75744
  loaded: !!session,
@@ -75713,17 +75746,6 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
75713
75746
  })]);
75714
75747
  };
75715
75748
 
75716
- var FailedToSaveError = /*#__PURE__*/function (_Error) {
75717
- function FailedToSaveError(message) {
75718
- var _this;
75719
- _this = _Error.call(this, "Failed to save dashboard.") || this;
75720
- _this.message = message;
75721
- return _this;
75722
- }
75723
- _inheritsLoose(FailedToSaveError, _Error);
75724
- return FailedToSaveError;
75725
- }( /*#__PURE__*/_wrapNativeSuper(Error));
75726
-
75727
75749
  var GlobalProvider = function GlobalProvider(props) {
75728
75750
  var _useState = useState(0),
75729
75751
  resetKey = _useState[0],
@@ -75749,6 +75771,9 @@ var GlobalProvider = function GlobalProvider(props) {
75749
75771
  };
75750
75772
  var GlobalProviderContents = function GlobalProviderContents(props) {
75751
75773
  var _props$id, _session$identityConf, _props$dateFilterOpti, _session$vizzly$savin;
75774
+ var _useState2 = useState(undefined),
75775
+ dashboardHash = _useState2[0],
75776
+ setDashboardHash = _useState2[1];
75752
75777
  var implementationMeta = buildImplementationMeta(props);
75753
75778
  var apiConfig = props.vizzlyApiHost ? {
75754
75779
  host: props.vizzlyApiHost
@@ -75772,7 +75797,11 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
75772
75797
  textOverride: textOverride,
75773
75798
  isEditor: props.isEditor
75774
75799
  });
75775
- useOnDashboardLoadCallback(session, props.onDashboardLoad);
75800
+ var updateDashboardHash = function updateDashboardHash(dashboard) {
75801
+ var definition = toSaveableDefinition(dashboard);
75802
+ setDashboardHash(crypto.createHash('md5').update(JSON.stringify(definition)).digest('hex'));
75803
+ };
75804
+ useOnDashboardLoadCallback(session, props.onDashboardLoad, updateDashboardHash);
75776
75805
  var variables = useVariables(props.variables, (_props$id = props.id) != null ? _props$id : '');
75777
75806
  if (session === null) return jsx(LoadingComponent, {
75778
75807
  override: props.renderLoadingComponent
@@ -75968,14 +75997,16 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
75968
75997
  labelFormat: props == null ? void 0 : props.labelFormat,
75969
75998
  filterLibrary: props == null ? void 0 : props.filterLibrary,
75970
75999
  valueAlias: props == null ? void 0 : props.valueAlias,
75971
- variables: variables
76000
+ variables: variables,
76001
+ onDashboardUpdate: props == null ? void 0 : props.onDashboardUpdate,
76002
+ updateDashboardHash: updateDashboardHash
75972
76003
  },
75973
76004
  ai: {
75974
76005
  onAction: aiOnAction,
75975
76006
  onAsk: aiOnAsk,
75976
76007
  fetchSuggestions: aiFetchSuggestions
75977
76008
  },
75978
- onDashboardUpdate: props == null ? void 0 : props.onDashboardUpdate,
76009
+ dashboardHash: dashboardHash,
75979
76010
  dashboard: session.dashboard,
75980
76011
  runQueriesCallback: runQueriesCallback,
75981
76012
  implementationMeta: implementationMeta,