@commercetools-frontend/staff-bar 0.0.0

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.
@@ -0,0 +1,989 @@
1
+ 'use strict';
2
+
3
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
7
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
8
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
9
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
10
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
11
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
12
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
13
+ var react = require('react');
14
+ var react$1 = require('@emotion/react');
15
+ var ReactDOM = require('react-dom');
16
+ var fullstory = require('@commercetools-frontend/fullstory');
17
+ var uiKit = require('@commercetools-frontend/ui-kit');
18
+ var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
19
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
20
+ var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
21
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
22
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
23
+ var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
24
+ var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
25
+ var isEqual = require('lodash/isEqual');
26
+ var applicationComponents = require('@commercetools-frontend/application-components');
27
+ var applicationShell = require('@commercetools-frontend/application-shell');
28
+ var constants = require('@commercetools-frontend/constants');
29
+ var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
30
+ var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
31
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
32
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
33
+ require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
34
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
35
+ require('@babel/runtime-corejs3/helpers/createClass');
36
+ require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
37
+ require('@babel/runtime-corejs3/helpers/getPrototypeOf');
38
+ require('@babel/runtime-corejs3/helpers/inherits');
39
+ var _URLSearchParams = require('@babel/runtime-corejs3/core-js-stable/url-search-params');
40
+ var reactRouterDom = require('react-router-dom');
41
+ var sortBy = require('lodash/sortBy');
42
+
43
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
44
+
45
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
46
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
47
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
48
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
49
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
50
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
51
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
52
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
53
+ var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);
54
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
55
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
56
+ var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
57
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
58
+ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
59
+ var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
60
+ var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
61
+ var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
62
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
63
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
64
+ var _URLSearchParams__default = /*#__PURE__*/_interopDefault(_URLSearchParams);
65
+ var sortBy__default = /*#__PURE__*/_interopDefault(sortBy);
66
+
67
+ var config = {
68
+ AmazonWebServicesATT: {
69
+ MerchantCenterFrontend: {
70
+ url: "https://mc.att.us-east-1.aws.commercetools.com"
71
+ }
72
+ },
73
+ AmazonWebServicesChina: {
74
+ MerchantCenterFrontend: {
75
+ url: "https://mc.cn-northwest-1.aws.commercetools.cn"
76
+ }
77
+ },
78
+ AmazonWebServicesChinaStaging: {
79
+ MerchantCenterFrontend: {
80
+ url: "https://mc.cn-northwest-1.aws.commercetoolscn.cn"
81
+ }
82
+ },
83
+ AmazonWebServicesFrankfurt: {
84
+ MerchantCenterFrontend: {
85
+ url: "https://mc.eu-central-1.aws.commercetools.com"
86
+ }
87
+ },
88
+ AmazonWebServicesOhio: {
89
+ MerchantCenterFrontend: {
90
+ url: "https://mc.us-east-2.aws.commercetools.com"
91
+ }
92
+ },
93
+ AmazonWebServicesVolkswagen: {
94
+ MerchantCenterFrontend: {
95
+ url: "https://mc.vw.eu-central-1.aws.commercetools.com"
96
+ }
97
+ },
98
+ AmazonWebServicesVolkswagenStaging: {
99
+ MerchantCenterFrontend: {
100
+ url: "https://mc.vw-stage.eu-central-1.aws.commercetools.com"
101
+ }
102
+ },
103
+ AzureEuropeStaging: {
104
+ MerchantCenterFrontend: {
105
+ url: "https://mc.northeurope.azure.escemo.com"
106
+ }
107
+ },
108
+ GoogleCloudPlatformAustralia: {
109
+ MerchantCenterFrontend: {
110
+ url: "https://mc.australia-southeast1.gcp.commercetools.com"
111
+ }
112
+ },
113
+ GoogleCloudPlatformEurope: {
114
+ MerchantCenterFrontend: {
115
+ url: "https://mc.europe-west1.gcp.commercetools.com"
116
+ }
117
+ },
118
+ GoogleCloudPlatformEuropeStaging: {
119
+ MerchantCenterFrontend: {
120
+ url: "https://mc.europe-west1.gcp.escemo.com"
121
+ }
122
+ },
123
+ GoogleCloudPlatformUnitedStates: {
124
+ MerchantCenterFrontend: {
125
+ url: "https://mc.us-central1.gcp.commercetools.com"
126
+ }
127
+ }
128
+ };
129
+
130
+ var _context, _context2, _context3, _context4;
131
+ const LOCAL_ENV = {
132
+ label: 'Local Dev',
133
+ value: 'http://localhost:3001'
134
+ };
135
+ const PREVIEW_BRANCH = {
136
+ label: 'Preview Branch',
137
+ value: ''
138
+ };
139
+ const IS_STAFFBAR_OPEN = 'isStaffBarOpen';
140
+
141
+ // Type guard to help with filtering arrays for nullish elements.
142
+ function nonNullable(value) {
143
+ return value !== null && value !== undefined;
144
+ }
145
+ const getOptionsForEnvironment = (label, config) => {
146
+ return {
147
+ label,
148
+ value: config.MerchantCenterFrontend.url
149
+ };
150
+ };
151
+ const GCP = _filterInstanceProperty__default["default"](_context = [getOptionsForEnvironment('GCP Australia', config.GoogleCloudPlatformAustralia), getOptionsForEnvironment('GCP Europe', config.GoogleCloudPlatformEurope), getOptionsForEnvironment('GCP USA', config.GoogleCloudPlatformUnitedStates), getOptionsForEnvironment('GCP Europe (Staging)', config.GoogleCloudPlatformEuropeStaging)]).call(_context, nonNullable);
152
+ const AWS = _filterInstanceProperty__default["default"](_context2 = [getOptionsForEnvironment('AWS China', config.AmazonWebServicesChina), getOptionsForEnvironment('AWS Frankfurt', config.AmazonWebServicesFrankfurt), getOptionsForEnvironment('AWS Ohio', config.AmazonWebServicesOhio), getOptionsForEnvironment('AWS China (Staging)', config.AmazonWebServicesChinaStaging)]).call(_context2, nonNullable);
153
+ const Azure = _filterInstanceProperty__default["default"](_context3 = [getOptionsForEnvironment('Azure Europe (Staging)', config.AzureEuropeStaging)]).call(_context3, nonNullable);
154
+ const PRIVATE = _filterInstanceProperty__default["default"](_context4 = [getOptionsForEnvironment('AWS AT&T', config.AmazonWebServicesATT), getOptionsForEnvironment('AWS Volkswagen', config.AmazonWebServicesVolkswagen), getOptionsForEnvironment('AWS Volkswagen (Staging)', config.AmazonWebServicesVolkswagenStaging)]).call(_context4, nonNullable);
155
+ const ENV = [{
156
+ options: GCP,
157
+ group: 'GCP'
158
+ }, {
159
+ options: AWS,
160
+ group: 'AWS'
161
+ }, {
162
+ options: Azure,
163
+ group: 'Azure'
164
+ }, {
165
+ options: PRIVATE,
166
+ group: 'Private'
167
+ }];
168
+
169
+ var _ref$5 = {
170
+ name: "10r8dle",
171
+ styles: "width:206px"
172
+ } ;
173
+ const EnvironmentSwitcher = () => {
174
+ const _useState = react.useState(),
175
+ _useState2 = _slicedToArray(_useState, 2),
176
+ value = _useState2[0],
177
+ setValue = _useState2[1];
178
+ react.useEffect(() => {
179
+ var _window;
180
+ const currentURL = (_window = window) === null || _window === void 0 || (_window = _window.location) === null || _window === void 0 ? void 0 : _window.origin;
181
+ if (currentURL === LOCAL_ENV.value) {
182
+ var _ENV$;
183
+ (_ENV$ = ENV[0]) === null || _ENV$ === void 0 || _ENV$.options.unshift(LOCAL_ENV);
184
+ }
185
+ if (_includesInstanceProperty__default["default"](currentURL).call(currentURL, 'preview')) {
186
+ var _ENV$2;
187
+ (_ENV$2 = ENV[0]) === null || _ENV$2 === void 0 || _ENV$2.options.unshift(PREVIEW_BRANCH);
188
+ }
189
+ if (_includesInstanceProperty__default["default"](currentURL).call(currentURL, 'preview')) {
190
+ setValue('');
191
+ } else {
192
+ var _ENV$map$flat$find, _context, _context2;
193
+ setValue((_ENV$map$flat$find = _findInstanceProperty__default["default"](_context = _flatInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](ENV).call(ENV, _ref2 => {
194
+ let options = _ref2.options;
195
+ return options;
196
+ })).call(_context2)).call(_context, _ref3 => {
197
+ let value = _ref3.value;
198
+ return value === currentURL;
199
+ })) === null || _ENV$map$flat$find === void 0 ? void 0 : _ENV$map$flat$find.value);
200
+ }
201
+ // eslint-disable-next-line react-hooks/exhaustive-deps
202
+ }, []);
203
+ return jsxRuntime.jsxs(uiKit.Spacings.Inline, {
204
+ alignItems: "center",
205
+ children: [jsxRuntime.jsx(uiKit.Text.Detail, {
206
+ children: "Environment"
207
+ }), jsxRuntime.jsx("div", {
208
+ css: _ref$5,
209
+ children: jsxRuntime.jsx(uiKit.SelectInput, {
210
+ id: 'env-selector',
211
+ name: 'env selector',
212
+ isSearchable: false,
213
+ horizontalConstraint: 5,
214
+ menuPortalTarget: document.body,
215
+ menuPortalZIndex: 30000,
216
+ onChange: event => {
217
+ setValue(event.target.value);
218
+ if (event.target.value) {
219
+ window.open(event.target.value, '_self');
220
+ }
221
+ },
222
+ value: value,
223
+ options: ENV,
224
+ showOptionGroupDivider: true
225
+ })
226
+ })]
227
+ });
228
+ };
229
+
230
+ const GITHUB_PR_URL = 'https://github.com/commercetools/merchant-center-frontend/pull/';
231
+ // Session storage keys
232
+ const FEATURE_FLAG_KEY = 'toggled-feature-flags';
233
+ const ACTIVE_TEAM_ID_KEY = 'activeTeamId';
234
+ const ENABLE_LOG_KEY = 'enable-log';
235
+ const USER_ROLES_WITH_ALLOWED_ACCESS = ['Engineer', 'ProductProjectManagerOrOwner'];
236
+
237
+ var FetchStaffBarUser = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchStaffBarUser" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", alias: { kind: "Name", value: "user" }, name: { kind: "Name", value: "me" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "launchdarklyTrackingGroup" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "launchdarklyTrackingSubgroup" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "businessRole" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 132, source: { body: "query FetchStaffBarUser {\n user: me {\n id\n launchdarklyTrackingGroup\n launchdarklyTrackingSubgroup\n businessRole\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
238
+ const useStaffBarUser = () => {
239
+ var _data$user, _data$user2, _data$user3;
240
+ const _useMcQuery = applicationShell.useMcQuery(FetchStaffBarUser, {
241
+ context: {
242
+ target: constants.GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND
243
+ },
244
+ // Use cache to avoid users from mocking response in browser to enable staffbar
245
+ fetchPolicy: 'cache-only'
246
+ }),
247
+ data = _useMcQuery.data,
248
+ error = _useMcQuery.error;
249
+ return {
250
+ userId: data === null || data === void 0 || (_data$user = data.user) === null || _data$user === void 0 ? void 0 : _data$user.id,
251
+ isStaffMember: (data === null || data === void 0 || (_data$user2 = data.user) === null || _data$user2 === void 0 ? void 0 : _data$user2.launchdarklyTrackingGroup) === 'commercetools',
252
+ isDevMember: _includesInstanceProperty__default["default"](USER_ROLES_WITH_ALLOWED_ACCESS).call(USER_ROLES_WITH_ALLOWED_ACCESS, data === null || data === void 0 || (_data$user3 = data.user) === null || _data$user3 === void 0 ? void 0 : _data$user3.businessRole),
253
+ error
254
+ };
255
+ };
256
+
257
+ const getActiveTeamId = () => window.sessionStorage.getItem(ACTIVE_TEAM_ID_KEY);
258
+ const setActiveTeamId = teamId => window.sessionStorage.setItem(ACTIVE_TEAM_ID_KEY, teamId);
259
+ const removeActiveTeamId = () => window.sessionStorage.removeItem(ACTIVE_TEAM_ID_KEY);
260
+
261
+ var FetchTeamsByProjectQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchTeamsByProjectQuery" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "where" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "myProjects" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "where" }, value: { kind: "Variable", name: { kind: "Name", value: "where" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "results" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "owner" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "teams" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "membersRef" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }] } }], loc: { start: 0, end: 286, source: { body: "query FetchTeamsByProjectQuery($where: String!) {\n myProjects(where: $where) {\n results {\n id\n key\n name\n owner {\n id\n name\n teams {\n id\n name\n membersRef {\n id\n }\n }\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
262
+ const defaultTeam = {
263
+ label: 'Default',
264
+ value: ''
265
+ };
266
+ const onlyTeamsWithMembership = function (userId) {
267
+ let teams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
268
+ return teams.length ? _filterInstanceProperty__default["default"](teams).call(teams, team => {
269
+ var _team$membersRef;
270
+ return (_team$membersRef = team.membersRef) === null || _team$membersRef === void 0 ? void 0 : _someInstanceProperty__default["default"](_team$membersRef).call(_team$membersRef, memberRef => memberRef.id === userId);
271
+ }) : [];
272
+ };
273
+ const getAdminTeamId = function () {
274
+ var _teams$find;
275
+ let teams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
276
+ return (_teams$find = _findInstanceProperty__default["default"](teams).call(teams, team => team.name === 'Administrators')) === null || _teams$find === void 0 ? void 0 : _teams$find.id;
277
+ };
278
+ const getStoredTeamId = function (storedId) {
279
+ let teams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
280
+ return _findInstanceProperty__default["default"](teams).call(teams, team => team.id === storedId);
281
+ };
282
+ const transformTeamsToOptions = function () {
283
+ let teams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
284
+ const hasAdminTeam = Boolean(getAdminTeamId(teams));
285
+ const options = _mapInstanceProperty__default["default"](teams).call(teams, team => ({
286
+ label: team === null || team === void 0 ? void 0 : team.name,
287
+ value: team === null || team === void 0 ? void 0 : team.id
288
+ }));
289
+ if (hasAdminTeam) {
290
+ return options;
291
+ } else if (options.length) {
292
+ return [defaultTeam, ...options];
293
+ } else {
294
+ return [];
295
+ }
296
+ };
297
+ const useTeams = () => {
298
+ var _data$myProjects, _ref;
299
+ const projectKey = applicationShellConnectors.useApplicationContext(applicationContext => {
300
+ var _applicationContext$p;
301
+ return (_applicationContext$p = applicationContext.project) === null || _applicationContext$p === void 0 ? void 0 : _applicationContext$p.key;
302
+ });
303
+ const _useStaffBarUser = useStaffBarUser(),
304
+ userId = _useStaffBarUser.userId;
305
+ const _useMcQuery = applicationShell.useMcQuery(FetchTeamsByProjectQuery, {
306
+ skip: !projectKey,
307
+ variables: {
308
+ where: "key=\"".concat(projectKey, "\"")
309
+ },
310
+ context: {
311
+ target: constants.GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
312
+ }
313
+ }),
314
+ data = _useMcQuery.data,
315
+ error = _useMcQuery.error,
316
+ loading = _useMcQuery.loading;
317
+ const teams = data === null || data === void 0 || (_data$myProjects = data.myProjects) === null || _data$myProjects === void 0 || (_data$myProjects = _data$myProjects.results) === null || _data$myProjects === void 0 || (_data$myProjects = _data$myProjects[0]) === null || _data$myProjects === void 0 || (_data$myProjects = _data$myProjects.owner) === null || _data$myProjects === void 0 ? void 0 : _data$myProjects.teams;
318
+ react.useEffect(() => {
319
+ if (loading) {
320
+ return;
321
+ }
322
+
323
+ // If user already simulated the permission and tries to change project then we need to clear the stored teamId
324
+ // otherwise the newly selected project might be from different organization and user will see 404 page.
325
+ const storedId = getActiveTeamId();
326
+ if (storedId && !getStoredTeamId(storedId, teams)) {
327
+ removeActiveTeamId();
328
+ window.location.reload();
329
+ }
330
+ }, [loading, teams]);
331
+ const options = transformTeamsToOptions(onlyTeamsWithMembership(userId || '', teams));
332
+ const adminTeamId = getAdminTeamId(onlyTeamsWithMembership(userId || '', teams));
333
+ const storedId = getActiveTeamId();
334
+ const activeTeamId = (_ref = storedId !== null && storedId !== void 0 ? storedId : adminTeamId) !== null && _ref !== void 0 ? _ref : defaultTeam.value;
335
+ return {
336
+ data,
337
+ options,
338
+ activeTeamId,
339
+ isLimitedPermission: storedId && storedId !== adminTeamId,
340
+ error,
341
+ loading
342
+ };
343
+ };
344
+
345
+ var _window$__flopflip__;
346
+ const launchdarklyAdapter = (_window$__flopflip__ = window.__flopflip__) === null || _window$__flopflip__ === void 0 ? void 0 : _window$__flopflip__.launchdarkly;
347
+ function getFlagValue(flag, defaultValue) {
348
+ // @ts-expect-error: getFlag exists not on all adapters and hence
349
+ // not the generic type. For ours it exists.
350
+ const result = launchdarklyAdapter === null || launchdarklyAdapter === void 0 ? void 0 : launchdarklyAdapter.getFlag(flag);
351
+ if (typeof result === 'boolean') {
352
+ return result;
353
+ } else if (typeof (result === null || result === void 0 ? void 0 : result.value) === 'boolean') {
354
+ return result;
355
+ }
356
+ return defaultValue;
357
+ }
358
+ function setFlag(flagName, flagValue) {
359
+ let lockFlags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
360
+ launchdarklyAdapter === null || launchdarklyAdapter === void 0 || launchdarklyAdapter.updateFlags({
361
+ [flagName]: flagValue
362
+ }, {
363
+ lockFlags
364
+ });
365
+ }
366
+
367
+ const getFromSessionStorage = key => {
368
+ const storedValue = window.sessionStorage.getItem(key);
369
+ return storedValue ? JSON.parse(storedValue) : {};
370
+ };
371
+ const setToSessionStorage = (key, value) => window.sessionStorage.setItem(key, _JSON$stringify__default["default"](value));
372
+
373
+ var _ref$4 = {
374
+ name: "mdo41b",
375
+ styles: "box-sizing:border-box;width:100%;margin:0;border:0;border-top-width:1px;border-style:solid;border-top-color:var(--color-neutral-90)"
376
+ } ;
377
+ function Divider() {
378
+ return jsxRuntime.jsx("hr", {
379
+ css: _ref$4
380
+ });
381
+ }
382
+
383
+ function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
384
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys$2(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys$2(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
385
+ var FeatureFlagTogglerIllustration = function FeatureFlagTogglerIllustration(props) {
386
+ return jsxRuntime.jsx("svg", _objectSpread$2(_objectSpread$2({}, props), {}, {
387
+ children: jsxRuntime.jsx("path", {
388
+ d: "M4.91 9.818c-1.365 0-2.524-.477-3.478-1.432C.477 7.432 0 6.273 0 4.91c0-1.364.477-2.523 1.432-3.477C2.386.477 3.545 0 4.909 0h8.182c1.364 0 2.523.477 3.477 1.432C17.523 2.386 18 3.545 18 4.909c0 1.364-.477 2.523-1.432 3.477-.954.955-2.114 1.432-3.477 1.432H4.909Zm0-1.227h8.18c1.024 0 1.893-.358 2.609-1.074.716-.716 1.074-1.585 1.074-2.608 0-1.023-.358-1.892-1.074-2.608-.716-.716-1.585-1.074-2.608-1.074H4.909c-1.023 0-1.892.358-2.608 1.074-.716.716-1.074 1.585-1.074 2.608 0 1.023.358 1.892 1.074 2.608.716.716 1.585 1.074 2.608 1.074Zm-.023-1.616c.574 0 1.062-.2 1.464-.602a1.99 1.99 0 0 0 .604-1.463c0-.573-.201-1.061-.603-1.463a1.99 1.99 0 0 0-1.462-.604c-.574 0-1.062.2-1.464.602a1.99 1.99 0 0 0-.603 1.463c0 .573.2 1.061.602 1.464a1.99 1.99 0 0 0 1.462.603Z",
389
+ fill: "#000"
390
+ })
391
+ }));
392
+ };
393
+ FeatureFlagTogglerIllustration.defaultProps = {
394
+ width: "18",
395
+ height: "10",
396
+ fill: "none",
397
+ xmlns: "http://www.w3.org/2000/svg"
398
+ };
399
+ function toggleFeatureFlag(flag, value) {
400
+ const cachedFeatureFlag = getFromSessionStorage(FEATURE_FLAG_KEY);
401
+ setToSessionStorage(FEATURE_FLAG_KEY, _objectSpread$2(_objectSpread$2({}, cachedFeatureFlag), {}, {
402
+ [flag]: value
403
+ }));
404
+ setFlag(flag, value);
405
+ }
406
+ const FeatureFlagToggler = props => {
407
+ var _context, _props$featureFlags;
408
+ const modalState = applicationComponents.useModalState();
409
+ const _useState = react.useState(false),
410
+ _useState2 = _slicedToArray(_useState, 2),
411
+ toggleAll = _useState2[0],
412
+ setToggleAll = _useState2[1];
413
+ const cachedFeatureFlag = getFromSessionStorage(FEATURE_FLAG_KEY);
414
+ const _useStaffBarUser = useStaffBarUser(),
415
+ isDevMember = _useStaffBarUser.isDevMember;
416
+ const _useState3 = react.useState(_mapInstanceProperty__default["default"](_context = _Object$entries__default["default"]((_props$featureFlags = props.featureFlags) !== null && _props$featureFlags !== void 0 ? _props$featureFlags : {})).call(_context, _ref => {
417
+ var _cachedFeatureFlag$fe;
418
+ let _ref2 = _slicedToArray(_ref, 2),
419
+ featureName = _ref2[0],
420
+ toggleValue = _ref2[1];
421
+ return {
422
+ featureName,
423
+ toggleValue: (_cachedFeatureFlag$fe = cachedFeatureFlag[featureName]) !== null && _cachedFeatureFlag$fe !== void 0 ? _cachedFeatureFlag$fe : getFlagValue(featureName, toggleValue)
424
+ };
425
+ })),
426
+ _useState4 = _slicedToArray(_useState3, 2),
427
+ options = _useState4[0],
428
+ setOptions = _useState4[1];
429
+ const originalValues = react.useMemo(() => {
430
+ var _context2, _props$featureFlags2;
431
+ return _mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"]((_props$featureFlags2 = props.featureFlags) !== null && _props$featureFlags2 !== void 0 ? _props$featureFlags2 : {})).call(_context2, _ref3 => {
432
+ var _getFlagValue;
433
+ let _ref4 = _slicedToArray(_ref3, 2),
434
+ featureName = _ref4[0],
435
+ toggleValue = _ref4[1];
436
+ return {
437
+ featureName,
438
+ toggleValue: (_getFlagValue = getFlagValue(featureName, toggleValue)) !== null && _getFlagValue !== void 0 ? _getFlagValue : 'false'
439
+ };
440
+ });
441
+ },
442
+ // eslint-disable-next-line react-hooks/exhaustive-deps
443
+ []);
444
+ const isTouched = react.useMemo(() => !isEqual__default["default"](originalValues, options), [originalValues, options]);
445
+ react.useEffect(() => {
446
+ // Persist toggled flags from other application
447
+ if (_Object$keys__default["default"](cachedFeatureFlag).length) {
448
+ var _context3;
449
+ _forEachInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](cachedFeatureFlag)).call(_context3, _ref5 => {
450
+ let _ref6 = _slicedToArray(_ref5, 2),
451
+ featureName = _ref6[0],
452
+ value = _ref6[1];
453
+ if (_findInstanceProperty__default["default"](options).call(options, option => option.featureName === featureName)) {
454
+ toggleFeatureFlag(featureName, value);
455
+ }
456
+ });
457
+ }
458
+ // eslint-disable-next-line react-hooks/exhaustive-deps
459
+ }, []);
460
+ const isToggled = toggleValue => {
461
+ if (typeof toggleValue === 'object' && toggleValue.value !== undefined) {
462
+ return toggleValue.value;
463
+ }
464
+ return toggleValue;
465
+ };
466
+ const toTitleCase = function () {
467
+ let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
468
+ const result = value.replace(/([A-Z])/g, ' $1');
469
+ return result.charAt(0).toUpperCase() + _sliceInstanceProperty__default["default"](result).call(result, 1);
470
+ };
471
+ const toggleAndGenerateNewOption = _ref7 => {
472
+ let featureName = _ref7.featureName,
473
+ toggleValue = _ref7.toggleValue,
474
+ options = _ref7.options,
475
+ index = _ref7.index;
476
+ const newOptions = [...options];
477
+ if (typeof toggleValue === 'boolean') {
478
+ toggleFeatureFlag(featureName, !toggleValue);
479
+ newOptions[index] = _objectSpread$2(_objectSpread$2({}, newOptions[index]), {}, {
480
+ toggleValue: !toggleValue
481
+ });
482
+ } else {
483
+ toggleFeatureFlag(featureName, {
484
+ value: !(toggleValue !== null && toggleValue !== void 0 && toggleValue.value)
485
+ });
486
+ newOptions[index] = _objectSpread$2(_objectSpread$2({}, newOptions[index]), {}, {
487
+ toggleValue: {
488
+ value: !(toggleValue !== null && toggleValue !== void 0 && toggleValue.value)
489
+ }
490
+ });
491
+ }
492
+ return newOptions;
493
+ };
494
+ const handleToggleAll = react.useCallback(() => {
495
+ let newOptions = [...options];
496
+ _forEachInstanceProperty__default["default"](options).call(options, (_ref8, index) => {
497
+ let featureName = _ref8.featureName,
498
+ toggleValue = _ref8.toggleValue;
499
+ newOptions = toggleAndGenerateNewOption({
500
+ featureName,
501
+ toggleValue: typeof toggleValue === 'boolean' ? toggleAll : {
502
+ value: toggleAll
503
+ },
504
+ index,
505
+ options: [...newOptions]
506
+ });
507
+ });
508
+ setOptions(newOptions);
509
+ setToggleAll(!toggleAll);
510
+ }, [toggleAll, options]);
511
+ const handleToggle = react.useCallback(_ref9 => {
512
+ let featureName = _ref9.featureName,
513
+ toggleValue = _ref9.toggleValue,
514
+ index = _ref9.index;
515
+ const newOptions = toggleAndGenerateNewOption({
516
+ featureName,
517
+ toggleValue,
518
+ index,
519
+ options: [...options]
520
+ });
521
+ setOptions(newOptions);
522
+ }, [options]);
523
+ const handleRevert = () => {
524
+ _forEachInstanceProperty__default["default"](originalValues).call(originalValues, (_ref10, index) => {
525
+ let featureName = _ref10.featureName,
526
+ toggleValue = _ref10.toggleValue;
527
+ toggleAndGenerateNewOption({
528
+ featureName,
529
+ toggleValue: typeof toggleValue === 'boolean' ? !toggleValue : {
530
+ value: !toggleValue.value
531
+ },
532
+ index,
533
+ options: [...options]
534
+ });
535
+ });
536
+ setOptions(originalValues);
537
+ setToggleAll(false);
538
+ window.sessionStorage.removeItem(FEATURE_FLAG_KEY);
539
+ };
540
+ if (!isDevMember) return null;
541
+ if (!options.length) return null;
542
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
543
+ children: [jsxRuntime.jsx(uiKit.IconButton, {
544
+ label: "Toggle Feature Flags",
545
+ icon: jsxRuntime.jsx(FeatureFlagTogglerIllustration, {}),
546
+ onClick: modalState.openModal,
547
+ color: "info"
548
+ }), jsxRuntime.jsx(applicationComponents.InfoDialog, {
549
+ title: 'Feature flags',
550
+ isOpen: modalState.isModalOpen,
551
+ onClose: modalState.closeModal,
552
+ zIndex: 30000,
553
+ getParentSelector: () => document.body,
554
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
555
+ scale: "m",
556
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
557
+ justifyContent: "flex-end",
558
+ scale: "m",
559
+ alignItems: "center",
560
+ children: [jsxRuntime.jsx(uiKit.FlatButton, {
561
+ onClick: handleToggleAll,
562
+ label: "Toggle All"
563
+ }), jsxRuntime.jsx(uiKit.SecondaryButton, {
564
+ label: "Revert",
565
+ onClick: handleRevert,
566
+ isDisabled: !isTouched
567
+ })]
568
+ }), jsxRuntime.jsx(uiKit.Spacings.Stack, {
569
+ scale: "m",
570
+ children: _mapInstanceProperty__default["default"](options).call(options, (_ref11, index) => {
571
+ let featureName = _ref11.featureName,
572
+ toggleValue = _ref11.toggleValue;
573
+ return jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
574
+ max: 'scale',
575
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
576
+ scale: "m",
577
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
578
+ justifyContent: "space-between",
579
+ alignItems: "center",
580
+ children: [jsxRuntime.jsxs("div", {
581
+ children: [jsxRuntime.jsx(uiKit.Text.Body, {
582
+ children: toTitleCase(featureName)
583
+ }), jsxRuntime.jsxs(uiKit.Text.Detail, {
584
+ tone: "secondary",
585
+ children: ["flag key: ", featureName]
586
+ })]
587
+ }), jsxRuntime.jsx(uiKit.ToggleInput, {
588
+ size: "small",
589
+ isChecked: isToggled(toggleValue),
590
+ onChange: () => handleToggle({
591
+ featureName,
592
+ toggleValue,
593
+ index
594
+ })
595
+ })]
596
+ }), jsxRuntime.jsx(Divider, {})]
597
+ })
598
+ }, featureName);
599
+ })
600
+ })]
601
+ })
602
+ })]
603
+ });
604
+ };
605
+
606
+ function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
607
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
608
+ var GitHubIcon = function GitHubIcon(props) {
609
+ return jsxRuntime.jsx("svg", _objectSpread$1(_objectSpread$1({}, props), {}, {
610
+ children: jsxRuntime.jsx("path", {
611
+ d: "M12 0C5.374 0 0 5.373 0 12c0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0 1 12 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z"
612
+ })
613
+ }));
614
+ };
615
+ GitHubIcon.defaultProps = {
616
+ xmlns: "http://www.w3.org/2000/svg",
617
+ width: "24",
618
+ height: "24"
619
+ };
620
+ function GitHubPullRequestLink() {
621
+ const previewUrl = window.location.hostname.match(/mc-(\d+)\.mc-preview/);
622
+ if (!previewUrl) return null;
623
+ const _previewUrl = _slicedToArray(previewUrl, 2),
624
+ PRNumber = _previewUrl[1];
625
+ return jsxRuntime.jsx(uiKit.IconButton, {
626
+ label: "GitHub Pull Request",
627
+ icon: jsxRuntime.jsx(GitHubIcon, {}),
628
+ onClick: () => {
629
+ var _context;
630
+ window.open(_concatInstanceProperty__default["default"](_context = "".concat(GITHUB_PR_URL)).call(_context, PRNumber));
631
+ }
632
+ });
633
+ }
634
+
635
+ var _ref$3 = {
636
+ name: "1jeqx8",
637
+ styles: "width:242px"
638
+ } ;
639
+ var _ref2$2 = {
640
+ name: "14ronv",
641
+ styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
642
+ } ;
643
+ const TeamSwitcher = () => {
644
+ const _useTeams = useTeams(),
645
+ options = _useTeams.options,
646
+ activeTeamId = _useTeams.activeTeamId,
647
+ isLimitedPermission = _useTeams.isLimitedPermission;
648
+ if (!(options !== null && options !== void 0 && options.length)) {
649
+ return null;
650
+ }
651
+ const bottomOption = {
652
+ options: [{
653
+ label: 'Select a team to limit permissions to those of that team.',
654
+ value: '',
655
+ isDisabled: true
656
+ }]
657
+ };
658
+ const optionsWithBottomOption = [{
659
+ options
660
+ }, bottomOption];
661
+ const portalContainer = document.querySelector("[id='left-of-profile']");
662
+ const container = jsxRuntime.jsx("div", {
663
+ "data-testid": "limited-permission",
664
+ css: _ref2$2,
665
+ children: jsxRuntime.jsx(uiKit.Stamp, {
666
+ tone: "warning",
667
+ label: "Limited Permission"
668
+ })
669
+ });
670
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
671
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
672
+ alignItems: "center",
673
+ children: [jsxRuntime.jsx(uiKit.Text.Detail, {
674
+ children: "Team"
675
+ }), jsxRuntime.jsx("div", {
676
+ css: _ref$3,
677
+ children: jsxRuntime.jsx(uiKit.SelectInput, {
678
+ id: "team-selector",
679
+ name: "Team Selector",
680
+ isSearchable: true,
681
+ horizontalConstraint: 5,
682
+ menuPortalTarget: document.body,
683
+ menuPortalZIndex: 30000,
684
+ onChange: event => {
685
+ if (event.target.value) {
686
+ setActiveTeamId(event.target.value);
687
+ } else {
688
+ removeActiveTeamId();
689
+ }
690
+ window.location.reload();
691
+ },
692
+ value: activeTeamId,
693
+ options: optionsWithBottomOption,
694
+ showOptionGroupDivider: true
695
+ })
696
+ })]
697
+ }), isLimitedPermission && portalContainer && /*#__PURE__*/ReactDOM__default["default"].createPortal(container, portalContainer)]
698
+ });
699
+ };
700
+
701
+ const LogEnabler = () => {
702
+ const history = reactRouterDom.useHistory();
703
+ const location = reactRouterDom.useLocation();
704
+ const queryParams = new _URLSearchParams__default["default"](location.search);
705
+ const debugFromQueryParams = queryParams.get('debug');
706
+ const isDebugLoggingEnabled = debugFromQueryParams === 'true';
707
+
708
+ // Synchronize the debug params.
709
+ react.useEffect(() => {
710
+ if (debugFromQueryParams) {
711
+ window.sessionStorage.setItem(ENABLE_LOG_KEY, debugFromQueryParams);
712
+ } else {
713
+ // Restore the query param based on the cached state.
714
+ const cachedDebugState = window.sessionStorage.getItem(ENABLE_LOG_KEY);
715
+ if (cachedDebugState) {
716
+ const cachedIsDebugLoggingEnabled = cachedDebugState === 'true';
717
+ queryParams.set('debug', String(cachedIsDebugLoggingEnabled));
718
+ history.push({
719
+ pathname: location.pathname,
720
+ search: queryParams.toString()
721
+ });
722
+ }
723
+ }
724
+ // eslint-disable-next-line react-hooks/exhaustive-deps
725
+ }, [debugFromQueryParams]);
726
+ function handleDebugLoggingChange() {
727
+ const nextIsDebugLoggingEnabled = !isDebugLoggingEnabled;
728
+
729
+ // Cache the new debug state value.
730
+ window.sessionStorage.setItem(ENABLE_LOG_KEY, String(nextIsDebugLoggingEnabled));
731
+
732
+ // Sync the state with the query params. This is what counts!
733
+ if (nextIsDebugLoggingEnabled) {
734
+ queryParams.set('debug', String(nextIsDebugLoggingEnabled));
735
+ } else {
736
+ queryParams.delete('debug');
737
+ }
738
+ history.push({
739
+ pathname: location.pathname,
740
+ search: queryParams.toString()
741
+ });
742
+ }
743
+ return jsxRuntime.jsx(uiKit.CheckboxInput, {
744
+ onChange: handleDebugLoggingChange,
745
+ isChecked: isDebugLoggingEnabled,
746
+ children: "Enable Logs"
747
+ });
748
+ };
749
+
750
+ function getDurationBetween(type, deployedAt) {
751
+ const deployedDate = new Date(deployedAt);
752
+ const today = new Date();
753
+ let value;
754
+ switch (type) {
755
+ case 'minutes':
756
+ value = 60000;
757
+ break;
758
+ case 'hours':
759
+ value = 3600000;
760
+ break;
761
+ case 'days':
762
+ default:
763
+ value = 8.64e7;
764
+ break;
765
+ }
766
+ return Math.round(Math.abs(+deployedDate - +today) / value);
767
+ }
768
+ var _ref$2 = {
769
+ name: "1nxezmo",
770
+ styles: "cursor:pointer!important;position:absolute;left:0;width:100%;button{width:100%;opacity:0;}"
771
+ } ;
772
+ var _ref2$1 = {
773
+ name: "bjn8wh",
774
+ styles: "position:relative"
775
+ } ;
776
+ const DeploymentTracker = () => {
777
+ const _useModalState = applicationComponents.useModalState(),
778
+ isModalOpen = _useModalState.isModalOpen,
779
+ openModal = _useModalState.openModal,
780
+ closeModal = _useModalState.closeModal;
781
+ const _useState = react.useState([]),
782
+ _useState2 = _slicedToArray(_useState, 2),
783
+ versions = _useState2[0],
784
+ setVersions = _useState2[1];
785
+ const getCurrentApplicationName = () => {
786
+ const entryPointUriPath = window.app.entryPointUriPath;
787
+ switch (entryPointUriPath) {
788
+ case 'welcome':
789
+ return 'fallback';
790
+ default:
791
+ return entryPointUriPath;
792
+ }
793
+ };
794
+ const currentApplication = getCurrentApplicationName();
795
+ react.useEffect(() => {
796
+ const abortController = new AbortController();
797
+ const fetchData = async () => {
798
+ let URL = window.location.origin;
799
+ if (URL === LOCAL_ENV.value) {
800
+ return;
801
+ }
802
+ try {
803
+ const response = await fetch("".concat(URL, "/versions"), {
804
+ signal: abortController.signal
805
+ });
806
+ let versions;
807
+ if (response.ok) {
808
+ versions = await response.json();
809
+ setVersions(sortBy__default["default"](versions, version => version.app));
810
+ } else {
811
+ const errorMessage = "Fetching the versions returned a ".concat(response.status, " HTTP status code.");
812
+ // eslint-disable-next-line no-console
813
+ console.error(errorMessage);
814
+ }
815
+ } catch (error) {
816
+ // eslint-disable-next-line no-console
817
+ console.error(error);
818
+ }
819
+ };
820
+ fetchData();
821
+ return () => {
822
+ abortController.abort();
823
+ };
824
+ }, []);
825
+ const getLastUpdate = application => {
826
+ var _versions$find;
827
+ const deployedAt = (_versions$find = _findInstanceProperty__default["default"](versions).call(versions, version => version.app === application)) === null || _versions$find === void 0 || (_versions$find = _versions$find.build) === null || _versions$find === void 0 ? void 0 : _versions$find.deployedAt;
828
+ if (!deployedAt) {
829
+ return {
830
+ value: 0,
831
+ text: '--'
832
+ };
833
+ }
834
+ var days = getDurationBetween('days', deployedAt);
835
+ if (days < 1) {
836
+ var hours = getDurationBetween('hours', deployedAt);
837
+ if (hours < 1) {
838
+ const minutes = getDurationBetween('minutes', deployedAt);
839
+ return {
840
+ value: Number(minutes.toFixed(0)),
841
+ text: "".concat(minutes.toFixed(0), " minutes ago")
842
+ };
843
+ }
844
+ return {
845
+ value: Number(hours.toFixed(0)),
846
+ text: "".concat(hours.toFixed(0), " hours ago")
847
+ };
848
+ }
849
+ return {
850
+ value: Number(days.toFixed(0)),
851
+ text: "".concat(days.toFixed(0), " days ago")
852
+ };
853
+ };
854
+ const getTone = _ref3 => {
855
+ let value = _ref3.value,
856
+ text = _ref3.text;
857
+ if (_includesInstanceProperty__default["default"](text).call(text, 'days')) {
858
+ if (value >= 5) return 'critical';
859
+ if (value >= 2) return 'warning';
860
+ }
861
+ return 'primary';
862
+ };
863
+ if (!(versions !== null && versions !== void 0 && versions.length)) return null;
864
+ return jsxRuntime.jsxs("div", {
865
+ css: _ref2$1,
866
+ children: [jsxRuntime.jsxs(uiKit.Stamp, {
867
+ tone: getTone(getLastUpdate(currentApplication)),
868
+ children: ["Last deployed: ", getLastUpdate(currentApplication).text, jsxRuntime.jsx("div", {
869
+ css: _ref$2,
870
+ children: jsxRuntime.jsx(uiKit.SecondaryButton, {
871
+ label: "",
872
+ onClick: openModal,
873
+ size: "medium"
874
+ })
875
+ })]
876
+ }), jsxRuntime.jsx(applicationComponents.InfoDialog, {
877
+ isOpen: isModalOpen,
878
+ title: 'App Deployment information',
879
+ onClose: closeModal,
880
+ children: jsxRuntime.jsx(uiKit.Spacings.Stack, {
881
+ children: _mapInstanceProperty__default["default"](versions).call(versions, version => jsxRuntime.jsxs(jsxRuntime.Fragment, {
882
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
883
+ justifyContent: "space-between",
884
+ children: [jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
885
+ max: 6,
886
+ children: jsxRuntime.jsx(uiKit.Text.Body, {
887
+ children: version.app
888
+ })
889
+ }), jsxRuntime.jsx(uiKit.Stamp, {
890
+ tone: getTone(getLastUpdate(version.app)),
891
+ children: getLastUpdate(version.app).text
892
+ })]
893
+ }, version.app), jsxRuntime.jsx(Divider, {})]
894
+ }))
895
+ })
896
+ })]
897
+ });
898
+ };
899
+
900
+ var _ref$1 = {
901
+ name: "tkfx1x",
902
+ styles: ">button{margin-right:27px!important;}"
903
+ } ;
904
+ function StaffBarInfo() {
905
+ const infoModalState = applicationComponents.useModalState();
906
+ return jsxRuntime.jsxs("div", {
907
+ css: _ref$1,
908
+ children: [jsxRuntime.jsx(uiKit.IconButton, {
909
+ size: "medium",
910
+ label: "",
911
+ icon: jsxRuntime.jsx(uiKit.InformationIcon, {}),
912
+ onClick: () => {
913
+ infoModalState.openModal();
914
+ }
915
+ }), jsxRuntime.jsx(applicationComponents.InfoDialog, {
916
+ isOpen: infoModalState.isModalOpen,
917
+ title: 'About the Staff bar',
918
+ onClose: infoModalState.closeModal,
919
+ getParentSelector: () => document.body,
920
+ zIndex: 30000,
921
+ size: 12,
922
+ children: jsxRuntime.jsx(uiKit.Text.Detail, {
923
+ children: "Staff bar is an experimental feature available only to commercetools employees. It allows to quickly switch environment, toggle different feature flags and other useful actions. This feature is not visible to end customers nor partners."
924
+ })
925
+ })]
926
+ });
927
+ }
928
+
929
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
930
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
931
+ var _ref = {
932
+ name: "16u25pc",
933
+ styles: "position:absolute;height:24px;width:56px;background:var(--color-accent-10);box-shadow:0px 1px 2px rgba(0, 0, 0, 0.25);border-radius:0px 0px 4px 4px;left:calc(50% - 23px);bottom:-23px;cursor:pointer;z-index:30000;display:flex;align-items:center;justify-content:center;:hover{background:var(--color-accent-20);}"
934
+ } ;
935
+ var _ref2 = {
936
+ name: "bjn8wh",
937
+ styles: "position:relative"
938
+ } ;
939
+ function StaffBar(props) {
940
+ const _useStaffBarUser = useStaffBarUser(),
941
+ isStaffMember = _useStaffBarUser.isStaffMember,
942
+ error = _useStaffBarUser.error;
943
+ const _useState = react.useState(localStorage.getItem(IS_STAFFBAR_OPEN) === 'true'),
944
+ _useState2 = _slicedToArray(_useState, 2),
945
+ isStaffBarOpen = _useState2[0],
946
+ setIsStaffBarOpen = _useState2[1];
947
+ const container = jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, fullstory.Marking.applyMarker('Staff Bar')), {}, {
948
+ css: _ref2,
949
+ children: jsxRuntime.jsxs("div", {
950
+ css: /*#__PURE__*/react$1.css("height:", isStaffBarOpen ? '56px' : '0', ";background:var(--color-neutral-95);transition:height 150ms;overflow:hidden;" + ("" ), "" ),
951
+ children: [jsxRuntime.jsx("div", {
952
+ "data-testid": "staffbar-handle",
953
+ css: _ref,
954
+ onClick: () => {
955
+ localStorage.setItem(IS_STAFFBAR_OPEN, (!isStaffBarOpen).toString());
956
+ setIsStaffBarOpen(!isStaffBarOpen);
957
+ },
958
+ children: isStaffBarOpen ? jsxRuntime.jsx(uiKit.AngleUpIcon, {
959
+ color: "surface",
960
+ size: "medium"
961
+ }) : jsxRuntime.jsx(uiKit.AngleDownIcon, {
962
+ color: "surface",
963
+ size: "medium"
964
+ })
965
+ }), jsxRuntime.jsx(uiKit.Spacings.InsetSquish, {
966
+ scale: "m",
967
+ children: jsxRuntime.jsxs(uiKit.Spacings.Inline, {
968
+ justifyContent: "space-between",
969
+ alignItems: "center",
970
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
971
+ scale: "l",
972
+ children: [jsxRuntime.jsx(GitHubPullRequestLink, {}), jsxRuntime.jsx(FeatureFlagToggler, {
973
+ featureFlags: props.featureFlags
974
+ }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {})]
975
+ }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
976
+ scale: "l",
977
+ alignItems: "center",
978
+ children: [jsxRuntime.jsx(DeploymentTracker, {}), jsxRuntime.jsx(LogEnabler, {}), jsxRuntime.jsx(StaffBarInfo, {})]
979
+ })]
980
+ })
981
+ })]
982
+ })
983
+ }));
984
+ const portalContainer = document.getElementById('above-top-navigation');
985
+ if (error || !isStaffMember || !portalContainer) return null;
986
+ return /*#__PURE__*/ReactDOM__default["default"].createPortal(container, portalContainer);
987
+ }
988
+
989
+ exports["default"] = StaffBar;