@vizzly/dashboard 0.15.0-dev-67a8f2b3c476fec9b95806eb843a397f087e47f5 → 0.15.0-dev-3d599f1049eba812c1f45d1985540f920617733b
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 +884 -854
- package/dist/dashboard.cjs.production.min.js +1 -1
- package/dist/dashboard.esm.js +884 -854
- 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;
|
|
@@ -69680,7 +69699,8 @@ var StudioContexts = function StudioContexts(props) {
|
|
|
69680
69699
|
trackEvent: props.trackEvent,
|
|
69681
69700
|
dashboard: props.dashboard,
|
|
69682
69701
|
componentEditor: props.componentEditor,
|
|
69683
|
-
onDashboardUpdate: props.onDashboardUpdate,
|
|
69702
|
+
onDashboardUpdate: props.dashboardBehaviour.onDashboardUpdate,
|
|
69703
|
+
dashboardHash: props.dashboardHash,
|
|
69684
69704
|
saving: props.saving,
|
|
69685
69705
|
runQueriesCallback: function runQueriesCallback(queries, params) {
|
|
69686
69706
|
var _props$identityConfig;
|
|
@@ -73495,848 +73515,74 @@ var EditorView$1 = function EditorView(props) {
|
|
|
73495
73515
|
});
|
|
73496
73516
|
};
|
|
73497
73517
|
|
|
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;
|
|
73518
|
+
var getParentDashboards$1 = function getParentDashboards(httpClient) {
|
|
73519
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
73520
|
+
var _yield$httpClient, status, body;
|
|
73613
73521
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73614
73522
|
while (1) switch (_context.prev = _context.next) {
|
|
73615
73523
|
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: {}
|
|
73524
|
+
_context.next = 2;
|
|
73525
|
+
return httpClient({
|
|
73526
|
+
path: "/api/v2/parent-dashboards",
|
|
73527
|
+
method: 'get'
|
|
73676
73528
|
});
|
|
73677
|
-
case
|
|
73678
|
-
|
|
73679
|
-
|
|
73680
|
-
|
|
73529
|
+
case 2:
|
|
73530
|
+
_yield$httpClient = _context.sent;
|
|
73531
|
+
status = _yield$httpClient.status;
|
|
73532
|
+
body = _yield$httpClient.body;
|
|
73533
|
+
if (!(status == 200)) {
|
|
73534
|
+
_context.next = 7;
|
|
73681
73535
|
break;
|
|
73682
73536
|
}
|
|
73683
|
-
|
|
73684
|
-
|
|
73685
|
-
|
|
73686
|
-
|
|
73687
|
-
|
|
73688
|
-
|
|
73689
|
-
|
|
73690
|
-
|
|
73691
|
-
|
|
73692
|
-
|
|
73537
|
+
return _context.abrupt("return", body.dashboards.map(function (rawDashboard) {
|
|
73538
|
+
return {
|
|
73539
|
+
id: rawDashboard.id,
|
|
73540
|
+
created_at: rawDashboard.created_at,
|
|
73541
|
+
updated_at: rawDashboard.updated_at,
|
|
73542
|
+
webhook_id: rawDashboard.webhook_id
|
|
73543
|
+
};
|
|
73544
|
+
}));
|
|
73545
|
+
case 7:
|
|
73546
|
+
return _context.abrupt("return", undefined);
|
|
73547
|
+
case 8:
|
|
73693
73548
|
case "end":
|
|
73694
73549
|
return _context.stop();
|
|
73695
73550
|
}
|
|
73696
73551
|
}, _callee);
|
|
73697
73552
|
}));
|
|
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
73553
|
};
|
|
73775
73554
|
|
|
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) {
|
|
73555
|
+
// If cronSchedule is `null`, then it means the scheduled
|
|
73556
|
+
// report is deleted.
|
|
73557
|
+
var saveScheduledReport = function saveScheduledReport(httpClient) {
|
|
73558
|
+
return /*#__PURE__*/function () {
|
|
73559
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
73560
|
+
var _yield$httpClient, status;
|
|
73561
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73562
|
+
while (1) switch (_context.prev = _context.next) {
|
|
73933
73563
|
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
|
|
73564
|
+
_context.next = 2;
|
|
73565
|
+
return httpClient({
|
|
73566
|
+
path: '/api/scheduled-report',
|
|
73567
|
+
method: 'post',
|
|
73568
|
+
body: {
|
|
73569
|
+
cronSchedule: params.cronSchedule,
|
|
73570
|
+
dashboardAccessToken: params.dashboardAccessToken,
|
|
73571
|
+
scheduledReportId: params.scheduledReportId
|
|
73572
|
+
}
|
|
73946
73573
|
});
|
|
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:
|
|
73574
|
+
case 2:
|
|
73575
|
+
_yield$httpClient = _context.sent;
|
|
73576
|
+
status = _yield$httpClient.status;
|
|
73577
|
+
return _context.abrupt("return", status == 200);
|
|
73578
|
+
case 5:
|
|
73964
73579
|
case "end":
|
|
73965
|
-
return
|
|
73580
|
+
return _context.stop();
|
|
73966
73581
|
}
|
|
73967
|
-
},
|
|
73582
|
+
}, _callee);
|
|
73968
73583
|
}));
|
|
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);
|
|
73584
|
+
return function (_x) {
|
|
73585
|
+
return _ref.apply(this, arguments);
|
|
74340
73586
|
};
|
|
74341
73587
|
}();
|
|
74342
73588
|
};
|
|
@@ -75076,6 +74322,28 @@ var api = function api(config) {
|
|
|
75076
74322
|
};
|
|
75077
74323
|
};
|
|
75078
74324
|
|
|
74325
|
+
var buildQueryEngineSignInUrl = function buildQueryEngineSignInUrl(queryEngineEndpoint, queryEngineAccessToken) {
|
|
74326
|
+
if (!queryEngineAccessToken) return '';
|
|
74327
|
+
var authToken = queryEngineAccessToken;
|
|
74328
|
+
authToken = encode(JSON.stringify({
|
|
74329
|
+
queryEngineAccessToken: queryEngineAccessToken,
|
|
74330
|
+
projectAccessToken: undefined
|
|
74331
|
+
}));
|
|
74332
|
+
var endpoint = buildPath(getHostFromQueryEngineEndpoint(queryEngineEndpoint), "/sign-in#" + authToken);
|
|
74333
|
+
return endpoint;
|
|
74334
|
+
};
|
|
74335
|
+
|
|
74336
|
+
var FailedToSaveError = /*#__PURE__*/function (_Error) {
|
|
74337
|
+
function FailedToSaveError(message) {
|
|
74338
|
+
var _this;
|
|
74339
|
+
_this = _Error.call(this, "Failed to save dashboard.") || this;
|
|
74340
|
+
_this.message = message;
|
|
74341
|
+
return _this;
|
|
74342
|
+
}
|
|
74343
|
+
_inheritsLoose(FailedToSaveError, _Error);
|
|
74344
|
+
return FailedToSaveError;
|
|
74345
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
74346
|
+
|
|
75079
74347
|
var StatusLine = function StatusLine(props) {
|
|
75080
74348
|
return jsxRuntime.jsx("div", {
|
|
75081
74349
|
children: jsxRuntime.jsxs("span", {
|
|
@@ -75546,6 +74814,17 @@ var InvalidIdentityFunctionNotice = function InvalidIdentityFunctionNotice(props
|
|
|
75546
74814
|
// />
|
|
75547
74815
|
// );
|
|
75548
74816
|
|
|
74817
|
+
var NoDataSetResolved = /*#__PURE__*/function (_Error) {
|
|
74818
|
+
function NoDataSetResolved() {
|
|
74819
|
+
var _this;
|
|
74820
|
+
_this = _Error.call(this, 'At least one data set must be built for the Vizzly dashboard to render.') || this;
|
|
74821
|
+
_this.name = 'NoDataSetResolved';
|
|
74822
|
+
return _this;
|
|
74823
|
+
}
|
|
74824
|
+
_inheritsLoose(NoDataSetResolved, _Error);
|
|
74825
|
+
return NoDataSetResolved;
|
|
74826
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
74827
|
+
|
|
75549
74828
|
var SetupError = function SetupError(props) {
|
|
75550
74829
|
logError(props.error);
|
|
75551
74830
|
var renderedError = jsxRuntime.jsx("p", {
|
|
@@ -75607,15 +74886,765 @@ var SetupError = function SetupError(props) {
|
|
|
75607
74886
|
});
|
|
75608
74887
|
};
|
|
75609
74888
|
|
|
75610
|
-
var
|
|
75611
|
-
if (
|
|
75612
|
-
|
|
75613
|
-
|
|
75614
|
-
|
|
75615
|
-
|
|
74889
|
+
var getDefaultParentDashboardId = function getDefaultParentDashboardId(parentDashboardId, parentDashboardIdOnDashboardAccessToken, dashboards) {
|
|
74890
|
+
if (parentDashboardId) {
|
|
74891
|
+
var parentDashboard = find$1(dashboards, parentDashboardId);
|
|
74892
|
+
if (!(parentDashboard != null && parentDashboard.parentDashboardId)) {
|
|
74893
|
+
return parentDashboardId;
|
|
74894
|
+
} else {
|
|
74895
|
+
throw '[Vizzly] `parentDashboardId` value must specify an ID for a parent dashboard.';
|
|
74896
|
+
}
|
|
74897
|
+
}
|
|
74898
|
+
var parentDashboards = getParentDashboards(dashboards);
|
|
74899
|
+
var programmaticDashboardId = checkAndReturnProgrammaticDashboardId(parentDashboards);
|
|
74900
|
+
if (programmaticDashboardId) return programmaticDashboardId;
|
|
74901
|
+
return parentDashboardIdOnDashboardAccessToken || getFirstCreated(parentDashboards).id;
|
|
74902
|
+
};
|
|
74903
|
+
|
|
74904
|
+
var getStrategy = function getStrategy(vizzly, requestedEndUserParentDashboardId, requestedEndUserDashboardId, isEditor) {
|
|
74905
|
+
if (!('dashboards' in vizzly)) return undefined;
|
|
74906
|
+
if (vizzly.loading || vizzly.error) return undefined;
|
|
74907
|
+
logDebug('Loading dashboard strategy, with props;', {
|
|
74908
|
+
dashboardId: requestedEndUserDashboardId,
|
|
74909
|
+
parentDashboardId: requestedEndUserParentDashboardId
|
|
74910
|
+
});
|
|
74911
|
+
// This is a temporary fix for the issue where the dashboard is not loaded due to multiple hooks.
|
|
74912
|
+
var checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks = isEditor && vizzly.dashboards.length === 0;
|
|
74913
|
+
if (checkToStopStrategyCheckingWhenDashboardNotLoadedDueToMultipleHooks) return undefined;
|
|
74914
|
+
var defaultParentDashboardId = getDefaultParentDashboardId(requestedEndUserParentDashboardId, vizzly.identityConfig.dashboardAccess.dashboardId, vizzly.dashboards);
|
|
74915
|
+
if (vizzly.accessType == 'admin') {
|
|
74916
|
+
logDebug('Admin access found, so we will show the parent dashboard.', defaultParentDashboardId);
|
|
74917
|
+
var dashboardId = defaultParentDashboardId;
|
|
74918
|
+
// If the user wants a specific dashboard, then fetch the parent dashboard of it.
|
|
74919
|
+
if (requestedEndUserDashboardId) {
|
|
74920
|
+
var foundRequestedChildDashboard = vizzly.dashboards.find(function (dashboard) {
|
|
74921
|
+
return dashboard.id == requestedEndUserDashboardId;
|
|
74922
|
+
});
|
|
74923
|
+
if (foundRequestedChildDashboard != null && foundRequestedChildDashboard.parentDashboardId) {
|
|
74924
|
+
logDebug('A child dashboard was provided whilst in admin mode. Therefore the parent of the given child will be shown to administer.', foundRequestedChildDashboard.parentDashboardId);
|
|
74925
|
+
dashboardId = foundRequestedChildDashboard.parentDashboardId;
|
|
74926
|
+
}
|
|
74927
|
+
}
|
|
74928
|
+
logDebug('Admin access found, so we will show the parent dashboard.', dashboardId);
|
|
74929
|
+
return {
|
|
74930
|
+
type: 'exact',
|
|
74931
|
+
dashboardId: dashboardId
|
|
74932
|
+
};
|
|
74933
|
+
}
|
|
74934
|
+
if (requestedEndUserDashboardId) {
|
|
74935
|
+
logDebug('Strategy will be to show dashboard', requestedEndUserDashboardId);
|
|
74936
|
+
return {
|
|
74937
|
+
type: 'exact',
|
|
74938
|
+
dashboardId: requestedEndUserDashboardId
|
|
74939
|
+
};
|
|
74940
|
+
}
|
|
74941
|
+
var childDashboards = vizzly.dashboards.filter(function (d) {
|
|
74942
|
+
var isChildDashboard = d.parentDashboardId != null;
|
|
74943
|
+
var hasNotRequestedEndUserParentDashboardId = requestedEndUserParentDashboardId === undefined;
|
|
74944
|
+
var isChildOfRequestedParent = hasNotRequestedEndUserParentDashboardId || d.parentDashboardId === requestedEndUserParentDashboardId;
|
|
74945
|
+
return isChildDashboard && isChildOfRequestedParent;
|
|
74946
|
+
});
|
|
74947
|
+
// Exactly one child dashboard for the user & in read-only mode so someone else is managing the dashboard with the same userReference.
|
|
74948
|
+
// We will show that one dashboard to allow for a common SaaS environment where
|
|
74949
|
+
// multiple users share the same userReference, but some of those users have `read_write` access and other users have read access.
|
|
74950
|
+
// Those with `read` access should see the dashboard managed by those other users...
|
|
74951
|
+
if (childDashboards.length === 1 && vizzly.identityConfig.dashboardAccess.scope == 'read') {
|
|
74952
|
+
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);
|
|
74953
|
+
return {
|
|
74954
|
+
type: 'exact',
|
|
74955
|
+
dashboardId: vizzly.dashboards.find(function (d) {
|
|
74956
|
+
return d.parentDashboardId != null;
|
|
74957
|
+
}).id
|
|
74958
|
+
};
|
|
74959
|
+
}
|
|
74960
|
+
// No specific dashboard requested, but dashboard access token only grants 'read' access.
|
|
74961
|
+
if (vizzly.identityConfig.dashboardAccess.scope == 'read' && defaultParentDashboardId) {
|
|
74962
|
+
logDebug('Strategy will be to return read-only view of the parent dashboard.', defaultParentDashboardId);
|
|
74963
|
+
return {
|
|
74964
|
+
type: 'exact',
|
|
74965
|
+
dashboardId: defaultParentDashboardId
|
|
74966
|
+
};
|
|
74967
|
+
}
|
|
74968
|
+
var dashboardIdSetInIdentityConfig = vizzly.identityConfig.dashboardAccess.dashboardId;
|
|
74969
|
+
if (dashboardIdSetInIdentityConfig) {
|
|
74970
|
+
var _vizzly$identityConfi, _vizzly$identityConfi2;
|
|
74971
|
+
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);
|
|
74972
|
+
return {
|
|
74973
|
+
type: 'instantCopyOf',
|
|
74974
|
+
parentDashboardId: (_vizzly$identityConfi2 = vizzly.identityConfig.dashboardAccess) == null ? void 0 : _vizzly$identityConfi2.dashboardId
|
|
74975
|
+
};
|
|
74976
|
+
} else {
|
|
74977
|
+
logDebug('Strategy will be to show a child of the parent dashboard', defaultParentDashboardId);
|
|
74978
|
+
return {
|
|
74979
|
+
type: 'instantCopyOf',
|
|
74980
|
+
parentDashboardId: defaultParentDashboardId
|
|
74981
|
+
};
|
|
74982
|
+
}
|
|
74983
|
+
};
|
|
74984
|
+
|
|
74985
|
+
var Mode;
|
|
74986
|
+
(function (Mode) {
|
|
74987
|
+
Mode["Admin"] = "admin";
|
|
74988
|
+
Mode["EndUser"] = "endUser";
|
|
74989
|
+
})(Mode || (Mode = {}));
|
|
74990
|
+
var Scope;
|
|
74991
|
+
(function (Scope) {
|
|
74992
|
+
Scope["Read"] = "read";
|
|
74993
|
+
Scope["ReadWrite"] = "read_write";
|
|
74994
|
+
})(Scope || (Scope = {}));
|
|
74995
|
+
|
|
74996
|
+
/*
|
|
74997
|
+
Currently, we just replicate the same behaviour as what we used to have on the API.
|
|
74998
|
+
*/
|
|
74999
|
+
var runStrategy = /*#__PURE__*/function () {
|
|
75000
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(strategy, vizzly) {
|
|
75001
|
+
var currentDashboard, scope, _parentDashboard$perm, parentDashboard, hasParentDashboardWritePermission, dashboardCopies, mostRecentlyUpdatedChildDashboard, created;
|
|
75002
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75003
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75004
|
+
case 0:
|
|
75005
|
+
if (!(strategy.type == 'exact')) {
|
|
75006
|
+
_context.next = 9;
|
|
75007
|
+
break;
|
|
75008
|
+
}
|
|
75009
|
+
currentDashboard = vizzly.dashboards.find(function (d) {
|
|
75010
|
+
return d.id === strategy.dashboardId;
|
|
75011
|
+
});
|
|
75012
|
+
if (currentDashboard.permission) {
|
|
75013
|
+
_context.next = 4;
|
|
75014
|
+
break;
|
|
75015
|
+
}
|
|
75016
|
+
throw '';
|
|
75017
|
+
case 4:
|
|
75018
|
+
scope = currentDashboard.permission.scope;
|
|
75019
|
+
logDebug('A specific dashboard has been requested. This will be rendered with', scope, 'scope.', strategy.dashboardId);
|
|
75020
|
+
return _context.abrupt("return", {
|
|
75021
|
+
dashboardId: strategy.dashboardId,
|
|
75022
|
+
mode: scope === 'read_write' && currentDashboard.parentDashboardId === null ? Mode.Admin : Mode.EndUser,
|
|
75023
|
+
scope: scope
|
|
75024
|
+
});
|
|
75025
|
+
case 9:
|
|
75026
|
+
if (!(strategy.type == 'instantCopyOf')) {
|
|
75027
|
+
_context.next = 29;
|
|
75028
|
+
break;
|
|
75029
|
+
}
|
|
75030
|
+
// If the user has write access to the parent dashboard, then we return that dashboard ID, with mode=admin
|
|
75031
|
+
parentDashboard = vizzly.dashboards.find(function (d) {
|
|
75032
|
+
return d.id === strategy.parentDashboardId;
|
|
75033
|
+
});
|
|
75034
|
+
hasParentDashboardWritePermission = ((_parentDashboard$perm = parentDashboard.permission) == null ? void 0 : _parentDashboard$perm.scope) === 'read_write';
|
|
75035
|
+
if (!hasParentDashboardWritePermission) {
|
|
75036
|
+
_context.next = 15;
|
|
75037
|
+
break;
|
|
75038
|
+
}
|
|
75039
|
+
logDebug('Write access to the parent dashboard has been found, so this dashboard will be shown with admin access.', strategy.parentDashboardId);
|
|
75040
|
+
return _context.abrupt("return", {
|
|
75041
|
+
dashboardId: strategy.parentDashboardId,
|
|
75042
|
+
mode: Mode.Admin,
|
|
75043
|
+
scope: Scope.ReadWrite
|
|
75044
|
+
});
|
|
75045
|
+
case 15:
|
|
75046
|
+
dashboardCopies = getCopiesOfParentDashboard(strategy.parentDashboardId, vizzly.dashboards);
|
|
75047
|
+
mostRecentlyUpdatedChildDashboard = takeMostRecentlyUpdated(dashboardCopies);
|
|
75048
|
+
if (!mostRecentlyUpdatedChildDashboard) {
|
|
75049
|
+
_context.next = 20;
|
|
75050
|
+
break;
|
|
75051
|
+
}
|
|
75052
|
+
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);
|
|
75053
|
+
return _context.abrupt("return", {
|
|
75054
|
+
dashboardId: mostRecentlyUpdatedChildDashboard.id,
|
|
75055
|
+
mode: Mode.EndUser,
|
|
75056
|
+
scope: mostRecentlyUpdatedChildDashboard.permission.scope
|
|
75057
|
+
});
|
|
75058
|
+
case 20:
|
|
75059
|
+
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.');
|
|
75060
|
+
_context.next = 23;
|
|
75061
|
+
return vizzly.createDashboard({
|
|
75062
|
+
parentDashboardId: parentDashboard.id,
|
|
75063
|
+
definition: toSaveableDefinition(parentDashboard),
|
|
75064
|
+
metadata: {}
|
|
75065
|
+
});
|
|
75066
|
+
case 23:
|
|
75067
|
+
created = _context.sent;
|
|
75068
|
+
if (created) {
|
|
75069
|
+
_context.next = 26;
|
|
75070
|
+
break;
|
|
75071
|
+
}
|
|
75072
|
+
throw 'Failed to create first child dashboard for the user.';
|
|
75073
|
+
case 26:
|
|
75074
|
+
return _context.abrupt("return", {
|
|
75075
|
+
dashboardId: created.id,
|
|
75076
|
+
scope: Scope.ReadWrite,
|
|
75077
|
+
mode: Mode.EndUser
|
|
75078
|
+
});
|
|
75079
|
+
case 29:
|
|
75080
|
+
throw "Unsupported strategy";
|
|
75081
|
+
case 30:
|
|
75082
|
+
case "end":
|
|
75083
|
+
return _context.stop();
|
|
75084
|
+
}
|
|
75085
|
+
}, _callee);
|
|
75616
75086
|
}));
|
|
75617
|
-
|
|
75618
|
-
|
|
75087
|
+
return function runStrategy(_x, _x2) {
|
|
75088
|
+
return _ref.apply(this, arguments);
|
|
75089
|
+
};
|
|
75090
|
+
}();
|
|
75091
|
+
|
|
75092
|
+
/*
|
|
75093
|
+
Stores which dashboard is the currently active one...
|
|
75094
|
+
*/
|
|
75095
|
+
var useDashboardStrategy = function useDashboardStrategy(strategy, vizzly, programmaticDashboard) {
|
|
75096
|
+
var _useState = React.useState(),
|
|
75097
|
+
state = _useState[0],
|
|
75098
|
+
setState = _useState[1];
|
|
75099
|
+
React.useEffect(function () {
|
|
75100
|
+
var doWork = /*#__PURE__*/function () {
|
|
75101
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75102
|
+
var _yield$runStrategy, mode, dashboardId, scope;
|
|
75103
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75104
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75105
|
+
case 0:
|
|
75106
|
+
if ('dashboards' in vizzly) {
|
|
75107
|
+
_context.next = 2;
|
|
75108
|
+
break;
|
|
75109
|
+
}
|
|
75110
|
+
return _context.abrupt("return");
|
|
75111
|
+
case 2:
|
|
75112
|
+
if (strategy) {
|
|
75113
|
+
_context.next = 4;
|
|
75114
|
+
break;
|
|
75115
|
+
}
|
|
75116
|
+
return _context.abrupt("return");
|
|
75117
|
+
case 4:
|
|
75118
|
+
if (!vizzly.loading) {
|
|
75119
|
+
_context.next = 6;
|
|
75120
|
+
break;
|
|
75121
|
+
}
|
|
75122
|
+
return _context.abrupt("return");
|
|
75123
|
+
case 6:
|
|
75124
|
+
_context.next = 8;
|
|
75125
|
+
return runStrategy(strategy, vizzly);
|
|
75126
|
+
case 8:
|
|
75127
|
+
_yield$runStrategy = _context.sent;
|
|
75128
|
+
mode = _yield$runStrategy.mode;
|
|
75129
|
+
dashboardId = _yield$runStrategy.dashboardId;
|
|
75130
|
+
scope = _yield$runStrategy.scope;
|
|
75131
|
+
if (dashboardId != (state == null ? void 0 : state.dashboardId)) setState({
|
|
75132
|
+
mode: mode,
|
|
75133
|
+
dashboardId: dashboardId,
|
|
75134
|
+
scope: scope
|
|
75135
|
+
});
|
|
75136
|
+
case 13:
|
|
75137
|
+
case "end":
|
|
75138
|
+
return _context.stop();
|
|
75139
|
+
}
|
|
75140
|
+
}, _callee);
|
|
75141
|
+
}));
|
|
75142
|
+
return function doWork() {
|
|
75143
|
+
return _ref.apply(this, arguments);
|
|
75144
|
+
};
|
|
75145
|
+
}();
|
|
75146
|
+
doWork();
|
|
75147
|
+
}, [JSON.stringify({
|
|
75148
|
+
strategy: strategy,
|
|
75149
|
+
loading: vizzly.loading
|
|
75150
|
+
})]);
|
|
75151
|
+
if (!('dashboards' in vizzly)) return null;
|
|
75152
|
+
if (!state) return null;
|
|
75153
|
+
if (vizzly.loading) return null;
|
|
75154
|
+
var dashboard = vizzly.dashboards.find(function (dash) {
|
|
75155
|
+
return dash.id == state.dashboardId;
|
|
75156
|
+
}) || null;
|
|
75157
|
+
return {
|
|
75158
|
+
mode: state.mode,
|
|
75159
|
+
dashboard: dashboard,
|
|
75160
|
+
scope: state.scope,
|
|
75161
|
+
isProgrammaticParent: !!programmaticDashboard
|
|
75162
|
+
};
|
|
75163
|
+
};
|
|
75164
|
+
|
|
75165
|
+
var useVizzly = function useVizzly(properties, options) {
|
|
75166
|
+
var _useState = React.useState({
|
|
75167
|
+
loading: true,
|
|
75168
|
+
error: undefined,
|
|
75169
|
+
dashboards: [],
|
|
75170
|
+
globalLibraries: []
|
|
75171
|
+
}),
|
|
75172
|
+
state = _useState[0],
|
|
75173
|
+
setState = _useState[1];
|
|
75174
|
+
var vizzlyRef = React.useRef();
|
|
75175
|
+
var vizzly = vizzlyRef.current;
|
|
75176
|
+
React.useEffect(function () {
|
|
75177
|
+
var abortController = new AbortController();
|
|
75178
|
+
var doWork = /*#__PURE__*/function () {
|
|
75179
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75180
|
+
var _yield$Promise$all, globalLibraries, dashboards;
|
|
75181
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75182
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75183
|
+
case 0:
|
|
75184
|
+
_context.prev = 0;
|
|
75185
|
+
_context.next = 3;
|
|
75186
|
+
return Vizzly$1.load(properties, {
|
|
75187
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75188
|
+
});
|
|
75189
|
+
case 3:
|
|
75190
|
+
vizzlyRef.current = _context.sent;
|
|
75191
|
+
_context.next = 6;
|
|
75192
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75193
|
+
abortController: abortController
|
|
75194
|
+
}), vizzlyRef.current.getDashboards({
|
|
75195
|
+
abortController: abortController
|
|
75196
|
+
})]);
|
|
75197
|
+
case 6:
|
|
75198
|
+
_yield$Promise$all = _context.sent;
|
|
75199
|
+
globalLibraries = _yield$Promise$all[0];
|
|
75200
|
+
dashboards = _yield$Promise$all[1];
|
|
75201
|
+
setState({
|
|
75202
|
+
loading: false,
|
|
75203
|
+
error: undefined,
|
|
75204
|
+
dashboards: dashboards,
|
|
75205
|
+
globalLibraries: globalLibraries
|
|
75206
|
+
});
|
|
75207
|
+
_context.next = 16;
|
|
75208
|
+
break;
|
|
75209
|
+
case 12:
|
|
75210
|
+
_context.prev = 12;
|
|
75211
|
+
_context.t0 = _context["catch"](0);
|
|
75212
|
+
logError('Error loading Vizzly', _context.t0);
|
|
75213
|
+
setState({
|
|
75214
|
+
loading: false,
|
|
75215
|
+
error: _context.t0,
|
|
75216
|
+
dashboards: [].concat(state.dashboards),
|
|
75217
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75218
|
+
});
|
|
75219
|
+
case 16:
|
|
75220
|
+
case "end":
|
|
75221
|
+
return _context.stop();
|
|
75222
|
+
}
|
|
75223
|
+
}, _callee, null, [[0, 12]]);
|
|
75224
|
+
}));
|
|
75225
|
+
return function doWork() {
|
|
75226
|
+
return _ref.apply(this, arguments);
|
|
75227
|
+
};
|
|
75228
|
+
}();
|
|
75229
|
+
doWork();
|
|
75230
|
+
return function () {
|
|
75231
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75232
|
+
};
|
|
75233
|
+
}, []);
|
|
75234
|
+
var refetch = /*#__PURE__*/function () {
|
|
75235
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
75236
|
+
var abortController, doWork;
|
|
75237
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
75238
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
75239
|
+
case 0:
|
|
75240
|
+
abortController = new AbortController();
|
|
75241
|
+
doWork = /*#__PURE__*/function () {
|
|
75242
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
75243
|
+
var _yield$Promise$all2, globalLibraries, dashboards;
|
|
75244
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75245
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75246
|
+
case 0:
|
|
75247
|
+
_context2.prev = 0;
|
|
75248
|
+
_context2.next = 3;
|
|
75249
|
+
return Vizzly$1.load(properties, {
|
|
75250
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75251
|
+
});
|
|
75252
|
+
case 3:
|
|
75253
|
+
vizzlyRef.current = _context2.sent;
|
|
75254
|
+
_context2.next = 6;
|
|
75255
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75256
|
+
abortController: abortController
|
|
75257
|
+
}), vizzlyRef.current.getDashboards({
|
|
75258
|
+
abortController: abortController
|
|
75259
|
+
})]);
|
|
75260
|
+
case 6:
|
|
75261
|
+
_yield$Promise$all2 = _context2.sent;
|
|
75262
|
+
globalLibraries = _yield$Promise$all2[0];
|
|
75263
|
+
dashboards = _yield$Promise$all2[1];
|
|
75264
|
+
setState({
|
|
75265
|
+
loading: false,
|
|
75266
|
+
error: undefined,
|
|
75267
|
+
dashboards: dashboards,
|
|
75268
|
+
globalLibraries: globalLibraries
|
|
75269
|
+
});
|
|
75270
|
+
_context2.next = 16;
|
|
75271
|
+
break;
|
|
75272
|
+
case 12:
|
|
75273
|
+
_context2.prev = 12;
|
|
75274
|
+
_context2.t0 = _context2["catch"](0);
|
|
75275
|
+
logError('Error loading Vizzly', _context2.t0);
|
|
75276
|
+
setState({
|
|
75277
|
+
loading: false,
|
|
75278
|
+
error: _context2.t0,
|
|
75279
|
+
dashboards: [].concat(state.dashboards),
|
|
75280
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75281
|
+
});
|
|
75282
|
+
case 16:
|
|
75283
|
+
case "end":
|
|
75284
|
+
return _context2.stop();
|
|
75285
|
+
}
|
|
75286
|
+
}, _callee2, null, [[0, 12]]);
|
|
75287
|
+
}));
|
|
75288
|
+
return function doWork() {
|
|
75289
|
+
return _ref3.apply(this, arguments);
|
|
75290
|
+
};
|
|
75291
|
+
}();
|
|
75292
|
+
doWork();
|
|
75293
|
+
return _context3.abrupt("return", function () {
|
|
75294
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75295
|
+
});
|
|
75296
|
+
case 4:
|
|
75297
|
+
case "end":
|
|
75298
|
+
return _context3.stop();
|
|
75299
|
+
}
|
|
75300
|
+
}, _callee3);
|
|
75301
|
+
}));
|
|
75302
|
+
return function refetch() {
|
|
75303
|
+
return _ref2.apply(this, arguments);
|
|
75304
|
+
};
|
|
75305
|
+
}();
|
|
75306
|
+
var createDashboard = /*#__PURE__*/function () {
|
|
75307
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
75308
|
+
var createdDashboard;
|
|
75309
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
75310
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
75311
|
+
case 0:
|
|
75312
|
+
if (!vizzly) {
|
|
75313
|
+
_context4.next = 15;
|
|
75314
|
+
break;
|
|
75315
|
+
}
|
|
75316
|
+
_context4.prev = 1;
|
|
75317
|
+
_context4.next = 4;
|
|
75318
|
+
return vizzly.createDashboard({
|
|
75319
|
+
definition: params.definition,
|
|
75320
|
+
// permissions: params.permissions,
|
|
75321
|
+
parentDashboardId: params.parentDashboardId,
|
|
75322
|
+
metadata: params.metadata || params.meta,
|
|
75323
|
+
abortSignal: params.abortSignal
|
|
75324
|
+
});
|
|
75325
|
+
case 4:
|
|
75326
|
+
createdDashboard = _context4.sent;
|
|
75327
|
+
setState(_extends({}, state, {
|
|
75328
|
+
dashboards: [].concat(state.dashboards, [createdDashboard])
|
|
75329
|
+
}));
|
|
75330
|
+
return _context4.abrupt("return", createdDashboard);
|
|
75331
|
+
case 9:
|
|
75332
|
+
_context4.prev = 9;
|
|
75333
|
+
_context4.t0 = _context4["catch"](1);
|
|
75334
|
+
logError(_context4.t0);
|
|
75335
|
+
return _context4.abrupt("return", null);
|
|
75336
|
+
case 13:
|
|
75337
|
+
_context4.next = 16;
|
|
75338
|
+
break;
|
|
75339
|
+
case 15:
|
|
75340
|
+
throw 'Unable to create a dashboard when vizzly has not been loaded.';
|
|
75341
|
+
case 16:
|
|
75342
|
+
case "end":
|
|
75343
|
+
return _context4.stop();
|
|
75344
|
+
}
|
|
75345
|
+
}, _callee4, null, [[1, 9]]);
|
|
75346
|
+
}));
|
|
75347
|
+
return function createDashboard(_x) {
|
|
75348
|
+
return _ref4.apply(this, arguments);
|
|
75349
|
+
};
|
|
75350
|
+
}();
|
|
75351
|
+
React.useEffect(function () {
|
|
75352
|
+
var abortController = new AbortController();
|
|
75353
|
+
var doWork = /*#__PURE__*/function () {
|
|
75354
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
75355
|
+
var _yield$Promise$all3, globalLibraries;
|
|
75356
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
75357
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
75358
|
+
case 0:
|
|
75359
|
+
_context5.prev = 0;
|
|
75360
|
+
_context5.next = 3;
|
|
75361
|
+
return Vizzly$1.load(properties, {
|
|
75362
|
+
apiHost: (options == null ? void 0 : options.apiHost) || 'https://api.vizzly.co'
|
|
75363
|
+
});
|
|
75364
|
+
case 3:
|
|
75365
|
+
vizzlyRef.current = _context5.sent;
|
|
75366
|
+
_context5.next = 6;
|
|
75367
|
+
return Promise.all([vizzlyRef.current.getGlobalLibraries({
|
|
75368
|
+
abortController: abortController
|
|
75369
|
+
})]);
|
|
75370
|
+
case 6:
|
|
75371
|
+
_yield$Promise$all3 = _context5.sent;
|
|
75372
|
+
globalLibraries = _yield$Promise$all3[0];
|
|
75373
|
+
setState(_extends({}, state, {
|
|
75374
|
+
globalLibraries: globalLibraries
|
|
75375
|
+
}));
|
|
75376
|
+
_context5.next = 15;
|
|
75377
|
+
break;
|
|
75378
|
+
case 11:
|
|
75379
|
+
_context5.prev = 11;
|
|
75380
|
+
_context5.t0 = _context5["catch"](0);
|
|
75381
|
+
logError('Error loading Vizzly', _context5.t0);
|
|
75382
|
+
setState({
|
|
75383
|
+
loading: false,
|
|
75384
|
+
error: _context5.t0,
|
|
75385
|
+
dashboards: [].concat(state.dashboards),
|
|
75386
|
+
globalLibraries: [].concat(state.globalLibraries)
|
|
75387
|
+
});
|
|
75388
|
+
case 15:
|
|
75389
|
+
case "end":
|
|
75390
|
+
return _context5.stop();
|
|
75391
|
+
}
|
|
75392
|
+
}, _callee5, null, [[0, 11]]);
|
|
75393
|
+
}));
|
|
75394
|
+
return function doWork() {
|
|
75395
|
+
return _ref5.apply(this, arguments);
|
|
75396
|
+
};
|
|
75397
|
+
}();
|
|
75398
|
+
if (vizzly) {
|
|
75399
|
+
var unsubscribe = Vizzly$1.subscription(function (eventBus) {
|
|
75400
|
+
if (eventBus.data.action === 'newViewsInGlobalLibrary') {
|
|
75401
|
+
doWork();
|
|
75402
|
+
}
|
|
75403
|
+
});
|
|
75404
|
+
return function () {
|
|
75405
|
+
return unsubscribe();
|
|
75406
|
+
};
|
|
75407
|
+
}
|
|
75408
|
+
return function () {
|
|
75409
|
+
return abortController.abort(new LoadingAborted('We stopped loading Vizzly because of an abort signal triggered by an unmount'));
|
|
75410
|
+
};
|
|
75411
|
+
}, [vizzly]);
|
|
75412
|
+
var updateDashboard = /*#__PURE__*/function () {
|
|
75413
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
75414
|
+
var updatedDashboard, dashboards;
|
|
75415
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
75416
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
75417
|
+
case 0:
|
|
75418
|
+
if (!vizzly) {
|
|
75419
|
+
_context6.next = 20;
|
|
75420
|
+
break;
|
|
75421
|
+
}
|
|
75422
|
+
setState(_extends({}, state, {
|
|
75423
|
+
saving: SavingState.InProgress
|
|
75424
|
+
}));
|
|
75425
|
+
_context6.prev = 2;
|
|
75426
|
+
_context6.next = 5;
|
|
75427
|
+
return vizzly.updateDashboard({
|
|
75428
|
+
dashboardId: params.dashboardId,
|
|
75429
|
+
definition: params.definition,
|
|
75430
|
+
deleted: params.deleted,
|
|
75431
|
+
metadata: params.metadata || params.meta,
|
|
75432
|
+
abortSignal: params.abortSignal,
|
|
75433
|
+
name: params.name
|
|
75434
|
+
});
|
|
75435
|
+
case 5:
|
|
75436
|
+
updatedDashboard = _context6.sent;
|
|
75437
|
+
_context6.next = 8;
|
|
75438
|
+
return vizzly.getDashboards();
|
|
75439
|
+
case 8:
|
|
75440
|
+
dashboards = _context6.sent;
|
|
75441
|
+
setState(function (prevState) {
|
|
75442
|
+
return _extends({}, prevState, {
|
|
75443
|
+
dashboards: dashboards,
|
|
75444
|
+
saving: SavingState.Saved
|
|
75445
|
+
});
|
|
75446
|
+
});
|
|
75447
|
+
setTimeout(function () {
|
|
75448
|
+
setState(_extends({}, state, {
|
|
75449
|
+
saving: SavingState.Undefined
|
|
75450
|
+
}));
|
|
75451
|
+
}, 500);
|
|
75452
|
+
return _context6.abrupt("return", updatedDashboard);
|
|
75453
|
+
case 14:
|
|
75454
|
+
_context6.prev = 14;
|
|
75455
|
+
_context6.t0 = _context6["catch"](2);
|
|
75456
|
+
logError('Error updating dashboard', _context6.t0);
|
|
75457
|
+
return _context6.abrupt("return", null);
|
|
75458
|
+
case 18:
|
|
75459
|
+
_context6.next = 21;
|
|
75460
|
+
break;
|
|
75461
|
+
case 20:
|
|
75462
|
+
throw 'Unable to update a dashboard when vizzly has not been loaded.';
|
|
75463
|
+
case 21:
|
|
75464
|
+
case "end":
|
|
75465
|
+
return _context6.stop();
|
|
75466
|
+
}
|
|
75467
|
+
}, _callee6, null, [[2, 14]]);
|
|
75468
|
+
}));
|
|
75469
|
+
return function updateDashboard(_x2) {
|
|
75470
|
+
return _ref6.apply(this, arguments);
|
|
75471
|
+
};
|
|
75472
|
+
}();
|
|
75473
|
+
|
|
75474
|
+
// Are these needed?
|
|
75475
|
+
var updateScheduledReport = function updateScheduledReport(dashboardAccessToken, reportId, newCron) {
|
|
75476
|
+
if (vizzly) {
|
|
75477
|
+
return vizzly.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
75478
|
+
}
|
|
75479
|
+
throw 'vizzly not set';
|
|
75480
|
+
};
|
|
75481
|
+
var getScheduledReports = function getScheduledReports(dashboardAccessToken) {
|
|
75482
|
+
if (vizzly) {
|
|
75483
|
+
return vizzly.getScheduledReports(dashboardAccessToken);
|
|
75484
|
+
}
|
|
75485
|
+
throw 'vizzly not set';
|
|
75486
|
+
};
|
|
75487
|
+
logDebug('useVizzly state.', state);
|
|
75488
|
+
if (!vizzly || !!state.error || state.loading) {
|
|
75489
|
+
return _extends({}, state, {
|
|
75490
|
+
loading: true,
|
|
75491
|
+
createDashboard: null,
|
|
75492
|
+
identityConfig: null,
|
|
75493
|
+
updateDashboard: null,
|
|
75494
|
+
queryEngineConfig: null,
|
|
75495
|
+
accessType: null,
|
|
75496
|
+
refetch: null,
|
|
75497
|
+
getScheduledReports: null,
|
|
75498
|
+
updateScheduledReport: null
|
|
75499
|
+
});
|
|
75500
|
+
}
|
|
75501
|
+
var identityConfig = vizzly.getIdentityConfig();
|
|
75502
|
+
return _extends({}, state, {
|
|
75503
|
+
loading: false,
|
|
75504
|
+
identityConfig: identityConfig,
|
|
75505
|
+
createDashboard: createDashboard,
|
|
75506
|
+
updateDashboard: updateDashboard,
|
|
75507
|
+
queryEngineConfig: vizzly.getViewConfiguration().queryEngineConfig,
|
|
75508
|
+
accessType: !!identityConfig.dashboardAdminOverride ? 'admin' : identityConfig.dashboardAccess.accessType,
|
|
75509
|
+
filterDashboards: Vizzly$1.filterDashboards,
|
|
75510
|
+
refetch: refetch,
|
|
75511
|
+
updateScheduledReport: updateScheduledReport,
|
|
75512
|
+
getScheduledReports: getScheduledReports
|
|
75513
|
+
});
|
|
75514
|
+
};
|
|
75515
|
+
|
|
75516
|
+
var useScheduledReports = function useScheduledReports(params, dashboardAccessToken) {
|
|
75517
|
+
var _useState = React.useState([]),
|
|
75518
|
+
reports = _useState[0],
|
|
75519
|
+
setReports = _useState[1];
|
|
75520
|
+
React.useEffect(function () {
|
|
75521
|
+
var doWork = /*#__PURE__*/function () {
|
|
75522
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
75523
|
+
var _yield$params$getSche, _reports;
|
|
75524
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75525
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75526
|
+
case 0:
|
|
75527
|
+
if (!(params.getScheduledReports && dashboardAccessToken)) {
|
|
75528
|
+
_context.next = 6;
|
|
75529
|
+
break;
|
|
75530
|
+
}
|
|
75531
|
+
_context.next = 3;
|
|
75532
|
+
return params.getScheduledReports(dashboardAccessToken);
|
|
75533
|
+
case 3:
|
|
75534
|
+
_yield$params$getSche = _context.sent;
|
|
75535
|
+
_reports = _yield$params$getSche.reports;
|
|
75536
|
+
setReports(_reports);
|
|
75537
|
+
case 6:
|
|
75538
|
+
case "end":
|
|
75539
|
+
return _context.stop();
|
|
75540
|
+
}
|
|
75541
|
+
}, _callee);
|
|
75542
|
+
}));
|
|
75543
|
+
return function doWork() {
|
|
75544
|
+
return _ref.apply(this, arguments);
|
|
75545
|
+
};
|
|
75546
|
+
}();
|
|
75547
|
+
doWork();
|
|
75548
|
+
}, [JSON.stringify({
|
|
75549
|
+
dashboardAccessToken: dashboardAccessToken,
|
|
75550
|
+
loadingVizzly: params
|
|
75551
|
+
})]);
|
|
75552
|
+
var updateScheduledReport = /*#__PURE__*/function () {
|
|
75553
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(reportId, newCron) {
|
|
75554
|
+
var updatedReport, newReports, uniqueNewReports;
|
|
75555
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75556
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75557
|
+
case 0:
|
|
75558
|
+
if (!(params.updateScheduledReport && dashboardAccessToken)) {
|
|
75559
|
+
_context2.next = 7;
|
|
75560
|
+
break;
|
|
75561
|
+
}
|
|
75562
|
+
_context2.next = 3;
|
|
75563
|
+
return params.updateScheduledReport(dashboardAccessToken, reportId, newCron);
|
|
75564
|
+
case 3:
|
|
75565
|
+
updatedReport = _context2.sent;
|
|
75566
|
+
if (updatedReport === true) {
|
|
75567
|
+
// Remove the deleted report...
|
|
75568
|
+
setReports([].concat(reports).filter(function (r) {
|
|
75569
|
+
return r.id != reportId;
|
|
75570
|
+
}));
|
|
75571
|
+
} else if (updatedReport) {
|
|
75572
|
+
// Upsert the report
|
|
75573
|
+
newReports = [].concat(reports, [updatedReport.report]).map(function (r) {
|
|
75574
|
+
return r.id == reportId ? updatedReport.report : r;
|
|
75575
|
+
});
|
|
75576
|
+
uniqueNewReports = _.uniqBy(newReports, function (r) {
|
|
75577
|
+
return r.id;
|
|
75578
|
+
});
|
|
75579
|
+
setReports(uniqueNewReports);
|
|
75580
|
+
}
|
|
75581
|
+
_context2.next = 8;
|
|
75582
|
+
break;
|
|
75583
|
+
case 7:
|
|
75584
|
+
console.warn('Function to update scheduled report not loaded.');
|
|
75585
|
+
case 8:
|
|
75586
|
+
case "end":
|
|
75587
|
+
return _context2.stop();
|
|
75588
|
+
}
|
|
75589
|
+
}, _callee2);
|
|
75590
|
+
}));
|
|
75591
|
+
return function updateScheduledReport(_x, _x2) {
|
|
75592
|
+
return _ref2.apply(this, arguments);
|
|
75593
|
+
};
|
|
75594
|
+
}();
|
|
75595
|
+
return {
|
|
75596
|
+
reports: reports,
|
|
75597
|
+
getScheduledReports: params.getScheduledReports,
|
|
75598
|
+
updateScheduledReport: updateScheduledReport
|
|
75599
|
+
};
|
|
75600
|
+
};
|
|
75601
|
+
|
|
75602
|
+
/*
|
|
75603
|
+
A context for managing the dashboard session.
|
|
75604
|
+
*/
|
|
75605
|
+
var STILL_LOADING = null;
|
|
75606
|
+
var useSessionContext = function useSessionContext(params) {
|
|
75607
|
+
var _loadedStrategy$dashb, _loadedStrategy$dashb2;
|
|
75608
|
+
var vizzly = useVizzly({
|
|
75609
|
+
queryEngine: params.queryEngine,
|
|
75610
|
+
identity: params.identityCallback,
|
|
75611
|
+
dataSets: params.loadDataSetsCallback,
|
|
75612
|
+
programmaticDashboard: params.programmaticDashboard
|
|
75613
|
+
}, {
|
|
75614
|
+
apiHost: params.apiConfig.host
|
|
75615
|
+
});
|
|
75616
|
+
var loadedStrategy = useDashboardStrategy(getStrategy(vizzly, params.parentDashboardId, params.dashboardId, params.isEditor), vizzly, params.programmaticDashboard);
|
|
75617
|
+
var _useScheduledReports = useScheduledReports(vizzly, loadedStrategy == null || (_loadedStrategy$dashb = loadedStrategy.dashboard) == null || (_loadedStrategy$dashb = _loadedStrategy$dashb.permission) == null ? void 0 : _loadedStrategy$dashb.token),
|
|
75618
|
+
reports = _useScheduledReports.reports,
|
|
75619
|
+
updateScheduledReport = _useScheduledReports.updateScheduledReport;
|
|
75620
|
+
if (!vizzly) return STILL_LOADING;
|
|
75621
|
+
if ('error' in vizzly && vizzly.error) return {
|
|
75622
|
+
error: vizzly.error
|
|
75623
|
+
};
|
|
75624
|
+
if ('loading' in vizzly && vizzly.loading) return STILL_LOADING;
|
|
75625
|
+
if (!('dashboards' in vizzly)) return STILL_LOADING;
|
|
75626
|
+
var identityConfig = vizzly.identityConfig,
|
|
75627
|
+
queryEngineConfig = vizzly.queryEngineConfig;
|
|
75628
|
+
if (!loadedStrategy) return null;
|
|
75629
|
+
if (((loadedStrategy == null || (_loadedStrategy$dashb2 = loadedStrategy.dashboard) == null ? void 0 : _loadedStrategy$dashb2.dataSets) || []).length === 0) {
|
|
75630
|
+
return {
|
|
75631
|
+
error: new NoDataSetResolved()
|
|
75632
|
+
};
|
|
75633
|
+
}
|
|
75634
|
+
var providedValues = {
|
|
75635
|
+
vizzly: vizzly,
|
|
75636
|
+
scope: loadedStrategy.scope,
|
|
75637
|
+
queryEngineConfig: queryEngineConfig,
|
|
75638
|
+
dashboard: loadedStrategy.dashboard,
|
|
75639
|
+
identityConfig: identityConfig,
|
|
75640
|
+
mode: loadedStrategy.mode,
|
|
75641
|
+
vizzlyApiConfig: params.apiConfig,
|
|
75642
|
+
isProgrammaticParent: loadedStrategy.isProgrammaticParent,
|
|
75643
|
+
globalLibraries: vizzly.globalLibraries,
|
|
75644
|
+
reports: reports,
|
|
75645
|
+
updateScheduledReport: updateScheduledReport
|
|
75646
|
+
};
|
|
75647
|
+
return providedValues;
|
|
75619
75648
|
};
|
|
75620
75649
|
|
|
75621
75650
|
var buildImplementationMeta = function buildImplementationMeta(props) {
|
|
@@ -75637,7 +75666,9 @@ var buildImplementationMeta = function buildImplementationMeta(props) {
|
|
|
75637
75666
|
};
|
|
75638
75667
|
};
|
|
75639
75668
|
|
|
75640
|
-
var
|
|
75669
|
+
var GlobalContext = /*#__PURE__*/React.createContext(undefined);
|
|
75670
|
+
|
|
75671
|
+
var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, onDashboardLoad, updateDashboardHash) {
|
|
75641
75672
|
var _session$dashboard2;
|
|
75642
75673
|
React.useEffect(function () {
|
|
75643
75674
|
var _session$dashboard;
|
|
@@ -75648,6 +75679,7 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
|
|
|
75648
75679
|
scope: session.scope,
|
|
75649
75680
|
dataSets: session.dashboard.dataSets
|
|
75650
75681
|
});
|
|
75682
|
+
updateDashboardHash(session.dashboard);
|
|
75651
75683
|
}
|
|
75652
75684
|
}, [JSON.stringify({
|
|
75653
75685
|
loaded: !!session,
|
|
@@ -75655,17 +75687,6 @@ var useOnDashboardLoadCallback = function useOnDashboardLoadCallback(session, on
|
|
|
75655
75687
|
})]);
|
|
75656
75688
|
};
|
|
75657
75689
|
|
|
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
75690
|
var GlobalProvider = function GlobalProvider(props) {
|
|
75670
75691
|
var _useState = React.useState(0),
|
|
75671
75692
|
resetKey = _useState[0],
|
|
@@ -75691,6 +75712,9 @@ var GlobalProvider = function GlobalProvider(props) {
|
|
|
75691
75712
|
};
|
|
75692
75713
|
var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
75693
75714
|
var _props$id, _session$identityConf, _props$dateFilterOpti, _session$vizzly$savin;
|
|
75715
|
+
var _useState2 = React.useState(undefined),
|
|
75716
|
+
dashboardHash = _useState2[0],
|
|
75717
|
+
setDashboardHash = _useState2[1];
|
|
75694
75718
|
var implementationMeta = buildImplementationMeta(props);
|
|
75695
75719
|
var apiConfig = props.vizzlyApiHost ? {
|
|
75696
75720
|
host: props.vizzlyApiHost
|
|
@@ -75714,7 +75738,11 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
|
75714
75738
|
textOverride: textOverride,
|
|
75715
75739
|
isEditor: props.isEditor
|
|
75716
75740
|
});
|
|
75717
|
-
|
|
75741
|
+
var updateDashboardHash = function updateDashboardHash(dashboard) {
|
|
75742
|
+
var definition = toSaveableDefinition(dashboard);
|
|
75743
|
+
setDashboardHash(crypto.createHash('md5').update(JSON.stringify(definition)).digest('hex'));
|
|
75744
|
+
};
|
|
75745
|
+
useOnDashboardLoadCallback(session, props.onDashboardLoad, updateDashboardHash);
|
|
75718
75746
|
var variables = useVariables(props.variables, (_props$id = props.id) != null ? _props$id : '');
|
|
75719
75747
|
if (session === null) return jsxRuntime.jsx(LoadingComponent, {
|
|
75720
75748
|
override: props.renderLoadingComponent
|
|
@@ -75910,14 +75938,16 @@ var GlobalProviderContents = function GlobalProviderContents(props) {
|
|
|
75910
75938
|
labelFormat: props == null ? void 0 : props.labelFormat,
|
|
75911
75939
|
filterLibrary: props == null ? void 0 : props.filterLibrary,
|
|
75912
75940
|
valueAlias: props == null ? void 0 : props.valueAlias,
|
|
75913
|
-
variables: variables
|
|
75941
|
+
variables: variables,
|
|
75942
|
+
onDashboardUpdate: props == null ? void 0 : props.onDashboardUpdate,
|
|
75943
|
+
updateDashboardHash: updateDashboardHash
|
|
75914
75944
|
},
|
|
75915
75945
|
ai: {
|
|
75916
75946
|
onAction: aiOnAction,
|
|
75917
75947
|
onAsk: aiOnAsk,
|
|
75918
75948
|
fetchSuggestions: aiFetchSuggestions
|
|
75919
75949
|
},
|
|
75920
|
-
|
|
75950
|
+
dashboardHash: dashboardHash,
|
|
75921
75951
|
dashboard: session.dashboard,
|
|
75922
75952
|
runQueriesCallback: runQueriesCallback,
|
|
75923
75953
|
implementationMeta: implementationMeta,
|