orc-shared 5.10.1-dev.2 → 5.10.1-dev.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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.useMenuProps = exports.default = exports.Menu = exports.CurrentApp = void 0;
5
- var _react = _interopRequireDefault(require("react"));
4
+ exports.useMenuProps = exports.sanitizeEnvironmentCode = exports.getAppEnvironmentInfo = exports.default = exports.Menu = exports.CurrentApp = void 0;
5
+ var _react = _interopRequireWildcard(require("react"));
6
6
  var _reactRedux = require("react-redux");
7
7
  var _reactIntl = require("react-intl");
8
8
  var _styles = require("@material-ui/core/styles");
@@ -16,9 +16,13 @@ var _DropMenu = _interopRequireDefault(require("../DropMenu"));
16
16
  var _Anchor = _interopRequireDefault(require("./Anchor"));
17
17
  var _Help = _interopRequireDefault(require("./Help"));
18
18
  var _sharedMessages = _interopRequireDefault(require("./../../sharedMessages"));
19
+ var _classnames = _interopRequireDefault(require("classnames"));
20
+ var _comparisonHelper = require("../../utils/comparisonHelper");
19
21
  var _excluded = ["menuLabel"],
20
22
  _excluded2 = ["applications", "applicationId", "currentApplication", "onClick", "helpUrl"];
21
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
25
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
26
  (function () {
23
27
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
24
28
  enterModule && enterModule(module);
@@ -27,6 +31,12 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
27
31
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
28
32
  enterModule && enterModule(module);
29
33
  })();
34
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
35
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
36
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
37
+ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(e, r) { return new BabelRegExp(e, void 0, r); }; var e = RegExp.prototype, r = new WeakMap(); function BabelRegExp(e, t, p) { var o = RegExp(e, t); return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype); } function buildGroups(e, t) { var p = r.get(t); return Object.keys(p).reduce(function (r, t) { var o = p[t]; if ("number" == typeof o) r[t] = e[o];else { for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++; r[t] = e[o[i]]; } return r; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) { var t = e.exec.call(this, r); if (t) { t.groups = buildGroups(t, this); var p = t.indices; p && (p.groups = buildGroups(p, this)); } return t; }, BabelRegExp.prototype[Symbol.replace] = function (t, p) { if ("string" == typeof p) { var o = r.get(this); return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) { var t = o[r]; return "$" + (Array.isArray(t) ? t.join("$") : t); })); } if ("function" == typeof p) { var i = this; return e[Symbol.replace].call(this, t, function () { var e = arguments; return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e); }); } return e[Symbol.replace].call(this, t, p); }, _wrapRegExp.apply(this, arguments); }
38
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
39
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
30
40
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
31
41
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
32
42
  var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
@@ -63,6 +73,22 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
63
73
  appLogo: {
64
74
  height: "30px",
65
75
  marginRight: "10px"
76
+ },
77
+ qaContainerColor: {
78
+ backgroundColor: "#9F0F18",
79
+ color: "#FFFFFF"
80
+ },
81
+ intContainerColor: {
82
+ backgroundColor: "#FCA311",
83
+ color: "#000000"
84
+ },
85
+ stgContainerColor: {
86
+ backgroundColor: "#19B9E6",
87
+ color: "#000000"
88
+ },
89
+ localdevContainerColor: {
90
+ backgroundColor: "#87E911",
91
+ color: "#000000"
66
92
  }
67
93
  };
68
94
  });
