orc-shared 5.8.0-dev.12 → 5.8.0-dev.14

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.
@@ -58,6 +58,9 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
58
58
  display: "flex",
59
59
  alignItems: "center"
60
60
  },
61
+ scopeLabelInactive: {
62
+ color: theme.palette.secondary.light
63
+ },
61
64
  scopeIcon: {
62
65
  marginRight: theme.spacing(0.7),
63
66
  height: theme.spacing(2.4),
@@ -150,7 +153,9 @@ var ScopeLabel = exports.ScopeLabel = function ScopeLabel(_ref2) {
150
153
  type = _ref2.type,
151
154
  isRootScope = _ref2.isRootScope,
152
155
  hasChildren = _ref2.hasChildren,
153
- isVirtualScope = _ref2.isVirtualScope;
156
+ isVirtualScope = _ref2.isVirtualScope,
157
+ _ref2$isActive = _ref2.isActive,
158
+ isActive = _ref2$isActive === void 0 ? true : _ref2$isActive;
154
159
  var classes = useStyles({
155
160
  hasChildren: hasChildren
156
161
  });
@@ -163,7 +168,7 @@ var ScopeLabel = exports.ScopeLabel = function ScopeLabel(_ref2) {
163
168
  // 16.8 height of 1 lines of text
164
169
 
165
170
  var label = /*#__PURE__*/_react.default.createElement("div", {
166
- className: classes.scopeLabel
171
+ className: (0, _classnames.default)(classes.scopeLabel, isActive === false ? classes.scopeLabelInactive : "")
167
172
  }, icon, /*#__PURE__*/_react.default.createElement(_MultipleLinesText.default, {
168
173
  textProps: multipleLinesTextProps,
169
174
  children: name
@@ -208,7 +213,8 @@ var TreeItem = function TreeItem(_ref3) {
208
213
  type: scope.type,
209
214
  isRootScope: isRootScope,
210
215
  isVirtualScope: isVirtualScope,
211
- hasChildren: hasChildren
216
+ hasChildren: hasChildren,
217
+ isActive: scope.isActive
212
218
  }),
213
219
  expandIcon: isRootScope ? null : expandIcon,
214
220
  collapseIcon: isRootScope ? null : collapseIcon,
@@ -20,8 +20,20 @@ var trimSpacesAndLeadingZeros = exports.trimSpacesAndLeadingZeros = function tri
20
20
  if (fallback === void 0) {
21
21
  fallback = "";
22
22
  }
23
- var trimmed = (value != null ? value : "").trim().replace(/^0+/, "");
24
- return trimmed === "" ? fallback : limitNumericValueLength(trimmed);
23
+ if (!value || isNaN(value)) {
24
+ return fallback;
25
+ }
26
+ var trimmed = value.trim();
27
+ var isNegative = trimmed[0] === "-";
28
+ if (isNegative) {
29
+ trimmed = trimmed.substring(1, trimmed.length);
30
+ }
31
+ var withoutLeadingZeros = trimmed.replace(/^0+/, "");
32
+ if (withoutLeadingZeros == "") {
33
+ return "0";
34
+ }
35
+ var cleanNumber = "".concat(isNegative ? "-" : "").concat(withoutLeadingZeros);
36
+ return limitNumericValueLength(cleanNumber);
25
37
  };
26
38
  var limitNumericValueLength = exports.limitNumericValueLength = function limitNumericValueLength(value, maximum) {
27
39
  if (maximum === void 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "5.8.0-dev.12",
3
+ "version": "5.8.0-dev.14",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "@testing-library/react": "^10.4.9"
56
56
  },
57
57
  "dependencies": {
58
- "orc-scripts": "^4.0.0-dev.7",
58
+ "orc-scripts": "^4.0.0-dev.9",
59
59
  "react-number-format": "^5.3.0"
60
60
  },
61
61
  "sideEffects": false,
@@ -34,6 +34,9 @@ const useStyles = makeStyles(theme => ({
34
34
  display: "flex",
35
35
  alignItems: "center",
36
36
  },
37
+ scopeLabelInactive: {
38
+ color: theme.palette.secondary.light,
39
+ },
37
40
  scopeIcon: {
38
41
  marginRight: theme.spacing(0.7),
39
42
  height: theme.spacing(2.4),
@@ -102,7 +105,7 @@ export const ScopeIcon = ({ type }) => {
102
105
  }
103
106
  };
104
107
 
105
- export const ScopeLabel = ({ name, type, isRootScope, hasChildren, isVirtualScope }) => {
108
+ export const ScopeLabel = ({ name, type, isRootScope, hasChildren, isVirtualScope, isActive = true }) => {
106
109
  const classes = useStyles({ hasChildren });
107
110
 
108
111
  const icon = <ScopeIcon type={type} />;
@@ -116,7 +119,7 @@ export const ScopeLabel = ({ name, type, isRootScope, hasChildren, isVirtualScop
116
119
  // 16.8 height of 1 lines of text
117
120
 
118
121
  const label = (
119
- <div className={classes.scopeLabel}>
122
+ <div className={classNames(classes.scopeLabel, isActive === false ? classes.scopeLabelInactive : "")}>
120
123
  {icon}
121
124
  <MultipleLinesText textProps={multipleLinesTextProps} children={name} />
122
125
  </div>
@@ -153,6 +156,7 @@ const TreeItem = ({ scope, rootId, onScopeSelect, isScopeSelectable, children })
153
156
  isRootScope={isRootScope}
154
157
  isVirtualScope={isVirtualScope}
155
158
  hasChildren={hasChildren}
159
+ isActive={scope.isActive}
156
160
  />
157
161
  }
158
162
  expandIcon={isRootScope ? null : expandIcon}
@@ -50,6 +50,14 @@ describe("TreeItem", () => {
50
50
  children: ["TestSale"],
51
51
  };
52
52
 
53
+ const inActiveScope = {
54
+ id: "TestInactive",
55
+ name: "Test Inactive",
56
+ type: scopeTypes.sale,
57
+ children: [],
58
+ isActive: false,
59
+ };
60
+
53
61
  const saleScope = {
54
62
  id: "TestSale",
55
63
  name: "Test Sale",
@@ -109,6 +117,37 @@ describe("TreeItem", () => {
109
117
  expect(component, "when mounted", "to satisfy", expected);
110
118
  });
111
119
 
120
+ it("Renders Tree Item correctly for not active Scope", () => {
121
+ const expectedVirtualLabel = (
122
+ <ScopeLabel
123
+ name={inActiveScope.name}
124
+ type={inActiveScope.type}
125
+ isRootScope={false}
126
+ isVirtualScope={false}
127
+ isActive={false}
128
+ />
129
+ );
130
+
131
+ const component = (
132
+ <TestWrapper provider={{ store }} memoryRouter stylesProvider muiThemeProvider={{ theme }}>
133
+ <TreeItem scope={inActiveScope} rootId={rootId} />
134
+ </TestWrapper>
135
+ );
136
+
137
+ const expected = (
138
+ <TestWrapper stylesProvider muiThemeProvider={{ theme }}>
139
+ <TreeItemMui
140
+ nodeId={inActiveScope.id}
141
+ label={expectedVirtualLabel}
142
+ expandIcon={expandIcon}
143
+ collapseIcon={collapseIcon}
144
+ />
145
+ </TestWrapper>
146
+ );
147
+
148
+ expect(component, "when mounted", "to satisfy", expected);
149
+ });
150
+
112
151
  it("Calls scope select handler on label click if scope type is not virtual", () => {
113
152
  const component = (
114
153
  <TestWrapper provider={{ store }} memoryRouter stylesProvider muiThemeProvider={{ theme }}>
@@ -1,6 +1,22 @@
1
1
  export const trimSpacesAndLeadingZeros = (value, fallback = "") => {
2
- const trimmed = (value ?? "").trim().replace(/^0+/, "");
3
- return trimmed === "" ? fallback : limitNumericValueLength(trimmed);
2
+ if (!value || isNaN(value)) {
3
+ return fallback;
4
+ }
5
+
6
+ let trimmed = value.trim();
7
+ const isNegative = trimmed[0] === "-";
8
+ if (isNegative) {
9
+ trimmed = trimmed.substring(1, trimmed.length);
10
+ }
11
+
12
+ const withoutLeadingZeros = trimmed.replace(/^0+/, "");
13
+ if (withoutLeadingZeros == "") {
14
+ return "0";
15
+ }
16
+
17
+ const cleanNumber = `${isNegative ? "-" : ""}${withoutLeadingZeros}`;
18
+
19
+ return limitNumericValueLength(cleanNumber);
4
20
  };
5
21
 
6
22
  export const limitNumericValueLength = (value, maximum = 9) => value.substring(0, maximum);
@@ -5,14 +5,26 @@ describe("Numeric Input Helper", () => {
5
5
  expect(trimSpacesAndLeadingZeros, "when called with", [" 00013 "], "to equal", "13");
6
6
  });
7
7
 
8
- it("trimSpacesAndLeadingZeros trims spaces and leading zeros returning fallback value", () => {
9
- expect(trimSpacesAndLeadingZeros, "when called with", [" 000 ", "def"], "to equal", "def");
8
+ it("trimSpacesAndLeadingZeros trims spaces and leading zeros returning 0 when 000 value", () => {
9
+ expect(trimSpacesAndLeadingZeros, "when called with", [" 000 ", "def"], "to equal", "0");
10
+ });
11
+
12
+ it("trimSpacesAndLeadingZeros trims spaces and leading zeros returning fallback when empty string value", () => {
13
+ expect(trimSpacesAndLeadingZeros, "when called with", ["", "def"], "to equal", "def");
14
+ });
15
+
16
+ it("trimSpacesAndLeadingZeros trims spaces and leading zeros returning 0 when 0 value", () => {
17
+ expect(trimSpacesAndLeadingZeros, "when called with", [" 0 ", "def"], "to equal", "0");
10
18
  });
11
19
 
12
20
  it("trimSpacesAndLeadingZeros should work on floating values", () => {
13
21
  expect(trimSpacesAndLeadingZeros, "when called with", ["042.2", "def"], "to equal", "42.2");
14
22
  });
15
23
 
24
+ it("trimSpacesAndLeadingZeros should work on negative values", () => {
25
+ expect(trimSpacesAndLeadingZeros, "when called with", ["-0012.2", "def"], "to equal", "-12.2");
26
+ });
27
+
16
28
  it("trimSpacesAndLeadingZeros returns fallback on null value", () => {
17
29
  expect(trimSpacesAndLeadingZeros, "when called with", [null, "def"], "to equal", "def");
18
30
  });
@@ -21,6 +33,10 @@ describe("Numeric Input Helper", () => {
21
33
  expect(trimSpacesAndLeadingZeros, "when called with", [undefined, "def"], "to equal", "def");
22
34
  });
23
35
 
36
+ it("trimSpacesAndLeadingZeros returns fallback when value is not a number", () => {
37
+ expect(trimSpacesAndLeadingZeros, "when called with", ["hello", "def"], "to equal", "def");
38
+ });
39
+
24
40
  it("limitNumericValueLength trims extra characters", () => {
25
41
  expect(limitNumericValueLength, "when called with", ["01234567890"], "to equal", "012345678");
26
42
  });