@beinformed/ui 1.60.5 → 1.60.6

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 (46) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/esm/hooks/__tests__/useForm.spec.js.flow +1 -1
  3. package/esm/hooks/useForm.js +15 -20
  4. package/esm/hooks/useForm.js.flow +5 -14
  5. package/esm/hooks/useForm.js.map +1 -1
  6. package/esm/hooks/useModularUI.d.ts +0 -1
  7. package/esm/hooks/useModularUI.js +3 -11
  8. package/esm/hooks/useModularUI.js.flow +4 -23
  9. package/esm/hooks/useModularUI.js.map +1 -1
  10. package/esm/redux/_modularui/ModularUIActions.d.ts +2 -2
  11. package/esm/redux/_modularui/ModularUIActions.js +27 -10
  12. package/esm/redux/_modularui/ModularUIActions.js.flow +24 -5
  13. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  14. package/esm/redux/_modularui/ModularUIMiddleware.js +1 -1
  15. package/esm/redux/_modularui/ModularUIMiddleware.js.flow +1 -1
  16. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  17. package/esm/redux/_modularui/ModularUIReducer.js +4 -2
  18. package/esm/redux/_modularui/ModularUIReducer.js.flow +10 -1
  19. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  20. package/esm/redux/_modularui/__tests__/actions.spec.js.flow +5 -1
  21. package/esm/redux/_modularui/types.d.ts +1 -0
  22. package/esm/redux/_modularui/types.js.flow +2 -0
  23. package/esm/redux/_modularui/types.js.map +1 -1
  24. package/lib/hooks/useForm.js +14 -19
  25. package/lib/hooks/useForm.js.map +1 -1
  26. package/lib/hooks/useModularUI.d.ts +0 -1
  27. package/lib/hooks/useModularUI.js +4 -13
  28. package/lib/hooks/useModularUI.js.map +1 -1
  29. package/lib/redux/_modularui/ModularUIActions.d.ts +2 -2
  30. package/lib/redux/_modularui/ModularUIActions.js +27 -10
  31. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  32. package/lib/redux/_modularui/ModularUIMiddleware.js +1 -1
  33. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  34. package/lib/redux/_modularui/ModularUIReducer.js +4 -2
  35. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  36. package/lib/redux/_modularui/types.d.ts +1 -0
  37. package/lib/redux/_modularui/types.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/hooks/__tests__/useForm.spec.js +1 -1
  40. package/src/hooks/useForm.js +5 -14
  41. package/src/hooks/useModularUI.js +4 -23
  42. package/src/redux/_modularui/ModularUIActions.js +24 -5
  43. package/src/redux/_modularui/ModularUIMiddleware.js +1 -1
  44. package/src/redux/_modularui/ModularUIReducer.js +10 -1
  45. package/src/redux/_modularui/__tests__/actions.spec.js +5 -1
  46. package/src/redux/_modularui/types.js +2 -0
@@ -10,7 +10,7 @@ import type {
10
10
  UpdateFormAction,
11
11
  } from "../redux/_modularui";
12
12
  import { loadModularUI, removeModelByKey } from "../redux/_modularui";
13
- import { createKeyForModularUIStore, useModularUI } from "./useModularUI";
13
+ import { useModularUI } from "./useModularUI";
14
14
 
