@commercetools-frontend/staff-bar 2.2.1 → 2.2.3

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.
@@ -28,6 +28,7 @@ var constants = require('@commercetools-frontend/constants');
28
28
  var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
29
29
  var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
30
30
  var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
31
+ var l10n = require('@commercetools-frontend/l10n');
31
32
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
32
33
  require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
33
34
  require('@babel/runtime-corejs3/helpers/classCallCheck');
@@ -79,16 +80,6 @@ var config = {
79
80
  url: "https://mc.us-east-2.aws.commercetools.com"
80
81
  }
81
82
  },
82
- AmazonWebServicesVolkswagen: {
83
- MerchantCenterFrontend: {
84
- url: "https://mc.vw.eu-central-1.aws.commercetools.com"
85
- }
86
- },
87
- AmazonWebServicesVolkswagenStaging: {
88
- MerchantCenterFrontend: {
89
- url: "https://mc.vw-stage.eu-central-1.aws.commercetools.com"
90
- }
91
- },
92
83
  GoogleCloudPlatformAustralia: {
93
84
  MerchantCenterFrontend: {
94
85
  url: "https://mc.australia-southeast1.gcp.commercetools.com"
@@ -138,7 +129,7 @@ const getOptionsForEnvironment = (label, config) => {
138
129
  };
139
130
  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);
140
131
  const AWS = _filterInstanceProperty__default["default"](_context2 = [getOptionsForEnvironment('AWS EU', config.AmazonWebServicesEurope), getOptionsForEnvironment('AWS US', config.AmazonWebServicesUnitedStates)]).call(_context2, nonNullable);
141
- const PRIVATE = _filterInstanceProperty__default["default"](_context3 = [getOptionsForEnvironment('AWS AT&T', config.AmazonWebServicesATT), getOptionsForEnvironment('AWS Volkswagen', config.AmazonWebServicesVolkswagen), getOptionsForEnvironment('AWS Volkswagen (Staging)', config.AmazonWebServicesVolkswagenStaging)]).call(_context3, nonNullable);
132
+ const PRIVATE = _filterInstanceProperty__default["default"](_context3 = [getOptionsForEnvironment('AWS AT&T', config.AmazonWebServicesATT)]).call(_context3, nonNullable);
142
133
  const ENV = [{
143
134
  options: GCP,
144
135
  group: 'GCP'
@@ -150,7 +141,7 @@ const ENV = [{
150
141
  group: 'Private'
151
142
  }];
152
143
 
153
- var _ref$5 = {
144
+ var _ref$6 = {
154
145
  name: "10r8dle",
155
146
  styles: "width:206px"
156
147
  } ;
@@ -186,7 +177,7 @@ const EnvironmentSwitcher = () => {
186
177
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
187
178
  children: "Environment"
188
179
  }), jsxRuntime.jsx("div", {
189
- css: _ref$5,
180
+ css: _ref$6,
190
181
  children: jsxRuntime.jsx(uiKit.SelectInput, {
191
182
  id: 'env-selector',
192
183
  name: 'env selector',
@@ -213,9 +204,10 @@ const GITHUB_PR_URL = 'https://github.com/commercetools/merchant-center-frontend
213
204
  const FEATURE_FLAG_KEY = 'toggled-feature-flags';
214
205
  const ACTIVE_TEAM_ID_KEY = 'activeTeamId';
215
206
  const ENABLE_LOG_KEY = 'enable-log';
207
+ const ACTIVE_USER_LANGUAGE_KEY = 'activeUserLanguage';
216
208
  const USER_ROLES_WITH_ALLOWED_ACCESS = ['Engineer', 'ProductProjectManagerOrOwner'];
217
209
 
218
- 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 } } } };
210
+ 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: [] }, { kind: "Field", name: { kind: "Name", value: "language" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 145, source: { body: "query FetchStaffBarUser {\n user: me {\n id\n launchdarklyTrackingGroup\n launchdarklyTrackingSubgroup\n businessRole\n language\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
219
211
  const useStaffBarUser = () => {
220
212
  const _useMcQuery = applicationShell.useMcQuery(FetchStaffBarUser, {
221
213
  context: {
@@ -230,6 +222,7 @@ const useStaffBarUser = () => {
230
222
  userId: data?.user?.id,
231
223
  isStaffMember: data?.user?.launchdarklyTrackingGroup === 'commercetools' || data?.user?.launchdarklyTrackingGroup === 'mailosaur',
232
224
  isDevMember: _includesInstanceProperty__default["default"](USER_ROLES_WITH_ALLOWED_ACCESS).call(USER_ROLES_WITH_ALLOWED_ACCESS, data?.user?.businessRole),
225
+ userLanguage: data?.user?.language,
233
226
  error
234
227
  };
235
228
  };
@@ -311,12 +304,19 @@ const useTeams = () => {
311
304
  data,
312
305
  options,
313
306
  activeTeamId,
314
- isLimitedPermission: storedId && storedId !== adminTeamId,
307
+ isLimitedPermission: Boolean(storedId) && storedId !== adminTeamId,
315
308
  error,
316
309
  loading
317
310
  };
318
311
  };
319
312
 
313
+ const useGetLanguagesUser = () => {
314
+ const userLocale = applicationShellConnectors.useApplicationContext(context => context?.user?.locale);
315
+ const _useLanguages = l10n.useLanguages(userLocale || ''),
316
+ data = _useLanguages.data;
317
+ return data;
318
+ };
319
+
320
320
  const launchdarklyAdapter = window.__flopflip__?.launchdarkly;
321
321
  function getFlagValue(flag, defaultValue) {
322
322
  // @ts-expect-error: getFlag exists not on all adapters and hence
@@ -344,13 +344,13 @@ const getFromSessionStorage = key => {
344
344
  };
345
345
  const setToSessionStorage = (key, value) => window.sessionStorage.setItem(key, _JSON$stringify__default["default"](value));
346
346
 
347
- var _ref$4 = {
347
+ var _ref$5 = {
348
348
  name: "mdo41b",
349
349
  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)"
350
350
  } ;
351
351
  function Divider() {
352
352
  return jsxRuntime.jsx("hr", {
353
- css: _ref$4
353
+ css: _ref$5
354
354
  });
355
355
  }
356
356
 
@@ -603,11 +603,11 @@ function GitHubPullRequestLink() {
603
603
  });
604
604
  }
605
605
 
606
- var _ref$3 = {
606
+ var _ref$4 = {
607
607
  name: "1jeqx8",
608
608
  styles: "width:242px"
609
609
  } ;
610
- var _ref2$2 = {
610
+ var _ref2$3 = {
611
611
  name: "14ronv",
612
612
  styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
613
613
  } ;
@@ -632,7 +632,7 @@ const TeamSwitcher = () => {
632
632
  const portalContainer = document.querySelector("[id='left-of-profile']");
633
633
  const container = jsxRuntime.jsx("div", {
634
634
  "data-testid": "limited-permission",
635
- css: _ref2$2,
635
+ css: _ref2$3,
636
636
  children: jsxRuntime.jsx(uiKit.Stamp, {
637
637
  tone: "warning",
638
638
  label: "Limited Permission"
@@ -644,7 +644,7 @@ const TeamSwitcher = () => {
644
644
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
645
645
  children: "Team"
646
646
  }), jsxRuntime.jsx("div", {
647
- css: _ref$3,
647
+ css: _ref$4,
648
648
  children: jsxRuntime.jsx(uiKit.SelectInput, {
649
649
  id: "team-selector",
650
650
  name: "Team Selector",
@@ -736,11 +736,11 @@ function getDurationBetween(type, deployedAt) {
736
736
  }
737
737
  return Math.round(Math.abs(+deployedDate - +today) / value);
738
738
  }
739
- var _ref$2 = {
739
+ var _ref$3 = {
740
740
  name: "1nxezmo",
741
741
  styles: "cursor:pointer!important;position:absolute;left:0;width:100%;button{width:100%;opacity:0;}"
742
742
  } ;
743
- var _ref2$1 = {
743
+ var _ref2$2 = {
744
744
  name: "bjn8wh",
745
745
  styles: "position:relative"
746
746
  } ;
@@ -832,11 +832,11 @@ const DeploymentTracker = () => {
832
832
  };
833
833
  if (!versions?.length) return null;
834
834
  return jsxRuntime.jsxs("div", {
835
- css: _ref2$1,
835
+ css: _ref2$2,
836
836
  children: [jsxRuntime.jsxs(uiKit.Stamp, {
837
837
  tone: getTone(getLastUpdate(currentApplication)),
838
838
  children: ["Last deployed: ", getLastUpdate(currentApplication).text, jsxRuntime.jsx("div", {
839
- css: _ref$2,
839
+ css: _ref$3,
840
840
  children: jsxRuntime.jsx(uiKit.SecondaryButton, {
841
841
  label: "",
842
842
  onClick: openModal,
@@ -867,14 +867,14 @@ const DeploymentTracker = () => {
867
867
  });
868
868
  };
869
869
 
870
- var _ref$1 = {
870
+ var _ref$2 = {
871
871
  name: "tkfx1x",
872
872
  styles: ">button{margin-right:27px!important;}"
873
873
  } ;
874
874
  function StaffBarInfo() {
875
875
  const infoModalState = applicationComponents.useModalState();
876
876
  return jsxRuntime.jsxs("div", {
877
- css: _ref$1,
877
+ css: _ref$2,
878
878
  children: [jsxRuntime.jsx(uiKit.IconButton, {
879
879
  size: "30",
880
880
  label: "",
@@ -896,6 +896,87 @@ function StaffBarInfo() {
896
896
  });
897
897
  }
898
898
 
899
+ const getActiveUserLanguage = () => window.sessionStorage.getItem(ACTIVE_USER_LANGUAGE_KEY);
900
+ const setActiveUserLanguage = language => window.sessionStorage.setItem(ACTIVE_USER_LANGUAGE_KEY, language);
901
+ const removeActiveUserLanguage = () => window.sessionStorage.removeItem(ACTIVE_USER_LANGUAGE_KEY);
902
+
903
+ var _ref$1 = {
904
+ name: "1jeqx8",
905
+ styles: "width:242px"
906
+ } ;
907
+ var _ref2$1 = {
908
+ name: "14ronv",
909
+ styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
910
+ } ;
911
+ const LanguageSwitcher = () => {
912
+ var _context;
913
+ const userLanguages = useGetLanguagesUser();
914
+ const _useStaffBarUser = useStaffBarUser(),
915
+ userDefaultLanguage = _useStaffBarUser.userLanguage;
916
+ const activeLanguage = getActiveUserLanguage() || userDefaultLanguage;
917
+ if (!userLanguages) {
918
+ return null;
919
+ }
920
+ const handleLanguageChange = (event, defaultLanguage) => {
921
+ const value = event.target.value;
922
+ if (value && typeof value === 'string') {
923
+ // If selected language matches the default from BE, remove from sessionStorage
924
+ // Otherwise, save the user's preference
925
+ if (value === defaultLanguage) {
926
+ removeActiveUserLanguage();
927
+ } else {
928
+ setActiveUserLanguage(value);
929
+ }
930
+ } else {
931
+ removeActiveUserLanguage();
932
+ }
933
+ window.location.reload();
934
+ };
935
+ const options = [{
936
+ options: _mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](userLanguages || {})).call(_context, _ref3 => {
937
+ let _ref4 = _slicedToArray(_ref3, 2),
938
+ locale = _ref4[0],
939
+ info = _ref4[1];
940
+ return {
941
+ value: locale,
942
+ label: info.country ? `${info.language} (${info.country}) (${locale})` : `${info.language} (${locale})`
943
+ };
944
+ })
945
+ }];
946
+ const isLanguageOverwritten = activeLanguage !== userDefaultLanguage;
947
+ const portalContainer = document.querySelector("[id='left-of-profile']");
948
+ const container = jsxRuntime.jsx("div", {
949
+ "data-testid": "limited-permission",
950
+ css: _ref2$1,
951
+ children: jsxRuntime.jsx(uiKit.Stamp, {
952
+ tone: "warning",
953
+ label: "User language overwritten"
954
+ })
955
+ });
956
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
957
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
958
+ alignItems: "center",
959
+ children: [jsxRuntime.jsx(uiKit.Text.Detail, {
960
+ children: "User Language"
961
+ }), jsxRuntime.jsx("div", {
962
+ css: _ref$1,
963
+ children: jsxRuntime.jsx(uiKit.SelectInput, {
964
+ id: "language-selector",
965
+ name: "Language Selector",
966
+ isSearchable: true,
967
+ horizontalConstraint: 5,
968
+ menuPortalTarget: document.body,
969
+ menuPortalZIndex: 30000,
970
+ onChange: event => handleLanguageChange(event, userDefaultLanguage),
971
+ value: activeLanguage,
972
+ options: options,
973
+ showOptionGroupDivider: true
974
+ })
975
+ })]
976
+ }), isLanguageOverwritten && portalContainer && /*#__PURE__*/ReactDOM__default["default"].createPortal(container, portalContainer)]
977
+ });
978
+ };
979
+
899
980
  var _ref = {
900
981
  name: "16u25pc",
901
982
  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);}"
@@ -939,7 +1020,7 @@ function StaffBar(props) {
939
1020
  scale: "l",
940
1021
  children: [jsxRuntime.jsx(GitHubPullRequestLink, {}), jsxRuntime.jsx(FeatureFlagToggler, {
941
1022
  featureFlags: props.featureFlags
942
- }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {})]
1023
+ }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {}), jsxRuntime.jsx(LanguageSwitcher, {})]
943
1024
  }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
944
1025
  scale: "l",
945
1026
  alignItems: "center",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/staff-bar",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Toolbar that makes testing inside Merchant Center easier",
5
5
  "license": "MIT",
6
6
  "main": "dist/commercetools-frontend-staff-bar.cjs.js",
@@ -16,33 +16,38 @@
16
16
  "@apollo/client": "3.12.4",
17
17
  "@babel/core": "^7.22.11",
18
18
  "@babel/runtime-corejs3": "^7.21.0",
19
- "@commercetools-frontend/application-components": "24.7.2",
20
- "@commercetools-frontend/application-shell": "24.7.2",
21
- "@commercetools-frontend/ui-kit": "20.2.3",
19
+ "@commercetools-frontend/l10n": "24.13.0",
20
+ "@commercetools-frontend/ui-kit": "20.3.0",
22
21
  "@flopflip/types": "14.0.1",
23
22
  "lodash": "4.17.21",
24
23
  "prop-types": "15.8.1",
25
- "react-dom": "19.2.0",
26
- "react-router-dom": "5.3.4",
27
24
  "typescript": "5.2.2"
28
25
  },
29
26
  "devDependencies": {
30
- "@commercetools-frontend/application-shell-connectors": "24.7.2",
31
- "@commercetools-frontend/constants": "24.7.2",
27
+ "@commercetools-frontend/application-components": "24.13.0",
28
+ "@commercetools-frontend/application-shell": "24.13.0",
29
+ "@commercetools-frontend/application-shell-connectors": "24.13.0",
30
+ "@commercetools-frontend/constants": "24.13.0",
32
31
  "@emotion/react": "11.14.0",
33
32
  "@manypkg/find-root": "2.2.3",
34
- "@types/react": "19.2.0",
35
- "@types/react-dom": "19.1.9",
33
+ "@types/react": "19.2.7",
34
+ "@types/react-dom": "19.2.3",
36
35
  "@types/react-router-dom": "5.3.3",
37
36
  "prettier": "2.8.8",
38
37
  "rcfile": "1.0.3",
39
- "react": "19.2.0"
38
+ "react": "19.2.3",
39
+ "react-dom": "19.2.3",
40
+ "react-router-dom": "5.3.4"
40
41
  },
41
42
  "peerDependencies": {
43
+ "@commercetools-frontend/application-components": "24.x",
44
+ "@commercetools-frontend/application-shell": "24.x",
42
45
  "@commercetools-frontend/application-shell-connectors": "24.x",
43
46
  "@commercetools-frontend/constants": "24.x",
44
47
  "@emotion/react": "11.x",
45
- "react": "19.x"
48
+ "react": "19.x",
49
+ "react-dom": "19.x",
50
+ "react-router-dom": "5.x"
46
51
  },
47
52
  "publishConfig": {
48
53
  "access": "public"