@commercetools-frontend/staff-bar 2.2.1 → 2.2.2

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');
@@ -150,7 +151,7 @@ const ENV = [{
150
151
  group: 'Private'
151
152
  }];
152
153
 
153
- var _ref$5 = {
154
+ var _ref$6 = {
154
155
  name: "10r8dle",
155
156
  styles: "width:206px"
156
157
  } ;
@@ -186,7 +187,7 @@ const EnvironmentSwitcher = () => {
186
187
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
187
188
  children: "Environment"
188
189
  }), jsxRuntime.jsx("div", {
189
- css: _ref$5,
190
+ css: _ref$6,
190
191
  children: jsxRuntime.jsx(uiKit.SelectInput, {
191
192
  id: 'env-selector',
192
193
  name: 'env selector',
@@ -213,9 +214,10 @@ const GITHUB_PR_URL = 'https://github.com/commercetools/merchant-center-frontend
213
214
  const FEATURE_FLAG_KEY = 'toggled-feature-flags';
214
215
  const ACTIVE_TEAM_ID_KEY = 'activeTeamId';
215
216
  const ENABLE_LOG_KEY = 'enable-log';
217
+ const ACTIVE_USER_LANGUAGE_KEY = 'activeUserLanguage';
216
218
  const USER_ROLES_WITH_ALLOWED_ACCESS = ['Engineer', 'ProductProjectManagerOrOwner'];
217
219
 
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 } } } };
220
+ 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
221
  const useStaffBarUser = () => {
220
222
  const _useMcQuery = applicationShell.useMcQuery(FetchStaffBarUser, {
221
223
  context: {
@@ -230,6 +232,7 @@ const useStaffBarUser = () => {
230
232
  userId: data?.user?.id,
231
233
  isStaffMember: data?.user?.launchdarklyTrackingGroup === 'commercetools' || data?.user?.launchdarklyTrackingGroup === 'mailosaur',
232
234
  isDevMember: _includesInstanceProperty__default["default"](USER_ROLES_WITH_ALLOWED_ACCESS).call(USER_ROLES_WITH_ALLOWED_ACCESS, data?.user?.businessRole),
235
+ userLanguage: data?.user?.language,
233
236
  error
234
237
  };
235
238
  };
@@ -311,12 +314,19 @@ const useTeams = () => {
311
314
  data,
312
315
  options,
313
316
  activeTeamId,
314
- isLimitedPermission: storedId && storedId !== adminTeamId,
317
+ isLimitedPermission: Boolean(storedId) && storedId !== adminTeamId,
315
318
  error,
316
319
  loading
317
320
  };
318
321
  };
319
322
 
323
+ const useGetLanguagesUser = () => {
324
+ const userLocale = applicationShellConnectors.useApplicationContext(context => context?.user?.locale);
325
+ const _useLanguages = l10n.useLanguages(userLocale || ''),
326
+ data = _useLanguages.data;
327
+ return data;
328
+ };
329
+
320
330
  const launchdarklyAdapter = window.__flopflip__?.launchdarkly;
321
331
  function getFlagValue(flag, defaultValue) {
322
332
  // @ts-expect-error: getFlag exists not on all adapters and hence
@@ -344,13 +354,13 @@ const getFromSessionStorage = key => {
344
354
  };
345
355
  const setToSessionStorage = (key, value) => window.sessionStorage.setItem(key, _JSON$stringify__default["default"](value));
346
356
 
347
- var _ref$4 = {
357
+ var _ref$5 = {
348
358
  name: "mdo41b",
349
359
  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
360
  } ;
351
361
  function Divider() {
352
362
  return jsxRuntime.jsx("hr", {
353
- css: _ref$4
363
+ css: _ref$5
354
364
  });
355
365
  }
356
366
 
@@ -603,11 +613,11 @@ function GitHubPullRequestLink() {
603
613
  });
604
614
  }
605
615
 
606
- var _ref$3 = {
616
+ var _ref$4 = {
607
617
  name: "1jeqx8",
608
618
  styles: "width:242px"
609
619
  } ;
610
- var _ref2$2 = {
620
+ var _ref2$3 = {
611
621
  name: "14ronv",
612
622
  styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
613
623
  } ;
@@ -632,7 +642,7 @@ const TeamSwitcher = () => {
632
642
  const portalContainer = document.querySelector("[id='left-of-profile']");
633
643
  const container = jsxRuntime.jsx("div", {
634
644
  "data-testid": "limited-permission",
635
- css: _ref2$2,
645
+ css: _ref2$3,
636
646
  children: jsxRuntime.jsx(uiKit.Stamp, {
637
647
  tone: "warning",
638
648
  label: "Limited Permission"
@@ -644,7 +654,7 @@ const TeamSwitcher = () => {
644
654
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
645
655
  children: "Team"
646
656
  }), jsxRuntime.jsx("div", {
647
- css: _ref$3,
657
+ css: _ref$4,
648
658
  children: jsxRuntime.jsx(uiKit.SelectInput, {
649
659
  id: "team-selector",
650
660
  name: "Team Selector",
@@ -736,11 +746,11 @@ function getDurationBetween(type, deployedAt) {
736
746
  }
737
747
  return Math.round(Math.abs(+deployedDate - +today) / value);
738
748
  }
739
- var _ref$2 = {
749
+ var _ref$3 = {
740
750
  name: "1nxezmo",
741
751
  styles: "cursor:pointer!important;position:absolute;left:0;width:100%;button{width:100%;opacity:0;}"
742
752
  } ;
743
- var _ref2$1 = {
753
+ var _ref2$2 = {
744
754
  name: "bjn8wh",
745
755
  styles: "position:relative"
746
756
  } ;
@@ -832,11 +842,11 @@ const DeploymentTracker = () => {
832
842
  };
833
843
  if (!versions?.length) return null;
834
844
  return jsxRuntime.jsxs("div", {
835
- css: _ref2$1,
845
+ css: _ref2$2,
836
846
  children: [jsxRuntime.jsxs(uiKit.Stamp, {
837
847
  tone: getTone(getLastUpdate(currentApplication)),
838
848
  children: ["Last deployed: ", getLastUpdate(currentApplication).text, jsxRuntime.jsx("div", {
839
- css: _ref$2,
849
+ css: _ref$3,
840
850
  children: jsxRuntime.jsx(uiKit.SecondaryButton, {
841
851
  label: "",
842
852
  onClick: openModal,
@@ -867,14 +877,14 @@ const DeploymentTracker = () => {
867
877
  });
868
878
  };
869
879
 
870
- var _ref$1 = {
880
+ var _ref$2 = {
871
881
  name: "tkfx1x",
872
882
  styles: ">button{margin-right:27px!important;}"
873
883
  } ;
874
884
  function StaffBarInfo() {
875
885
  const infoModalState = applicationComponents.useModalState();
876
886
  return jsxRuntime.jsxs("div", {
877
- css: _ref$1,
887
+ css: _ref$2,
878
888
  children: [jsxRuntime.jsx(uiKit.IconButton, {
879
889
  size: "30",
880
890
  label: "",
@@ -896,6 +906,87 @@ function StaffBarInfo() {
896
906
  });
897
907
  }
898
908
 
909
+ const getActiveUserLanguage = () => window.sessionStorage.getItem(ACTIVE_USER_LANGUAGE_KEY);
910
+ const setActiveUserLanguage = language => window.sessionStorage.setItem(ACTIVE_USER_LANGUAGE_KEY, language);
911
+ const removeActiveUserLanguage = () => window.sessionStorage.removeItem(ACTIVE_USER_LANGUAGE_KEY);
912
+
913
+ var _ref$1 = {
914
+ name: "1jeqx8",
915
+ styles: "width:242px"
916
+ } ;
917
+ var _ref2$1 = {
918
+ name: "14ronv",
919
+ styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
920
+ } ;
921
+ const LanguageSwitcher = () => {
922
+ var _context;
923
+ const userLanguages = useGetLanguagesUser();
924
+ const _useStaffBarUser = useStaffBarUser(),
925
+ userDefaultLanguage = _useStaffBarUser.userLanguage;
926
+ const activeLanguage = getActiveUserLanguage() || userDefaultLanguage;
927
+ if (!userLanguages) {
928
+ return null;
929
+ }
930
+ const handleLanguageChange = (event, defaultLanguage) => {
931
+ const value = event.target.value;
932
+ if (value && typeof value === 'string') {
933
+ // If selected language matches the default from BE, remove from sessionStorage
934
+ // Otherwise, save the user's preference
935
+ if (value === defaultLanguage) {
936
+ removeActiveUserLanguage();
937
+ } else {
938
+ setActiveUserLanguage(value);
939
+ }
940
+ } else {
941
+ removeActiveUserLanguage();
942
+ }
943
+ window.location.reload();
944
+ };
945
+ const options = [{
946
+ options: _mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](userLanguages || {})).call(_context, _ref3 => {
947
+ let _ref4 = _slicedToArray(_ref3, 2),
948
+ locale = _ref4[0],
949
+ info = _ref4[1];
950
+ return {
951
+ value: locale,
952
+ label: info.country ? `${info.language} (${info.country}) (${locale})` : `${info.language} (${locale})`
953
+ };
954
+ })
955
+ }];
956
+ const isLanguageOverwritten = activeLanguage !== userDefaultLanguage;
957
+ const portalContainer = document.querySelector("[id='left-of-profile']");
958
+ const container = jsxRuntime.jsx("div", {
959
+ "data-testid": "limited-permission",
960
+ css: _ref2$1,
961
+ children: jsxRuntime.jsx(uiKit.Stamp, {
962
+ tone: "warning",
963
+ label: "User language overwritten"
964
+ })
965
+ });
966
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
967
+ children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
968
+ alignItems: "center",
969
+ children: [jsxRuntime.jsx(uiKit.Text.Detail, {
970
+ children: "User Language"
971
+ }), jsxRuntime.jsx("div", {
972
+ css: _ref$1,
973
+ children: jsxRuntime.jsx(uiKit.SelectInput, {
974
+ id: "language-selector",
975
+ name: "Language Selector",
976
+ isSearchable: true,
977
+ horizontalConstraint: 5,
978
+ menuPortalTarget: document.body,
979
+ menuPortalZIndex: 30000,
980
+ onChange: event => handleLanguageChange(event, userDefaultLanguage),
981
+ value: activeLanguage,
982
+ options: options,
983
+ showOptionGroupDivider: true
984
+ })
985
+ })]
986
+ }), isLanguageOverwritten && portalContainer && /*#__PURE__*/ReactDOM__default["default"].createPortal(container, portalContainer)]
987
+ });
988
+ };
989
+
899
990
  var _ref = {
900
991
  name: "16u25pc",
901
992
  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 +1030,7 @@ function StaffBar(props) {
939
1030
  scale: "l",
940
1031
  children: [jsxRuntime.jsx(GitHubPullRequestLink, {}), jsxRuntime.jsx(FeatureFlagToggler, {
941
1032
  featureFlags: props.featureFlags
942
- }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {})]
1033
+ }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {}), jsxRuntime.jsx(LanguageSwitcher, {})]
943
1034
  }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
944
1035
  scale: "l",
945
1036
  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.2",
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.11.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.11.0",
28
+ "@commercetools-frontend/application-shell": "24.11.0",
29
+ "@commercetools-frontend/application-shell-connectors": "24.11.0",
30
+ "@commercetools-frontend/constants": "24.11.0",
32
31
  "@emotion/react": "11.14.0",
33
32
  "@manypkg/find-root": "2.2.3",
34
- "@types/react": "19.2.0",
33
+ "@types/react": "19.2.2",
35
34
  "@types/react-dom": "19.1.9",
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.0",
39
+ "react-dom": "19.2.0",
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"