orc-shared 1.2.0-dev.12 → 1.2.0-dev.13

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.
@@ -29,6 +29,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
29
  enterModule && enterModule(module);
30
30
  })();
31
31
 
32
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
33
+
34
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
35
+
36
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
37
+
38
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
39
+
40
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
41
+
42
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
43
+
32
44
  var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
33
45
  return a;
34
46
  };
@@ -159,11 +171,36 @@ var InputBase = function InputBase(_ref) {
159
171
 
160
172
  var onChangeHandler = function onChangeHandler(event) {
161
173
  event.persist();
162
- update(event.target.value, metadata);
174
+
175
+ if (!event.target.value || window.bypassDebounce === true) {
176
+ update(event.target.value, metadata);
177
+ }
178
+
179
+ setInputText(event.target.value);
163
180
  };
164
181
 
165
182
  var inputBaseInputStyle = inputProps == null ? void 0 : inputProps.getStyle(_InputBaseProps.default.ruleNames.input);
166
183
  var errorTextStyle = inputProps == null ? void 0 : inputProps.getStyle(_InputBaseProps.default.ruleNames.errorText);
184
+
185
+ var _React$useState = _react.default.useState(null),
186
+ _React$useState2 = _slicedToArray(_React$useState, 2),
187
+ inputText = _React$useState2[0],
188
+ setInputText = _React$useState2[1];
189
+
190
+ var textToDisplay = inputText != null ? inputText : value;
191
+
192
+ _react.default.useEffect(function () {
193
+ if (inputText !== value && inputText != null && window.bypassDebounce !== true) {
194
+ var timeOutId = setTimeout(function () {
195
+ return update(inputText, metadata);
196
+ }, 100);
197
+ return function () {
198
+ return clearTimeout(timeOutId);
199
+ };
200
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
201
+
202
+ }, [inputText, value]);
203
+
167
204
  return /*#__PURE__*/_react.default.createElement("div", {
168
205
  className: classes.container
169
206
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -182,7 +219,7 @@ var InputBase = function InputBase(_ref) {
182
219
  onClick: onClick,
183
220
  type: type,
184
221
  placeholder: placeholder,
185
- value: value,
222
+ value: textToDisplay,
186
223
  fullWidth: true,
187
224
  onChange: function onChange(event) {
188
225
  return onChangeHandler(event);
@@ -201,11 +238,11 @@ var InputBase = function InputBase(_ref) {
201
238
  }, error));
202
239
  };
203
240
 
204
- __signature__(InputBase, "useStyles{classes}", function () {
241
+ __signature__(InputBase, "useStyles{classes}\nuseState{[inputText, setInputText](null)}\nuseEffect{}", function () {
205
242
  return [useStyles];
206
243
  });
207
244
 
208
- __signature__(InputBase, "useStyles{classes}", function () {
245
+ __signature__(InputBase, "useStyles{classes}\nuseState{[inputText, setInputText](null)}\nuseEffect{}", function () {
209
246
  return [useStyles];
210
247
  });
211
248
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.2.0-dev.12",
3
+ "version": "1.2.0-dev.13",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -18,6 +18,8 @@ describe("Translations ", () => {
18
18
  const theme = createMuiTheme();
19
19
 
20
20
  beforeEach(() => {
21
+ window.bypassDebounce = true;
22
+
21
23
  collapsibleListProps = new CollapsibleListProps();
22
24
  collapsibleListProps.set(CollapsibleListProps.propNames.hasMessage, true);
23
25
  collapsibleListProps.set(
@@ -32,6 +34,10 @@ describe("Translations ", () => {
32
34
  collapsibleListProps.set(CollapsibleListProps.propNames.containerWidth, "unset");
33
35
  });
34
36
 
37
+ afterEach(() => {
38
+ delete window.bypassDebounce;
39
+ });
40
+
35
41
  it("Renders Translations correctly", () => {
36
42
  const component = (
37
43
  <TestWrapper stylesProvider muiThemeProvider={{ theme }} intlProvider={{ messages }}>
@@ -135,7 +141,7 @@ describe("Translations ", () => {
135
141
  expect(component, "when mounted", "to satisfy", expected);
136
142
  });
137
143
 
138
- it("Translations component handles change", () => {
144
+ it("Translations component handles change", () => {
139
145
  const aValue = "aValue";
140
146
  const update = sinon.spy().named("update");
141
147
 
@@ -111,12 +111,29 @@ const InputBase = ({ inputProps }) => {
111
111
 
112
112
  const onChangeHandler = event => {
113
113
  event.persist();
114
- update(event.target.value, metadata);
114
+
115
+ if (!event.target.value || window.bypassDebounce === true) {
116
+ update(event.target.value, metadata);
117
+ }
118
+
119
+ setInputText(event.target.value);
115
120
  };
116
121
 
117
122
  const inputBaseInputStyle = inputProps?.getStyle(InputBaseProps.ruleNames.input);
118
123
  const errorTextStyle = inputProps?.getStyle(InputBaseProps.ruleNames.errorText);
119
124
 
125
+ const [inputText, setInputText] = React.useState(null);
126
+
127
+ const textToDisplay = inputText ?? value;
128
+
129
+ React.useEffect(() => {
130
+ if (inputText !== value && inputText != null && window.bypassDebounce !== true) {
131
+ const timeOutId = setTimeout(() => update(inputText, metadata), 100);
132
+ return () => clearTimeout(timeOutId);
133
+ }
134
+ // eslint-disable-next-line react-hooks/exhaustive-deps
135
+ }, [inputText, value]);
136
+
120
137
  return (
121
138
  <div className={classes.container}>
122
139
  <div className={classes.inputContainer}>
@@ -133,7 +150,7 @@ const InputBase = ({ inputProps }) => {
133
150
  onClick={onClick}
134
151
  type={type}
135
152
  placeholder={placeholder}
136
- value={value}
153
+ value={textToDisplay}
137
154
  fullWidth={true}
138
155
  onChange={event => onChangeHandler(event)}
139
156
  error={!!error}
@@ -5,15 +5,19 @@ import InputBaseMUI from "@material-ui/core/InputBase";
5
5
  import sinon from "sinon";
6
6
  import { ignoreConsoleError } from "../../../utils/testUtils";
7
7
  import InputBaseProps from "./InputBaseProps";
8
+ import { act } from "unexpected-reaction";
8
9
 
9
10
  describe("InputBase Component", () => {
10
11
  let update, container;
11
12
  beforeEach(() => {
13
+ window.bypassDebounce = true;
14
+
12
15
  container = document.createElement("div");
13
16
  document.body.appendChild(container);
14
17
  update = sinon.spy().named("update");
15
18
  });
16
19
  afterEach(() => {
20
+ delete window.bypassDebounce;
17
21
  document.body.removeChild(container);
18
22
  container = null;
19
23
  });
@@ -243,3 +247,67 @@ describe("InputBase Component", () => {
243
247
  expect(mountedComponent.containsMatchingElement(expected), "to be truthy");
244
248
  });
245
249
  });
250
+
251
+ describe("InputBase component debouce", () => {
252
+ const clock = sinon.useFakeTimers();
253
+ let update, container;
254
+
255
+ beforeEach(() => {
256
+ container = document.createElement("div");
257
+ document.body.appendChild(container);
258
+ update = sinon.spy().named("update");
259
+ });
260
+
261
+ afterEach(() => {
262
+ clock.restore();
263
+ });
264
+
265
+ it("InputBase component updates when debounced update", async () => {
266
+ const inputProps = new InputBaseProps();
267
+ const aLabel = "aLabel";
268
+ const aValue = "value";
269
+
270
+ const metadata = {
271
+ test: "value",
272
+ };
273
+
274
+ inputProps.set(InputBaseProps.propNames.value, "");
275
+ inputProps.set(InputBaseProps.propNames.update, update);
276
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
277
+ inputProps.set(InputBaseProps.propNames.metadata, metadata);
278
+
279
+ const component = <InputBase inputProps={inputProps} />;
280
+ const mountedComponent = mount(component);
281
+
282
+ const input = mountedComponent.find("input");
283
+ input.simulate("change", { target: { value: aValue } });
284
+
285
+ act(() => {
286
+ clock.tick(200);
287
+ });
288
+
289
+ input.simulate("change", { target: { value: "differentValue" } });
290
+ expect(update, "to have calls satisfying", [{ args: [aValue, metadata] }]);
291
+ });
292
+
293
+ it("InputBase component update to empty when text to display is null", async () => {
294
+ const inputProps = new InputBaseProps();
295
+ const aLabel = "aLabel";
296
+
297
+ const metadata = {
298
+ test: "value",
299
+ };
300
+
301
+ inputProps.set(InputBaseProps.propNames.value, null);
302
+ inputProps.set(InputBaseProps.propNames.update, update);
303
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
304
+ inputProps.set(InputBaseProps.propNames.metadata, metadata);
305
+
306
+ const component = <InputBase inputProps={inputProps} />;
307
+ const mountedComponent = mount(component);
308
+
309
+ const input = mountedComponent.find("input");
310
+ input.simulate("change", { target: { value: null } });
311
+ expect(input.get(0).props.value, "to equal", "");
312
+ });
313
+ });
@@ -204,10 +204,14 @@ describe("ScopeBar", () => {
204
204
  describe("Scope", () => {
205
205
  let nodeState;
206
206
  beforeEach(() => {
207
+ window.bypassDebounce = true;
208
+
207
209
  nodeState = { foo: true, bar: false };
208
210
  state = state.setIn(["view", "scopeSelector", "nodeState"], Immutable.fromJS(nodeState));
209
211
  });
210
212
 
213
+ afterEach(() => delete window.bypassDebounce);
214
+
211
215
  it("renders a scope bar, selector panel with handlers, and viewport", () => {
212
216
  const scopes = [
213
217
  {