15
15
  import {
16
16
  addRepeatableAttributeSet,
@@ -47,8 +47,6 @@ type AttributeUpdateHook = (
47
47
  options: UpdateFormOptions,
48
48
  ) => void;
49
49
 
50
- const FORM_MODEL_KEY = "form";
51
-
52
50
  /**
53
51
  * Load a form by href
54
52
  */
@@ -59,7 +57,7 @@ export const useForm = (href: string | Href, data?: Object): ?FormModel => {
59
57
  formHref.addParameter("commit", "false");
60
58
  }
61
59
 
62
- const form = useModularUI(FORM_MODEL_KEY, formHref, {
60
+ const form = useModularUI("form", formHref, {
63
61
  method: HTTP_METHODS.POST,
64
62
  targetModel: FormModel,
65
63
  removeOnUnmount: true,
@@ -83,15 +81,9 @@ export const useFormNavigation = (): FormNavigationHook => {
83
81
 
84
82
  const cancel = (form: FormModel) => dispatch(cancelForm(form));
85
83
 
86
- const submit = (form: FormModel) => {
87
- const connectKey = createKeyForModularUIStore(
88
- FORM_MODEL_KEY,
89
- form.selfhref.toString(),
90
- form.locale,
91
- );
92
-
93
- return dispatch(
94
- loadModularUI(connectKey, form.selfhref, {
84
+ const submit = (form: FormModel) =>
85
+ dispatch(
86
+ loadModularUI(form.connectKey, form.selfhref, {
95
87
  method: HTTP_METHODS.POST,
96
88
  data: form.formdata,
97
89
  updateHandler: (newModel: ModularUIModel): ModularUIModel => {
@@ -105,7 +97,6 @@ export const useFormNavigation = (): FormNavigationHook => {
105
97
  targetModel: FormModel,
106
98
  }),
107
99
  );
108
- };
109
100
 
110
101
  const remove = (form: FormModel) =>
111
102
  dispatch(removeModelByKey(form.connectKey));
@@ -18,26 +18,11 @@ import type { RequestModularUIOptions } from "../utils";
18
18
 
19
19
  /**
20
20
  */
21
- export const createKeyForModularUIStore = (
22
- modelKey: string,
23
- url: string,
24
- locale: string,
25
- ): string => {
26
- return `${modelKey}(${url})(${locale})`;
27
- };
28
-
29
- /**
30
- */
31
- const useKeyForHook = (
32
- modelKey: string,
33
- url: string,
34
- removeQuerystringFromKey: boolean = true,
35
- ): string => {
21
+ const useKeyForHook = (modelKey: string, url: string) => {
36
22
  const locale = useLocale();
37
- const href = removeQuerystringFromKey ? url.split("?")[0] : url;
38
23
  return useMemo(
39
- () => createKeyForModularUIStore(modelKey, href, locale),
40
- [modelKey, href, locale],
24
+ () => `${modelKey}(${url.split("?")[0]})(${locale})`,
25
+ [modelKey, url, locale],
41
26
  );
42
27
  };
43
28
 
@@ -54,11 +39,7 @@ export const useModularUI = (
54
39
  ): any => {
55
40
  const dispatch = useDispatch();
56
41
  const href = useMemo(() => url?.toString() || "", [url]);
57
- const key = useKeyForHook(
58
- modelKey,
59
- href,
60
- !options.method || options.method === HTTP_METHODS.GET,
61
- );
42
+ const key = useKeyForHook(modelKey, href);
62
43
 
63
44
  const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);
64
45
  const model = useSelector(modelSelector);
@@ -81,9 +81,10 @@ export const resetModularUI = (): ResetModularUIAction => ({
81
81
  export const updateStatus = (
82
82
  key: string,
83
83
  status: $Keys<typeof MODULARUI_STATUS>,
84
+ requestOptions: any,
84
85
  ): UpdateStatusAction => ({
85
86
  type: "MODULARUI/STATUS",
86
- payload: { key, status },
87
+ payload: { key, status, requestOptions },
87
88
  });
88
89
 
89
90
  /**
@@ -177,13 +178,31 @@ export const loadModularUI =
177
178
  key: string,
178
179
  href: Href | string,
179
180
  options?: RequestModularUIOptions,
181
+ retryCount: number = 3,
182
+ retryDelay: number = 200,
180
183
  ): ThunkAction =>
181
184
  (dispatch: Dispatch, getState) => {
182
185
  const modularuiStore = getState()?.modularui;
183
- if (
184
- modularuiStore &&
185
- modularuiStore[key]?.status === MODULARUI_STATUS.LOADING
186
- ) {
186
+ const currentRequest = modularuiStore?.[key];
187
+
188
+ const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;
189
+
190
+ if (isLoading) {
191
+ const isDifferentRequest =
192
+ currentRequest.requestOptions?.href?.toString() !== href.toString();
193
+ if (isDifferentRequest && retryCount > 0) {
194
+ return new Promise((resolve) => {
195
+ setTimeout(() => {
196
+ resolve(
197
+ dispatch(
198
+ loadModularUI(key, href, options, retryCount - 1, retryDelay),
199
+ ),
200
+ );
201
+ }, retryDelay);
202
+ });
203
+ }
204
+
205
+ // Same request is already loading — do nothing
187
206
  return Promise.resolve();
188
207
  }
189
208
 
@@ -150,7 +150,7 @@ const handleFetch = (
150
150
 
151
151
  const modularuiRequest = createRequest(requestOptions);
152
152
 
153
- dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));
153
+ dispatch(updateStatus(key, MODULARUI_STATUS.LOADING, requestOptions));
154
154
 
155
155
  return modularuiRequest
156
156
  .fetch()
@@ -11,7 +11,15 @@ import type { ModularUIModel } from "../../models";
11
11
  */
12
12
  const updateStatus = (
13
13
  state: ModularUIState,
14
- { key, status }: { key: string, status: $Keys<typeof MODULARUI_STATUS> },
14
+ {
15
+ key,
16
+ status,
17
+ requestOptions,
18
+ }: {
19
+ key: string,
20
+ status: $Keys<typeof MODULARUI_STATUS>,
21
+ requestOptions: any,
22
+ },
15
23
  ) => {
16
24
  // model should always be available when status is not loading
17
25
  if (status !== MODULARUI_STATUS.LOADING && !state[key]) {
@@ -24,6 +32,7 @@ const updateStatus = (
24
32
  ...state[key],
25
33
  status,
26
34
  lastModification: Date.now(),
35
+ requestOptions: requestOptions || state[key]?.requestOptions,
27
36
  },
28
37
  };
29
38
  };
@@ -72,7 +72,11 @@ describe("modularui actions", () => {
72
72
  expect(store.getActions()).toStrictEqual([
73
73
  {
74
74
  type: "MODULARUI/STATUS",
75
- payload: { key: "application", status: MODULARUI_STATUS.LOADING },
75
+ payload: {
76
+ key: "application",
77
+ status: MODULARUI_STATUS.LOADING,
78
+ requestOptions: undefined,
79
+ },
76
80
  },
77
81
  ]);
78
82
  });
@@ -21,6 +21,7 @@ export type ModelEntry = {
21
21
  +status: string,
22
22
  +model: ModularUIModel,
23
23
  +lastModification: number,
24
+ +requestOptions?: any,
24
25
  };
25
26
 
26
27
  export type ModularUIState = {
@@ -111,6 +112,7 @@ export type UpdateStatusAction = {
111
112
  payload: {
112
113
  key: string,
113
114
  status: $Keys<MODULARUI_STATUS>,
115
+ requestOptions: any,
114
116
  },
115
117
  };
116
118