@wise/dynamic-flow-client 3.7.2-experimental-1ba6fef → 3.8.0-experimental-da4e1e5

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.
Files changed (39) hide show
  1. package/build/index.js +3 -3
  2. package/build/legacy/common/hooks/useExternal/useExternal.js +1 -2
  3. package/build/legacy/common/hooks/useExternal/useExternal.spec.js +35 -21
  4. package/build/main.js +16722 -16711
  5. package/build/main.min.js +1 -1
  6. package/build/main.mjs +14265 -14254
  7. package/build/revamp/DynamicFlowWise.js +12 -2
  8. package/build/revamp/domain/components/IntegerInputComponent.js +4 -1
  9. package/build/revamp/domain/components/NumberInputComponent.js +6 -3
  10. package/build/revamp/domain/components/TextInputComponent.js +6 -3
  11. package/build/revamp/domain/components/utils/debounce.js +2 -2
  12. package/build/revamp/domain/features/refresh/getPerformRefresh.js +5 -42
  13. package/build/revamp/domain/mappers/schema/integerSchemaToComponent.js +2 -2
  14. package/build/revamp/domain/mappers/schema/numberSchemaToComponent.js +2 -2
  15. package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.js +2 -2
  16. package/build/revamp/tests/legacy/RefreshStepOnChange.debouncing.spec.js +127 -11
  17. package/build/types/index.d.ts +6 -6
  18. package/build/types/legacy/common/utils/schema-utils.d.ts +1 -1
  19. package/build/types/legacy/dynamicFlow/utils/useLoader.d.ts +1 -1
  20. package/build/types/legacy/layout/search/useSearch.d.ts +1 -1
  21. package/build/types/revamp/DynamicFlowCore.d.ts +1 -5
  22. package/build/types/revamp/DynamicFlowWise.d.ts +2 -2
  23. package/build/types/revamp/domain/components/AllOfComponent.d.ts +1 -1
  24. package/build/types/revamp/domain/components/BooleanInputComponent.d.ts +1 -1
  25. package/build/types/revamp/domain/components/ConstComponent.d.ts +1 -1
  26. package/build/types/revamp/domain/components/DateInputComponent.d.ts +1 -1
  27. package/build/types/revamp/domain/components/IntegerInputComponent.d.ts +2 -2
  28. package/build/types/revamp/domain/components/MultiUploadInputComponent.d.ts +1 -1
  29. package/build/types/revamp/domain/components/NumberInputComponent.d.ts +4 -4
  30. package/build/types/revamp/domain/components/ObjectComponent.d.ts +1 -1
  31. package/build/types/revamp/domain/components/SelectInputComponent.d.ts +1 -1
  32. package/build/types/revamp/domain/components/StepDomainComponent.d.ts +1 -1
  33. package/build/types/revamp/domain/components/TextInputComponent.d.ts +4 -4
  34. package/build/types/revamp/domain/components/UploadInputComponent.d.ts +1 -1
  35. package/build/types/revamp/domain/components/repeatableComponent/RepeatableComponent.d.ts +1 -1
  36. package/build/types/revamp/domain/features/refresh/getPerformRefresh.d.ts +2 -2
  37. package/build/types/revamp/types.d.ts +10 -5
  38. package/build/types/revamp/wise/renderers/getWiseRenderers.d.ts +2 -1
  39. package/package.json +1 -1
@@ -45,6 +45,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
48
57
  import { jsx as _jsx } from "react/jsx-runtime";
49
58
  import { useMemo } from 'react';
50
59
  import { useIntl } from 'react-intl';
@@ -52,11 +61,12 @@ import { HttpClientProvider } from '../common/httpClientContext';
52
61
  import { getWiseRenderers } from './wise/renderers/getWiseRenderers';
53
62
  import { mergeRequestInit } from '../common/makeHttpClient';
54
63
  import { DynamicFlowCore } from './DynamicFlowCore';
55
- var renderers = getWiseRenderers();
64
+ var wiseRenderers = getWiseRenderers();
56
65
  function DynamicFlowWise(props) {
57
- var httpClient = props.httpClient;
66
+ var httpClient = props.httpClient, customRenderers = props.renderers;
58
67
  var locale = useIntl().locale;
59
68
  var wiseHttpClient = useMemo(function () { return makeWiseHttpClient(httpClient, locale); }, [httpClient, locale]);
69
+ var renderers = useMemo(function () { return __spreadArray(__spreadArray([], (customRenderers !== null && customRenderers !== void 0 ? customRenderers : []), true), wiseRenderers, true); }, [customRenderers]);
60
70
  return (_jsx(HttpClientProvider, { httpClient: wiseHttpClient, children: _jsx(DynamicFlowCore, __assign({}, props, { renderers: renderers })) }));
61
71
  }
62
72
  export default DynamicFlowWise;
