@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.
- package/dist/dashboard/src/contexts/GlobalProvider/GlobalProvider.d.ts +4 -2
- package/dist/dashboard/src/contexts/GlobalProvider/useGlobalProvider.d.ts +18 -0
- package/dist/dashboard/src/contexts/GlobalProvider/useOnDashboardLoadCallback.d.ts +3 -2
- package/dist/dashboard/src/types.d.ts +6 -5
- package/dist/dashboard.cjs.development.js +888 -857
- package/dist/dashboard.cjs.production.min.js +1 -1
- package/dist/dashboard.esm.js +888 -857
- package/dist/shared-ui/src/components/Studio/StudioContexts.d.ts +1 -1
- package/dist/shared-ui/src/contexts/DashboardBehaviour/context.d.ts +2 -2
- package/dist/shared-ui/src/contexts/DashboardBehaviour/types.d.ts +16 -13
- package/dist/shared-ui/src/contexts/DashboardContext/context.d.ts +4 -1
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ var ReactDOM__default = _interopDefault(ReactDOM);
|
|
|
23
23
|
var Fuse = _interopDefault(require('fuse.js'));
|
|
24
24
|
var solid = require('@heroicons/react/solid');
|
|
25
25
|
var outline = require('@heroicons/react/outline');
|
|
26
|
+
var crypto = _interopDefault(require('crypto'));
|
|
26
27
|
var moment$1 = _interopDefault(require('moment'));
|
|
27
28
|
var reactPopper = require('react-popper');
|
|
28
29
|
require('react-dates-17/initialize');
|
|
@@ -15627,7 +15628,7 @@ var DashboardBehaviourContext = /*#__PURE__*/React__default.createContext( /*#__
|
|
|
15627
15628
|
setOverrideDeveloperInfo: noOp
|
|
15628
15629
|
}));
|
|
15629
15630
|
var DashboardBehaviourContextProvider = function DashboardBehaviourContextProvider(props) {
|
|
15630
|
-
var _props$dashboardBehav, _props$dashboardBehav2, _props$dashboardBehav3, _props$dashboardBehav4, _props$dashboardBehav5;
|
|
15631
|
+
var _props$dashboardBehav, _props$dashboardBehav2, _props$dashboardBehav3, _props$dashboardBehav4, _props$dashboardBehav5, _props$dashboardBehav6;
|
|
15631
15632
|
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),
|
|
15632
15633
|
featureToggles = _useFeatureTogglesSet.featureToggles;
|
|
15633
15634
|
var textOverride = props.textOverride || defaultText;
|
|
@@ -15659,7 +15660,8 @@ var DashboardBehaviourContextProvider = function DashboardBehaviourContextProvid
|
|
|
15659
15660
|
id: props.id,
|
|
15660
15661
|
featureToggles: featureToggles,
|
|
15661
15662
|
valueAlias: props.valueAlias,
|
|
15662
|
-
variables: props.variables
|
|
15663
|
+
variables: props.variables,
|
|
15664
|
+
updateDashboardHash: (_props$dashboardBehav6 = props.dashboardBehaviour) == null ? void 0 : _props$dashboardBehav6.updateDashboardHash
|
|
15663
15665
|
}),
|
|
15664
15666
|
children: props.children
|
|
15665
15667
|
});
|
|
@@ -23636,7 +23638,9 @@ var DashboardContextProvider = function DashboardContextProvider(props) {
|
|
|
23636
23638
|
var dashboard = props.dashboard,
|
|
23637
23639
|
children = props.children,
|
|
23638
23640
|
trackEvent = props.trackEvent,
|
|
23639
|
-
componentEditor = props.componentEditor
|
|
23641
|
+
componentEditor = props.componentEditor,
|
|
23642
|
+
onDashboardUpdate = props.onDashboardUpdate,
|
|
23643
|
+
dashboardHash = props.dashboardHash;
|
|
23640
23644
|
var _useDashboardReducer = useDashboardReducer({
|
|
23641
23645
|
componentEditor: componentEditor ? componentEditor : null,
|
|
23642
23646
|
dashboard: dashboard ? mergeAPIIntoStoredTheme(dashboard, props.theme) : dashboard
|
|
@@ -23644,8 +23648,21 @@ var DashboardContextProvider = function DashboardContextProvider(props) {
|
|
|
23644
23648
|
state = _useDashboardReducer[0],
|
|
23645
23649
|
dispatch = _useDashboardReducer[1];
|
|
23646
23650
|
React.useEffect(function () {
|
|
23647
|
-
(
|
|
23648
|
-
|
|
23651
|
+
if (!onDashboardUpdate) return;
|
|
23652
|
+
if (!dashboardHash) {
|
|
23653
|
+
onDashboardUpdate(state.dashboard, {
|
|
23654
|
+
hasUnsavedChanges: false
|
|
23655
|
+
});
|
|
23656
|
+
return;
|
|
23657
|
+
}
|
|
23658
|
+
var definition = toSaveableDefinition(state.dashboard);
|
|
23659
|
+
var serializedDefinition = JSON.stringify(definition);
|
|
23660
|
+
var newHash = crypto.createHash('md5').update(serializedDefinition).digest('hex');
|
|
23661
|
+
var hasUnsavedChanges = dashboardHash !== newHash;
|
|
23662
|
+
onDashboardUpdate(state.dashboard, {
|
|
23663
|
+
hasUnsavedChanges: hasUnsavedChanges
|
|
23664
|
+
});
|
|
23665
|
+
}, [JSON.stringify(state.dashboard), dashboardHash, onDashboardUpdate]);
|
|
23649
23666
|
var trackEventFallback = function trackEventFallback() {};
|
|
23650
23667
|
return jsxRuntime.jsx(DashboardContext.Provider, {
|
|
23651
23668
|
value: _extends({}, state, {
|
|
@@ -41349,7 +41366,8 @@ var AdminTools = function AdminTools(props) {
|
|
|
41349
41366
|
onSave = _useDashboardBehaviou.onSave,
|
|
41350
41367
|
queryEngineConfig = _useDashboardBehaviou.queryEngineConfig,
|
|
41351
41368
|
onOpenConfigManagerUi = _useDashboardBehaviou.onOpenConfigManagerUi,
|
|
41352
|
-
disableToolbar = _useDashboardBehaviou.disableToolbar
|
|
41369
|
+
disableToolbar = _useDashboardBehaviou.disableToolbar,
|
|
41370
|
+
updateDashboardHash = _useDashboardBehaviou.updateDashboardHash;
|
|
41353
41371
|
var saveableDashboard = toSaveableDefinition(dashboard);
|
|
41354
41372
|
var supportsConfigManagerUi = supportsFeature(queryEngineConfig, 'configManagerUi') && onOpenConfigManagerUi;
|
|
41355
41373
|
React.useEffect(function () {
|
|
@@ -41390,6 +41408,7 @@ var AdminTools = function AdminTools(props) {
|
|
|
41390
41408
|
if (data.save) {
|
|
41391
41409
|
logDebug('Received from VizzlyState, `save()`');
|
|
41392
41410
|
doSave();
|
|
41411
|
+
updateDashboardHash && updateDashboardHash(dashboard);
|
|
41393
41412
|
}
|
|
41394
41413
|
}, undefined, [dashboard]);
|
|
41395
41414
|
if (disableToolbar) return null;
|
|
@@ -67714,10 +67733,11 @@ function useGoalLine(initialGoalLine, onAddingGoalLine) {
|
|
|
67714
67733
|
});
|
|
67715
67734
|
}
|
|
67716
67735
|
var isDisabled$2 = function isDisabled(state) {
|
|
67717
|
-
var _goalLineSchema$valid = goalLineSchema().validate(state
|
|
67736
|
+
var _goalLineSchema$valid = goalLineSchema().validate(state, {
|
|
67737
|
+
presence: 'required'
|
|
67738
|
+
}),
|
|
67718
67739
|
error = _goalLineSchema$valid.error;
|
|
67719
|
-
|
|
67720
|
-
return false;
|
|
67740
|
+
return !!error;
|
|
67721
67741
|
};
|
|
67722
67742
|
|
|
67723
67743
|
var GoalLineModal = function GoalLineModal(props) {
|
|
@@ -69680,7 +69700,8 @@ var StudioContexts = function StudioContexts(props) {
|
|
|
69680
69700
|
trackEvent: props.trackEvent,
|
|
69681
69701
|
dashboard: props.dashboard,
|
|
69682
69702
|
componentEditor: props.componentEditor,
|
|
69683
|
-
onDashboardUpdate: props.onDashboardUpdate,
|
|
69703
|
+
onDashboardUpdate: props.dashboardBehaviour.onDashboardUpdate,
|
|
69704
|
+
dashboardHash: props.dashboardHash,
|
|
69684
69705
|
saving: props.saving,
|
|
69685
69706
|
runQueriesCallback: function runQueriesCallback(queries, params) {
|
|
69686
69707
|
var _props$identityConfig;
|
|
@@ -73495,848 +73516,74 @@ var EditorView$1 = function EditorView(props) {
|
|
|
73495
73516
|
});
|
|
73496
73517
|
};
|
|
73497
73518
|
|
|
73498
|
-
var
|
|
73499
|
-
|
|
73500
|
-
var
|
|
73501
|
-
if (parentDashboardId) {
|
|
73502
|
-
var parentDashboard = find$1(dashboards, parentDashboardId);
|
|
73503
|
-
if (!(parentDashboard != null && parentDashboard.parentDashboardId)) {
|
|
73504
|
-
return parentDashboardId;
|
|
73505
|
-
} else {
|
|
73506
|
-
throw '[Vizzly] `parentDashboardId` value must specify an ID for a parent dashboard.';
|
|
73507
|
-
}
|
|
73508
|
-
}
|
|
73509
|
-
var parentDashboards = getParentDashboards(dashboards);
|
|
73510
|
-
var programmaticDashboardId = checkAndReturnProgrammaticDashboardId(parentDashboards);
|
|
73511
|
-
if (programmaticDashboardId) return programmaticDashboardId;
|
|
73512
|
-
return parentDashboardIdOnDashboardAccessToken || getFirstCreated(parentDashboards).id;
|
|
73513
|
-
};
|
|
73514
|
-
|
|
73515
|
-
var getStrategy = function getStrategy(vizzly, requestedEndUserParentDashboardId, requestedEndUserDashboardId, isEditor) {
|
|
73516
|
-
if (!('dashboards' in vizzly)) return undefined;
|
|
73517
|
-
if (vizzly.loading || vizzly.error) return undefined;
|
|
73518
|
-
logDebug('Loading dashboard strategy, with props;', {
|
|
73519
|
-
dashboardId: requestedEndUserDashboardId,
|
|
73520
|
-
parentDashboardId: requestedEndUserParentDashboardId
|
|
73521
|
-
});
|
|
73522
|
-
// This is a temporary fix for the issue where the dashboard is not loaded due to multiple hooks.
|
|
73523
|
-
var checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks = isEditor && vizzly.dashboards.length === 0;
|
|
73524
|
-
if (checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks) return undefined;
|
|
73525
|
-
var defaultParentDashboardId = getDefaultParentDashboardId(requestedEndUserParentDashboardId, vizzly.identityConfig.dashboardAccess.dashboardId, vizzly.dashboards);
|
|
73526
|
-
if (vizzly.accessType == 'admin') {
|
|
73527
|
-
logDebug('Admin access found, so we will show the parent dashboard.', defaultParentDashboardId);
|
|
73528
|
-
var dashboardId = defaultParentDashboardId;
|
|
73529
|
-
// If the user wants a specific dashboard, then fetch the parent dashboard of it.
|
|
73530
|
-
if (requestedEndUserDashboardId) {
|
|
73531
|
-
var foundRequestedChildDashboard = vizzly.dashboards.find(function (dashboard) {
|
|
73532
|
-
return dashboard.id == requestedEndUserDashboardId;
|
|
73533
|
-
});
|
|
73534
|
-
if (foundRequestedChildDashboard != null && foundRequestedChildDashboard.parentDashboardId) {
|
|
73535
|
-
logDebug('A child dashboard was provided whilst in admin mode. Therefore the parent of the given child will be shown to administer.', foundRequestedChildDashboard.parentDashboardId);
|
|
73536
|
-
dashboardId = foundRequestedChildDashboard.parentDashboardId;
|
|
73537
|
-
}
|
|
73538
|
-
}
|
|
73539
|
-
logDebug('Admin access found, so we will show the parent dashboard.', dashboardId);
|
|
73540
|
-
return {
|
|
73541
|
-
type: 'exact',
|
|
73542
|
-
dashboardId: dashboardId
|
|
73543
|
-
};
|
|
73544
|
-
}
|
|
73545
|
-
if (requestedEndUserDashboardId) {
|
|
73546
|
-
logDebug('Strategy will be to show dashboard', requestedEndUserDashboardId);
|
|
73547
|
-
return {
|
|
73548
|
-
type: 'exact',
|
|
73549
|
-
dashboardId: requestedEndUserDashboardId
|
|
73550
|
-
};
|
|
73551
|
-
}
|
|
73552
|
-
var childDashboards = vizzly.dashboards.filter(function (d) {
|
|
73553
|
-
var isChildDashboard = d.parentDashboardId != null;
|
|
73554
|
-
var hasNotRequestedEndUserParentDashboardId = requestedEndUserParentDashboardId === undefined;
|
|
73555
|
-
var isChildOfRequestedParent = hasNotRequestedEndUserParentDashboardId || d.parentDashboardId === requestedEndUserParentDashboardId;
|
|
73556
|
-
return isChildDashboard && isChildOfRequestedParent;
|
|
73557
|
-
});
|
|
73558
|
-
// Exactly one child dashboard for the user & in read-only mode so someone else is managing the dashboard with the same userReference.
|
|
73559
|
-
// We will show that one dashboard to allow for a common SaaS environment where
|
|
73560
|
-
// multiple users share the same userReference, but some of those users have `read_write` access and other users have read access.
|
|
73561
|
-
// Those with `read` access should see the dashboard managed by those other users...
|
|
73562
|
-
if (childDashboards.length === 1 && vizzly.identityConfig.dashboardAccess.scope == 'read') {
|
|
73563
|
-
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);
|
|
73564
|
-
return {
|
|
73565
|
-
type: 'exact',
|
|
73566
|
-
dashboardId: vizzly.dashboards.find(function (d) {
|
|
73567
|
-
return d.parentDashboardId != null;
|
|
73568
|
-
}).id
|
|
73569
|
-
};
|
|
73570
|
-
}
|
|
73571
|
-
// No specific dashboard requested, but dashboard access token only grants 'read' access.
|
|
73572
|
-
if (vizzly.identityConfig.dashboardAccess.scope == 'read' && defaultParentDashboardId) {
|
|
73573
|
-
logDebug('Strategy will be to return read-only view of the parent dashboard.', defaultParentDashboardId);
|
|
73574
|
-
return {
|
|
73575
|
-
type: 'exact',
|
|
73576
|
-
dashboardId: defaultParentDashboardId
|
|
73577
|
-
};
|
|
73578
|
-
}
|
|
73579
|
-
var dashboardIdSetInIdentityConfig = vizzly.identityConfig.dashboardAccess.dashboardId;
|
|
73580
|
-
if (dashboardIdSetInIdentityConfig) {
|
|
73581
|
-
var _vizzly$identityConfi, _vizzly$identityConfi2;
|
|
73582
|
-
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);
|
|
73583
|
-
return {
|
|
73584
|
-
type: 'instantCopyOf',
|
|
73585
|
-
parentDashboardId: (_vizzly$identityConfi2 = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi2.dashboardId
|
|
73586
|
-
};
|
|
73587
|
-
} else {
|
|
73588
|
-
logDebug('Strategy will be to show a child of the parent dashboard', defaultParentDashboardId);
|
|
73589
|
-
return {
|
|
73590
|
-
type: 'instantCopyOf',
|
|
73591
|
-
parentDashboardId: defaultParentDashboardId
|
|
73592
|
-
};
|
|
73593
|
-
}
|
|
73594
|
-
};
|
|
73595
|
-
|
|
73596
|
-
var Mode;
|
|
73597
|
-
(function (Mode) {
|
|
73598
|
-
Mode["Admin"] = "admin";
|
|
73599
|
-
Mode["EndUser"] = "endUser";
|
|
73600
|
-
})(Mode || (Mode = {}));
|
|
73601
|
-
var Scope;
|
|
73602
|
-
(function (Scope) {
|
|
73603
|
-
Scope["Read"] = "read";
|
|
73604
|
-
Scope["ReadWrite"] = "read_write";
|
|
73605
|
-
})(Scope || (Scope = {}));
|
|
73606
|
-
|
|
73607
|
-
/*
|
|
73608
|
-
Currently, we just replicate the same behaviour as what we used to have on the API.
|
|
73609
|
-
*/
|
|
73610
|
-
var runStrategy = /*#__PURE__*/function () {
|
|
73611
|
-
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(strategy, vizzly) {
|
|
73612
|
-
var currentDashboard, scope, _parentDashboard$perm, parentDashboard, hasParentDashboardWritePermission, dashboardCopies, mostRecentlyUpdatedChildDashboard, created;
|
|
73519
|
+
var getParentDashboards$1 = function getParentDashboards(httpClient) {
|
|
73520
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
73521
|
+
var _yield$httpClient, status, body;
|
|
73613
73522
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73614
73523
|
while (1) switch (_context.prev = _context.next) {
|
|
73615
73524
|
case 0:
|
|
73616
|
-
|
|
73617
|
-
|
|
73618
|
-
|
|
73619
|
-
|
|
73620
|
-
currentDashboard = vizzly.dashboards.find(function (d) {
|
|
73621
|
-
return d.id === strategy.dashboardId;
|
|
73622
|
-
});
|
|
73623
|
-
if (currentDashboard.permission) {
|
|
73624
|
-
_context.next = 4;
|
|
73625
|
-
break;
|
|
73626
|
-
}
|
|
73627
|
-
throw '';
|
|
73628
|
-
case 4:
|
|
73629
|
-
scope = currentDashboard.permission.scope;
|
|
73630
|
-
logDebug('A specific dashboard has been requested. This will be rendered with', scope, 'scope.', strategy.dashboardId);
|
|
73631
|
-
return _context.abrupt("return", {
|
|
73632
|
-
dashboardId: strategy.dashboardId,
|
|
73633
|
-
mode: scope === 'read_write' && currentDashboard.parentDashboardId === null ? Mode.Admin : Mode.EndUser,
|
|
73634
|
-
scope: scope
|
|
73635
|
-
});
|
|
73636
|
-
case 9:
|
|
73637
|
-
if (!(strategy.type == 'instantCopyOf')) {
|
|
73638
|
-
_context.next = 29;
|
|
73639
|
-
break;
|
|
73640
|
-
}
|
|
73641
|
-
// If the user has write access to the parent dashboard, then we return that dashboard ID, with mode=admin
|
|
73642
|
-
parentDashboard = vizzly.dashboards.find(function (d) {
|
|
73643
|
-
return d.id === strategy.parentDashboardId;
|
|
73644
|
-
});
|
|
73645
|
-
hasParentDashboardWritePermission = ((_parentDashboard$perm = parentDashboard.permission) == null ? void 0 : _parentDashboard$perm.scope) === 'read_write';
|
|
73646
|
-
if (!hasParentDashboardWritePermission) {
|
|
73647
|
-
_context.next = 15;
|
|
73648
|
-
break;
|
|
73649
|
-
}
|
|
73650
|
-
logDebug('Write access to the parent dashboard has been found, so this dashboard will be shown with admin access.', strategy.parentDashboardId);
|
|
73651
|
-
return _context.abrupt("return", {
|
|
73652
|
-
dashboardId: strategy.parentDashboardId,
|
|
73653
|
-
mode: Mode.Admin,
|
|
73654
|
-
scope: Scope.ReadWrite
|
|
73655
|
-
});
|
|
73656
|
-
case 15:
|
|
73657
|
-
dashboardCopies = getCopiesOfParentDashboard(strategy.parentDashboardId, vizzly.dashboards);
|
|
73658
|
-
mostRecentlyUpdatedChildDashboard = takeMostRecentlyUpdated(dashboardCopies);
|
|
73659
|
-
if (!mostRecentlyUpdatedChildDashboard) {
|
|
73660
|
-
_context.next = 20;
|
|
73661
|
-
break;
|
|
73662
|
-
}
|
|
73663
|
-
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);
|
|
73664
|
-
return _context.abrupt("return", {
|
|
73665
|
-
dashboardId: mostRecentlyUpdatedChildDashboard.id,
|
|
73666
|
-
mode: Mode.EndUser,
|
|
73667
|
-
scope: mostRecentlyUpdatedChildDashboard.permission.scope
|
|
73668
|
-
});
|
|
73669
|
-
case 20:
|
|
73670
|
-
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.');
|
|
73671
|
-
_context.next = 23;
|
|
73672
|
-
return vizzly.createDashboard({
|
|
73673
|
-
parentDashboardId: parentDashboard.id,
|
|
73674
|
-
definition: toSaveableDefinition(parentDashboard),
|
|
73675
|
-
metadata: {}
|
|
73525
|
+
_context.next = 2;
|
|
73526
|
+
return httpClient({
|
|
73527
|
+
path: "/api/v2/parent-dashboards",
|
|
73528
|
+
method: 'get'
|
|
73676
73529
|
});
|
|
73677
|
-
case
|
|
73678
|
-
|
|
73679
|
-
|
|
73680
|
-
|
|
73530
|
+
case 2:
|
|
73531
|
+
_yield$httpClient = _context.sent;
|
|
73532
|
+
status = _yield$httpClient.status;
|
|
73533
|
+
body = _yield$httpClient.body;
|
|
73534
|
+
if (!(status == 200)) {
|
|
73535
|
+
_context.next = 7;
|
|
73681
73536
|
break;
|
|
73682
73537
|
}
|
|
73683
|
-
|
|
73684
|
-
|
|
73685
|
-
|
|
73686
|
-
|
|
73687
|
-
|
|
73688
|
-
|
|
73689
|
-
|
|
73690
|
-
|
|
73691
|
-
|
|
73692
|
-
|
|
73538
|
+
return _context.abrupt("return", body.dashboards.map(function (rawDashboard) {
|
|
73539
|
+
return {
|
|
73540
|
+
id: rawDashboard.id,
|
|
73541
|
+
created_at: rawDashboard.created_at,
|
|
73542
|
+
updated_at: rawDashboard.updated_at,
|
|
73543
|
+
webhook_id: rawDashboard.webhook_id
|
|
73544
|
+
};
|
|
73545
|
+
}));
|
|
73546
|
+
case 7:
|
|
73547
|
+
return _context.abrupt("return", undefined);
|
|
73548
|
+
case 8:
|
|
73693
73549
|
case "end":
|
|
73694
73550
|
return _context.stop();
|
|
73695
73551
|
}
|
|
73696
73552
|
}, _callee);
|
|
73697
73553
|
}));
|
|
73698
|
-
return function runStrategy(_x, _x2) {
|
|
73699
|
-
return _ref.apply(this, arguments);
|
|
73700
|
-
};
|
|
73701
|
-
}();
|
|
73702
|
-
|
|
73703
|
-
/*
|
|
73704
|
-
Stores which dashboard is the currently active one...
|
|
73705
|
-
*/
|
|
73706
|
-
var useDashboardStrategy = function useDashboardStrategy(strategy, vizzly, programmaticDashboard) {
|
|
73707
|
-
var _useState = React.useState(),
|
|
73708
|
-
state = _useState[0],
|
|
73709
|
-
setState = _useState[1];
|
|
73710
|
-
React.useEffect(function () {
|
|
73711
|
-
var doWork = /*#__PURE__*/function () {
|
|
73712
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
73713
|
-
var _yield$runStrategy, mode, dashboardId, scope;
|
|
73714
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73715
|
-
while (1) switch (_context.prev = _context.next) {
|
|
73716
|
-
case 0:
|
|
73717
|
-
if ('dashboards' in vizzly) {
|
|
73718
|
-
_context.next = 2;
|
|
73719
|
-
break;
|
|
73720
|
-
}
|
|
73721
|
-
return _context.abrupt("return");
|
|
73722
|
-
case 2:
|
|
73723
|
-
if (strategy) {
|
|
73724
|
-
_context.next = 4;
|
|
73725
|
-
break;
|
|
73726
|
-
}
|
|
73727
|
-
return _context.abrupt("return");
|
|
73728
|
-
case 4:
|
|
73729
|
-
if (!vizzly.loading) {
|
|
73730
|
-
_context.next = 6;
|
|
73731
|
-
break;
|
|
73732
|
-
}
|
|
73733
|
-
return _context.abrupt("return");
|
|
73734
|
-
case 6:
|
|
73735
|
-
_context.next = 8;
|
|
73736
|
-
return runStrategy(strategy, vizzly);
|
|
73737
|
-
case 8:
|
|
73738
|
-
_yield$runStrategy = _context.sent;
|
|
73739
|
-
mode = _yield$runStrategy.mode;
|
|
73740
|
-
dashboardId = _yield$runStrategy.dashboardId;
|
|
73741
|
-
scope = _yield$runStrategy.scope;
|
|
73742
|
-
if (dashboardId != (state == null ? void 0 : state.dashboardId)) setState({
|
|
73743
|
-
mode: mode,
|
|
73744
|
-
dashboardId: dashboardId,
|
|
73745
|
-
scope: scope
|
|
73746
|
-
});
|
|
73747
|
-
case 13:
|
|
73748
|
-
case "end":
|
|
73749
|
-
return _context.stop();
|
|
73750
|
-
}
|
|
73751
|
-
}, _callee);
|
|
73752
|
-
}));
|
|
73753
|
-
return function doWork() {
|
|
73754
|
-
return _ref.apply(this, arguments);
|
|
73755
|
-
};
|
|
73756
|
-
}();
|
|
73757
|
-
doWork();
|
|
73758
|
-
}, [JSON.stringify({
|
|
73759
|
-
strategy: strategy,
|
|
73760
|
-
loading: vizzly.loading
|
|
73761
|
-
})]);
|
|
73762
|
-
if (!('dashboards' in vizzly)) return null;
|
|
73763
|
-
if (!state) return null;
|
|
73764
|
-
if (vizzly.loading) return null;
|
|
73765
|
-
var dashboard = vizzly.dashboards.find(function (dash) {
|
|
73766
|
-
return dash.id == state.dashboardId;
|
|
73767
|
-
}) || null;
|
|
73768
|
-
return {
|
|
73769
|
-
mode: state.mode,
|
|
73770
|
-
dashboard: dashboard,
|
|
73771
|
-
scope: state.scope,
|
|
73772
|
-
isProgrammaticParent: !!programmaticDashboard
|
|
73773
|
-
};
|
|
73774
73554
|
};
|
|
73775
73555
|
|
|
73776
|
-
|
|
73777
|
-
|
|
73778
|
-
|
|
73779
|
-
|
|
73780
|
-
|
|
73781
|
-
|
|
73782
|
-
|
|
73783
|
-
|
|
73784
|
-
return NoDataSetResolved;
|
|
73785
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
73786
|
-
|
|
73787
|
-
var useVizzly = function useVizzly(properties, options) {
|
|
73788
|
-
var _useState = React.useState({
|
|
73789
|
-
loading: true,
|
|
73790
|
-
error: undefined,
|
|
73791
|
-
dashboards: [],
|
|
73792
|
-
globalLibraries: []
|
|
73793
|
-
}),
|
|
73794
|
-
state = _useState[0],
|
|
73795
|
-
setState = _useState[1];
|
|
73796
|
-
var vizzlyRef = React.useRef();
|
|
73797
|
-
var vizzly = vizzlyRef.current;
|
|
73798
|
-
React.useEffect(function () {
|
|
73799
|
-
var abortController = new AbortController();
|
|
73800
|
-
var doWork = /*#__PURE__*/function () {
|
|
73801
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
73802
|
-
var _yield$Promise$all, globalLibraries, dashboards;
|
|
73803
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73804
|
-
while (1) switch (_context.prev = _context.next) {
|
|
73805
|
-
case 0:
|
|
73806
|
-
_context.prev = 0;
|
|
73807
|
-
_context.next = 3;
|
|
73808
|
-
return Vizzly$1.load(properties, {
|
|
73809
|
-
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
73810
|
-
});
|
|
73811
|
-
case 3:
|
|
73812
|
-
vizzlyRef.current = _context.sent;
|
|
73813
|
-
_context.next = 6;
|
|
73814
|
-
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
73815
|
-
abortController: abortController
|
|
73816
|
-
}), vizzlyRef.current.getDashboards({
|
|
73817
|
-
abortController: abortController
|
|
73818
|
-
})]);
|
|
73819
|
-
case 6:
|
|
73820
|
-
_yield$Promise$all = _context.sent;
|
|
73821
|
-
globalLibraries = _yield$Promise$all[0];
|
|
73822
|
-
dashboards = _yield$Promise$all[1];
|
|
73823
|
-
setState({
|
|
73824
|
-
loading: false,
|
|
73825
|
-
error: undefined,
|
|
73826
|
-
dashboards: dashboards,
|
|
73827
|
-
globalLibraries: globalLibraries
|
|
73828
|
-
});
|
|
73829
|
-
_context.next = 16;
|
|
73830
|
-
break;
|
|
73831
|
-
case 12:
|
|
73832
|
-
_context.prev = 12;
|
|
73833
|
-
_context.t0 = _context["catch"](0);
|
|
73834
|
-
logError('Error loading Vizzly', _context.t0);
|
|
73835
|
-
setState({
|
|
73836
|
-
loading: false,
|
|
73837
|
-
error: _context.t0,
|
|
73838
|
-
dashboards: [].concat(state.dashboards),
|
|
73839
|
-
globalLibraries: [].concat(state.globalLibraries)
|
|
73840
|
-
});
|
|
73841
|
-
case 16:
|
|
73842
|
-
case "end":
|
|
73843
|
-
return _context.stop();
|
|
73844
|
-
}
|
|
73845
|
-
}, _callee, null, [[0, 12]]);
|
|
73846
|
-
}));
|
|
73847
|
-
return function doWork() {
|
|
73848
|
-
return _ref.apply(this, arguments);
|
|
73849
|
-
};
|
|
73850
|
-
}();
|
|
73851
|
-
doWork();
|
|
73852
|
-
return function () {
|
|
73853
|
-
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
73854
|
-
};
|
|
73855
|
-
}, []);
|
|
73856
|
-
var refetch = /*#__PURE__*/function () {
|
|
73857
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
73858
|
-
var abortController, doWork;
|
|
73859
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
73860
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
73861
|
-
case 0:
|
|
73862
|
-
abortController = new AbortController();
|
|
73863
|
-
doWork = /*#__PURE__*/function () {
|
|
73864
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
73865
|
-
var _yield$Promise$all2, globalLibraries, dashboards;
|
|
73866
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
73867
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
73868
|
-
case 0:
|
|
73869
|
-
_context2.prev = 0;
|
|
73870
|
-
_context2.next = 3;
|
|
73871
|
-
return Vizzly$1.load(properties, {
|
|
73872
|
-
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
73873
|
-
});
|
|
73874
|
-
case 3:
|
|
73875
|
-
vizzlyRef.current = _context2.sent;
|
|
73876
|
-
_context2.next = 6;
|
|
73877
|
-
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
73878
|
-
abortController: abortController
|
|
73879
|
-
}), vizzlyRef.current.getDashboards({
|
|
73880
|
-
abortController: abortController
|
|
73881
|
-
})]);
|
|
73882
|
-
case 6:
|
|
73883
|
-
_yield$Promise$all2 = _context2.sent;
|
|
73884
|
-
globalLibraries = _yield$Promise$all2[0];
|
|
73885
|
-
dashboards = _yield$Promise$all2[1];
|
|
73886
|
-
setState({
|
|
73887
|
-
loading: false,
|
|
73888
|
-
error: undefined,
|
|
73889
|
-
dashboards: dashboards,
|
|
73890
|
-
globalLibraries: globalLibraries
|
|
73891
|
-
});
|
|
73892
|
-
_context2.next = 16;
|
|
73893
|
-
break;
|
|
73894
|
-
case 12:
|
|
73895
|
-
_context2.prev = 12;
|
|
73896
|
-
_context2.t0 = _context2["catch"](0);
|
|
73897
|
-
logError('Error loading Vizzly', _context2.t0);
|
|
73898
|
-
setState({
|
|
73899
|
-
loading: false,
|
|
73900
|
-
error: _context2.t0,
|
|
73901
|
-
dashboards: [].concat(state.dashboards),
|
|
73902
|
-
globalLibraries: [].concat(state.globalLibraries)
|
|
73903
|
-
});
|
|
73904
|
-
case 16:
|
|
73905
|
-
case "end":
|
|
73906
|
-
return _context2.stop();
|
|
73907
|
-
}
|
|
73908
|
-
}, _callee2, null, [[0, 12]]);
|
|
73909
|
-
}));
|
|
73910
|
-
return function doWork() {
|
|
73911
|
-
return _ref3.apply(this, arguments);
|
|
73912
|
-
};
|
|
73913
|
-
}();
|
|
73914
|
-
doWork();
|
|
73915
|
-
return _context3.abrupt("return", function () {
|
|
73916
|
-
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
73917
|
-
});
|
|
73918
|
-
case 4:
|
|
73919
|
-
case "end":
|
|
73920
|
-
return _context3.stop();
|
|
73921
|
-
}
|
|
73922
|
-
}, _callee3);
|
|
73923
|
-
}));
|
|
73924
|
-
return function refetch() {
|
|
73925
|
-
return _ref2.apply(this, arguments);
|
|
73926
|
-
};
|
|
73927
|
-
}();
|
|
73928
|
-
var createDashboard = /*#__PURE__*/function () {
|
|
73929
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
73930
|
-
var createdDashboard;
|
|
73931
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
73932
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
73556
|
+
// If cronSchedule is `null`, then it means the scheduled
|
|
73557
|
+
// report is deleted.
|
|
73558
|
+
var saveScheduledReport = function saveScheduledReport(httpClient) {
|
|
73559
|
+
return /*#__PURE__*/function () {
|
|
73560
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
73561
|
+
var _yield$httpClient, status;
|
|
73562
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73563
|
+
while (1) switch (_context.prev = _context.next) {
|
|
73933
73564
|
case 0:
|
|
73934
|
-
|
|
73935
|
-
|
|
73936
|
-
|
|
73937
|
-
|
|
73938
|
-
|
|
73939
|
-
|
|
73940
|
-
|
|
73941
|
-
|
|
73942
|
-
|
|
73943
|
-
parentDashboardId: params.parentDashboardId,
|
|
73944
|
-
metadata: params.metadata || params.meta,
|
|
73945
|
-
abortSignal: params.abortSignal
|
|
73565
|
+
_context.next = 2;
|
|
73566
|
+
return httpClient({
|
|
73567
|
+
path: '/api/scheduled-report',
|
|
73568
|
+
method: 'post',
|
|
73569
|
+
body: {
|
|
73570
|
+
cronSchedule: params.cronSchedule,
|
|
73571
|
+
dashboardAccessToken: params.dashboardAccessToken,
|
|
73572
|
+
scheduledReportId: params.scheduledReportId
|
|
73573
|
+
}
|
|
73946
73574
|
});
|
|
73947
|
-
case
|
|
73948
|
-
|
|
73949
|
-
|
|
73950
|
-
|
|
73951
|
-
|
|
73952
|
-
return _context4.abrupt("return", createdDashboard);
|
|
73953
|
-
case 9:
|
|
73954
|
-
_context4.prev = 9;
|
|
73955
|
-
_context4.t0 = _context4["catch"](1);
|
|
73956
|
-
logError(_context4.t0);
|
|
73957
|
-
return _context4.abrupt("return", null);
|
|
73958
|
-
case 13:
|
|
73959
|
-
_context4.next = 16;
|
|
73960
|
-
break;
|
|
73961
|
-
case 15:
|
|
73962
|
-
throw 'Unable to create a dashboard when vizzly has not been loaded.';
|
|
73963
|
-
case 16:
|
|
73575
|
+
case 2:
|
|
73576
|
+
_yield$httpClient = _context.sent;
|
|
73577
|
+
status = _yield$httpClient.status;
|
|
73578
|
+
return _context.abrupt("return", status == 200);
|
|
73579
|
+
case 5:
|
|
73964
73580
|
case "end":
|
|
73965
|
-
return
|
|
73581
|
+
return _context.stop();
|
|
73966
73582
|
}
|
|
73967
|
-
},
|
|
73583
|
+
}, _callee);
|
|
73968
73584
|
}));
|
|
73969
|
-
return function
|
|
73970
|
-
return
|
|
73971
|
-
};
|
|
73972
|
-
}();
|
|
73973
|
-
React.useEffect(function () {
|
|
73974
|
-
var abortController = new AbortController();
|
|
73975
|
-
var doWork = /*#__PURE__*/function () {
|
|
73976
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
73977
|
-
var _yield$Promise$all3, globalLibraries;
|
|
73978
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
73979
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
73980
|
-
case 0:
|
|
73981
|
-
_context5.prev = 0;
|
|
73982
|
-
_context5.next = 3;
|
|
73983
|
-
return Vizzly$1.load(properties, {
|
|
73984
|
-
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
73985
|
-
});
|
|
73986
|
-
case 3:
|
|
73987
|
-
vizzlyRef.current = _context5.sent;
|
|
73988
|
-
_context5.next = 6;
|
|
73989
|
-
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
73990
|
-
abortController: abortController
|
|
73991
|
-
})]);
|
|
73992
|
-
case 6:
|
|
73993
|
-
_yield$Promise$all3 = _context5.sent;
|
|
73994
|
-
globalLibraries = _yield$Promise$all3[0];
|
|
73995
|
-
setState(_extends({}, state, {
|
|
73996
|
-
globalLibraries: globalLibraries
|
|
73997
|
-
}));
|
|
73998
|
-
_context5.next = 15;
|
|
73999
|
-
break;
|
|
74000
|
-
case 11:
|
|
74001
|
-
_context5.prev = 11;
|
|
74002
|
-
_context5.t0 = _context5["catch"](0);
|
|
74003
|
-
logError('Error loading Vizzly', _context5.t0);
|
|
74004
|
-
setState({
|
|
74005
|
-
loading: false,
|
|
74006
|
-
error: _context5.t0,
|
|
74007
|
-
dashboards: [].concat(state.dashboards),
|
|
74008
|
-
globalLibraries: [].concat(state.globalLibraries)
|
|
74009
|
-
});
|
|
74010
|
-
case 15:
|
|
74011
|
-
case "end":
|
|
74012
|
-
return _context5.stop();
|
|
74013
|
-
}
|
|
74014
|
-
}, _callee5, null, [[0, 11]]);
|
|
74015
|
-
}));
|
|
74016
|
-
return function doWork() {
|
|
74017
|
-
return _ref5.apply(this, arguments);
|
|
74018
|
-
};
|
|
74019
|
-
}();
|
|
74020
|
-
if (vizzly) {
|
|
74021
|
-
var unsubscribe = Vizzly$1.subscription(function (eventBus) {
|
|
74022
|
-
if (eventBus.data.action === 'newViewsInGlobalLibrary') {
|
|
74023
|
-
doWork();
|
|
74024
|
-
}
|
|
74025
|
-
});
|
|
74026
|
-
return function () {
|
|
74027
|
-
return unsubscribe();
|
|
74028
|
-
};
|
|
74029
|
-
}
|
|
74030
|
-
return function () {
|
|
74031
|
-
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
74032
|
-
};
|
|
74033
|
-
}, [vizzly]);
|
|
74034
|
-
var updateDashboard = /*#__PURE__*/function () {
|
|
74035
|
-
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
74036
|
-
var updatedDashboard, dashboards;
|
|
74037
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
74038
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
74039
|
-
case 0:
|
|
74040
|
-
if (!vizzly) {
|
|
74041
|
-
_context6.next = 20;
|
|
74042
|
-
break;
|
|
74043
|
-
}
|
|
74044
|
-
setState(_extends({}, state, {
|
|
74045
|
-
saving: SavingState.InProgress
|
|
74046
|
-
}));
|
|
74047
|
-
_context6.prev = 2;
|
|
74048
|
-
_context6.next = 5;
|
|
74049
|
-
return vizzly.updateDashboard({
|
|
74050
|
-
dashboardId: params.dashboardId,
|
|
74051
|
-
definition: params.definition,
|
|
74052
|
-
deleted: params.deleted,
|
|
74053
|
-
metadata: params.metadata || params.meta,
|
|
74054
|
-
abortSignal: params.abortSignal,
|
|
74055
|
-
name: params.name
|
|
74056
|
-
});
|
|
74057
|
-
case 5:
|
|
74058
|
-
updatedDashboard = _context6.sent;
|
|
74059
|
-
_context6.next = 8;
|
|
74060
|
-
return vizzly.getDashboards();
|
|
74061
|
-
case 8:
|
|
74062
|
-
dashboards = _context6.sent;
|
|
74063
|
-
setState(function (prevState) {
|
|
74064
|
-
return _extends({}, prevState, {
|
|
74065
|
-
dashboards: dashboards,
|
|
74066
|
-
saving: SavingState.Saved
|
|
74067
|
-
});
|
|
74068
|
-
});
|
|
74069
|
-
setTimeout(function () {
|
|
74070
|
-
setState(_extends({}, state, {
|
|
74071
|
-
saving: SavingState.Undefined
|
|
74072
|
-
}));
|
|
74073
|
-
}, 500);
|
|
74074
|
-
return _context6.abrupt("return", updatedDashboard);
|
|
74075
|
-
case 14:
|
|
74076
|
-
_context6.prev = 14;
|
|
74077
|
-
_context6.t0 = _context6["catch"](2);
|
|
74078
|
-
logError('Error updating dashboard', _context6.t0);
|
|
74079
|
-
return _context6.abrupt("return", null);
|
|
74080
|
-
case 18:
|
|
74081
|
-
_context6.next = 21;
|
|
74082
|
-
break;
|
|
74083
|
-
case 20:
|
|
74084
|
-
throw 'Unable to update a dashboard when vizzly has not been loaded.';
|
|
74085
|
-
case 21:
|
|
74086
|
-
case "end":
|
|
74087
|
-
return _context6.stop();
|
|
74088
|
-
}
|
|
74089
|
-
}, _callee6, null, [[2, 14]]);
|
|
74090
|
-
}));
|
|
74091
|
-
return function updateDashboard(_x2) {
|
|
74092
|
-
return _ref6.apply(this, arguments);
|
|
74093
|
-
};
|
|
74094
|
-
}();
|
|
74095
|
-
|
|
74096
|
-
// Are these needed?
|
|
74097
|
-
var updateScheduledReport = function updateScheduledReport(dashboardAccessToken, reportId, newCron) {
|
|
74098
|
-
if (vizzly) {
|
|
74099
|
-
return vizzly.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
74100
|
-
}
|
|
74101
|
-
throw 'vizzly not set';
|
|
74102
|
-
};
|
|
74103
|
-
var getScheduledReports = function getScheduledReports(dashboardAccessToken) {
|
|
74104
|
-
if (vizzly) {
|
|
74105
|
-
return vizzly.getScheduledReports(dashboardAccessToken);
|
|
74106
|
-
}
|
|
74107
|
-
throw 'vizzly not set';
|
|
74108
|
-
};
|
|
74109
|
-
logDebug('useVizzly state.', state);
|
|
74110
|
-
if (!vizzly || !!state.error || state.loading) {
|
|
74111
|
-
return _extends({}, state, {
|
|
74112
|
-
loading: true,
|
|
74113
|
-
createDashboard: null,
|
|
74114
|
-
identityConfig: null,
|
|
74115
|
-
updateDashboard: null,
|
|
74116
|
-
queryEngineConfig: null,
|
|
74117
|
-
accessType: null,
|
|
74118
|
-
refetch: null,
|
|
74119
|
-
getScheduledReports: null,
|
|
74120
|
-
updateScheduledReport: null
|
|
74121
|
-
});
|
|
74122
|
-
}
|
|
74123
|
-
var identityConfig = vizzly.getIdentityConfig();
|
|
74124
|
-
return _extends({}, state, {
|
|
74125
|
-
loading: false,
|
|
74126
|
-
identityConfig: identityConfig,
|
|
74127
|
-
createDashboard: createDashboard,
|
|
74128
|
-
updateDashboard: updateDashboard,
|
|
74129
|
-
queryEngineConfig: vizzly.getViewConfiguration().queryEngineConfig,
|
|
74130
|
-
accessType: !!identityConfig.dashboardAdminOverride ? 'admin' : identityConfig.dashboardAccess.accessType,
|
|
74131
|
-
filterDashboards: Vizzly$1.filterDashboards,
|
|
74132
|
-
refetch: refetch,
|
|
74133
|
-
updateScheduledReport: updateScheduledReport,
|
|
74134
|
-
getScheduledReports: getScheduledReports
|
|
74135
|
-
});
|
|
74136
|
-
};
|
|
74137
|
-
|
|
74138
|
-
var useScheduledReports = function useScheduledReports(params, dashboardAccessToken) {
|
|
74139
|
-
var _useState = React.useState([]),
|
|
74140
|
-
reports = _useState[0],
|
|
74141
|
-
setReports = _useState[1];
|
|
74142
|
-
React.useEffect(function () {
|
|
74143
|
-
var doWork = /*#__PURE__*/function () {
|
|
74144
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
74145
|
-
var _yield$params$getSche, _reports;
|
|
74146
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74147
|
-
while (1) switch (_context.prev = _context.next) {
|
|
74148
|
-
case 0:
|
|
74149
|
-
if (!(params.getScheduledReports && dashboardAccessToken)) {
|
|
74150
|
-
_context.next = 6;
|
|
74151
|
-
break;
|
|
74152
|
-
}
|
|
74153
|
-
_context.next = 3;
|
|
74154
|
-
return params.getScheduledReports(dashboardAccessToken);
|
|
74155
|
-
case 3:
|
|
74156
|
-
_yield$params$getSche = _context.sent;
|
|
74157
|
-
_reports = _yield$params$getSche.reports;
|
|
74158
|
-
setReports(_reports);
|
|
74159
|
-
case 6:
|
|
74160
|
-
case "end":
|
|
74161
|
-
return _context.stop();
|
|
74162
|
-
}
|
|
74163
|
-
}, _callee);
|
|
74164
|
-
}));
|
|
74165
|
-
return function doWork() {
|
|
74166
|
-
return _ref.apply(this, arguments);
|
|
74167
|
-
};
|
|
74168
|
-
}();
|
|
74169
|
-
doWork();
|
|
74170
|
-
}, [JSON.stringify({
|
|
74171
|
-
dashboardAccessToken: dashboardAccessToken,
|
|
74172
|
-
loadingVizzly: params
|
|
74173
|
-
})]);
|
|
74174
|
-
var updateScheduledReport = /*#__PURE__*/function () {
|
|
74175
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(reportId, newCron) {
|
|
74176
|
-
var updatedReport, newReports, uniqueNewReports;
|
|
74177
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
74178
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
74179
|
-
case 0:
|
|
74180
|
-
if (!(params.updateScheduledReport && dashboardAccessToken)) {
|
|
74181
|
-
_context2.next = 7;
|
|
74182
|
-
break;
|
|
74183
|
-
}
|
|
74184
|
-
_context2.next = 3;
|
|
74185
|
-
return params.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
74186
|
-
case 3:
|
|
74187
|
-
updatedReport = _context2.sent;
|
|
74188
|
-
if (updatedReport === true) {
|
|
74189
|
-
// Remove the deleted report...
|
|
74190
|
-
setReports([].concat(reports).filter(function (r) {
|
|
74191
|
-
return r.id != reportId;
|
|
74192
|
-
}));
|
|
74193
|
-
} else if (updatedReport) {
|
|
74194
|
-
// Upsert the report
|
|
74195
|
-
newReports = [].concat(reports, [updatedReport.report]).map(function (r) {
|
|
74196
|
-
return r.id == reportId ? updatedReport.report : r;
|
|
74197
|
-
});
|
|
74198
|
-
uniqueNewReports = _.uniqBy(newReports, function (r) {
|
|
74199
|
-
return r.id;
|
|
74200
|
-
});
|
|
74201
|
-
setReports(uniqueNewReports);
|
|
74202
|
-
}
|
|
74203
|
-
_context2.next = 8;
|
|
74204
|
-
break;
|
|
74205
|
-
case 7:
|
|
74206
|
-
console.warn('Function to update scheduled report not loaded.');
|
|
74207
|
-
case 8:
|
|
74208
|
-
case "end":
|
|
74209
|
-
return _context2.stop();
|
|
74210
|
-
}
|
|
74211
|
-
}, _callee2);
|
|
74212
|
-
}));
|
|
74213
|
-
return function updateScheduledReport(_x, _x2) {
|
|
74214
|
-
return _ref2.apply(this, arguments);
|
|
74215
|
-
};
|
|
74216
|
-
}();
|
|
74217
|
-
return {
|
|
74218
|
-
reports: reports,
|
|
74219
|
-
getScheduledReports: params.getScheduledReports,
|
|
74220
|
-
updateScheduledReport: updateScheduledReport
|
|
74221
|
-
};
|
|
74222
|
-
};
|
|
74223
|
-
|
|
74224
|
-
/*
|
|
74225
|
-
A context for managing the dashboard session.
|
|
74226
|
-
*/
|
|
74227
|
-
var STILL_LOADING = null;
|
|
74228
|
-
var useSessionContext = function useSessionContext(params) {
|
|
74229
|
-
var _loadedStrategy$dashb, _loadedStrategy$dashb2;
|
|
74230
|
-
var vizzly = useVizzly({
|
|
74231
|
-
queryEngine: params.queryEngine,
|
|
74232
|
-
identity: params.identityCallback,
|
|
74233
|
-
dataSets: params.loadDataSetsCallback,
|
|
74234
|
-
programmaticDashboard: params.programmaticDashboard
|
|
74235
|
-
}, {
|
|
74236
|
-
apiHost: params.apiConfig.host
|
|
74237
|
-
});
|
|
74238
|
-
var loadedStrategy = useDashboardStrategy(getStrategy(vizzly, params.parentDashboardId, params.dashboardId, params.isEditor), vizzly, params.programmaticDashboard);
|
|
74239
|
-
var _useScheduledReports = useScheduledReports(vizzly, loadedStrategy == null || (_loadedStrategy$dashb = loadedStrategy.dashboard) == null || (_loadedStrategy$dashb = _loadedStrategy$dashb.permission) == null ? void 0 : _loadedStrategy$dashb.token),
|
|
74240
|
-
reports = _useScheduledReports.reports,
|
|
74241
|
-
updateScheduledReport = _useScheduledReports.updateScheduledReport;
|
|
74242
|
-
if (!vizzly) return STILL_LOADING;
|
|
74243
|
-
if ('error' in vizzly && vizzly.error) return {
|
|
74244
|
-
error: vizzly.error
|
|
74245
|
-
};
|
|
74246
|
-
if ('loading' in vizzly && vizzly.loading) return STILL_LOADING;
|
|
74247
|
-
if (!('dashboards' in vizzly)) return STILL_LOADING;
|
|
74248
|
-
var identityConfig = vizzly.identityConfig,
|
|
74249
|
-
queryEngineConfig = vizzly.queryEngineConfig;
|
|
74250
|
-
if (!loadedStrategy) return null;
|
|
74251
|
-
if (((loadedStrategy == null || (_loadedStrategy$dashb2 = loadedStrategy.dashboard) == null ? void 0 : _loadedStrategy$dashb2.dataSets) || []).length === 0) {
|
|
74252
|
-
return {
|
|
74253
|
-
error: new NoDataSetResolved()
|
|
74254
|
-
};
|
|
74255
|
-
}
|
|
74256
|
-
var providedValues = {
|
|
74257
|
-
vizzly: vizzly,
|
|
74258
|
-
scope: loadedStrategy.scope,
|
|
74259
|
-
queryEngineConfig: queryEngineConfig,
|
|
74260
|
-
dashboard: loadedStrategy.dashboard,
|
|
74261
|
-
identityConfig: identityConfig,
|
|
74262
|
-
mode: loadedStrategy.mode,
|
|
74263
|
-
vizzlyApiConfig: params.apiConfig,
|
|
74264
|
-
isProgrammaticParent: loadedStrategy.isProgrammaticParent,
|
|
74265
|
-
globalLibraries: vizzly.globalLibraries,
|
|
74266
|
-
reports: reports,
|
|
74267
|
-
updateScheduledReport: updateScheduledReport
|
|
74268
|
-
};
|
|
74269
|
-
return providedValues;
|
|
74270
|
-
};
|
|
74271
|
-
|
|
74272
|
-
var getParentDashboards$1 = function getParentDashboards(httpClient) {
|
|
74273
|
-
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
74274
|
-
var _yield$httpClient, status, body;
|
|
74275
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74276
|
-
while (1) switch (_context.prev = _context.next) {
|
|
74277
|
-
case 0:
|
|
74278
|
-
_context.next = 2;
|
|
74279
|
-
return httpClient({
|
|
74280
|
-
path: "/api/v2/parent-dashboards",
|
|
74281
|
-
method: 'get'
|
|
74282
|
-
});
|
|
74283
|
-
case 2:
|
|
74284
|
-
_yield$httpClient = _context.sent;
|
|
74285
|
-
status = _yield$httpClient.status;
|
|
74286
|
-
body = _yield$httpClient.body;
|
|
74287
|
-
if (!(status == 200)) {
|
|
74288
|
-
_context.next = 7;
|
|
74289
|
-
break;
|
|
74290
|
-
}
|
|
74291
|
-
return _context.abrupt("return", body.dashboards.map(function (rawDashboard) {
|
|
74292
|
-
return {
|
|
74293
|
-
id: rawDashboard.id,
|
|
74294
|
-
created_at: rawDashboard.created_at,
|
|
74295
|
-
updated_at: rawDashboard.updated_at,
|
|
74296
|
-
webhook_id: rawDashboard.webhook_id
|
|
74297
|
-
};
|
|
74298
|
-
}));
|
|
74299
|
-
case 7:
|
|
74300
|
-
return _context.abrupt("return", undefined);
|
|
74301
|
-
case 8:
|
|
74302
|
-
case "end":
|
|
74303
|
-
return _context.stop();
|
|
74304
|
-
}
|
|
74305
|
-
}, _callee);
|
|
74306
|
-
}));
|
|
74307
|
-
};
|
|
74308
|
-
|
|
74309
|
-
// If cronSchedule is `null`, then it means the scheduled
|
|
74310
|
-
// report is deleted.
|
|
74311
|
-
var saveScheduledReport = function saveScheduledReport(httpClient) {
|
|
74312
|
-
return /*#__PURE__*/function () {
|
|
74313
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
74314
|
-
var _yield$httpClient, status;
|
|
74315
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74316
|
-
while (1) switch (_context.prev = _context.next) {
|
|
74317
|
-
case 0:
|
|
74318
|
-
_context.next = 2;
|
|
74319
|
-
return httpClient({
|
|
74320
|
-
path: '/api/scheduled-report',
|
|
74321
|
-
method: 'post',
|
|
74322
|
-
body: {
|
|
74323
|
-
cronSchedule: params.cronSchedule,
|
|
74324
|
-
dashboardAccessToken: params.dashboardAccessToken,
|
|
74325
|
-
scheduledReportId: params.scheduledReportId
|
|
74326
|
-
}
|
|
74327
|
-
});
|
|
74328
|
-
case 2:
|
|
74329
|
-
_yield$httpClient = _context.sent;
|
|
74330
|
-
status = _yield$httpClient.status;
|
|
74331
|
-
return _context.abrupt("return", status == 200);
|
|
74332
|
-
case 5:
|
|
74333
|
-
case "end":
|
|
74334
|
-
return _context.stop();
|
|
74335
|
-
}
|
|
74336
|
-
}, _callee);
|
|
74337
|
-
}));
|
|
74338
|
-
return function (_x) {
|
|
74339
|
-
return _ref.apply(this, arguments);
|
|
73585
|
+
return function (_x) {
|
|
73586
|
+
return _ref.apply(this, arguments);
|
|
74340
73587
|
};
|
|
74341
73588
|
}();
|
|
74342
73589
|
};
|
|
@@ -75076,6 +74323,28 @@ var api = function api(config) {
|
|
|
75076
74323
|
};
|
|
75077
74324
|
};
|
|
75078
74325
|
|
|
74326
|
+
var buildQueryEngineSignInUrl = function buildQueryEngineSignInUrl(queryEngineEndpoint, queryEngineAccessToken) {
|
|
74327
|
+
if (!queryEngineAccessToken) return '';
|
|
74328
|
+
var authToken = queryEngineAccessToken;
|
|
74329
|
+
authToken = encode(JSON.stringify({
|
|
74330
|
+
queryEngineAccessToken: queryEngineAccessToken,
|
|
74331
|
+
projectAccessToken: undefined
|
|
74332
|
+
}));
|
|
74333
|
+
var endpoint = buildPath(getHostFromQueryEngineEndpoint(queryEngineEndpoint), "/sign-in#" + authToken);
|
|
74334
|
+
return endpoint;
|
|
74335
|
+
};
|
|
74336
|
+
|
|
74337
|
+
var FailedToSaveError = /*#__PURE__*/function (_Error) {
|
|
74338
|
+
function FailedToSaveError(message) {
|
|
74339
|
+
var _this;
|
|
74340
|
+
_this = _Error.call(this, "Failed to save dashboard.") || this;
|
|
74341
|
+
_this.message = message;
|
|
74342
|
+
return _this;
|
|
74343
|
+
}
|
|
74344
|
+
_inheritsLoose(FailedToSaveError, _Error);
|
|
74345
|
+
return FailedToSaveError;
|
|
74346
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
74347
|
+
|
|
75079
74348
|
var StatusLine = function StatusLine(props) {
|
|
75080
74349
|
return jsxRuntime.jsx("div", {
|
|
75081
74350
|
children: jsxRuntime.jsxs("span", {
|
|
@@ -75546,6 +74815,17 @@ var InvalidIdentityFunctionNotice = function InvalidIdentityFunctionNotice(props
|
|
|
75546
74815
|
// />
|
|
75547
74816
|
// );
|
|
75548
74817
|
|
|
74818
|
+
var NoDataSetResolved = /*#__PURE__*/function (_Error) {
|
|
74819
|
+
function NoDataSetResolved() {
|
|
74820
|
+
var _this;
|
|
74821
|
+
_this = _Error.call(this, 'At least one data set must be built for the Vizzly dashboard to render.') || this;
|
|
74822
|
+
_this.name = 'NoDataSetResolved';
|
|
74823
|
+
return _this;
|
|
74824
|
+
}
|
|
74825
|
+
_inheritsLoose(NoDataSetResolved, _Error);
|
|
74826
|
+
return NoDataSetResolved;
|
|
74827
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
74828
|
+
|
|
75549
74829
|
var SetupError = function SetupError(props) {
|
|
75550
74830
|
logError(props.error);
|
|
75551
74831
|
var renderedError = jsxRuntime.jsx("p", {
|
|
@@ -75607,15 +74887,765 @@ var SetupError = function SetupError(props) {
|
|
|
75607
74887
|
});
|
|
75608
74888
|
};
|
|
75609
74889
|
|
|
75610
|
-
var
|
|
75611
|
-
if (
|
|
75612
|
-
|
|
75613
|
-
|
|
75614
|
-
|
|
75615
|
-
|
|
74890
|
+
var getDefaultParentDashboardId = function getDefaultParentDashboardId(parentDashboardId, parentDashboardIdOnDashboardAccessToken, dashboards) {
|
|
74891
|
+
if (parentDashboardId) {
|
|
74892
|
+
var parentDashboard = find$1(dashboards, parentDashboardId);
|
|
74893
|
+
if (!(parentDashboard != null && parentDashboard.parentDashboardId)) {
|
|
74894
|
+
return parentDashboardId;
|
|
74895
|
+
} else {
|
|
74896
|
+
throw '[Vizzly] `parentDashboardId` value must specify an ID for a parent dashboard.';
|
|
74897
|
+
}
|
|
74898
|
+
}
|
|
74899
|
+
var parentDashboards = getParentDashboards(dashboards);
|
|
74900
|
+
var programmaticDashboardId = checkAndReturnProgrammaticDashboardId(parentDashboards);
|
|
74901
|
+
if (programmaticDashboardId) return programmaticDashboardId;
|
|
74902
|
+
return parentDashboardIdOnDashboardAccessToken || getFirstCreated(parentDashboards).id;
|
|
74903
|
+
};
|
|
74904
|
+
|
|
74905
|
+
var getStrategy = function getStrategy(vizzly, requestedEndUserParentDashboardId, requestedEndUserDashboardId, isEditor) {
|
|
74906
|
+
if (!('dashboards' in vizzly)) return undefined;
|
|
74907
|
+
if (vizzly.loading || vizzly.error) return undefined;
|
|
74908
|
+
logDebug('Loading dashboard strategy, with props;', {
|
|
74909
|
+
dashboardId: requestedEndUserDashboardId,
|
|
74910
|
+
parentDashboardId: requestedEndUserParentDashboardId
|
|
74911
|
+
});
|
|
74912
|
+
// This is a temporary fix for the issue where the dashboard is not loaded due to multiple hooks.
|
|
74913
|
+
var checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks = isEditor && vizzly.dashboards.length === 0;
|
|
74914
|
+
if (checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks) return undefined;
|
|
74915
|
+
var defaultParentDashboardId = getDefaultParentDashboardId(requestedEndUserParentDashboardId, vizzly.identityConfig.dashboardAccess.dashboardId, vizzly.dashboards);
|
|
74916
|
+
if (vizzly.accessType == 'admin') {
|
|
74917
|
+
logDebug('Admin access found, so we will show the parent dashboard.', defaultParentDashboardId);
|
|
74918
|
+
var dashboardId = defaultParentDashboardId;
|
|
74919
|
+
// If the user wants a specific dashboard, then fetch the parent dashboard of it.
|
|
74920
|
+
if (requestedEndUserDashboardId) {
|
|
74921
|
+
var foundRequestedChildDashboard = vizzly.dashboards.find(function (dashboard) {
|
|
74922
|
+
return dashboard.id == requestedEndUserDashboardId;
|
|
74923
|
+
});
|
|
74924
|
+
if (foundRequestedChildDashboard != null && foundRequestedChildDashboard.parentDashboardId) {
|
|
74925
|
+
logDebug('A child dashboard was provided whilst in admin mode. Therefore the parent of the given child will be shown to administer.', foundRequestedChildDashboard.parentDashboardId);
|
|
74926
|
+
dashboardId = foundRequestedChildDashboard.parentDashboardId;
|
|
74927
|
+
}
|
|
74928
|
+
}
|
|
74929
|
+
logDebug('Admin access found, so we will show the parent dashboard.', dashboardId);
|
|
74930
|
+
return {
|
|
74931
|
+
type: 'exact',
|
|
74932
|
+
dashboardId: dashboardId
|
|
74933
|
+
};
|
|
74934
|
+
}
|
|
74935
|
+
if (requestedEndUserDashboardId) {
|
|
74936
|
+
logDebug('Strategy will be to show dashboard', requestedEndUserDashboardId);
|
|
74937
|
+
return {
|
|
74938
|
+
type: 'exact',
|
|
74939
|
+
dashboardId: requestedEndUserDashboardId
|
|
74940
|
+
};
|
|
74941
|
+
}
|
|
74942
|
+
var childDashboards = vizzly.dashboards.filter(function (d) {
|
|
74943
|
+
var isChildDashboard = d.parentDashboardId != null;
|
|
74944
|
+
var hasNotRequestedEndUserParentDashboardId = requestedEndUserParentDashboardId === undefined;
|
|
74945
|
+
var isChildOfRequestedParent = hasNotRequestedEndUserParentDashboardId || d.parentDashboardId === requestedEndUserParentDashboardId;
|
|
74946
|
+
return isChildDashboard && isChildOfRequestedParent;
|
|
74947
|
+
});
|
|
74948
|
+
// Exactly one child dashboard for the user & in read-only mode so someone else is managing the dashboard with the same userReference.
|
|
74949
|
+
// We will show that one dashboard to allow for a common SaaS environment where
|
|
74950
|
+
// multiple users share the same userReference, but some of those users have `read_write` access and other users have read access.
|
|
74951
|
+
// Those with `read` access should see the dashboard managed by those other users...
|
|
74952
|
+
if (childDashboards.length === 1 && vizzly.identityConfig.dashboardAccess.scope == 'read') {
|
|
74953
|
+
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);
|
|
74954
|
+
return {
|
|
74955
|
+
type: 'exact',
|
|
74956
|
+
dashboardId: vizzly.dashboards.find(function (d) {
|
|
74957
|
+
return d.parentDashboardId != null;
|
|
74958
|
+
}).id
|
|
74959
|
+
};
|
|
74960
|
+
}
|
|
74961
|
+
// No specific dashboard requested, but dashboard access token only grants 'read' access.
|
|
74962
|
+
if (vizzly.identityConfig.dashboardAccess.scope == 'read' && defaultParentDashboardId) {
|
|
74963
|
+
logDebug('Strategy will be to return read-only view of the parent dashboard.', defaultParentDashboardId);
|
|
74964
|
+
return {
|
|
74965
|
+
type: 'exact',
|
|
74966
|
+
dashboardId: defaultParentDashboardId
|
|
74967
|
+
};
|
|
74968
|
+
}
|
|
74969
|
+
var dashboardIdSetInIdentityConfig = vizzly.identityConfig.dashboardAccess.dashboardId;
|
|
74970
|
+
if (dashboardIdSetInIdentityConfig) {
|
|
74971
|
+
var _vizzly$identityConfi, _vizzly$identityConfi2;
|
|
74972
|
+
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);
|
|
74973
|
+
return {
|
|
74974
|
+
type: 'instantCopyOf',
|
|
74975
|
+
parentDashboardId: (_vizzly$identityConfi2 = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi2.dashboardId
|
|
74976
|
+
};
|
|
74977
|
+
} else {
|
|
74978
|
+
logDebug('Strategy will be to show a child of the parent dashboard', defaultParentDashboardId);
|
|
74979
|
+
return {
|
|
74980
|
+
type: 'instantCopyOf',
|
|
74981
|
+
parentDashboardId: defaultParentDashboardId
|
|
74982
|
+
};
|
|
74983
|
+
}
|
|
74984
|
+
};
|
|
74985
|
+
|
|
74986
|
+
var Mode;
|
|
74987
|
+
(function (Mode) {
|
|
74988
|
+
Mode["Admin"] = "admin";
|
|
74989
|
+
Mode["EndUser"] = "endUser";
|
|
74990
|
+
})(Mode || (Mode = {}));
|
|
74991
|
+
var Scope;
|
|
74992
|
+
(function (Scope) {
|
|
74993
|
+
Scope["Read"] = "read";
|
|
74994
|
+
Scope["ReadWrite"] = "read_write";
|
|
74995
|
+
})(Scope || (Scope = {}));
|
|
74996
|
+
|
|
74997
|
+
/*
|
|
74998
|
+
Currently, we just replicate the same behaviour as what we used to have on the API.
|
|
74999
|
+
*/
|
|
75000
|
+
var runStrategy = /*#__PURE__*/function () {
|
|
75001
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(strategy, vizzly) {
|
|
75002
|
+
var currentDashboard, scope, _parentDashboard$perm, parentDashboard, hasParentDashboardWritePermission, dashboardCopies, mostRecentlyUpdatedChildDashboard, created;
|
|
75003
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75004
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75005
|
+
case 0:
|
|
75006
|
+
if (!(strategy.type == 'exact')) {
|
|
75007
|
+
_context.next = 9;
|
|
75008
|
+
break;
|
|
75009
|
+
}
|
|
75010
|
+
currentDashboard = vizzly.dashboards.find(function (d) {
|
|
75011
|
+
return d.id === strategy.dashboardId;
|
|
75012
|
+
});
|
|
75013
|
+
if (currentDashboard.permission) {
|
|
75014
|
+
_context.next = 4;
|
|
75015
|
+
break;
|
|
75016
|
+
}
|
|
75017
|
+
throw '';
|
|
75018
|
+
case 4:
|
|
75019
|
+
scope = currentDashboard.permission.scope;
|
|
75020
|
+
logDebug('A specific dashboard has been requested. This will be rendered with', scope, 'scope.', strategy.dashboardId);
|
|
75021
|
+
return _context.abrupt("return", {
|
|
75022
|
+
dashboardId: strategy.dashboardId,
|
|
75023
|
+
mode: scope === 'read_write' && currentDashboard.parentDashboardId === null ? Mode.Admin : Mode.EndUser,
|
|
75024
|
+
scope: scope
|
|
75025
|
+
});
|
|
75026
|
+
case 9:
|
|
75027
|
+
if (!(strategy.type == 'instantCopyOf')) {
|
|
75028
|
+
_context.next = 29;
|
|
75029
|
+
break;
|
|
75030
|
+
}
|
|
75031
|
+
// If the user has write access to the parent dashboard, then we return that dashboard ID, with mode=admin
|
|
75032
|
+
parentDashboard = vizzly.dashboards.find(function (d) {
|
|
75033
|
+
return d.id === strategy.parentDashboardId;
|
|
75034
|
+
});
|
|
75035
|
+
hasParentDashboardWritePermission = ((_parentDashboard$perm = parentDashboard.permission) == null ? void 0 : _parentDashboard$perm.scope) === 'read_write';
|
|
75036
|
+
if (!hasParentDashboardWritePermission) {
|
|
75037
|
+
_context.next = 15;
|
|
75038
|
+
break;
|
|
75039
|
+
}
|
|
75040
|
+
logDebug('Write access to the parent dashboard has been found, so this dashboard will be shown with admin access.', strategy.parentDashboardId);
|
|
75041
|
+
return _context.abrupt("return", {
|
|
75042
|
+
dashboardId: strategy.parentDashboardId,
|
|
75043
|
+
mode: Mode.Admin,
|
|
75044
|
+
scope: Scope.ReadWrite
|
|
75045
|
+
});
|
|
75046
|
+
case 15:
|
|
75047
|
+
dashboardCopies = getCopiesOfParentDashboard(strategy.parentDashboardId, vizzly.dashboards);
|
|
75048
|
+
mostRecentlyUpdatedChildDashboard = takeMostRecentlyUpdated(dashboardCopies);
|
|
75049
|
+
if (!mostRecentlyUpdatedChildDashboard) {
|
|
75050
|
+
_context.next = 20;
|
|
75051
|
+
break;
|
|
75052
|
+
}
|
|
75053
|
+
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);
|
|
75054
|
+
return _context.abrupt("return", {
|
|
75055
|
+
dashboardId: mostRecentlyUpdatedChildDashboard.id,
|
|
75056
|
+
mode: Mode.EndUser,
|
|
75057
|
+
scope: mostRecentlyUpdatedChildDashboard.permission.scope
|
|
75058
|
+
});
|
|
75059
|
+
case 20:
|
|
75060
|
+
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.');
|
|
75061
|
+
_context.next = 23;
|
|
75062
|
+
return vizzly.createDashboard({
|
|
75063
|
+
parentDashboardId: parentDashboard.id,
|
|
75064
|
+
definition: toSaveableDefinition(parentDashboard),
|
|
75065
|
+
metadata: {}
|
|
75066
|
+
});
|
|
75067
|
+
case 23:
|
|
75068
|
+
created = _context.sent;
|
|
75069
|
+
if (created) {
|
|
75070
|
+
_context.next = 26;
|
|
75071
|
+
break;
|
|
75072
|
+
}
|
|
75073
|
+
throw 'Failed to create first child dashboard for the user.';
|
|
75074
|
+
case 26:
|
|
75075
|
+
return _context.abrupt("return", {
|
|
75076
|
+
dashboardId: created.id,
|
|
75077
|
+
scope: Scope.ReadWrite,
|
|
75078
|
+
mode: Mode.EndUser
|
|
75079
|
+
});
|
|
75080
|
+
case 29:
|
|
75081
|
+
throw "Unsupported strategy";
|
|
75082
|
+
case 30:
|
|
75083
|
+
case "end":
|
|
75084
|
+
return _context.stop();
|
|
75085
|
+
}
|
|
75086
|
+
}, _callee);
|
|
75616
75087
|
}));
|
|
75617
|
-
|
|
75618
|
-
|
|
75088
|
+
return function runStrategy(_x, _x2) {
|
|
75089
|
+
return _ref.apply(this, arguments);
|
|
75090
|
+
};
|
|
75091
|
+
}();
|
|
75092
|
+
|
|
75093
|
+
/*
|
|
75094
|
+
Stores which dashboard is the currently active one...
|
|
75095
|
+
*/
|
|
75096
|
+
var useDashboardStrategy = function useDashboardStrategy(strategy, vizzly, programmaticDashboard) {
|
|
75097
|
+
var _useState = React.useState(),
|
|
75098
|
+
state = _useState[0],
|
|
75099
|
+
setState = _useState[1];
|
|
75100
|
+
React.useEffect(function () {
|
|
75101
|
+
var doWork = /*#__PURE__*/function () {
|
|
75102
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75103
|
+
var _yield$runStrategy, mode, dashboardId, scope;
|
|
75104
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75105
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75106
|
+
case 0:
|
|
75107
|
+
if ('dashboards' in vizzly) {
|
|
75108
|
+
_context.next = 2;
|
|
75109
|
+
break;
|
|
75110
|
+
}
|
|
75111
|
+
return _context.abrupt("return");
|
|
75112
|
+
case 2:
|
|
75113
|
+
if (strategy) {
|
|
75114
|
+
_context.next = 4;
|
|
75115
|
+
break;
|
|
75116
|
+
}
|
|
75117
|
+
return _context.abrupt("return");
|
|
75118
|
+
case 4:
|
|
75119
|
+
if (!vizzly.loading) {
|
|
75120
|
+
_context.next = 6;
|
|
75121
|
+
break;
|
|
75122
|
+
}
|
|
75123
|
+
return _context.abrupt("return");
|
|
75124
|
+
case 6:
|
|
75125
|
+
_context.next = 8;
|
|
75126
|
+
return runStrategy(strategy, vizzly);
|
|
75127
|
+
case 8:
|
|
75128
|
+
_yield$runStrategy = _context.sent;
|
|
75129
|
+
mode = _yield$runStrategy.mode;
|
|
75130
|
+
dashboardId = _yield$runStrategy.dashboardId;
|
|
75131
|
+
scope = _yield$runStrategy.scope;
|
|
75132
|
+
if (dashboardId != (state == null ? void 0 : state.dashboardId)) setState({
|
|
75133
|
+
mode: mode,
|
|
75134
|
+
dashboardId: dashboardId,
|
|
75135
|
+
scope: scope
|
|
75136
|
+
});
|
|
75137
|
+
case 13:
|
|
75138
|
+
case "end":
|
|
75139
|
+
return _context.stop();
|
|
75140
|
+
}
|
|
75141
|
+
}, _callee);
|
|
75142
|
+
}));
|
|
75143
|
+
return function doWork() {
|
|
75144
|
+
return _ref.apply(this, arguments);
|
|
75145
|
+
};
|
|
75146
|
+
}();
|
|
75147
|
+
doWork();
|
|
75148
|
+
}, [JSON.stringify({
|
|
75149
|
+
strategy: strategy,
|
|
75150
|
+
loading: vizzly.loading
|
|
75151
|
+
})]);
|
|
75152
|
+
if (!('dashboards' in vizzly)) return null;
|
|
75153
|
+
if (!state) return null;
|
|
75154
|
+
if (vizzly.loading) return null;
|
|
75155
|
+
var dashboard = vizzly.dashboards.find(function (dash) {
|
|
75156
|
+
return dash.id == state.dashboardId;
|
|
75157
|
+
}) || null;
|
|
75158
|
+
return {
|
|
75159
|
+
mode: state.mode,
|
|
75160
|
+
dashboard: dashboard,
|
|
75161
|
+
scope: state.scope,
|
|
75162
|
+
isProgrammaticParent: !!programmaticDashboard
|
|
75163
|
+
};
|
|
75164
|
+
};
|
|
75165
|
+
|
|
75166
|
+
var useVizzly = function useVizzly(properties, options) {
|
|
75167
|
+
var _useState = React.useState({
|
|
75168
|
+
loading: true,
|
|
75169
|
+
error: undefined,
|
|
75170
|
+
dashboards: [],
|
|
75171
|
+
globalLibraries: []
|
|
75172
|
+
}),
|
|
75173
|
+
state = _useState[0],
|
|
75174
|
+
setState = _useState[1];
|
|
75175
|
+
var vizzlyRef = React.useRef();
|
|
75176
|
+
var vizzly = vizzlyRef.current;
|
|
75177
|
+
React.useEffect(function () {
|
|
75178
|
+
var abortController = new AbortController();
|
|
75179
|
+
var doWork = /*#__PURE__*/function () {
|
|
75180
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75181
|
+
var _yield$Promise$all, globalLibraries, dashboards;
|
|
75182
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75183
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75184
|
+
case 0:
|
|
75185
|
+
_context.prev = 0;
|
|
75186
|
+
_context.next = 3;
|
|
75187
|
+
return Vizzly$1.load(properties, {
|
|
75188
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75189
|
+
});
|
|
75190
|
+
case 3:
|
|
75191
|
+
vizzlyRef.current = _context.sent;
|
|
75192
|
+
_context.next = 6;
|
|
75193
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75194
|
+
abortController: abortController
|
|
75195
|
+
}), vizzlyRef.current.getDashboards({
|
|
75196
|
+
abortController: abortController
|
|
75197
|
+
})]);
|
|
75198
|
+
case 6:
|
|
75199
|
+
_yield$Promise$all = _context.sent;
|
|
75200
|
+
globalLibraries = _yield$Promise$all[0];
|
|
75201
|
+
dashboards = _yield$Promise$all[1];
|
|
75202
|
+
setState({
|
|
75203
|
+
loading: false,
|
|
75204
|
+
error: undefined,
|
|
75205
|
+
dashboards: dashboards,
|
|
75206
|
+
globalLibraries: globalLibraries
|
|
75207
|
+
});
|
|
75208
|
+
_context.next = 16;
|
|
75209
|
+
break;
|
|
75210
|
+
case 12:
|
|
75211
|
+
_context.prev = 12;
|
|
75212
|
+
_context.t0 = _context["catch"](0);
|
|
75213
|
+
logError('Error loading Vizzly', _context.t0);
|
|
75214
|
+
setState({
|
|
75215
|
+
loading: false,
|
|
75216
|
+
error: _context.t0,
|
|
75217
|
+
dashboards: [].concat(state.dashboards),
|
|
75218
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75219
|
+
});
|
|
75220
|
+
case 16:
|
|
75221
|
+
case "end":
|
|
75222
|
+
return _context.stop();
|
|
75223
|
+
}
|
|
75224
|
+
}, _callee, null, [[0, 12]]);
|
|
75225
|
+
}));
|
|
75226
|
+
return function doWork() {
|
|
75227
|
+
return _ref.apply(this, arguments);
|
|
75228
|
+
};
|
|
75229
|
+
}();
|
|
75230
|
+
doWork();
|
|
75231
|
+
return function () {
|
|
75232
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75233
|
+
};
|
|
75234
|
+
}, []);
|
|
75235
|
+
var refetch = /*#__PURE__*/function () {
|
|
75236
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
75237
|
+
var abortController, doWork;
|
|
75238
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
75239
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
75240
|
+
case 0:
|
|
75241
|
+
abortController = new AbortController();
|
|
75242
|
+
doWork = /*#__PURE__*/function () {
|
|
75243
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
75244
|
+
var _yield$Promise$all2, globalLibraries, dashboards;
|
|
75245
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75246
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75247
|
+
case 0:
|
|
75248
|
+
_context2.prev = 0;
|
|
75249
|
+
_context2.next = 3;
|
|
75250
|
+
return Vizzly$1.load(properties, {
|
|
75251
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75252
|
+
});
|
|
75253
|
+
case 3:
|
|
75254
|
+
vizzlyRef.current = _context2.sent;
|
|
75255
|
+
_context2.next = 6;
|
|
75256
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75257
|
+
abortController: abortController
|
|
75258
|
+
}), vizzlyRef.current.getDashboards({
|
|
75259
|
+
abortController: abortController
|
|
75260
|
+
})]);
|
|
75261
|
+
case 6:
|
|
75262
|
+
_yield$Promise$all2 = _context2.sent;
|
|
75263
|
+
globalLibraries = _yield$Promise$all2[0];
|
|
75264
|
+
dashboards = _yield$Promise$all2[1];
|
|
75265
|
+
setState({
|
|
75266
|
+
loading: false,
|
|
75267
|
+
error: undefined,
|
|
75268
|
+
dashboards: dashboards,
|
|
75269
|
+
globalLibraries: globalLibraries
|
|
75270
|
+
});
|
|
75271
|
+
_context2.next = 16;
|
|
75272
|
+
break;
|
|
75273
|
+
case 12:
|
|
75274
|
+
_context2.prev = 12;
|
|
75275
|
+
_context2.t0 = _context2["catch"](0);
|
|
75276
|
+
logError('Error loading Vizzly', _context2.t0);
|
|
75277
|
+
setState({
|
|
75278
|
+
loading: false,
|
|
75279
|
+
error: _context2.t0,
|
|
75280
|
+
dashboards: [].concat(state.dashboards),
|
|
75281
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75282
|
+
});
|
|
75283
|
+
case 16:
|
|
75284
|
+
case "end":
|
|
75285
|
+
return _context2.stop();
|
|
75286
|
+
}
|
|
75287
|
+
}, _callee2, null, [[0, 12]]);
|
|
75288
|
+
}));
|
|
75289
|
+
return function doWork() {
|
|
75290
|
+
return _ref3.apply(this, arguments);
|
|
75291
|
+
};
|
|
75292
|
+
}();
|
|
75293
|
+
doWork();
|
|
75294
|
+
return _context3.abrupt("return", function () {
|
|
75295
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75296
|
+
});
|
|
75297
|
+
case 4:
|
|
75298
|
+
case "end":
|
|
75299
|
+
return _context3.stop();
|
|
75300
|
+
}
|
|
75301
|
+
}, _callee3);
|
|
75302
|
+
}));
|
|
75303
|
+
return function refetch() {
|
|
75304
|
+
return _ref2.apply(this, arguments);
|
|
75305
|
+
};
|
|
75306
|
+
}();
|
|
75307
|
+
var createDashboard = /*#__PURE__*/function () {
|
|
75308
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
75309
|
+
var createdDashboard;
|
|
75310
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
75311
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
75312
|
+
case 0:
|
|
75313
|
+
if (!vizzly) {
|
|
75314
|
+
_context4.next = 15;
|
|
75315
|
+
break;
|
|
75316
|
+
}
|
|
75317
|
+
_context4.prev = 1;
|
|
75318
|
+
_context4.next = 4;
|
|
75319
|
+
return vizzly.createDashboard({
|
|
75320
|
+
definition: params.definition,
|
|
75321
|
+
// permissions: params.permissions,
|
|
75322
|
+
parentDashboardId: params.parentDashboardId,
|
|
75323
|
+
metadata: params.metadata || params.meta,
|
|
75324
|
+
abortSignal: params.abortSignal
|
|
75325
|
+
});
|
|
75326
|
+
case 4:
|
|
75327
|
+
createdDashboard = _context4.sent;
|
|
75328
|
+
setState(_extends({}, state, {
|
|
75329
|
+
dashboards: [].concat(state.dashboards, [createdDashboard])
|
|
75330
|
+
}));
|
|
75331
|
+
return _context4.abrupt("return", createdDashboard);
|
|
75332
|
+
case 9:
|
|
75333
|
+
_context4.prev = 9;
|
|
75334
|
+
_context4.t0 = _context4["catch"](1);
|
|
75335
|
+
logError(_context4.t0);
|
|
75336
|
+
return _context4.abrupt("return", null);
|
|
75337
|
+
case 13:
|
|
75338
|
+
_context4.next = 16;
|
|
75339
|
+
break;
|
|
75340
|
+
case 15:
|
|
75341
|
+
throw 'Unable to create a dashboard when vizzly has not been loaded.';
|
|
75342
|
+
case 16:
|
|
75343
|
+
case "end":
|
|
75344
|
+
return _context4.stop();
|
|
75345
|
+
}
|
|
75346
|
+
}, _callee4, null, [[1, 9]]);
|
|
75347
|
+
}));
|
|
75348
|
+
return function createDashboard(_x) {
|
|
75349
|
+
return _ref4.apply(this, arguments);
|
|
75350
|
+
};
|
|
75351
|
+
}();
|
|
75352
|
+
React.useEffect(function () {
|
|
75353
|
+
var abortController = new AbortController();
|
|
75354
|
+
var doWork = /*#__PURE__*/function () {
|
|
75355
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
75356
|
+
var _yield$Promise$all3, globalLibraries;
|
|
75357
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
75358
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
75359
|
+
case 0:
|
|
75360
|
+
_context5.prev = 0;
|
|
75361
|
+
_context5.next = 3;
|
|
75362
|
+
return Vizzly$1.load(properties, {
|
|
75363
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75364
|
+
});
|
|
75365
|
+
case 3:
|
|
75366
|
+
vizzlyRef.current = _context5.sent;
|
|
75367
|
+
_context5.next = 6;
|
|
75368
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75369
|
+
abortController: abortController
|
|
75370
|
+
})]);
|
|
75371
|
+
case 6:
|
|
75372
|
+
_yield$Promise$all3 = _context5.sent;
|
|
75373
|
+
globalLibraries = _yield$Promise$all3[0];
|
|
75374
|
+
setState(_extends({}, state, {
|
|
75375
|
+
globalLibraries: globalLibraries
|
|
75376
|
+
}));
|
|
75377
|
+
_context5.next = 15;
|
|
75378
|
+
break;
|
|
75379
|
+
case 11:
|
|
75380
|
+
_context5.prev = 11;
|
|
75381
|
+
_context5.t0 = _context5["catch"](0);
|
|
75382
|
+
logError('Error loading Vizzly', _context5.t0);
|
|
75383
|
+
setState({
|
|
75384
|
+
loading: false,
|
|
75385
|
+
error: _context5.t0,
|
|
75386
|
+
dashboards: [].concat(state.dashboards),
|
|
75387
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75388
|
+
});
|
|
75389
|
+
case 15:
|
|
75390
|
+
case "end":
|
|
75391
|
+
return _context5.stop();
|
|
75392
|
+
}
|
|
75393
|
+
}, _callee5, null, [[0, 11]]);
|
|
75394
|
+
}));
|
|
75395
|
+
return function doWork() {
|
|
75396
|
+
return _ref5.apply(this, arguments);
|
|
75397
|
+
};
|
|
75398
|
+
}();
|
|
75399
|
+
if (vizzly) {
|
|
75400
|
+
var unsubscribe = Vizzly$1.subscription(function (eventBus) {
|
|
75401
|
+
if (eventBus.data.action === 'newViewsInGlobalLibrary') {
|
|
75402
|
+
doWork();
|
|
75403
|
+
}
|
|
75404
|
+
});
|
|
75405
|
+
return function () {
|
|
75406
|
+
return unsubscribe();
|
|
75407
|
+
};
|
|
75408
|
+
}
|
|
75409
|
+
return function () {
|
|
75410
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75411
|
+
};
|
|
75412
|
+
}, [vizzly]);
|
|
75413
|
+
var updateDashboard = /*#__PURE__*/function () {
|
|
75414
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
75415
|
+
var updatedDashboard, dashboards;
|
|
75416
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
75417
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
75418
|
+
case 0:
|
|
75419
|
+
if (!vizzly) {
|
|
75420
|
+
_context6.next = 20;
|
|
75421
|
+
break;
|
|
75422
|
+
}
|
|
75423
|
+
setState(_extends({}, state, {
|
|
75424
|
+
saving: SavingState.InProgress
|
|
75425
|
+
}));
|
|
75426
|
+
_context6.prev = 2;
|
|
75427
|
+
_context6.next = 5;
|
|
75428
|
+
return vizzly.updateDashboard({
|
|
75429
|
+
dashboardId: params.dashboardId,
|
|
75430
|
+
definition: params.definition,
|
|
75431
|
+
deleted: params.deleted,
|
|
75432
|
+
metadata: params.metadata || params.meta,
|
|
75433
|
+
abortSignal: params.abortSignal,
|
|
75434
|
+
name: params.name
|
|
75435
|
+
});
|
|
75436
|
+
case 5:
|
|
75437
|
+
updatedDashboard = _context6.sent;
|
|
75438
|
+
_context6.next = 8;
|
|
75439
|
+
return vizzly.getDashboards();
|
|
75440
|
+
case 8:
|
|
75441
|
+
dashboards = _context6.sent;
|
|
75442
|
+
setState(function (prevState) {
|
|
75443
|
+
return _extends({}, prevState, {
|
|
75444
|
+
dashboards: dashboards,
|
|
75445
|
+
saving: SavingState.Saved
|
|
75446
|
+
});
|
|
75447
|
+
});
|
|
75448
|
+
setTimeout(function () {
|
|
75449
|
+
setState(_extends({}, state, {
|
|
75450
|
+
saving: SavingState.Undefined
|
|
75451
|
+
}));
|
|
75452
|
+
}, 500);
|
|
75453
|
+
return _context6.abrupt("return", updatedDashboard);
|
|
75454
|
+
case 14:
|
|
75455
|
+
_context6.prev = 14;
|
|
75456
|
+
_context6.t0 = _context6["catch"](2);
|
|
75457
|
+
logError('Error updating dashboard', _context6.t0);
|
|
75458
|
+
return _context6.abrupt("return", null);
|
|
75459
|
+
case 18:
|
|
75460
|
+
_context6.next = 21;
|
|
75461
|
+
break;
|
|
75462
|
+
case 20:
|
|
75463
|
+
throw 'Unable to update a dashboard when vizzly has not been loaded.';
|
|
75464
|
+
case 21:
|
|
75465
|
+
case "end":
|
|
75466
|
+
return _context6.stop();
|
|
75467
|
+
}
|
|
75468
|
+
}, _callee6, null, [[2, 14]]);
|
|
75469
|
+
}));
|
|
75470
|
+
return function updateDashboard(_x2) {
|
|
75471
|
+
return _ref6.apply(this, arguments);
|
|
75472
|
+
};
|
|
75473
|
+
}();
|
|
75474
|
+
|
|
75475
|
+
// Are these needed?
|
|
75476
|
+
var updateScheduledReport = function updateScheduledReport(dashboardAccessToken, reportId, newCron) {
|
|
75477
|
+
if (vizzly) {
|
|
75478
|
+
return vizzly.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
75479
|
+
}
|
|
75480
|
+
throw 'vizzly not set';
|
|
75481
|
+
};
|
|
75482
|
+
var getScheduledReports = function getScheduledReports(dashboardAccessToken) {
|
|
75483
|
+
if (vizzly) {
|
|
75484
|
+
return vizzly.getScheduledReports(dashboardAccessToken);
|
|
75485
|
+
}
|
|
75486
|
+
throw 'vizzly not set';
|
|
75487
|
+
};
|
|
75488
|
+
logDebug('useVizzly state.', state);
|
|
75489
|
+
if (!vizzly || !!state.error || state.loading) {
|
|
75490
|
+
return _extends({}, state, {
|
|
75491
|
+
loading: true,
|
|
75492
|
+
createDashboard: null,
|
|
75493
|
+
identityConfig: null,
|
|
75494
|
+
updateDashboard: null,
|
|
75495
|
+
queryEngineConfig: null,
|
|
75496
|
+
accessType: null,
|
|
75497
|
+
refetch: null,
|
|
75498
|
+
getScheduledReports: null,
|
|
75499
|
+
updateScheduledReport: null
|
|
75500
|
+
});
|
|
75501
|
+
}
|
|
75502
|
+
var identityConfig = vizzly.getIdentityConfig();
|
|
75503
|
+
return _extends({}, state, {
|
|
75504
|
+
loading: false,
|
|
75505
|
+
identityConfig: identityConfig,
|
|
75506
|
+
createDashboard: createDashboard,
|
|
75507
|
+
updateDashboard: updateDashboard,
|
|
75508
|
+
queryEngineConfig: vizzly.getViewConfiguration().queryEngineConfig,
|
|
75509
|
+
accessType: !!identityConfig.dashboardAdminOverride ? 'admin' : identityConfig.dashboardAccess.accessType,
|
|
75510
|
+
filterDashboards: Vizzly$1.filterDashboards,
|
|
75511
|
+
refetch: refetch,
|
|
75512
|
+
updateScheduledReport: updateScheduledReport,
|
|
75513
|
+
getScheduledReports: getScheduledReports
|
|
75514
|
+
});
|
|
75515
|
+
};
|
|
75516
|
+
|
|
75517
|
+
var useScheduledReports = function useScheduledReports(params, dashboardAccessToken) {
|
|
75518
|
+
var _useState = React.useState([]),
|
|
75519
|
+
reports = _useState[0],
|
|
75520
|
+
setReports = _useState[1];
|
|
75521
|
+
React.useEffect(function () {
|
|
75522
|
+
var doWork = /*#__PURE__*/function () {
|
|
75523
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75524
|
+
var _yield$params$getSche, _reports;
|
|
75525
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75526
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75527
|
+
case 0:
|
|
75528
|
+
if (!(params.getScheduledReports && dashboardAccessToken)) {
|
|
75529
|
+
_context.next = 6;
|
|
75530
|
+
break;
|
|
75531
|
+
}
|
|
75532
|
+
_context.next = 3;
|
|
75533
|
+
return params.getScheduledReports(dashboardAccessToken);
|
|
75534
|
+
case 3:
|
|
75535
|
+
_yield$params$getSche = _context.sent;
|
|
75536
|
+
_reports = _yield$params$getSche.reports;
|
|
75537
|
+
setReports(_reports);
|
|
75538
|
+
case 6:
|
|
75539
|
+
case "end":
|
|
75540
|
+
return _context.stop();
|
|
75541
|
+
}
|
|
75542
|
+
}, _callee);
|
|
75543
|
+
}));
|
|
75544
|
+
return function doWork() {
|
|
75545
|
+
return _ref.apply(this, arguments);
|
|
75546
|
+
};
|
|
75547
|
+
}();
|
|
75548
|
+
doWork();
|
|
75549
|
+
}, [JSON.stringify({
|
|
75550
|
+
dashboardAccessToken: dashboardAccessToken,
|
|
75551
|
+
loadingVizzly: params
|
|
75552
|
+
})]);
|
|
75553
|
+
var updateScheduledReport = /*#__PURE__*/function () {
|
|
75554
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(reportId, newCron) {
|
|
75555
|
+
var updatedReport, newReports, uniqueNewReports;
|
|
75556
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75557
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75558
|
+
case 0:
|
|
75559
|
+
if (!(params.updateScheduledReport && dashboardAccessToken)) {
|
|
75560
|
+
_context2.next = 7;
|
|
75561
|
+
break;
|
|
75562
|
+
}
|
|
75563
|
+
_context2.next = 3;
|
|
75564
|
+
return params.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
75565
|
+
case 3:
|
|
75566
|
+
updatedReport = _context2.sent;
|
|
75567
|
+
if (updatedReport === true) {
|
|
75568
|
+
// Remove the deleted report...
|
|
75569
|
+
setReports([].concat(reports).filter(function (r) {
|
|
75570
|
+
return r.id != reportId;
|
|
75571
|
+
}));
|
|
75572
|
+
} else if (updatedReport) {
|
|
75573
|
+
// Upsert the report
|
|
75574
|
+
newReports = [].concat(reports, [updatedReport.report]).map(function (r) {
|
|
75575
|
+
return r.id == reportId ? updatedReport.report : r;
|
|
75576
|
+
});
|
|
75577
|
+
uniqueNewReports = _.uniqBy(newReports, function (r) {
|
|
75578
|
+
return r.id;
|
|
75579
|
+
});
|
|
75580
|
+
setReports(uniqueNewReports);
|
|
75581
|
+
}
|
|
75582
|
+
_context2.next = 8;
|
|
75583
|
+
break;
|
|
75584
|
+
case 7:
|
|
75585
|
+
console.warn('Function to update scheduled report not loaded.');
|
|
75586
|
+
case 8:
|
|
75587
|
+
case "end":
|
|
75588
|
+
return _context2.stop();
|
|
75589
|
+
}
|
|
75590
|
+
}, _callee2);
|
|
75591
|
+
}));
|
|
75592
|
+
return function updateScheduledReport(_x, _x2) {
|
|
75593
|
+
return _ref2.apply(this, arguments);
|
|
75594
|
+
};
|
|
75595
|
+
}();
|
|
75596
|
+
return {
|
|
75597
|
+
reports: reports,
|
|
75598
|
+
getScheduledReports: params.getScheduledReports,
|
|
75599
|
+
updateScheduledReport: updateScheduledReport
|
|
75600
|
+
};
|
|
75601
|
+
};
|
|
75602
|
+
|
|
75603
|
+
/*
|
|
75604
|
+
A context for managing the dashboard session.
|
|
75605
|
+
*/
|
|
75606
|
+
var STILL_LOADING = null;
|
|
75607
|
+
var useSessionContext = function useSessionContext(params) {
|
|
75608
|
+
var _loadedStrategy$dashb, _loadedStrategy$dashb2;
|
|
75609
|
+
var vizzly = useVizzly({
|
|
75610
|
+
queryEngine: params.queryEngine,
|
|
75611
|
+
identity: params.identityCallback,
|
|
75612
|
+
dataSets: params.loadDataSetsCallback,
|
|
75613
|
+
programmaticDashboard: params.programmaticDashboard
|
|
75614
|
+
}, {
|
|
75615
|
+
apiHost: params.apiConfig.host
|
|
75616
|
+
});
|
|
75617
|
+
var loadedStrategy = useDashboardStrategy(getStrategy(vizzly, params.parentDashboardId, params.dashboardId, params.isEditor), vizzly, params.programmaticDashboard);
|
|
75618
|
+
var _useScheduledReports = useScheduledReports(vizzly, loadedStrategy == null || (_loadedStrategy$dashb = loadedStrategy.dashboard) == null || (_loadedStrategy$dashb = _loadedStrategy$dashb.permission) == null ? void 0 : _loadedStrategy$dashb.token),
|
|
75619
|
+
reports = _useScheduledReports.reports,
|
|
75620
|
+
updateScheduledReport = _useScheduledReports.updateScheduledReport;
|
|
75621
|
+
if (!vizzly) return STILL_LOADING;
|
|
75622
|
+
if ('error' in vizzly && vizzly.error) return {
|
|
75623
|
+
error: vizzly.error
|
|
75624
|
+
};
|
|
75625
|
+
if ('loading' in vizzly && vizzly.loading) return STILL_LOADING;
|
|
75626
|
+
if (!('dashboards' in vizzly)) return STILL_LOADING;
|
|
75627
|
+
var identityConfig = vizzly.identityConfig,
|
|
75628
|
+
queryEngineConfig = vizzly.queryEngineConfig;
|
|
75629
|
+
if (!loadedStrategy) return null;
|
|
75630
|
+
if (((loadedStrategy == null || (_loadedStrategy$dashb2 = loadedStrategy.dashboard) == null ? void 0 : _loadedStrategy$dashb2.dataSets) || []).length === 0) {
|
|
75631
|
+
return {
|
|
75632
|
+
error: new NoDataSetResolved()
|
|
75633
|
+
};
|
|
75634
|
+
}
|
|
75635
|
+
var providedValues = {
|
|
75636
|
+
vizzly: vizzly,
|
|
75637
|
+
scope: loadedStrategy.scope,
|
|
75638
|
+
queryEngineConfig: queryEngineConfig,
|
|
75639
|
+
dashboard: loadedStrategy.dashboard,
|
|
75640
|
+
identityConfig: identityConfig,
|
|
75641
|
+
mode: loadedStrategy.mode,
|
|
75642
|
+
vizzlyApiConfig: params.apiConfig,
|
|
75643
|
+
isProgrammaticParent: loadedStrategy.isProgrammaticParent,
|
|
75644
|
+
globalLibraries: vizzly.globalLibraries,
|
|
75645
|
+
reports: reports,
|
|
75646
|
+
updateScheduledReport: updateScheduledReport
|
|
75647
|
+
};
|
|
75648
|
+
return providedValues;
|
|
75619
75649
|
};
|
|
75620
75650
|
|
|
75621
75651
|
var buildImplementationMeta = function buildImplementationMeta(props) {
|
|
@@ -75637,7 +75667,9 @@ var buildImplementationMeta = function buildImplementationMeta(props) {
|
|
|
75637
75667
|
};
|
|
75638
75668
|
};
|
|
75639
75669
|
|
|
75640
|
-
var
|
|
75670
|
+
var GlobalContext = /*#__PURE__*/React.createContext(undefined);
|
|
75671
|
+
|
|
75672
|
+
var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, onDashboardLoad, updateDashboardHash) {
|
|
75641
75673
|
var _session$dashboard2;
|
|
75642
75674
|
React.useEffect(function () {
|
|
75643
75675
|
var _session$dashboard;
|
|
@@ -75648,6 +75680,7 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
|
|
|
75648
75680
|
scope: session.scope,
|
|
75649
75681
|
dataSets: session.dashboard.dataSets
|
|
75650
75682
|
});
|
|
75683
|
+
updateDashboardHash(session.dashboard);
|
|
75651
75684
|
}
|
|
75652
75685
|
}, [JSON.stringify({
|
|
75653
75686
|
loaded: !!session,
|
|
@@ -75655,17 +75688,6 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
|
|
|
75655
75688
|
})]);
|
|
75656
75689
|
};
|
|
75657
75690
|
|
|
75658
|
-
var FailedToSaveError = /*#__PURE__*/function (_Error) {
|
|
75659
|
-
function FailedToSaveError(message) {
|
|
75660
|
-
var _this;
|
|
75661
|
-
_this = _Error.call(this, "Failed to save dashboard.") || this;
|
|
75662
|
-
_this.message = message;
|
|
75663
|
-
return _this;
|
|
75664
|
-
}
|
|
75665
|
-
_inheritsLoose(FailedToSaveError, _Error);
|
|
75666
|
-
return FailedToSaveError;
|
|
75667
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
75668
|
-
|
|
75669
75691
|
var GlobalProvider = function GlobalProvider(props) {
|
|
75670
75692
|
var _useState = React.useState(0),
|
|
75671
75693
|
resetKey = _useState[0],
|
|
@@ -75691,6 +75713,9 @@ var GlobalProvider = function GlobalProvider(props) {
|
|
|
75691
75713
|
};
|
|
75692
75714
|
var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
75693
75715
|
var _props$id, _session$identityConf, _props$dateFilterOpti, _session$vizzly$savin;
|
|
75716
|
+
var _useState2 = React.useState(undefined),
|
|
75717
|
+
dashboardHash = _useState2[0],
|
|
75718
|
+
setDashboardHash = _useState2[1];
|
|
75694
75719
|
var implementationMeta = buildImplementationMeta(props);
|
|
75695
75720
|
var apiConfig = props.vizzlyApiHost ? {
|
|
75696
75721
|
host: props.vizzlyApiHost
|
|
@@ -75714,7 +75739,11 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
|
75714
75739
|
textOverride: textOverride,
|
|
75715
75740
|
isEditor: props.isEditor
|
|
75716
75741
|
});
|
|
75717
|
-
|
|
75742
|
+
var updateDashboardHash = function updateDashboardHash(dashboard) {
|
|
75743
|
+
var definition = toSaveableDefinition(dashboard);
|
|
75744
|
+
setDashboardHash(crypto.createHash('md5').update(JSON.stringify(definition)).digest('hex'));
|
|
75745
|
+
};
|
|
75746
|
+
useOnDashboardLoadCallback(session, props.onDashboardLoad, updateDashboardHash);
|
|
75718
75747
|
var variables = useVariables(props.variables, (_props$id = props.id) != null ? _props$id : '');
|
|
75719
75748
|
if (session === null) return jsxRuntime.jsx(LoadingComponent, {
|
|
75720
75749
|
override: props.renderLoadingComponent
|
|
@@ -75910,14 +75939,16 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
|
75910
75939
|
labelFormat: props == null ? void 0 : props.labelFormat,
|
|
75911
75940
|
filterLibrary: props == null ? void 0 : props.filterLibrary,
|
|
75912
75941
|
valueAlias: props == null ? void 0 : props.valueAlias,
|
|
75913
|
-
variables: variables
|
|
75942
|
+
variables: variables,
|
|
75943
|
+
onDashboardUpdate: props == null ? void 0 : props.onDashboardUpdate,
|
|
75944
|
+
updateDashboardHash: updateDashboardHash
|
|
75914
75945
|
},
|
|
75915
75946
|
ai: {
|
|
75916
75947
|
onAction: aiOnAction,
|
|
75917
75948
|
onAsk: aiOnAsk,
|
|
75918
75949
|
fetchSuggestions: aiFetchSuggestions
|
|
75919
75950
|
},
|
|
75920
|
-
|
|
75951
|
+
dashboardHash: dashboardHash,
|
|
75921
75952
|
dashboard: session.dashboard,
|
|
75922
75953
|
runQueriesCallback: runQueriesCallback,
|
|
75923
75954
|
implementationMeta: implementationMeta,
|