@commercetools-frontend/application-shell 21.23.9 → 21.24.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.
- package/dist/application-entry-point-2a64a561.cjs.dev.js +116 -0
- package/dist/application-entry-point-3bb7f8bd.cjs.prod.js +99 -0
- package/dist/application-entry-point-58dd4b7f.esm.js +101 -0
- package/dist/{box-dd9e7e68.esm.js → box-4395623b.esm.js} +1 -3
- package/dist/{box-fdb2ccb6.cjs.dev.js → box-6b5be9a9.cjs.dev.js} +1 -3
- package/dist/{box-d849ea03.cjs.prod.js → box-8850277f.cjs.prod.js} +1 -3
- package/dist/{cart-ad0aba9b.cjs.prod.js → cart-0698b97d.cjs.prod.js} +1 -3
- package/dist/{cart-b92f3a8e.cjs.dev.js → cart-41f0b7bc.cjs.dev.js} +1 -3
- package/dist/{cart-167fea3b.esm.js → cart-a49faf67.esm.js} +1 -3
- package/dist/commercetools-frontend-application-shell.cjs.dev.js +49 -68
- package/dist/commercetools-frontend-application-shell.cjs.prod.js +49 -68
- package/dist/commercetools-frontend-application-shell.esm.js +39 -58
- package/dist/configure-apollo-1f39e35a.cjs.dev.js +930 -0
- package/dist/configure-apollo-5f1fd942.esm.js +873 -0
- package/dist/configure-apollo-d11de242.cjs.prod.js +922 -0
- package/dist/{connected-square-4743b7de.esm.js → connected-square-3cac6bd7.esm.js} +1 -3
- package/dist/connected-square-47233754.cjs.dev.js +32 -0
- package/dist/connected-square-b2e25621.cjs.prod.js +32 -0
- package/dist/{constants-69249abd.esm.js → constants-7f04db3f.esm.js} +9 -9
- package/dist/{constants-88fb9ef8.cjs.prod.js → constants-e6409334.cjs.prod.js} +8 -8
- package/dist/{constants-c2d56f3d.cjs.dev.js → constants-e6f058e5.cjs.dev.js} +8 -8
- package/dist/declarations/src/apollo-links/utils.d.ts +2 -2
- package/dist/declarations/src/components/application-entry-point/application-entry-point.d.ts +4 -4
- package/dist/declarations/src/components/application-shell/application-shell.d.ts +7 -15
- package/dist/declarations/src/components/application-shell-authenticated/application-shell-authenticated.d.ts +21 -0
- package/dist/declarations/src/components/application-shell-provider/application-shell-provider.d.ts +6 -7
- package/dist/declarations/src/components/application-shell-provider/use-coerced-environment-values.d.ts +1 -23
- package/dist/declarations/src/components/authenticated/authenticated.d.ts +2 -2
- package/dist/declarations/src/components/authenticated/oidc-callback.async.d.ts +6 -0
- package/dist/declarations/src/components/authenticated/oidc-callback.d.ts +2 -2
- package/dist/declarations/src/components/configure-intl-provider/configure-intl-provider.d.ts +1 -1
- package/dist/declarations/src/components/error-apologizer/index.d.ts +6 -1
- package/dist/declarations/src/components/fetch-project/fetch-project.d.ts +4 -4
- package/dist/declarations/src/components/fetch-user/fetch-user.d.ts +3 -3
- package/dist/declarations/src/components/inject-reducers/inject-reducers.d.ts +1 -1
- package/dist/declarations/src/components/navbar/index.d.ts +100 -1
- package/dist/declarations/src/components/navbar/loading-navbar.d.ts +5 -0
- package/dist/declarations/src/components/navbar/menu-items.d.ts +99 -0
- package/dist/declarations/src/components/navbar/navbar.d.ts +6 -15
- package/dist/declarations/src/components/project-container/index.d.ts +78 -1
- package/dist/declarations/src/components/project-container/project-container.d.ts +6 -8
- package/dist/declarations/src/components/quick-access/butler-command/butler-command.d.ts +1 -1
- package/dist/declarations/src/components/quick-access/index.d.ts +2 -2
- package/dist/declarations/src/components/quick-access/types.d.ts +1 -1
- package/dist/declarations/src/components/redirect-to-login/index.d.ts +6 -0
- package/dist/declarations/src/components/redirect-to-logout/index.d.ts +5 -0
- package/dist/declarations/src/components/redirect-to-project-create/index.d.ts +6 -1
- package/dist/declarations/src/components/requests-in-flight-loader/index.d.ts +6 -1
- package/dist/declarations/src/components/route-catch-all/index.d.ts +3 -1
- package/dist/declarations/src/components/setup-flop-flip-provider/setup-flop-flip-provider.d.ts +3 -3
- package/dist/declarations/src/components/suspended-route/suspended-route.d.ts +1 -1
- package/dist/declarations/src/components/user-settings-menu/index.d.ts +12 -1
- package/dist/declarations/src/components/version-tracker/index.d.ts +6 -1
- package/dist/declarations/src/hooks/apollo-hooks/apollo-hooks.d.ts +1 -1
- package/dist/declarations/src/test-utils/test-utils.d.ts +2 -2
- package/dist/declarations/src/types/generated/mc.d.ts +3 -3
- package/dist/declarations/src/utils/get-mc-origin/get-mc-origin.d.ts +2 -0
- package/dist/declarations/src/utils/get-mc-origin/index.d.ts +1 -0
- package/dist/error-apologizer-c336db61.cjs.dev.js +56 -0
- package/dist/error-apologizer-c55ec6f7.cjs.prod.js +56 -0
- package/dist/error-apologizer-f8772b68.esm.js +42 -0
- package/dist/gear-2890f7fb.cjs.prod.js +32 -0
- package/dist/{gear-8418cd46.esm.js → gear-300dd24c.esm.js} +1 -3
- package/dist/gear-e8014c5a.cjs.dev.js +32 -0
- package/dist/get-mc-origin-314b77a2.cjs.dev.js +57 -0
- package/dist/get-mc-origin-5df60933.esm.js +50 -0
- package/dist/get-mc-origin-7968e04f.cjs.prod.js +57 -0
- package/dist/heart-000a023d.cjs.prod.js +32 -0
- package/dist/{heart-48c28091.esm.js → heart-dded66b4.esm.js} +1 -3
- package/dist/heart-f21b7d39.cjs.dev.js +32 -0
- package/dist/index-5048bf47.cjs.dev.js +3054 -0
- package/dist/index-b002eca6.esm.js +2970 -0
- package/dist/index-e0ab178f.cjs.prod.js +2870 -0
- package/dist/{list-with-search-c154a56e.esm.js → list-with-search-a3302710.esm.js} +1 -3
- package/dist/list-with-search-a5b72b33.cjs.prod.js +32 -0
- package/dist/list-with-search-ee796e9e.cjs.dev.js +32 -0
- package/dist/navbar-40650ed4.cjs.dev.js +670 -0
- package/dist/navbar-997b4a36.cjs.prod.js +649 -0
- package/dist/navbar-f4b482d0.esm.js +650 -0
- package/dist/oidc-0638d0c8.cjs.dev.js +67 -0
- package/dist/oidc-10fa96f0.esm.js +59 -0
- package/dist/oidc-540a091a.cjs.prod.js +67 -0
- package/dist/oidc-callback-1047744c.cjs.dev.js +254 -0
- package/dist/oidc-callback-b32405ab.cjs.prod.js +251 -0
- package/dist/oidc-callback-e2ca889b.esm.js +240 -0
- package/dist/paperclip-23d1e69c.cjs.prod.js +32 -0
- package/dist/{paperclip-18785dda.esm.js → paperclip-a61112e8.esm.js} +1 -3
- package/dist/paperclip-d653c134.cjs.dev.js +32 -0
- package/dist/plugin-0ee6aee4.cjs.dev.js +32 -0
- package/dist/{plugin-53c047bb.esm.js → plugin-3d353a5b.esm.js} +1 -3
- package/dist/plugin-7e57f237.cjs.prod.js +32 -0
- package/dist/project-container-05a4e261.esm.js +368 -0
- package/dist/project-container-1cf9964e.cjs.dev.js +387 -0
- package/dist/project-container-65fccf05.cjs.prod.js +369 -0
- package/dist/{project-expired-b84abd3a.esm.js → project-expired-0d18d9ef.esm.js} +47 -68
- package/dist/{project-expired-0c72c956.cjs.dev.js → project-expired-b8480245.cjs.dev.js} +47 -68
- package/dist/{project-expired-0f9d4a23.cjs.prod.js → project-expired-e757e66c.cjs.prod.js} +47 -68
- package/dist/{project-not-found-14dc05c1.cjs.dev.js → project-not-found-1b4527b4.cjs.dev.js} +42 -61
- package/dist/{project-not-found-8002ba67.esm.js → project-not-found-4bc57bab.esm.js} +42 -61
- package/dist/{project-not-found-419be633.cjs.prod.js → project-not-found-6808c525.cjs.prod.js} +42 -61
- package/dist/{project-not-initialized-cd8e8160.cjs.dev.js → project-not-initialized-3351f8b7.cjs.prod.js} +47 -68
- package/dist/{project-not-initialized-3a477d13.esm.js → project-not-initialized-5eef98f9.esm.js} +47 -68
- package/dist/{project-not-initialized-10cbf15a.cjs.prod.js → project-not-initialized-d13a6be3.cjs.dev.js} +47 -68
- package/dist/{project-suspended-243ddda8.cjs.dev.js → project-suspended-4ed362c3.cjs.prod.js} +44 -63
- package/dist/{project-suspended-50c6dd60.esm.js → project-suspended-7843e028.esm.js} +44 -63
- package/dist/{project-suspended-dffcecd1.cjs.prod.js → project-suspended-c5b996b0.cjs.dev.js} +44 -63
- package/dist/quick-access-3acb2b6a.cjs.dev.js +1937 -0
- package/dist/{quick-access-fc734889.cjs.prod.js → quick-access-5c5074c7.cjs.prod.js} +573 -957
- package/dist/quick-access-fdb9024d.esm.js +1907 -0
- package/dist/redirect-to-login-5ac864e2.cjs.prod.js +149 -0
- package/dist/redirect-to-login-80d7ff2f.cjs.dev.js +149 -0
- package/dist/redirect-to-login-824d52b9.esm.js +147 -0
- package/dist/redirect-to-logout-6df9b79c.esm.js +138 -0
- package/dist/redirect-to-logout-7d5c817e.cjs.prod.js +151 -0
- package/dist/redirect-to-logout-a78f7193.cjs.dev.js +151 -0
- package/dist/redirect-to-project-create-048efa71.cjs.prod.js +61 -0
- package/dist/redirect-to-project-create-052f293e.esm.js +52 -0
- package/dist/redirect-to-project-create-f0e7b35e.cjs.dev.js +61 -0
- package/dist/{gear-28ff4f04.cjs.dev.js → redirector-0d98f9df.cjs.dev.js} +44 -5
- package/dist/redirector-47a6be71.esm.js +58 -0
- package/dist/{gear-6f8c30e3.cjs.prod.js → redirector-77ce2f5c.cjs.prod.js} +44 -5
- package/dist/requests-in-flight-loader-3bc8dd8a.cjs.dev.js +144 -0
- package/dist/requests-in-flight-loader-c3e4205b.cjs.prod.js +144 -0
- package/dist/requests-in-flight-loader-fe4c165f.esm.js +129 -0
- package/dist/rocket-3e3f0a98.cjs.prod.js +32 -0
- package/dist/{rocket-ba116b5e.esm.js → rocket-4b088727.esm.js} +1 -3
- package/dist/rocket-95b6858d.cjs.dev.js +32 -0
- package/dist/route-catch-all-01cf0095.esm.js +41 -0
- package/dist/route-catch-all-3b490df1.cjs.prod.js +43 -0
- package/dist/route-catch-all-9ac99936.cjs.dev.js +43 -0
- package/dist/{service-page-project-switcher-e3195b51.cjs.prod.js → service-page-project-switcher-6865e150.cjs.prod.js} +5 -7
- package/dist/{service-page-project-switcher-fa253254.cjs.dev.js → service-page-project-switcher-e8a7e5d7.cjs.dev.js} +6 -8
- package/dist/{service-page-project-switcher-6c39bf55.esm.js → service-page-project-switcher-fcc8d186.esm.js} +6 -8
- package/dist/{speedometer-c1b94505.esm.js → speedometer-08a11d5a.esm.js} +1 -3
- package/dist/speedometer-2881cef6.cjs.prod.js +32 -0
- package/dist/speedometer-54f872f2.cjs.dev.js +32 -0
- package/dist/{star-da9123e0.esm.js → star-15244db1.esm.js} +1 -3
- package/dist/star-52bf7a64.cjs.dev.js +32 -0
- package/dist/star-f8502efb.cjs.prod.js +32 -0
- package/dist/tag-multi-1d1553b6.cjs.dev.js +32 -0
- package/dist/{tag-multi-c650b738.esm.js → tag-multi-3be995ac.esm.js} +1 -3
- package/dist/tag-multi-f9acb1c2.cjs.prod.js +32 -0
- package/dist/tree-structure-4650688d.cjs.dev.js +32 -0
- package/dist/{tree-structure-6af6fc3a.esm.js → tree-structure-c8753526.esm.js} +1 -3
- package/dist/tree-structure-f24ee3f6.cjs.prod.js +32 -0
- package/dist/use-applications-menu-1925f36a.esm.js +172 -0
- package/dist/use-applications-menu-7e438b2a.cjs.prod.js +188 -0
- package/dist/use-applications-menu-f6f68bf7.cjs.dev.js +188 -0
- package/dist/use-is-served-by-proxy-2b4916e5.cjs.dev.js +42 -0
- package/dist/use-is-served-by-proxy-499bfa16.esm.js +39 -0
- package/dist/use-is-served-by-proxy-51e76976.cjs.prod.js +42 -0
- package/dist/{user-filled-41729d77.esm.js → user-filled-2dc4e79e.esm.js} +1 -3
- package/dist/user-filled-2e6cb25e.cjs.dev.js +32 -0
- package/dist/user-filled-815b49a0.cjs.prod.js +32 -0
- package/dist/user-settings-menu-96de467a.cjs.prod.js +496 -0
- package/dist/user-settings-menu-d831de89.esm.js +497 -0
- package/dist/user-settings-menu-e38c73ac.cjs.dev.js +523 -0
- package/dist/version-tracker-51646901.cjs.prod.js +107 -0
- package/dist/version-tracker-57ea3aa1.cjs.dev.js +107 -0
- package/dist/version-tracker-afb522da.esm.js +101 -0
- package/dist/world-973090a5.cjs.dev.js +32 -0
- package/dist/{world-d91df1ee.esm.js → world-c5ea311a.esm.js} +1 -3
- package/dist/world-e1f9dbf8.cjs.prod.js +32 -0
- package/package.json +39 -39
- package/ssr/dist/commercetools-frontend-application-shell-ssr.cjs.dev.js +2 -3
- package/ssr/dist/commercetools-frontend-application-shell-ssr.cjs.prod.js +2 -3
- package/ssr/dist/commercetools-frontend-application-shell-ssr.esm.js +2 -3
- package/test-utils/dist/commercetools-frontend-application-shell-test-utils.cjs.dev.js +182 -215
- package/test-utils/dist/commercetools-frontend-application-shell-test-utils.cjs.prod.js +182 -215
- package/test-utils/dist/commercetools-frontend-application-shell-test-utils.esm.js +173 -206
- package/dist/application-entry-point-180dbaa1.cjs.prod.js +0 -1225
- package/dist/application-entry-point-55376ed2.esm.js +0 -1180
- package/dist/application-entry-point-63abd0c1.cjs.dev.js +0 -1250
- package/dist/connected-square-abf36852.cjs.prod.js +0 -34
- package/dist/connected-square-ac52014f.cjs.dev.js +0 -34
- package/dist/declarations/src/components/application-shell/helpers.d.ts +0 -1
- package/dist/heart-33cd94c6.cjs.prod.js +0 -34
- package/dist/heart-fb31cf30.cjs.dev.js +0 -34
- package/dist/index-27953285.esm.js +0 -4809
- package/dist/index-4508ebb0.cjs.prod.js +0 -4643
- package/dist/index-d693db30.cjs.dev.js +0 -4888
- package/dist/list-with-search-34cd926c.cjs.dev.js +0 -34
- package/dist/list-with-search-a0b22169.cjs.prod.js +0 -34
- package/dist/oidc-1c91f5ee.cjs.prod.js +0 -67
- package/dist/oidc-5b2e4f8f.cjs.dev.js +0 -67
- package/dist/oidc-77749f1b.esm.js +0 -59
- package/dist/paperclip-2cd45b86.cjs.dev.js +0 -34
- package/dist/paperclip-b1b806ab.cjs.prod.js +0 -34
- package/dist/plugin-7cb7827e.cjs.dev.js +0 -34
- package/dist/plugin-e97ae3e6.cjs.prod.js +0 -34
- package/dist/quick-access-1b241811.cjs.dev.js +0 -2321
- package/dist/quick-access-6159845a.esm.js +0 -2290
- package/dist/rocket-37c1aa11.cjs.dev.js +0 -34
- package/dist/rocket-b2dbda7f.cjs.prod.js +0 -34
- package/dist/speedometer-13b393fb.cjs.dev.js +0 -34
- package/dist/speedometer-1e69fd13.cjs.prod.js +0 -34
- package/dist/star-ab4be629.cjs.prod.js +0 -34
- package/dist/star-e165111e.cjs.dev.js +0 -34
- package/dist/tag-multi-5f498a7d.cjs.dev.js +0 -34
- package/dist/tag-multi-fb817131.cjs.prod.js +0 -34
- package/dist/tree-structure-779fcc36.cjs.prod.js +0 -34
- package/dist/tree-structure-ed6cdff8.cjs.dev.js +0 -34
- package/dist/user-filled-384a2eaf.cjs.prod.js +0 -34
- package/dist/user-filled-53d2eae0.cjs.dev.js +0 -34
- package/dist/world-12528632.cjs.prod.js +0 -34
- package/dist/world-6471d9f6.cjs.dev.js +0 -34
- /package/dist/declarations/src/components/{application-shell → redirect-to-login}/redirect-to-login.d.ts +0 -0
- /package/dist/declarations/src/components/{application-shell → redirect-to-logout}/redirect-to-logout.d.ts +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
2
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
3
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
4
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
5
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
6
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
7
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
8
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
9
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
10
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
11
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
12
|
+
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
13
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
14
|
+
import { useState, useEffect } from 'react';
|
|
15
|
+
import { useApolloClient } from '@apollo/client';
|
|
16
|
+
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
|
|
17
|
+
import { u as useMcQuery } from './index-b002eca6.esm.js';
|
|
18
|
+
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
+
var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
23
|
+
const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
|
|
24
|
+
const defaultApiUrl = window.location.origin;
|
|
25
|
+
|
|
26
|
+
const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
|
|
27
|
+
let mappedLabelAllLocales = labelAllLocales;
|
|
28
|
+
|
|
29
|
+
if (defaultLabel) {
|
|
30
|
+
// Map all supported locales with the given localized labels.
|
|
31
|
+
// If a locale is not defined in the config, we use the `default` label as the value.
|
|
32
|
+
// This is only needed for development as we're trying to map two different schemas.
|
|
33
|
+
mappedLabelAllLocales = _mapInstanceProperty(supportedLocales).call(supportedLocales, supportedLocale => {
|
|
34
|
+
const existingField = _findInstanceProperty(labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
|
|
35
|
+
|
|
36
|
+
if (existingField) return existingField;
|
|
37
|
+
return {
|
|
38
|
+
locale: supportedLocale,
|
|
39
|
+
value: defaultLabel
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
} // Add the `__typename`.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
return _mapInstanceProperty(mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
|
|
46
|
+
__typename: 'LocalizedField'
|
|
47
|
+
}, field));
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
|
|
51
|
+
* This is only needed for development.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
|
|
56
|
+
var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
|
|
57
|
+
|
|
58
|
+
const entryPointUriPath = applicationConfig.entryPointUriPath;
|
|
59
|
+
const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
60
|
+
|
|
61
|
+
const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
|
|
62
|
+
return {
|
|
63
|
+
applicationsMenu: {
|
|
64
|
+
__typename: 'ApplicationsMenu',
|
|
65
|
+
navBar: menuLinks ? [{
|
|
66
|
+
__typename: 'NavbarMenu',
|
|
67
|
+
key: entryPointUriPath,
|
|
68
|
+
uriPath: entryPointUriPath,
|
|
69
|
+
icon: menuLinks.icon,
|
|
70
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
|
|
71
|
+
permissions: menuLinks.permissions,
|
|
72
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
73
|
+
featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
|
|
74
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
75
|
+
menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
|
|
76
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
77
|
+
actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
|
|
78
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
79
|
+
dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
|
|
80
|
+
submenu: _mapInstanceProperty(_context = menuLinks.submenuLinks).call(_context, submenuLink => {
|
|
81
|
+
var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
__typename: 'BaseMenu',
|
|
85
|
+
key: _concatInstanceProperty(_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
|
|
86
|
+
uriPath: submenuLink.uriPath,
|
|
87
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
|
|
88
|
+
permissions: submenuLink.permissions,
|
|
89
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
90
|
+
featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
|
|
91
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
92
|
+
menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
|
|
93
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
94
|
+
actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
|
|
95
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
96
|
+
dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
}] : [],
|
|
100
|
+
appBar: _mapInstanceProperty(accountLinks).call(accountLinks, menuLink => {
|
|
101
|
+
var _menuLink$featureTogg;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
__typename: 'BaseMenu',
|
|
105
|
+
key: menuLink.uriPath,
|
|
106
|
+
uriPath: menuLink.uriPath,
|
|
107
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
|
|
108
|
+
permissions: menuLink.permissions,
|
|
109
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
110
|
+
featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
|
|
111
|
+
};
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
function useApplicationsMenu(menuKey, config) {
|
|
118
|
+
var _config$queryOptions;
|
|
119
|
+
|
|
120
|
+
const apolloClient = useApolloClient();
|
|
121
|
+
const mcProxyApiUrl = useApplicationContext(context => context.environment.mcProxyApiUrl);
|
|
122
|
+
|
|
123
|
+
const _useState = useState(false),
|
|
124
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
125
|
+
hasWrittenToCache = _useState2[0],
|
|
126
|
+
setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
|
|
127
|
+
// For local development, we don't fetch data from the remote server but use
|
|
128
|
+
// only the configuration for the menu links defined for the application.
|
|
129
|
+
// To do so, we manually write the data in the Apollo cache and use the
|
|
130
|
+
// `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
|
|
131
|
+
// NOTE: In development, we skip the query as long as the data hasn't been written
|
|
132
|
+
// into the cache. If not, Apollo throws an error like
|
|
133
|
+
// `Can't find field 'applicationMenu' on ROOT_QUERY object`.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
const _useMcQuery = useMcQuery(FetchApplicationsMenu, {
|
|
137
|
+
skip: config.environment.servedByProxy ? // Production environment
|
|
138
|
+
false : // Development environment
|
|
139
|
+
!hasWrittenToCache,
|
|
140
|
+
onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
|
|
141
|
+
fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
|
|
142
|
+
context: {
|
|
143
|
+
// Allow to overwrite the API url from application config
|
|
144
|
+
uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
|
|
145
|
+
skipGraphQlTargetCheck: true
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
|
|
149
|
+
// write it into the Apollo cache.
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
154
|
+
config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
|
|
155
|
+
const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
|
|
156
|
+
apolloClient.writeQuery({
|
|
157
|
+
query: FetchApplicationsMenu,
|
|
158
|
+
data: applicationMenu
|
|
159
|
+
});
|
|
160
|
+
setHasWrittenToCache(true);
|
|
161
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
162
|
+
|
|
163
|
+
}, [hasWrittenToCache]); // Only subscribe to state changes.
|
|
164
|
+
|
|
165
|
+
if (menuQueryResult && menuQueryResult.applicationsMenu) {
|
|
166
|
+
return menuQueryResult.applicationsMenu[menuKey];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { useApplicationsMenu as u };
|
|
@@ -0,0 +1,188 @@
|
|
|
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 _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
12
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
14
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
15
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var client = require('@apollo/client');
|
|
18
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
19
|
+
var dist_commercetoolsFrontendApplicationShell = require('./index-e0ab178f.cjs.prod.js');
|
|
20
|
+
|
|
21
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
24
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
25
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
26
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
27
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
28
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
29
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
30
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
31
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
32
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
33
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
34
|
+
|
|
35
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
36
|
+
|
|
37
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
38
|
+
var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
39
|
+
const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
|
|
40
|
+
const defaultApiUrl = window.location.origin;
|
|
41
|
+
|
|
42
|
+
const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
|
|
43
|
+
let mappedLabelAllLocales = labelAllLocales;
|
|
44
|
+
|
|
45
|
+
if (defaultLabel) {
|
|
46
|
+
// Map all supported locales with the given localized labels.
|
|
47
|
+
// If a locale is not defined in the config, we use the `default` label as the value.
|
|
48
|
+
// This is only needed for development as we're trying to map two different schemas.
|
|
49
|
+
mappedLabelAllLocales = _mapInstanceProperty__default["default"](supportedLocales).call(supportedLocales, supportedLocale => {
|
|
50
|
+
const existingField = _findInstanceProperty__default["default"](labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
|
|
51
|
+
|
|
52
|
+
if (existingField) return existingField;
|
|
53
|
+
return {
|
|
54
|
+
locale: supportedLocale,
|
|
55
|
+
value: defaultLabel
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
} // Add the `__typename`.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
return _mapInstanceProperty__default["default"](mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
|
|
62
|
+
__typename: 'LocalizedField'
|
|
63
|
+
}, field));
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
|
|
67
|
+
* This is only needed for development.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
|
|
72
|
+
var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
|
|
73
|
+
|
|
74
|
+
const entryPointUriPath = applicationConfig.entryPointUriPath;
|
|
75
|
+
const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
76
|
+
|
|
77
|
+
const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
|
|
78
|
+
return {
|
|
79
|
+
applicationsMenu: {
|
|
80
|
+
__typename: 'ApplicationsMenu',
|
|
81
|
+
navBar: menuLinks ? [{
|
|
82
|
+
__typename: 'NavbarMenu',
|
|
83
|
+
key: entryPointUriPath,
|
|
84
|
+
uriPath: entryPointUriPath,
|
|
85
|
+
icon: menuLinks.icon,
|
|
86
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
|
|
87
|
+
permissions: menuLinks.permissions,
|
|
88
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
89
|
+
featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
|
|
90
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
91
|
+
menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
|
|
92
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
93
|
+
actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
|
|
94
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
95
|
+
dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
|
|
96
|
+
submenu: _mapInstanceProperty__default["default"](_context = menuLinks.submenuLinks).call(_context, submenuLink => {
|
|
97
|
+
var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
__typename: 'BaseMenu',
|
|
101
|
+
key: _concatInstanceProperty__default["default"](_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
|
|
102
|
+
uriPath: submenuLink.uriPath,
|
|
103
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
|
|
104
|
+
permissions: submenuLink.permissions,
|
|
105
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
106
|
+
featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
|
|
107
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
108
|
+
menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
|
|
109
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
110
|
+
actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
|
|
111
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
112
|
+
dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
|
|
113
|
+
};
|
|
114
|
+
})
|
|
115
|
+
}] : [],
|
|
116
|
+
appBar: _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => {
|
|
117
|
+
var _menuLink$featureTogg;
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
__typename: 'BaseMenu',
|
|
121
|
+
key: menuLink.uriPath,
|
|
122
|
+
uriPath: menuLink.uriPath,
|
|
123
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
|
|
124
|
+
permissions: menuLink.permissions,
|
|
125
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
126
|
+
featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
|
|
127
|
+
};
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
function useApplicationsMenu(menuKey, config) {
|
|
134
|
+
var _config$queryOptions;
|
|
135
|
+
|
|
136
|
+
const apolloClient = client.useApolloClient();
|
|
137
|
+
const mcProxyApiUrl = applicationShellConnectors.useApplicationContext(context => context.environment.mcProxyApiUrl);
|
|
138
|
+
|
|
139
|
+
const _useState = react.useState(false),
|
|
140
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
141
|
+
hasWrittenToCache = _useState2[0],
|
|
142
|
+
setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
|
|
143
|
+
// For local development, we don't fetch data from the remote server but use
|
|
144
|
+
// only the configuration for the menu links defined for the application.
|
|
145
|
+
// To do so, we manually write the data in the Apollo cache and use the
|
|
146
|
+
// `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
|
|
147
|
+
// NOTE: In development, we skip the query as long as the data hasn't been written
|
|
148
|
+
// into the cache. If not, Apollo throws an error like
|
|
149
|
+
// `Can't find field 'applicationMenu' on ROOT_QUERY object`.
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const _useMcQuery = dist_commercetoolsFrontendApplicationShell.useMcQuery(FetchApplicationsMenu, {
|
|
153
|
+
skip: config.environment.servedByProxy ? // Production environment
|
|
154
|
+
false : // Development environment
|
|
155
|
+
!hasWrittenToCache,
|
|
156
|
+
onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
|
|
157
|
+
fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
|
|
158
|
+
context: {
|
|
159
|
+
// Allow to overwrite the API url from application config
|
|
160
|
+
uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
|
|
161
|
+
skipGraphQlTargetCheck: true
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
|
|
165
|
+
// write it into the Apollo cache.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
react.useEffect(() => {
|
|
169
|
+
if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
170
|
+
config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
|
|
171
|
+
const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
|
|
172
|
+
apolloClient.writeQuery({
|
|
173
|
+
query: FetchApplicationsMenu,
|
|
174
|
+
data: applicationMenu
|
|
175
|
+
});
|
|
176
|
+
setHasWrittenToCache(true);
|
|
177
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
|
+
|
|
179
|
+
}, [hasWrittenToCache]); // Only subscribe to state changes.
|
|
180
|
+
|
|
181
|
+
if (menuQueryResult && menuQueryResult.applicationsMenu) {
|
|
182
|
+
return menuQueryResult.applicationsMenu[menuKey];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
exports.useApplicationsMenu = useApplicationsMenu;
|
|
@@ -0,0 +1,188 @@
|
|
|
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 _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
12
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
14
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
15
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var client = require('@apollo/client');
|
|
18
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
19
|
+
var dist_commercetoolsFrontendApplicationShell = require('./index-5048bf47.cjs.dev.js');
|
|
20
|
+
|
|
21
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
24
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
25
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
26
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
27
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
28
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
29
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
30
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
31
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
32
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
33
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
34
|
+
|
|
35
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
36
|
+
|
|
37
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
38
|
+
var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
39
|
+
const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
|
|
40
|
+
const defaultApiUrl = window.location.origin;
|
|
41
|
+
|
|
42
|
+
const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
|
|
43
|
+
let mappedLabelAllLocales = labelAllLocales;
|
|
44
|
+
|
|
45
|
+
if (defaultLabel) {
|
|
46
|
+
// Map all supported locales with the given localized labels.
|
|
47
|
+
// If a locale is not defined in the config, we use the `default` label as the value.
|
|
48
|
+
// This is only needed for development as we're trying to map two different schemas.
|
|
49
|
+
mappedLabelAllLocales = _mapInstanceProperty__default["default"](supportedLocales).call(supportedLocales, supportedLocale => {
|
|
50
|
+
const existingField = _findInstanceProperty__default["default"](labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
|
|
51
|
+
|
|
52
|
+
if (existingField) return existingField;
|
|
53
|
+
return {
|
|
54
|
+
locale: supportedLocale,
|
|
55
|
+
value: defaultLabel
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
} // Add the `__typename`.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
return _mapInstanceProperty__default["default"](mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
|
|
62
|
+
__typename: 'LocalizedField'
|
|
63
|
+
}, field));
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
|
|
67
|
+
* This is only needed for development.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
|
|
72
|
+
var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
|
|
73
|
+
|
|
74
|
+
const entryPointUriPath = applicationConfig.entryPointUriPath;
|
|
75
|
+
const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
76
|
+
|
|
77
|
+
const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
|
|
78
|
+
return {
|
|
79
|
+
applicationsMenu: {
|
|
80
|
+
__typename: 'ApplicationsMenu',
|
|
81
|
+
navBar: menuLinks ? [{
|
|
82
|
+
__typename: 'NavbarMenu',
|
|
83
|
+
key: entryPointUriPath,
|
|
84
|
+
uriPath: entryPointUriPath,
|
|
85
|
+
icon: menuLinks.icon,
|
|
86
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
|
|
87
|
+
permissions: menuLinks.permissions,
|
|
88
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
89
|
+
featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
|
|
90
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
91
|
+
menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
|
|
92
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
93
|
+
actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
|
|
94
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
95
|
+
dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
|
|
96
|
+
submenu: _mapInstanceProperty__default["default"](_context = menuLinks.submenuLinks).call(_context, submenuLink => {
|
|
97
|
+
var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
__typename: 'BaseMenu',
|
|
101
|
+
key: _concatInstanceProperty__default["default"](_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
|
|
102
|
+
uriPath: submenuLink.uriPath,
|
|
103
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
|
|
104
|
+
permissions: submenuLink.permissions,
|
|
105
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
106
|
+
featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
|
|
107
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
108
|
+
menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
|
|
109
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
110
|
+
actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
|
|
111
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
112
|
+
dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
|
|
113
|
+
};
|
|
114
|
+
})
|
|
115
|
+
}] : [],
|
|
116
|
+
appBar: _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => {
|
|
117
|
+
var _menuLink$featureTogg;
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
__typename: 'BaseMenu',
|
|
121
|
+
key: menuLink.uriPath,
|
|
122
|
+
uriPath: menuLink.uriPath,
|
|
123
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
|
|
124
|
+
permissions: menuLink.permissions,
|
|
125
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
126
|
+
featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
|
|
127
|
+
};
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
function useApplicationsMenu(menuKey, config) {
|
|
134
|
+
var _config$queryOptions;
|
|
135
|
+
|
|
136
|
+
const apolloClient = client.useApolloClient();
|
|
137
|
+
const mcProxyApiUrl = applicationShellConnectors.useApplicationContext(context => context.environment.mcProxyApiUrl);
|
|
138
|
+
|
|
139
|
+
const _useState = react.useState(false),
|
|
140
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
141
|
+
hasWrittenToCache = _useState2[0],
|
|
142
|
+
setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
|
|
143
|
+
// For local development, we don't fetch data from the remote server but use
|
|
144
|
+
// only the configuration for the menu links defined for the application.
|
|
145
|
+
// To do so, we manually write the data in the Apollo cache and use the
|
|
146
|
+
// `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
|
|
147
|
+
// NOTE: In development, we skip the query as long as the data hasn't been written
|
|
148
|
+
// into the cache. If not, Apollo throws an error like
|
|
149
|
+
// `Can't find field 'applicationMenu' on ROOT_QUERY object`.
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const _useMcQuery = dist_commercetoolsFrontendApplicationShell.useMcQuery(FetchApplicationsMenu, {
|
|
153
|
+
skip: config.environment.servedByProxy ? // Production environment
|
|
154
|
+
false : // Development environment
|
|
155
|
+
!hasWrittenToCache,
|
|
156
|
+
onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
|
|
157
|
+
fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
|
|
158
|
+
context: {
|
|
159
|
+
// Allow to overwrite the API url from application config
|
|
160
|
+
uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
|
|
161
|
+
skipGraphQlTargetCheck: true
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
|
|
165
|
+
// write it into the Apollo cache.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
react.useEffect(() => {
|
|
169
|
+
if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
170
|
+
config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
|
|
171
|
+
const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
|
|
172
|
+
apolloClient.writeQuery({
|
|
173
|
+
query: FetchApplicationsMenu,
|
|
174
|
+
data: applicationMenu
|
|
175
|
+
});
|
|
176
|
+
setHasWrittenToCache(true);
|
|
177
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
|
+
|
|
179
|
+
}, [hasWrittenToCache]); // Only subscribe to state changes.
|
|
180
|
+
|
|
181
|
+
if (menuQueryResult && menuQueryResult.applicationsMenu) {
|
|
182
|
+
return menuQueryResult.applicationsMenu[menuKey];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
exports.useApplicationsMenu = useApplicationsMenu;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NOTE
|
|
7
|
+
* This module wraps `replace` and `reload` from the window's location.
|
|
8
|
+
* This mainly helps in tests as we often expect that a reload or
|
|
9
|
+
* replace on the location happened.
|
|
10
|
+
* In previous code we could just overwrite the properties by:
|
|
11
|
+
* `window.location.replace = jest.fn()`
|
|
12
|
+
* This will fail in never versions of JSDOM (e.g. v16) as these
|
|
13
|
+
* properties are not writable anymore. JSDOM follows the browser standards
|
|
14
|
+
* which also state that these should not be writable.
|
|
15
|
+
* There are different options to solve this:
|
|
16
|
+
* 1. Extract those functions as a module an use `jest.mock` to mock them under test
|
|
17
|
+
* 2. Use `Object.defineProperty` to overwrite the property
|
|
18
|
+
* - The community opinion is that this is not preferred and does
|
|
19
|
+
* not work in all cases
|
|
20
|
+
* 3. Delete the property via `delete window.location` to re-create it after
|
|
21
|
+
* - This is quite repetiive and noisy in tests and can also remote
|
|
22
|
+
* other properties from under location
|
|
23
|
+
* Given option 2. and 3. being quite noisy on tests and against working with
|
|
24
|
+
* the stndards of the browser we will use 1. Here we only utilise the module
|
|
25
|
+
* mocking system of Jest and no other trickery.
|
|
26
|
+
* */
|
|
27
|
+
const replace = url => window.location.replace(url);
|
|
28
|
+
|
|
29
|
+
const reload = () => window.location.reload();
|
|
30
|
+
|
|
31
|
+
const location = {
|
|
32
|
+
replace,
|
|
33
|
+
reload
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const useIsServedByProxy = () => {
|
|
37
|
+
const servedByProxy = applicationShellConnectors.useApplicationContext(context => context.environment.servedByProxy);
|
|
38
|
+
return servedByProxy;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.location = location;
|
|
42
|
+
exports.useIsServedByProxy = useIsServedByProxy;
|