@@ -116,21 +142,126 @@ __signature__(Menu, "useMenuProps{{ menuLabel, ...menuProps }}", function () {
116
142
  __signature__(Menu, "useMenuProps{{ menuLabel, ...menuProps }}", function () {
117
143
  return [useMenuProps];
118
144
  });
145
+ var sanitizeEnvironmentCode = exports.sanitizeEnvironmentCode = function sanitizeEnvironmentCode(envCode) {
146
+ if (!envCode) {
147
+ return envCode;
148
+ }
149
+ envCode = envCode.toLowerCase();
150
+ var partialEnvCodes = ["prd",
151
+ // to support the old prdhi / prdlow used by SBD
152
+ "int",
153
+ // to support int, int2, etc
154
+ "qa",
155
+ // to support qa, qa2, etc
156
+ "stg",
157
+ // to support stg, stg2, etc
158
+ "localdev" // local development of the platform by product or service teams
159
+ ];
160
+ for (var _i = 0, _partialEnvCodes = partialEnvCodes; _i < _partialEnvCodes.length; _i++) {
161
+ var partialEnvCode = _partialEnvCodes[_i];
162
+ if (envCode.startsWith(partialEnvCode)) {
163
+ return partialEnvCode;
164
+ }
165
+ }
166
+ return envCode; // other names will be used as-is
167
+ };
168
+ var getAppEnvironmentInfo = exports.getAppEnvironmentInfo = function getAppEnvironmentInfo(currentLocation, uiContainerName) {
169
+ var environmentCode = null;
170
+ var sanitizedEnvironmentCode = null;
171
+ var isDeployedLocalDevEnv = false;
172
+ var domainMatch = currentLocation == null ? void 0 : currentLocation.match(/*#__PURE__*/_wrapRegExp(/^([^.]+)\.([^.]+)\.([^.]+)\.orckestra\.(cloud|org)$/, {
173
+ appName: 1,
174
+ envCode: 2,
175
+ clientCode: 3
176
+ }));
177
+ if (domainMatch) {
178
+ environmentCode = domainMatch.groups.envCode;
179
+ } else if (currentLocation != null && currentLocation.toLowerCase().endsWith("local.develop.orckestra.cloud") || (currentLocation == null ? void 0 : currentLocation.toLowerCase()) === "localhost") {
180
+ environmentCode = "localdev";
181
+ } else if (currentLocation != null && currentLocation.toLowerCase().endsWith("develop.orckestra.cloud")) {
182
+ environmentCode = "localdev";
183
+ isDeployedLocalDevEnv = true;
184
+ }
185
+
186
+ // uncomment if you want to force a specific environment / color
187
+ // environmentCode = "prd";
188
+
189
+ sanitizedEnvironmentCode = sanitizeEnvironmentCode(environmentCode);
190
+ if (!sanitizedEnvironmentCode || sanitizedEnvironmentCode === "rel") {
191
+ // we never want a different color / text for our rel environment
192
+ return {
193
+ name: "",
194
+ cssClassCategory: null
195
+ };
196
+ }
197
+ if (!uiContainerName) {
198
+ uiContainerName = "prd"; // fallback in case the container is not defined in a meta tag
199
+ }
200
+ var needCustomCssClass = !!sanitizedEnvironmentCode && !(0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "prd") || !(0, _comparisonHelper.areEqualCaseInsensitive)(uiContainerName, "prd");
201
+ var cssClassCategory = null;
202
+ var nameParts = [];
203
+ if (!(0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "prd")) {
204
+ nameParts.push(environmentCode);
205
+ }
206
+ if (needCustomCssClass) {
207
+ var needBuildNumber = false;
208
+ var isPrdUiContainer = (0, _comparisonHelper.areEqualCaseInsensitive)(uiContainerName, "prd");
209
+ if ((0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "prd")) {
210
+ cssClassCategory = "qa"; // if we end up here, it means that our prd environment is using a different UI container
211
+ needBuildNumber = !isPrdUiContainer;
212
+ } else if ((0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "localdev")) {
213
+ cssClassCategory = "localdev";
214
+ needBuildNumber = !isPrdUiContainer && isDeployedLocalDevEnv;
215
+ } else if ((0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "qa")) {
216
+ cssClassCategory = "qa";
217
+ needBuildNumber = !isPrdUiContainer;
218
+ } else if ((0, _comparisonHelper.areEqualCaseInsensitive)(sanitizedEnvironmentCode, "stg")) {
219
+ cssClassCategory = "stg";
220
+ needBuildNumber = !isPrdUiContainer;
221
+ } else {
222
+ // any other container have the int look
223
+ cssClassCategory = "int";
224
+ needBuildNumber = !isPrdUiContainer;
225
+ }
226
+ if (needBuildNumber) {
227
+ nameParts.push("".concat(window.BUILD_NUMBER, "/").concat(uiContainerName));
228
+ }
229
+ }
230
+ return {
231
+ name: nameParts.join(" — "),
232
+ cssClassCategory: cssClassCategory
233
+ };
234
+ };
119
235
  var CurrentApp = exports.CurrentApp = function CurrentApp(_ref) {
120
236
  var displayName = _ref.displayName,
121
237
  iconUri = _ref.iconUri;
122
238
  var classes = useStyles();
239
+ var containerInfo = (0, _react.useMemo)(function () {
240
+ var _document$querySelect;
241
+ return getAppEnvironmentInfo(window.location.hostname, (_document$querySelect = document.querySelector('meta[name="cdn-container-name"]')) == null ? void 0 : _document$querySelect.getAttribute("content"));
242
+ }, []);
243
+ var name;
244
+ if (containerInfo.name) {
245
+ if (displayName) {
246
+ // to avoid issues with tests where "undefined" ends up in the name
247
+ name = "".concat(displayName, " \u2014 ").concat(containerInfo.name);
248
+ } else {
249
+ name = " \u2014 ".concat(containerInfo.name);
250
+ }
251
+ } else {
252
+ name = displayName;
253
+ }
123
254
  return /*#__PURE__*/_react.default.createElement("div", {
124
- className: classes.appLabel
255
+ className: (0, _classnames.default)(classes.appLabel, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, classes.qaContainerColor, containerInfo.cssClassCategory === "qa"), classes.intContainerColor, containerInfo.cssClassCategory === "int"), classes.stgContainerColor, containerInfo.cssClassCategory === "stg"), classes.localdevContainerColor, containerInfo.cssClassCategory === "localdev"))
125
256
  }, /*#__PURE__*/_react.default.createElement("img", {
126
257
  src: iconUri,
127
258
  className: classes.appLogo
128
- }), displayName);
259
+ }), name);
129
260
  };