@@ -59,9 +59,11 @@ var __rest = (this && this.__rest) || function (s, e) {
59
59
  import { getLocalValueValidator } from '../features/validation/validation-functions';
60
60
  import { getInputUpdateFunction } from './utils/component-utils';
61
61
  import { getComponentPersistAsync } from '../features/persistAsync/getComponentPersistAsync';
62
+ import { getDebouncedPerformRefresh, } from '../features/refresh/getPerformRefresh';
62
63
  import { getComponentValidationAsync } from '../features/validationAsync/getComponentValidationAsync';
63
64
  export var createIntegerInputComponent = function (integerInputProps, updateComponent) {
64
65
  var uid = integerInputProps.uid, id = integerInputProps.id, checks = integerInputProps.checks, value = integerInputProps.value, performPersistAsync = integerInputProps.performPersistAsync, performRefresh = integerInputProps.performRefresh, performValidationAsync = integerInputProps.performValidationAsync, summariser = integerInputProps.summariser, rest = __rest(integerInputProps, ["uid", "id", "checks", "value", "performPersistAsync", "performRefresh", "performValidationAsync", "summariser"]);
66
+ var performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
65
67
  var update = getInputUpdateFunction(uid, updateComponent);
66
68
  var getValidationErrors = getLocalValueValidator(checks);
67
69
  var getAndSetValidationErrors = function (currentValue) {
@@ -73,6 +75,7 @@ export var createIntegerInputComponent = function (integerInputProps, updateComp
73
75
  };
74
76
  var integerComponent = __assign({ type: 'integer', uid: uid, id: id, value: value, onBlur: function () {
75
77
  getAndSetValidationErrors(this.getLocalValue());
78
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh.flush();
76
79
  }, onFocus: function () { }, // Noop
77
80
  onChange: function (updatedValue) {
78
81
  update(function (draft) {
@@ -80,7 +83,7 @@ export var createIntegerInputComponent = function (integerInputProps, updateComp
80
83
  draft.validationState.messages = {};
81
84
  draft.value = updatedValue;
82
85
  });
83
- performRefresh === null || performRefresh === void 0 ? void 0 : performRefresh();
86
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh();
84
87
  }, getSubmittableValue: function () {
85
88
  var _a;
86
89
  return __awaiter(this, void 0, void 0, function () {
@@ -56,12 +56,14 @@ var __rest = (this && this.__rest) || function (s, e) {
56
56
  }
57
57
  return t;
58
58
  };
59
- import { getLocalValueValidator } from '../features/validation/validation-functions';
60
- import { getInputUpdateFunction } from './utils/component-utils';
61
59
  import { getComponentPersistAsync } from '../features/persistAsync/getComponentPersistAsync';
60
+ import { getDebouncedPerformRefresh, } from '../features/refresh/getPerformRefresh';
61
+ import { getLocalValueValidator } from '../features/validation/validation-functions';
62
62
  import { getComponentValidationAsync } from '../features/validationAsync/getComponentValidationAsync';
63
+ import { getInputUpdateFunction } from './utils/component-utils';
63
64
  export var createNumberInputComponent = function (numberInputProps, updateComponent) {
64
65
  var uid = numberInputProps.uid, id = numberInputProps.id, checks = numberInputProps.checks, performPersistAsync = numberInputProps.performPersistAsync, performRefresh = numberInputProps.performRefresh, performValidationAsync = numberInputProps.performValidationAsync, summariser = numberInputProps.summariser, rest = __rest(numberInputProps, ["uid", "id", "checks", "performPersistAsync", "performRefresh", "performValidationAsync", "summariser"]);
66
+ var performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
65
67
  var update = getInputUpdateFunction(uid, updateComponent);
66
68
  var getValidationErrors = getLocalValueValidator(checks);
67
69
  var getAndSetValidationErrors = function (currentValue) {
@@ -73,6 +75,7 @@ export var createNumberInputComponent = function (numberInputProps, updateCompon
73
75
  };
74
76
  var numberComponent = __assign({ type: 'number', uid: uid, id: id, onBlur: function () {
75
77
  getAndSetValidationErrors(this.getLocalValue());
78
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh.flush();
76
79
  }, onFocus: function () { }, // Noop
77
80
  onChange: function (updatedValue) {
78
81
  update(function (draft) {
@@ -80,7 +83,7 @@ export var createNumberInputComponent = function (numberInputProps, updateCompon
80
83
  draft.validationState.messages = {};
81
84
  draft.value = updatedValue;
82
85
  });
83
- performRefresh === null || performRefresh === void 0 ? void 0 : performRefresh();
86
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh();
84
87
  }, getSubmittableValue: function () {
85
88
  var _a;
86
89
  return __awaiter(this, void 0, void 0, function () {
@@ -56,12 +56,14 @@ var __rest = (this && this.__rest) || function (s, e) {
56
56
  }
57
57
  return t;
58
58
  };
59
- import { getLocalValueValidator } from '../features/validation/validation-functions';
60
- import { getInputUpdateFunction } from './utils/component-utils';
61
59
  import { getComponentPersistAsync } from '../features/persistAsync/getComponentPersistAsync';
60
+ import { getDebouncedPerformRefresh, } from '../features/refresh/getPerformRefresh';
61
+ import { getLocalValueValidator } from '../features/validation/validation-functions';
62
62
  import { getComponentValidationAsync } from '../features/validationAsync/getComponentValidationAsync';
63
+ import { getInputUpdateFunction } from './utils/component-utils';
63
64
  export var createTextInputComponent = function (textInputProps, updateComponent) {
64
65
  var uid = textInputProps.uid, id = textInputProps.id, checks = textInputProps.checks, performPersistAsync = textInputProps.performPersistAsync, performRefresh = textInputProps.performRefresh, performValidationAsync = textInputProps.performValidationAsync, summariser = textInputProps.summariser, value = textInputProps.value, rest = __rest(textInputProps, ["uid", "id", "checks", "performPersistAsync", "performRefresh", "performValidationAsync", "summariser", "value"]);
66
+ var performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
65
67
  var update = getInputUpdateFunction(uid, updateComponent);
66
68
  var getValidationErrors = getLocalValueValidator(checks);
67
69
  var getAndSetValidationErrors = function (currentValue) {
@@ -73,6 +75,7 @@ export var createTextInputComponent = function (textInputProps, updateComponent)
73
75
  };
74
76
  var inputComponent = __assign({ type: 'text', uid: uid, id: id, value: value, onBlur: function () {
75
77
  getAndSetValidationErrors(this.getLocalValue());
78
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh.flush();
76
79
  }, onFocus: function () { }, // Noop
77
80
  onChange: function (updatedValue) {
78
81
  update(function (draft) {
@@ -80,7 +83,7 @@ export var createTextInputComponent = function (textInputProps, updateComponent)
80
83
  draft.validationState.messages = {};
81
84
  draft.value = updatedValue;
82
85
  });
83
- performRefresh === null || performRefresh === void 0 ? void 0 : performRefresh();
86
+ performDebouncedRefresh === null || performDebouncedRefresh === void 0 ? void 0 : performDebouncedRefresh();
84
87
  }, getSubmittableValue: function () {
85
88
  var _a;
86
89
  return __awaiter(this, void 0, void 0, function () {
@@ -1,6 +1,6 @@
1
1
  export var debounce = function (callback, waitMs) {
2
- var timeoutId;
3
- var lastArgs;
2
+ var timeoutId = null;
3
+ var lastArgs = null;
4
4
  var clearTimer = function () {
5
5
  if (timeoutId) {
6
6
  clearTimeout(timeoutId);
@@ -1,39 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { debounce } from '../../components/utils/debounce';
38
2
  export var getPerformRefresh = function (schema, onRefresh) {
39
3
  var _a, _b;
@@ -41,13 +5,12 @@ export var getPerformRefresh = function (schema, onRefresh) {
41
5
  ('refreshFormOnChange' in schema && ((_b = schema.refreshFormOnChange) !== null && _b !== void 0 ? _b : false))) {
42
6
  var $id = schema.$id, analyticsId = schema.analyticsId, refreshUrl_1 = schema.refreshUrl, refreshFormUrl_1 = schema.refreshFormUrl;
43
7
  var schemaId_1 = analyticsId !== null && analyticsId !== void 0 ? analyticsId : $id;
44
- return function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
45
- return [2 /*return*/, onRefresh(schemaId_1, refreshUrl_1 !== null && refreshUrl_1 !== void 0 ? refreshUrl_1 : refreshFormUrl_1)];
46
- }); }); };
8
+ return function () {
9
+ void onRefresh(schemaId_1, refreshUrl_1 !== null && refreshUrl_1 !== void 0 ? refreshUrl_1 : refreshFormUrl_1);
10
+ };
47
11
  }
48
12
  return undefined;
49
13
  };
50
- export var getDebouncedPerformRefresh = function (schema, onRefresh) {
51
- var debouncedOnRefresh = debounce(onRefresh, 1000);
52
- return getPerformRefresh(schema, debouncedOnRefresh);
14
+ export var getDebouncedPerformRefresh = function (performRefresh) {
15
+ return performRefresh ? debounce(performRefresh, 1000) : undefined;
53
16
  };
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { isInteger } from '../../../utils/type-validators';
13
13
  import { createIntegerInputComponent } from '../../components/IntegerInputComponent';
14
- import { getDebouncedPerformRefresh } from '../../features/refresh/getPerformRefresh';
14
+ import { getPerformRefresh } from '../../features/refresh/getPerformRefresh';
15
15
  import { getAboveMaximumCheck, getBelowMinimumCheck, getRequiredCheck, } from '../../features/validation/value-checks';
16
16
  import { getAutocompleteString } from '../utils/getAutocompleteString';
17
17
  import { getPersistAsyncInitialState } from './utils/getPersistAsyncInitialState';
@@ -32,5 +32,5 @@ export var integerSchemaToComponent = function (schemaMapperProps, mapperProps)
32
32
  getBelowMinimumCheck(schema, errorMessageFunctions),
33
33
  getAboveMaximumCheck(schema, errorMessageFunctions),
34
34
  ];
35
- return createIntegerInputComponent(__assign(__assign({}, mapCommonSchemaProps(schemaMapperProps)), { autoComplete: getAutocompleteString(autocompleteHint), checks: checks, persistedState: persistedState, value: value, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getDebouncedPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
35
+ return createIntegerInputComponent(__assign(__assign({}, mapCommonSchemaProps(schemaMapperProps)), { autoComplete: getAutocompleteString(autocompleteHint), checks: checks, persistedState: persistedState, value: value, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
36
36
  };
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { isNumber } from '../../../utils/type-validators';
13
13
  import { createNumberInputComponent } from '../../components/NumberInputComponent';
14
- import { getDebouncedPerformRefresh } from '../../features/refresh/getPerformRefresh';
14
+ import { getPerformRefresh } from '../../features/refresh/getPerformRefresh';
15
15
  import { getAboveMaximumCheck, getBelowMinimumCheck, getRequiredCheck, } from '../../features/validation/value-checks';
16
16
  import { getAutocompleteString } from '../utils/getAutocompleteString';
17
17
  import { getPersistAsyncInitialState } from './utils/getPersistAsyncInitialState';
@@ -31,5 +31,5 @@ export var numberSchemaToComponent = function (schemaMapperProps, mapperProps) {
31
31
  getRequiredCheck(required, errorMessageFunctions),
32
32
  getBelowMinimumCheck(schema, errorMessageFunctions),
33
33
  getAboveMaximumCheck(schema, errorMessageFunctions),
34
- ], value: value, persistedState: persistedState, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getDebouncedPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
34
+ ], value: value, persistedState: persistedState, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
35
35
  };
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { createTextInputComponent } from '../../../components/TextInputComponent';
13
13
  import { isString } from '../../../../utils/type-validators';
14
- import { getDebouncedPerformRefresh } from '../../../features/refresh/getPerformRefresh';
14
+ import { getPerformRefresh } from '../../../features/refresh/getPerformRefresh';
15
15
  import { getAboveMaxLengthCheck, getBelowMinLengthCheck, getNotAdheringToPatternCheck, getRequiredCheck, } from '../../../features/validation/value-checks';
16
16
  import { getAutocompleteString } from '../../utils/getAutocompleteString';
17
17
  import { getPersistAsyncInitialState } from '../utils/getPersistAsyncInitialState';
@@ -35,7 +35,7 @@ export var stringSchemaToTextInputComponent = function (schemaMapperProps, mappe
35
35
  getAboveMaxLengthCheck(schema, errorMessageFunctions),
36
36
  getBelowMinLengthCheck(schema, errorMessageFunctions),
37
37
  getNotAdheringToPatternCheck(schema, errorMessageFunctions),
38
- ], control: control !== null && control !== void 0 ? control : controlForLegacyFormat, displayFormat: displayFormat, value: value, persistedState: persistedState, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getDebouncedPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
38
+ ], control: control !== null && control !== void 0 ? control : controlForLegacyFormat, displayFormat: displayFormat, value: value, persistedState: persistedState, validationState: validationState, performPersistAsync: performPersistAsync, performRefresh: getPerformRefresh(schema, onRefresh), performValidationAsync: performValidationAsync }), updateComponent);
39
39
  };
40
40
  var getControlForLegacyFormat = function (format) {
41
41
  if (format && ['numeric', 'phone-number', 'email', 'password'].includes(format)) {
@@ -51,6 +51,16 @@ import { userEvent } from '@testing-library/user-event';
51
51
  import DynamicFlowWise from '../../DynamicFlowWise';
52
52
  import { renderWithProviders } from '../../../test-utils';
53
53
  var user = userEvent.setup({ advanceTimers: function (delay) { return jest.advanceTimersByTime(delay); } });
54
+ var mockHttpClient = jest.fn();
55
+ var getProps = function (step, overrides) {
56
+ if (overrides === void 0) { overrides = {}; }
57
+ return (__assign({ flowId: 'debounced-refresh-flow-id', initialStep: step, httpClient: mockHttpClient, onCompletion: jest.fn(), onError: jest.fn(), onEvent: jest.fn(), onLog: jest.fn() }, overrides));
58
+ };
59
+ beforeAll(function () { return jest.useFakeTimers(); });
60
+ beforeEach(function () {
61
+ mockHttpClient.mockClear();
62
+ });
63
+ afterAll(function () { return jest.useRealTimers(); });
54
64
  describe('useDebouncedRefresh', function () {
55
65
  var debounceableSchema = {
56
66
  $id: '#debounced-schema',
@@ -120,16 +130,6 @@ describe('useDebouncedRefresh', function () {
120
130
  schemas: [debounceableDeprecatedSchema],
121
131
  model: {},
122
132
  };
123
- var mockHttpClient = jest.fn();
124
- var getProps = function (step, overrides) {
125
- if (overrides === void 0) { overrides = {}; }
126
- return (__assign({ flowId: 'debounced-refresh-flow-id', initialStep: step, httpClient: mockHttpClient, onCompletion: jest.fn(), onError: jest.fn(), onEvent: jest.fn(), onLog: jest.fn() }, overrides));
127
- };
128
- beforeAll(function () { return jest.useFakeTimers(); });
129
- beforeEach(function () {
130
- mockHttpClient.mockClear();
131
- });
132
- afterAll(function () { return jest.useRealTimers(); });
133
133
  describe('when the schema is debounceable', function () {
134
134
  describe("and the url doesn't change", function () {
135
135
  it('triggers only once, after the interval, with the latest data', function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -191,7 +191,7 @@ describe('useDebouncedRefresh', function () {
191
191
  case 5:
192
192
  _a.sent();
193
193
  expect(props.httpClient).toHaveBeenCalledWith('/refresh1', expect.objectContaining({
194
- body: '{"name":"Colin Robinson","address":"New","terms":false}',
194
+ body: '{"name":"Colin Robinson","terms":false}',
195
195
  // body: '{"terms":false,"name":"Colin Robinson"}',
196
196
  }));
197
197
  expect(props.httpClient).toHaveBeenCalledWith('/refresh2', expect.objectContaining({
@@ -234,3 +234,119 @@ describe('useDebouncedRefresh', function () {
234
234
  }); });
235
235
  });
236
236
  });
237
+ describe('when the user types in a debounceable field, and then immediately submits the form', function () {
238
+ it('should suppress submission until the refresh is complete', function () { return __awaiter(void 0, void 0, void 0, function () {
239
+ var initialStep, secondStep, props, httpClient;
240
+ return __generator(this, function (_a) {
241
+ switch (_a.label) {
242
+ case 0:
243
+ initialStep = {
244
+ id: 'debounced-refresh-initial-step',
245
+ title: 'debounced refresh test',
246
+ refreshUrl: '/refresh',
247
+ layout: [
248
+ { type: 'form', schemaId: '#debounced-schema' },
249
+ { type: 'button', title: 'Submit', action: { url: '/submit', method: 'POST' } },
250
+ ],
251
+ schemas: [
252
+ {
253
+ $id: '#debounced-schema',
254
+ type: 'object',
255
+ title: 'Debounced Refresh',
256
+ description: 'debounced refresh',
257
+ displayOrder: ['name'],
258
+ properties: {
259
+ name: {
260
+ title: 'Name',
261
+ type: 'string',
262
+ refreshStepOnChange: true,
263
+ },
264
+ },
265
+ },
266
+ ],
267
+ model: {},
268
+ };
269
+ secondStep = {
270
+ id: 'debounced-refresh-second-step',
271
+ title: 'second step',
272
+ layout: [{ type: 'paragraph', text: 'second step paragraph' }],
273
+ schemas: [],
274
+ model: {},
275
+ };
276
+ props = getProps(initialStep);
277
+ httpClient = jest.fn(function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
278
+ var model;
279
+ return __generator(this, function (_a) {
280
+ switch (input) {
281
+ case '/refresh': {
282
+ model = JSON.parse(init === null || init === void 0 ? void 0 : init.body);
283
+ return [2 /*return*/, Promise.resolve(new Response(JSON.stringify(__assign(__assign({}, initialStep), { model: model })), { status: 200 }))];
284
+ }
285
+ case '/submit':
286
+ return [2 /*return*/, Promise.resolve(new Response(JSON.stringify(secondStep), { status: 200 }))];
287
+ default:
288
+ return [2 /*return*/, Promise.resolve(new Response('', { status: 404 }))];
289
+ }
290
+ return [2 /*return*/];
291
+ });
292
+ }); });
293
+ renderWithProviders(_jsx(DynamicFlowWise, __assign({}, props, { httpClient: httpClient })));
294
+ // enter a value into a debounceable field
295
+ return [4 /*yield*/, user.type(screen.getByLabelText('Name'), 'Colin')];
296
+ case 1:
297
+ // enter a value into a debounceable field
298
+ _a.sent();
299
+ // then immediately submit the form
300
+ return [4 /*yield*/, user.click(screen.getByRole('button', { name: 'Submit' }))];
301
+ case 2:
302
+ // then immediately submit the form
303
+ _a.sent();
304
+ return [4 /*yield*/, waitFor(function () {
305
+ expect(httpClient).toHaveBeenCalledTimes(0);
306
+ })];
307
+ case 3:
308
+ _a.sent();
309
+ return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
310
+ return __generator(this, function (_a) {
311
+ jest.advanceTimersByTime(2000); // debounce delay
312
+ return [2 /*return*/];
313
+ });
314
+ }); })];
315
+ case 4:
316
+ _a.sent();
317
+ return [4 /*yield*/, waitFor(function () {
318
+ expect(httpClient).toHaveBeenCalledWith('/refresh', expect.objectContaining({ body: '{"name":"Colin"}' }));
319
+ })];
320
+ case 5:
321
+ _a.sent();
322
+ return [4 /*yield*/, waitFor(function () {
323
+ expect(screen.getByText('debounced refresh test')).toBeInTheDocument();
324
+ })];
325
+ case 6:
326
+ _a.sent();
327
+ return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
328
+ return __generator(this, function (_a) {
329
+ jest.advanceTimersByTime(2000); // debounce delay
330
+ return [2 /*return*/];
331
+ });
332
+ }); })];
333
+ case 7:
334
+ _a.sent();
335
+ expect(httpClient).toHaveBeenCalledTimes(1);
336
+ // click submit a second time
337
+ return [4 /*yield*/, user.click(screen.getByRole('button', { name: 'Submit' }))];
338
+ case 8:
339
+ // click submit a second time
340
+ _a.sent();
341
+ // this time the submission goes through
342
+ return [4 /*yield*/, waitFor(function () {
343
+ expect(httpClient).toHaveBeenCalledWith('/submit', expect.objectContaining({ body: '{"name":"Colin"}' }));
344
+ })];
345
+ case 9:
346
+ // this time the submission goes through
347
+ _a.sent();
348
+ return [2 /*return*/];
349
+ }
350
+ });
351
+ }); });
352
+ });
@@ -1,12 +1,12 @@
1
+ export { makeHttpClient } from './common/makeHttpClient';
2
+ export { default as translations } from './i18n';
3
+ export type { Step, Model } from '@wise/dynamic-flow-types';
4
+ export type { DynamicFlowWiseProps as DynamicFlowRevampProps, DynamicFlowWisePropsWithInitialAction as DynamicFlowRevampPropsWithInitialAction, DynamicFlowWisePropsWithInitialStep as DynamicFlowRevampPropsWithInitialStep, } from './revamp/types';
5
+ export { default as DynamicFlowRevamp } from './revamp/DynamicFlowWise';
6
+ export type { DynamicFlowProps, InitialAction } from './legacy/dynamic-flow-types';
1
7
  export { convertStepToLayout, inlineReferences } from './legacy/step/layoutStep/utils';
2
8
  export { default as DynamicFlow } from './legacy/dynamicFlow';
3
- export { makeHttpClient } from './common/makeHttpClient';
4
9
  export { default as JsonSchemaForm } from './legacy/jsonSchemaForm';
5
10
  export { DynamicLayout as Layout } from './legacy/layout';
6
11
  export { isValidSchema } from './legacy/common/validators';
7
- export { default as translations } from './i18n';
8
12
  export * from './legacy/dynamicFlow/DynamicFlow';
9
- export type { DynamicFlowProps, InitialAction } from './legacy/dynamic-flow-types';
10
- export type { Step } from '@wise/dynamic-flow-types';
11
- export { default as DynamicFlowRevamp } from './revamp/DynamicFlowWise';
12
- export type { DynamicFlowProps as DynamicFlowRevampProps } from './revamp/types';
@@ -23,4 +23,4 @@ export declare function isFileUploadSchema(schema: {
23
23
  }): schema is FileUploadSchema;
24
24
  export declare const isMultipleFileUploadSchema: (schema: Schema) => schema is MultipleFileUploadSchema;
25
25
  export declare const isMultiSelectConstSchema: (schema: Schema) => schema is MultiSelectSchema;
26
- export declare const getSchemaType: (schema: Schema) => "allOf" | "persistAsync" | "array" | "object" | "oneOf" | "readOnly" | "validationAsync" | "promotedOneOf" | "basic" | null;
26
+ export declare const getSchemaType: (schema: Schema) => "object" | "array" | "allOf" | "oneOf" | "persistAsync" | "readOnly" | "validationAsync" | "promotedOneOf" | "basic" | null;
@@ -3,7 +3,7 @@ import type { DynamicFlowProps } from '../../dynamic-flow-types';
3
3
  type LoadingState = 'idle' | 'initial' | 'refresh' | 'submission';
4
4
  export declare function useLoader(loaderConfig: DynamicFlowProps['loaderConfig'], initialState: LoadingState): {
5
5
  isLoading: boolean;
6
- setLoadingState: import("react").Dispatch<import("react").SetStateAction<"initial" | "idle" | "refresh" | "submission">>;
6
+ setLoadingState: import("react").Dispatch<import("react").SetStateAction<"idle" | "submission" | "refresh" | "initial">>;
7
7
  loader: JSX.Element | null;
8
8
  };
9
9
  export {};
@@ -10,7 +10,7 @@ export type SearchState = {
10
10
  status: 'error';
11
11
  };
12
12
  export declare const useSearch: (defaultSearchConfig: SearchConfig) => {
13
- status: "success" | "loading" | "error" | "idle";
13
+ status: "error" | "idle" | "loading" | "success";
14
14
  results: SearchResult[];
15
15
  search: (query: string, { url, method, param }?: SearchConfig) => Promise<void>;
16
16
  };
@@ -1,6 +1,2 @@
1
- import type { DynamicFlowProps, Renderers } from './types';
2
- type DynamicFlowCoreProps = DynamicFlowProps & {
3
- renderers: Renderers;
4
- };
1
+ import type { DynamicFlowCoreProps } from './types';
5
2
  export declare function DynamicFlowCore(props: DynamicFlowCoreProps): JSX.Element;
6
- export {};
@@ -1,3 +1,3 @@
1
- import type { DynamicFlowProps } from './types';
2
- declare function DynamicFlowWise(props: DynamicFlowProps): JSX.Element;
1
+ import type { DynamicFlowWiseProps } from './types';
2
+ declare function DynamicFlowWise(props: DynamicFlowWiseProps): JSX.Element;
3
3
  export default DynamicFlowWise;
@@ -11,7 +11,7 @@ export type AllOfComponent = BaseComponent & {
11
11
  getChildren: () => DomainComponent[];
12
12
  getLocalValue: () => LocalValue;
13
13
  };
14
- export declare const createAllOfComponent: (allOfProps: Pick<AllOfComponent, "description" | "help" | "hidden" | "title" | "control" | "components"> & {
14
+ export declare const createAllOfComponent: (allOfProps: Pick<AllOfComponent, "control" | "title" | "components" | "description" | "hidden" | "help"> & {
15
15
  uid: string;
16
16
  analyticsId?: string | undefined;
17
17
  summariser: (value: Model | null) => RepeatableSummary;
@@ -8,7 +8,7 @@ export type BooleanInputComponent = InputComponent<boolean> & {
8
8
  validationState: ValidationState;
9
9
  onChange: (value: boolean) => void;
10
10
  };
11
- export declare const createBooleanInputComponent: (booleanInputProps: Pick<BooleanInputComponent, "analyticsId" | "description" | "disabled" | "help" | "hidden" | "title" | "control" | "id" | "errors" | "required" | "value" | "uid" | "persistedState" | "validationState"> & {
11
+ export declare const createBooleanInputComponent: (booleanInputProps: Pick<BooleanInputComponent, "value" | "id" | "uid" | "control" | "analyticsId" | "title" | "description" | "errors" | "hidden" | "help" | "disabled" | "required" | "persistedState" | "validationState"> & {
12
12
  performPersistAsync: PerformPersistAsync | undefined;
13
13
  performRefresh: PerformRefresh | undefined;
14
14
  performValidationAsync: PerformValidationAsync | undefined;
@@ -4,7 +4,7 @@ export type ConstComponent = BaseComponent & {
4
4
  type: 'const';
5
5
  getLocalValue: () => LocalValue;
6
6
  };
7
- export declare const createConstComponent: (hiddenProps: Pick<ConstComponent, "analyticsId" | "uid"> & {
7
+ export declare const createConstComponent: (hiddenProps: Pick<ConstComponent, "uid" | "analyticsId"> & {
8
8
  value: Model;
9
9
  summary: RepeatableSummary;
10
10
  }) => ConstComponent;
@@ -11,7 +11,7 @@ export type DateInputComponent = InputComponent<string | null> & {
11
11
  validationState: ValidationState;
12
12
  onChange: (value: string | null) => void;
13
13
  };
14
- export declare const createDateInputComponent: (textInputProps: Pick<DateInputComponent, "analyticsId" | "description" | "disabled" | "help" | "hidden" | "title" | "placeholder" | "control" | "id" | "errors" | "required" | "value" | "autoComplete" | "minimumDate" | "maximumDate" | "uid" | "persistedState" | "validationState"> & {
14
+ export declare const createDateInputComponent: (textInputProps: Pick<DateInputComponent, "value" | "id" | "uid" | "control" | "analyticsId" | "title" | "description" | "errors" | "hidden" | "help" | "disabled" | "placeholder" | "required" | "autoComplete" | "persistedState" | "validationState" | "minimumDate" | "maximumDate"> & {
15
15
  checks: IsInvalidCheck<string | null>[];
16
16
  performPersistAsync: PerformPersistAsync | undefined;
17
17
  performRefresh: PerformRefresh | undefined;
@@ -1,7 +1,7 @@
1
1
  import type { InputComponent, PersistedState, RepeatableSummary, UpdateComponent, ValidationState } from '../types';
2
2
  import type { IsInvalidCheck } from '../features/validation/value-checks';
3
3
  import type { PerformPersistAsync } from '../features/persistAsync/getPerformPersistAsync';
4
- import type { PerformRefresh } from '../features/refresh/getPerformRefresh';
4
+ import { type PerformRefresh } from '../features/refresh/getPerformRefresh';
5
5
  import type { PerformValidationAsync } from '../features/validationAsync/getPerformValidationAsync';
6
6
  export type IntegerInputComponent = InputComponent<number | null> & {
7
7
  type: 'integer';
@@ -9,7 +9,7 @@ export type IntegerInputComponent = InputComponent<number | null> & {
9
9
  validationState: ValidationState;
10
10
  onChange: (value: number | null) => void;
11
11
  };
12
- export declare const createIntegerInputComponent: (integerInputProps: Pick<IntegerInputComponent, "analyticsId" | "description" | "disabled" | "help" | "hidden" | "title" | "placeholder" | "control" | "id" | "errors" | "required" | "value" | "autoComplete" | "uid" | "persistedState" | "validationState"> & {
12
+ export declare const createIntegerInputComponent: (integerInputProps: Pick<IntegerInputComponent, "value" | "id" | "uid" | "control" | "analyticsId" | "title" | "description" | "errors" | "hidden" | "help" | "disabled" | "placeholder" | "required" | "autoComplete" | "persistedState" | "validationState"> & {
13
13
  checks: IsInvalidCheck<number | null>[];
14
14
  performPersistAsync: PerformPersistAsync | undefined;
15
15
  performRefresh: PerformRefresh | undefined;
@@ -14,7 +14,7 @@ export type MultiUploadInputComponent = InputComponent<File[]> & {
14
14
  onDelete: (fileId: string) => Promise<void>;
15
15
  onUpload: (file: File, fileId: string) => Promise<void>;
16
16
  };
17
- export declare const createMultiUploadInputComponent: (uploadInputProps: Pick<MultiUploadInputComponent, "analyticsId" | "description" | "disabled" | "format" | "help" | "hidden" | "title" | "placeholder" | "control" | "maxSize" | "accepts" | "id" | "errors" | "minItems" | "maxItems" | "required" | "value" | "autoComplete" | "uid" | "persistedState" | "uploadLabel"> & {
17
+ export declare const createMultiUploadInputComponent: (uploadInputProps: Pick<MultiUploadInputComponent, "value" | "id" | "uid" | "control" | "analyticsId" | "title" | "maxItems" | "minItems" | "description" | "errors" | "hidden" | "help" | "disabled" | "placeholder" | "accepts" | "maxSize" | "required" | "format" | "autoComplete" | "persistedState" | "uploadLabel"> & {
18
18
  checks: IsInvalidCheck<File[]>[];
19
19
  performPersistAsync: PerformPersistAsync | undefined;
20
20
  summariser: (value: string[]) => RepeatableSummary;
@@ -1,15 +1,15 @@
1
- import type { InputComponent, PersistedState, RepeatableSummary, UpdateComponent, ValidationState } from '../types';
2
- import type { IsInvalidCheck } from '../features/validation/value-checks';
3
1
  import type { PerformPersistAsync } from '../features/persistAsync/getPerformPersistAsync';
4
- import type { PerformRefresh } from '../features/refresh/getPerformRefresh';
2
+ import { type PerformRefresh } from '../features/refresh/getPerformRefresh';
3
+ import type { IsInvalidCheck } from '../features/validation/value-checks';
5
4
  import type { PerformValidationAsync } from '../features/validationAsync/getPerformValidationAsync';
5
+ import type { InputComponent, PersistedState, RepeatableSummary, UpdateComponent, ValidationState } from '../types';
6
6
  export type NumberInputComponent = InputComponent<number | null> & {
7
7
  type: 'number';
8
8
  persistedState: PersistedState;
9
9
  validationState: ValidationState;
10
10
  onChange: (value: number | null) => void;
11
11
  };
12
- export declare const createNumberInputComponent: (numberInputProps: Pick<NumberInputComponent, "analyticsId" | "description" | "disabled" | "help" | "hidden" | "title" | "placeholder" | "control" | "id" | "errors" | "required" | "value" | "autoComplete" | "uid" | "persistedState" | "validationState"> & {
12
+ export declare const createNumberInputComponent: (numberInputProps: Pick<NumberInputComponent, "value" | "id" | "uid" | "control" | "analyticsId" | "title" | "description" | "errors" | "hidden" | "help" | "disabled" | "placeholder" | "required" | "autoComplete" | "persistedState" | "validationState"> & {
13
13
  checks: IsInvalidCheck<number | null>[];
14
14
  performPersistAsync: PerformPersistAsync | undefined;
15
15
  performRefresh: PerformRefresh | undefined;
@@ -5,7 +5,7 @@ export type ObjectComponent = ComponentWithTitle & {
5
5
  getChildren: () => DomainComponent[];
6
6
  getLocalValue: () => LocalValueObject;
7
7
  };
8
- export declare const createObjectComponent: (objectProps: Pick<ObjectComponent, "description" | "help" | "hidden" | "title" | "control" | "componentMap"> & {
8
+ export declare const createObjectComponent: (objectProps: Pick<ObjectComponent, "control" | "title" | "description" | "hidden" | "help" | "componentMap"> & {
9
9
  uid: string;
10
10
  analyticsId?: string | undefined;
11
11
  displayOrder: string[];
@@ -22,7 +22,7 @@ export type SelectInputOption = {
22
22
  keywords?: string[];
23
23
  disabled: boolean;
24
24
  };
25
- export declare const createSelectInputComponent: (selectProps: Pick<SelectInputComponent, "analyticsId" | "description" | "disabled" | "help" | "hidden" | "title" | "placeholder" | "control" | "id" | "errors" | "required" | "autoComplete" | "uid" | "persistedState"> & {
25
+ export declare const createSelectInputComponent: (selectProps: Pick<SelectInputComponent, "id" | "uid" | "control" | "analyticsId" | "title" | "description" | "errors" | "hidden" | "help" | "disabled" | "placeholder" | "required" | "autoComplete" | "persistedState"> & {
26
26
  initialValue: LocalValue;
27
27
  options: (SelectInputOption & {
28
28
  component: DomainComponent;
@@ -18,7 +18,7 @@ type BackNavigation = {
18
18
  title?: string;
19
19
  onClick: () => void;
20
20
  };
21
- export declare const createStepComponent: (stepProps: Pick<StepDomainComponent, "external" | "components" | "back" | "loadingState" | "uid" | "trackEvent"> & {
21
+ export declare const createStepComponent: (stepProps: Pick<StepDomainComponent, "uid" | "components" | "external" | "trackEvent" | "back" | "loadingState"> & {
22
22
  stepPolling?: StepPolling | undefined;
23
23
  updateComponent: UpdateComponent;
24
24
  }) => StepDomainComponent;