@commercetools-frontend/staff-bar 2.2.0 → 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');
@@ -110,6 +111,8 @@ var config = {
110
111
  }
111
112
  },
112
113
  "default": {
114
+ },
115
+ "module.exports": {
113
116
  }
114
117
  };
115
118
 
@@ -148,7 +151,7 @@ const ENV = [{
148
151
  group: 'Private'
149
152
  }];
150
153
 
151
- var _ref$5 = {
154
+ var _ref$6 = {
152
155
  name: "10r8dle",
153
156
  styles: "width:206px"
154
157
  } ;
@@ -184,7 +187,7 @@ const EnvironmentSwitcher = () => {
184
187
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
185
188
  children: "Environment"
186
189
  }), jsxRuntime.jsx("div", {
187
- css: _ref$5,
190
+ css: _ref$6,
188
191
  children: jsxRuntime.jsx(uiKit.SelectInput, {
189
192
  id: 'env-selector',
190
193
  name: 'env selector',
@@ -211,9 +214,10 @@ const GITHUB_PR_URL = 'https://github.com/commercetools/merchant-center-frontend
211
214
  const FEATURE_FLAG_KEY = 'toggled-feature-flags';
212
215
  const ACTIVE_TEAM_ID_KEY = 'activeTeamId';
213
216
  const ENABLE_LOG_KEY = 'enable-log';
217
+ const ACTIVE_USER_LANGUAGE_KEY = 'activeUserLanguage';
214
218
  const USER_ROLES_WITH_ALLOWED_ACCESS = ['Engineer', 'ProductProjectManagerOrOwner'];
215
219
 
216
- 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 } } } };
217
221
  const useStaffBarUser = () => {
218
222
  const _useMcQuery = applicationShell.useMcQuery(FetchStaffBarUser, {
219
223
  context: {
@@ -226,8 +230,9 @@ const useStaffBarUser = () => {
226
230
  error = _useMcQuery.error;
227
231
  return {
228
232
  userId: data?.user?.id,
229
- isStaffMember: data?.user?.launchdarklyTrackingGroup === 'commercetools',
233
+ isStaffMember: data?.user?.launchdarklyTrackingGroup === 'commercetools' || data?.user?.launchdarklyTrackingGroup === 'mailosaur',
230
234
  isDevMember: _includesInstanceProperty__default["default"](USER_ROLES_WITH_ALLOWED_ACCESS).call(USER_ROLES_WITH_ALLOWED_ACCESS, data?.user?.businessRole),
235
+ userLanguage: data?.user?.language,
231
236
  error
232
237
  };
233
238
  };
@@ -309,12 +314,19 @@ const useTeams = () => {
309
314
  data,
310
315
  options,
311
316
  activeTeamId,
312
- isLimitedPermission: storedId && storedId !== adminTeamId,
317
+ isLimitedPermission: Boolean(storedId) && storedId !== adminTeamId,
313
318
  error,
314
319
  loading
315
320
  };
316
321
  };
317
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
+
318
330
  const launchdarklyAdapter = window.__flopflip__?.launchdarkly;
319
331
  function getFlagValue(flag, defaultValue) {
320
332
  // @ts-expect-error: getFlag exists not on all adapters and hence
@@ -342,13 +354,13 @@ const getFromSessionStorage = key => {
342
354
  };
343
355
  const setToSessionStorage = (key, value) => window.sessionStorage.setItem(key, _JSON$stringify__default["default"](value));
344
356
 
345
- var _ref$4 = {
357
+ var _ref$5 = {
346
358
  name: "mdo41b",
347
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)"
348
360
  } ;
349
361
  function Divider() {
350
362
  return jsxRuntime.jsx("hr", {
351
- css: _ref$4
363
+ css: _ref$5
352
364
  });
353
365
  }
354
366
 
@@ -601,11 +613,11 @@ function GitHubPullRequestLink() {
601
613
  });
602
614
  }
603
615
 
604
- var _ref$3 = {
616
+ var _ref$4 = {
605
617
  name: "1jeqx8",
606
618
  styles: "width:242px"
607
619
  } ;
608
- var _ref2$2 = {
620
+ var _ref2$3 = {
609
621
  name: "14ronv",
610
622
  styles: "z-index:20001;display:flex;align-items:center;margin-right:16px;height:100%"
611
623
  } ;
@@ -630,7 +642,7 @@ const TeamSwitcher = () => {
630
642
  const portalContainer = document.querySelector("[id='left-of-profile']");
631
643
  const container = jsxRuntime.jsx("div", {
632
644
  "data-testid": "limited-permission",
633
- css: _ref2$2,
645
+ css: _ref2$3,
634
646
  children: jsxRuntime.jsx(uiKit.Stamp, {
635
647
  tone: "warning",
636
648
  label: "Limited Permission"
@@ -642,7 +654,7 @@ const TeamSwitcher = () => {
642
654
  children: [jsxRuntime.jsx(uiKit.Text.Detail, {
643
655
  children: "Team"
644
656
  }), jsxRuntime.jsx("div", {
645
- css: _ref$3,
657
+ css: _ref$4,
646
658
  children: jsxRuntime.jsx(uiKit.SelectInput, {
647
659
  id: "team-selector",
648
660
  name: "Team Selector",
@@ -734,11 +746,11 @@ function getDurationBetween(type, deployedAt) {
734
746
  }
735
747
  return Math.round(Math.abs(+deployedDate - +today) / value);
736
748
  }
737
- var _ref$2 = {
749
+ var _ref$3 = {
738
750
  name: "1nxezmo",
739
751
  styles: "cursor:pointer!important;position:absolute;left:0;width:100%;button{width:100%;opacity:0;}"
740
752
  } ;
741
- var _ref2$1 = {
753
+ var _ref2$2 = {
742
754
  name: "bjn8wh",
743
755
  styles: "position:relative"
744
756
  } ;
@@ -830,11 +842,11 @@ const DeploymentTracker = () => {
830
842
  };
831
843
  if (!versions?.length) return null;
832
844
  return jsxRuntime.jsxs("div", {
833
- css: _ref2$1,
845
+ css: _ref2$2,
834
846
  children: [jsxRuntime.jsxs(uiKit.Stamp, {
835
847
  tone: getTone(getLastUpdate(currentApplication)),
836
848
  children: ["Last deployed: ", getLastUpdate(currentApplication).text, jsxRuntime.jsx("div", {
837
- css: _ref$2,
849
+ css: _ref$3,
838
850
  children: jsxRuntime.jsx(uiKit.SecondaryButton, {
839
851
  label: "",
840
852
  onClick: openModal,
@@ -865,14 +877,14 @@ const DeploymentTracker = () => {
865
877
  });
866
878
  };
867
879
 
868
- var _ref$1 = {
880
+ var _ref$2 = {
869
881
  name: "tkfx1x",
870
882
  styles: ">button{margin-right:27px!important;}"
871
883
  } ;
872
884
  function StaffBarInfo() {
873
885
  const infoModalState = applicationComponents.useModalState();
874
886
  return jsxRuntime.jsxs("div", {
875
- css: _ref$1,
887
+ css: _ref$2,
876
888
  children: [jsxRuntime.jsx(uiKit.IconButton, {
877
889
  size: "30",
878
890
  label: "",
@@ -894,6 +906,87 @@ function StaffBarInfo() {
894
906
  });
895
907
  }
896
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
+
897
990
  var _ref = {
898
991
  name: "16u25pc",
899
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);}"
@@ -937,7 +1030,7 @@ function StaffBar(props) {
937
1030
  scale: "l",
938
1031
  children: [jsxRuntime.jsx(GitHubPullRequestLink, {}), jsxRuntime.jsx(FeatureFlagToggler, {
939
1032
  featureFlags: props.featureFlags
940
- }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {})]
1033
+ }), jsxRuntime.jsx(EnvironmentSwitcher, {}), jsxRuntime.jsx(TeamSwitcher, {}), jsxRuntime.jsx(LanguageSwitcher, {})]
941
1034
  }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
942
1035
  scale: "l",
943
1036
  alignItems: "center",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/staff-bar",
3
- "version": "2.2.0",
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.2.1",
20
- "@commercetools-frontend/application-shell": "24.2.1",
21
- "@commercetools-frontend/ui-kit": "20.2.2",
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.0.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.2.1",
31
- "@commercetools-frontend/constants": "24.2.1",
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.0.0",
35
- "@types/react-dom": "19.0.0",
33
+ "@types/react": "19.2.2",
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.0.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"