130
- __signature__(CurrentApp, "useStyles{classes}", function () {
261
+ __signature__(CurrentApp, "useStyles{classes}\nuseMemo{containerInfo}", function () {
131
262
  return [useStyles];
132
263
  });
133
- __signature__(CurrentApp, "useStyles{classes}", function () {
264
+ __signature__(CurrentApp, "useStyles{classes}\nuseMemo{containerInfo}", function () {
134
265
  return [useStyles];
135
266
  });
136
267
  CurrentApp.displayName = "CurrentApp";
@@ -173,6 +304,8 @@ var _default3 = exports.default = _default2;
173
304
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
174
305
  reactHotLoader.register(useMenuProps, "useMenuProps", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
175
306
  reactHotLoader.register(Menu, "Menu", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
307
+ reactHotLoader.register(sanitizeEnvironmentCode, "sanitizeEnvironmentCode", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
308
+ reactHotLoader.register(getAppEnvironmentInfo, "getAppEnvironmentInfo", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
176
309
  reactHotLoader.register(CurrentApp, "CurrentApp", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
177
310
  reactHotLoader.register(Topbar, "Topbar", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
178
311
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
@@ -191,6 +324,8 @@ var _default3 = exports.default = _default2;
191
324
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
192
325
  reactHotLoader.register(useMenuProps, "useMenuProps", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
193
326
  reactHotLoader.register(Menu, "Menu", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
327
+ reactHotLoader.register(sanitizeEnvironmentCode, "sanitizeEnvironmentCode", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
328
+ reactHotLoader.register(getAppEnvironmentInfo, "getAppEnvironmentInfo", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
194
329
  reactHotLoader.register(CurrentApp, "CurrentApp", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
195
330
  reactHotLoader.register(Topbar, "Topbar", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
196
331
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/AppFrame/Topbar.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "5.10.1-dev.2",
3
+ "version": "5.10.1-dev.3",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { useDispatch, useSelector } from "react-redux";
3
3
  import { useIntl } from "react-intl";
4
4
  import { makeStyles } from "@material-ui/core/styles";
@@ -12,6 +12,8 @@ import DropMenu from "../DropMenu";
12
12
  import Anchor from "./Anchor";
13
13
  import Help from "./Help";
14
14
  import sharedMessages from "./../../sharedMessages";
15
+ import classNames from "classnames";
16
+ import { areEqualCaseInsensitive } from "../../utils/comparisonHelper";
15
17
 
16
18
  const useStyles = makeStyles(theme => ({
17
19
  wrapper: {
@@ -41,6 +43,22 @@ const useStyles = makeStyles(theme => ({
41
43
  height: "30px",
42
44
  marginRight: "10px",
43
45
  },
46
+ qaContainerColor: {
47
+ backgroundColor: "#9F0F18",
48
+ color: "#FFFFFF",
49
+ },
50
+ intContainerColor: {
51
+ backgroundColor: "#FCA311",
52
+ color: "#000000",
53
+ },
54
+ stgContainerColor: {
55
+ backgroundColor: "#19B9E6",
56
+ color: "#000000",
57
+ },
58
+ localdevContainerColor: {
59
+ backgroundColor: "#87E911",
60
+ color: "#000000",
61
+ },
44
62
  }));
45
63
 
46
64
  export const useMenuProps = () => {
@@ -81,13 +99,146 @@ export const Menu = () => {
81
99
  );
82
100
  };
83
101
 
102
+ export const sanitizeEnvironmentCode = envCode => {
103
+ if (!envCode) {
104
+ return envCode;
105
+ }
106
+
107
+ envCode = envCode.toLowerCase();
108
+
109
+ const partialEnvCodes = [
110
+ "prd", // to support the old prdhi / prdlow used by SBD
111
+ "int", // to support int, int2, etc
112
+ "qa", // to support qa, qa2, etc
113
+ "stg", // to support stg, stg2, etc
114
+ "localdev", // local development of the platform by product or service teams
115
+ ];
116
+
117
+ for (const partialEnvCode of partialEnvCodes) {
118
+ if (envCode.startsWith(partialEnvCode)) {
119
+ return partialEnvCode;
120
+ }
121
+ }
122
+
123
+ return envCode; // other names will be used as-is
124
+ };
125
+
126
+ export const getAppEnvironmentInfo = (currentLocation, uiContainerName) => {
127
+ let environmentCode = null;
128
+ let sanitizedEnvironmentCode = null;
129
+ let isDeployedLocalDevEnv = false;
130
+
131
+ const domainMatch = currentLocation?.match(
132
+ /^(?<appName>[^.]+)\.(?<envCode>[^.]+)\.(?<clientCode>[^.]+)\.orckestra\.(cloud|org)$/,
133
+ );
134
+
135
+ if (domainMatch) {
136
+ environmentCode = domainMatch.groups.envCode;
137
+ } else if (
138
+ currentLocation?.toLowerCase().endsWith("local.develop.orckestra.cloud") ||
139
+ currentLocation?.toLowerCase() === "localhost"
140
+ ) {
141
+ environmentCode = "localdev";
142
+ } else if (currentLocation?.toLowerCase().endsWith("develop.orckestra.cloud")) {
143
+ environmentCode = "localdev";
144
+ isDeployedLocalDevEnv = true;
145
+ }
146
+
147
+ // uncomment if you want to force a specific environment / color
148
+ // environmentCode = "prd";
149
+
150
+ sanitizedEnvironmentCode = sanitizeEnvironmentCode(environmentCode);
151
+
152
+ if (!sanitizedEnvironmentCode || sanitizedEnvironmentCode === "rel") {
153
+ // we never want a different color / text for our rel environment
154
+ return {
155
+ name: "",
156
+ cssClassCategory: null,
157
+ };
158
+ }
159
+
160
+ if (!uiContainerName) {
161
+ uiContainerName = "prd"; // fallback in case the container is not defined in a meta tag
162
+ }
163
+
164
+ const needCustomCssClass =
165
+ (!!sanitizedEnvironmentCode && !areEqualCaseInsensitive(sanitizedEnvironmentCode, "prd")) ||
166
+ !areEqualCaseInsensitive(uiContainerName, "prd");
167
+
168
+ let cssClassCategory = null;
169
+
170
+ const nameParts = [];
171
+
172
+ if (!areEqualCaseInsensitive(sanitizedEnvironmentCode, "prd")) {
173
+ nameParts.push(environmentCode);
174
+ }
175
+
176
+ if (needCustomCssClass) {
177
+ let needBuildNumber = false;
178
+ const isPrdUiContainer = areEqualCaseInsensitive(uiContainerName, "prd");
179
+
180
+ if (areEqualCaseInsensitive(sanitizedEnvironmentCode, "prd")) {
181
+ cssClassCategory = "qa"; // if we end up here, it means that our prd environment is using a different UI container
182
+ needBuildNumber = !isPrdUiContainer;
183
+ } else if (areEqualCaseInsensitive(sanitizedEnvironmentCode, "localdev")) {
184
+ cssClassCategory = "localdev";
185
+ needBuildNumber = !isPrdUiContainer && isDeployedLocalDevEnv;
186
+ } else if (areEqualCaseInsensitive(sanitizedEnvironmentCode, "qa")) {
187
+ cssClassCategory = "qa";
188
+ needBuildNumber = !isPrdUiContainer;
189
+ } else if (areEqualCaseInsensitive(sanitizedEnvironmentCode, "stg")) {
190
+ cssClassCategory = "stg";
191
+ needBuildNumber = !isPrdUiContainer;
192
+ } else {
193
+ // any other container have the int look
194
+ cssClassCategory = "int";
195
+ needBuildNumber = !isPrdUiContainer;
196
+ }
197
+
198
+ if (needBuildNumber) {
199
+ nameParts.push(`${window.BUILD_NUMBER}/${uiContainerName}`);
200
+ }
201
+ }
202
+
203
+ return {
204
+ name: nameParts.join(" — "),
205
+ cssClassCategory: cssClassCategory,
206
+ };
207
+ };
208
+
84
209
  export const CurrentApp = ({ displayName, iconUri }) => {
85
210
  const classes = useStyles();
211
+ const containerInfo = useMemo(() => {
212
+ return getAppEnvironmentInfo(
213
+ window.location.hostname,
214
+ document.querySelector('meta[name="cdn-container-name"]')?.getAttribute("content"),
215
+ );
216
+ }, []);
217
+
218
+ let name;
219
+
220
+ if (containerInfo.name) {
221
+ if (displayName) {
222
+ // to avoid issues with tests where "undefined" ends up in the name
223
+ name = `${displayName} — ${containerInfo.name}`;
224
+ } else {
225
+ name = ` — ${containerInfo.name}`;
226
+ }
227
+ } else {
228
+ name = displayName;
229
+ }
86
230
 
87
231
  return (
88
- <div className={classes.appLabel}>
232
+ <div
233
+ className={classNames(classes.appLabel, {
234
+ [classes.qaContainerColor]: containerInfo.cssClassCategory === "qa",
235
+ [classes.intContainerColor]: containerInfo.cssClassCategory === "int",
236
+ [classes.stgContainerColor]: containerInfo.cssClassCategory === "stg",
237
+ [classes.localdevContainerColor]: containerInfo.cssClassCategory === "localdev",
238
+ })}
239
+ >
89
240
  <img src={iconUri} className={classes.appLogo} />
90
- {displayName}
241
+ {name}
91
242
  </div>
92
243
  );
93
244
  };
@@ -10,7 +10,7 @@ import { SIGN_OUT_REQUEST, SIGN_OUT_SUCCESS, SIGN_OUT_FAILURE } from "../../acti
10
10
  import { PREFS_NAME } from "./Preferences";
11
11
  import { ABOUT_NAME } from "./About";
12
12
  import ApplicationSelector from "./ApplicationSelector";
13
- import Topbar, { CurrentApp, useMenuProps } from "./Topbar";
13
+ import Topbar, { CurrentApp, getAppEnvironmentInfo, sanitizeEnvironmentCode, useMenuProps } from "./Topbar";
14
14
 
15
15
  jest.mock("../../utils/buildUrl", () => {
16
16
  const modExport = {};
@@ -80,7 +80,7 @@ describe("Topbar", () => {
80
80
  <ApplicationSelector {...props} />
81
81
  <div>
82
82
  <img src="/test/url" />
83
- Test label
83
+ Test label — localdev
84
84
  </div>
85
85
  </div>
86
86
  <Ignore />
@@ -102,6 +102,7 @@ describe("Topbar", () => {
102
102
  <Ignore />
103
103
  <div>
104
104
  <img />
105
+ {" — localdev"}
105
106
  </div>
106
107
  </div>
107
108
  <Ignore />
@@ -123,6 +124,7 @@ describe("Topbar", () => {
123
124
  <Ignore />
124
125
  <div>
125
126
  <img />
127
+ {" — localdev"}
126
128
  </div>
127
129
  </div>
128
130
  <Ignore />
@@ -232,7 +234,20 @@ describe("useMenuProps", () => {
232
234
  ));
233
235
  });
234
236
 
235
- describe("CurrentApp", () => {
237
+ describe("CurrentApp for production site", () => {
238
+ const { location } = window;
239
+
240
+ beforeAll(() => {
241
+ delete window.location;
242
+
243
+ window.location = {
244
+ hostname: "oco.prd.platform.orckestra.cloud",
245
+ };
246
+ });
247
+ afterAll(() => {
248
+ window.location = location;
249
+ });
250
+
236
251
  it("renders the app logo and name", () =>
237
252
  expect(
238
253
  <CurrentApp displayName="Test label" iconUri="/test/url" />,
@@ -244,3 +259,143 @@ describe("CurrentApp", () => {
244
259
  </div>,
245
260
  ));
246
261
  });
262
+
263
+ describe("CurrentApp for localhost", () => {
264
+ it("renders the app logo and name and with build info", () => {
265
+ expect(
266
+ <CurrentApp displayName="Test label" iconUri="/test/url" />,
267
+ "when mounted",
268
+ "to satisfy",
269
+ <div>
270
+ <img src="/test/url" />
271
+ Test label — localdev
272
+ </div>,
273
+ );
274
+ });
275
+ });
276
+
277
+ describe("sanitizeEnvironmentCode", () => {
278
+ it.each([
279
+ [null, null],
280
+ [undefined, undefined],
281
+ ["demo1", "demo1"],
282
+ ["prd", "prd"],
283
+ ["prdhi", "prd"],
284
+ ["prd2", "prd"],
285
+ ["qa", "qa"],
286
+ ["qahi", "qa"],
287
+ ["qa2", "qa"],
288
+ ["int", "int"],
289
+ ["inthi", "int"],
290
+ ["int2", "int"],
291
+ ["stg", "stg"],
292
+ ["stghi", "stg"],
293
+ ["stg2", "stg"],
294
+ ["localdev", "localdev"],
295
+ ["localdevhi", "localdev"],
296
+ ["localdev2", "localdev"],
297
+ ])("Should sanitize %s as %s", (code, expectedSanitizedVersion) => {
298
+ const sanitizedVersion = sanitizeEnvironmentCode(code);
299
+
300
+ expect(sanitizedVersion, "to equal", expectedSanitizedVersion);
301
+ });
302
+ });
303
+
304
+ describe("getAppEnvironmentInfo", () => {
305
+ let originalBuildNumber;
306
+
307
+ beforeEach(() => {
308
+ originalBuildNumber = window.BUILD_NUMBER;
309
+ window.BUILD_NUMBER = "1.2-alpha888";
310
+ });
311
+
312
+ afterEach(() => {
313
+ window.BUILD_NUMBER = originalBuildNumber;
314
+ });
315
+
316
+ it.each([
317
+ [null, "prd", "", null],
318
+ ["", "prd", "", null],
319
+ ["prd", null, "", null],
320
+ ["prd", "", "", null],
321
+ ["prd", "prd", "", null],
322
+ ["prd", "qa", "1.2-alpha888/qa", "qa"],
323
+ ["prd", "int", "1.2-alpha888/int", "qa"],
324
+ ["qa", "prd", "qa", "qa"],
325
+ ["qa", "qa", "qa — 1.2-alpha888/qa", "qa"],
326
+ ["qa", "int", "qa — 1.2-alpha888/int", "qa"],
327
+ ["int", "prd", "int", "int"],
328
+ ["int", "qa", "int — 1.2-alpha888/qa", "int"],
329
+ ["int", "int", "int — 1.2-alpha888/int", "int"],
330
+ ["stg", "prd", "stg", "stg"],
331
+ ["stg", "stg", "stg — 1.2-alpha888/stg", "stg"],
332
+ ["stg", "int", "stg — 1.2-alpha888/int", "stg"],
333
+ ["demo1", "prd", "demo1", "int"],
334
+ ["demo1", "stg", "demo1 — 1.2-alpha888/stg", "int"],
335
+ ["demo1", "int", "demo1 — 1.2-alpha888/int", "int"],
336
+ ["rel", "prd", "", null],
337
+ ["rel", "stg", "", null],
338
+ ["rel", "int", "", null],
339
+ ["localdev", "prd", "localdev", "localdev"],
340
+ ["localdev", "qa", "localdev", "localdev"],
341
+ ])(
342
+ "getAppEnvironmentInfo for %s url and %s UI container",
343
+ (envCode, uiContainerName, expectedName, expectedCssClassCategory) => {
344
+ const info = getAppEnvironmentInfo(
345
+ envCode ? `oco.${envCode}.platform.orckestra.cloud` : envCode,
346
+ uiContainerName,
347
+ );
348
+
349
+ const expected = {
350
+ name: expectedName,
351
+ cssClassCategory: expectedCssClassCategory,
352
+ };
353
+
354
+ expect(info, "to equal", expected);
355
+ },
356
+ );
357
+
358
+ it("getAppEnvironmentInfo for localdev (occ-dev-oco.develop.orckestra.cloud) and prd UI container", () => {
359
+ const info = getAppEnvironmentInfo("occ-dev-oco.develop.orckestra.cloud", "prd");
360
+
361
+ const expected = {
362
+ name: "localdev",
363
+ cssClassCategory: "localdev",
364
+ };
365
+
366
+ expect(info, "to equal", expected);
367
+ });
368
+
369
+ it("getAppEnvironmentInfo for localdev (occ-dev-oco.develop.orckestra.cloud) and qa UI container", () => {
370
+ const info = getAppEnvironmentInfo("occ-dev-oco.develop.orckestra.cloud", "qa");
371
+
372
+ const expected = {
373
+ name: "localdev — 1.2-alpha888/qa",
374
+ cssClassCategory: "localdev",
375
+ };
376
+
377
+ expect(info, "to equal", expected);
378
+ });
379
+
380
+ it("getAppEnvironmentInfo for localdev (local.develop.orckestra.cloud) and prd UI container", () => {
381
+ const info = getAppEnvironmentInfo("local.develop.orckestra.cloud", "prd");
382
+
383
+ const expected = {
384
+ name: "localdev",
385
+ cssClassCategory: "localdev",
386
+ };
387
+
388
+ expect(info, "to equal", expected);
389
+ });
390
+
391
+ it("getAppEnvironmentInfo for localdev (localhost) and prd UI container", () => {
392
+ const info = getAppEnvironmentInfo("localhost", "prd");
393
+
394
+ const expected = {
395
+ name: "localdev",
396
+ cssClassCategory: "localdev",
397
+ };
398
+
399
+ expect(info, "to equal", expected);
400
+ });
401
+ });