@beinformed/ui 1.42.2 → 1.43.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.43.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.42.2...v1.43.0) (2024-03-11)
6
+
7
+
8
+ ### Features
9
+
10
+ * **models:** new method on useModels hook to reload models by filter ([591a375](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/591a375a9ebfcd5e5477234bb01559c90f590840))
11
+
5
12
  ## [1.42.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.42.1...v1.42.2) (2024-03-08)
6
13
 
7
14
 
@@ -1,13 +1,27 @@
1
- import { useDispatch } from "react-redux";
1
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
2
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
3
+ import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
4
+ import { useSelector, useDispatch } from "react-redux";
2
5
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
6
+ import { MODULARUI_STATUS } from "../constants/Constants";
3
7
  /**
4
8
  * Hook that contains the reload property that can be used to reload a model
5
9
  */
6
10
  export const useModels = () => {
7
11
  const dispatch = useDispatch();
12
+ const modularuiModels = useSelector(state => {
13
+ var _context, _context2;
14
+ return _mapInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$values(state.modularui)).call(_context2, model => model.status === MODULARUI_STATUS.FINISHED)).call(_context, model => model.model);
15
+ });
8
16
  return {
9
17
  reload: (model, options) => {
10
18
  dispatch(reloadModel(model, options));
19
+ },
20
+ reloadWithFilter: (callbackFn, options) => {
21
+ const modelsToReload = _filterInstanceProperty(modularuiModels).call(modularuiModels, callbackFn);
22
+ for (const modelToReload of modelsToReload) {
23
+ dispatch(reloadModel(modelToReload, options));
24
+ }
11
25
  }
12
26
  };
13
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModels.js","names":["useDispatch","reloadModel","useModels","dispatch","reload","model","options"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport { reloadModel } from \"../redux/_modularui/ModularUIActions\";\n\nimport type { ModularUIModel } from \"../models/types\";\n\ntype UseModels = () => {\n reload: (model: ModularUIModel, options?: any) => void,\n};\n\n/**\n * Hook that contains the reload property that can be used to reload a model\n */\nexport const useModels: UseModels = () => {\n const dispatch = useDispatch();\n return {\n reload: (model: ModularUIModel, options?: Object) => {\n dispatch(reloadModel(model, options));\n },\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,aAAa;AAEzC,SAASC,WAAW,QAAQ,sCAAsC;AAQlE;AACA;AACA;AACA,OAAO,MAAMC,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAGH,WAAW,CAAC,CAAC;EAC9B,OAAO;IACLI,MAAM,EAAEA,CAACC,KAAqB,EAAEC,OAAgB,KAAK;MACnDH,QAAQ,CAACF,WAAW,CAACI,KAAK,EAAEC,OAAO,CAAC,CAAC;IACvC;EACF,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModels.js","names":["useSelector","useDispatch","reloadModel","MODULARUI_STATUS","useModels","dispatch","modularuiModels","state","_context","_context2","_mapInstanceProperty","_filterInstanceProperty","_Object$values","modularui","call","model","status","FINISHED","reload","options","reloadWithFilter","callbackFn","modelsToReload","modelToReload"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { reloadModel } from \"../redux/_modularui/ModularUIActions\";\nimport { MODULARUI_STATUS } from \"../constants/Constants\";\n\nimport type { ModularUIModel } from \"../models/types\";\n\ntype ReloadCallback = (model: ModularUIModel) => boolean;\n\ntype UseModels = () => {\n reload: (model: ModularUIModel, options?: any) => void,\n reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,\n};\n\n/**\n * Hook that contains the reload property that can be used to reload a model\n */\nexport const useModels: UseModels = () => {\n const dispatch = useDispatch();\n const modularuiModels = useSelector((state) =>\n Object.values(state.modularui)\n .filter((model) => model.status === MODULARUI_STATUS.FINISHED)\n .map((model) => model.model),\n );\n\n return {\n reload: (model: ModularUIModel, options?: Object) => {\n dispatch(reloadModel(model, options));\n },\n reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {\n const modelsToReload = modularuiModels.filter(callbackFn);\n for (const modelToReload of modelsToReload) {\n dispatch(reloadModel(modelToReload, options));\n }\n },\n };\n};\n"],"mappings":";;;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,aAAa;AAEtD,SAASC,WAAW,QAAQ,sCAAsC;AAClE,SAASC,gBAAgB,QAAQ,wBAAwB;AAWzD;AACA;AACA;AACA,OAAO,MAAMC,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAGJ,WAAW,CAAC,CAAC;EAC9B,MAAMK,eAAe,GAAGN,WAAW,CAAEO,KAAK;IAAA,IAAAC,QAAA,EAAAC,SAAA;IAAA,OACxCC,oBAAA,CAAAF,QAAA,GAAAG,uBAAA,CAAAF,SAAA,GAAAG,cAAA,CAAcL,KAAK,CAACM,SAAS,CAAC,EAAAC,IAAA,CAAAL,SAAA,EACnBM,KAAK,IAAKA,KAAK,CAACC,MAAM,KAAKb,gBAAgB,CAACc,QAAQ,CAAC,EAAAH,IAAA,CAAAN,QAAA,EACxDO,KAAK,IAAKA,KAAK,CAACA,KAAK,CAAC;EAAA,CAChC,CAAC;EAED,OAAO;IACLG,MAAM,EAAEA,CAACH,KAAqB,EAAEI,OAAgB,KAAK;MACnDd,QAAQ,CAACH,WAAW,CAACa,KAAK,EAAEI,OAAO,CAAC,CAAC;IACvC,CAAC;IACDC,gBAAgB,EAAEA,CAACC,UAA0B,EAAEF,OAAgB,KAAK;MAClE,MAAMG,cAAc,GAAGX,uBAAA,CAAAL,eAAe,EAAAQ,IAAA,CAAfR,eAAe,EAAQe,UAAU,CAAC;MACzD,KAAK,MAAME,aAAa,IAAID,cAAc,EAAE;QAC1CjB,QAAQ,CAACH,WAAW,CAACqB,aAAa,EAAEJ,OAAO,CAAC,CAAC;MAC/C;IACF;EACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
4
4
  import configureMockStore from "redux-mock-store";
5
5
 
6
6
  import application from "../../models/application/__mock__/application";
7
+ import caselist from "../../models/list/__mock__/caselist";
8
+
7
9
  import thunk from "redux-thunk";
8
10
  import { Href } from "../../models";
9
11
 
@@ -11,7 +13,7 @@ const middlewares = [thunk];
11
13
  const mockStore = configureMockStore(middlewares);
12
14
 
13
15
  describe("model hooks", () => {
14
- it("useModels", () => {
16
+ it("useModels.reload", () => {
15
17
  application.connectKey = "application(/)(en)";
16
18
  const store = mockStore({
17
19
  modularui: {
@@ -49,4 +51,97 @@ describe("model hooks", () => {
49
51
  },
50
52
  ]);
51
53
  });
54
+
55
+ it("useModels.reloadWithFilter - only root", () => {
56
+ application.connectKey = "application(/)(en)";
57
+ const store = mockStore({
58
+ modularui: {
59
+ "application(/)(en)": {
60
+ status: "FINISHED",
61
+ model: application,
62
+ lastModification: 0,
63
+ },
64
+ "list(/books/books)(en)": {
65
+ status: "FINISHED",
66
+ model: caselist,
67
+ lastModification: 0,
68
+ },
69
+ },
70
+ });
71
+
72
+ const wrapper = ({ children }) => (
73
+ <Provider store={store}>{children}</Provider>
74
+ );
75
+
76
+ const { result } = renderHook(() => useModels(), {
77
+ wrapper,
78
+ });
79
+
80
+ expect(typeof result.current.reloadWithFilter).toBe("function");
81
+
82
+ result.current.reloadWithFilter((model) =>
83
+ model.selfhref.equals(new Href("/")),
84
+ );
85
+ expect(store.getActions()).toStrictEqual([
86
+ {
87
+ type: "MODULARUI/STATUS",
88
+ payload: { key: "application(/)(en)", status: "LOADING" },
89
+ },
90
+ { type: "START_PROGRESS" },
91
+ {
92
+ type: "MODULARUI/FETCH",
93
+ payload: expect.objectContaining({
94
+ href: new Href("/", "Application"),
95
+ locale: "en",
96
+ }),
97
+ },
98
+ ]);
99
+ });
100
+
101
+ it("useModels.reloadWithFilter - only tab", () => {
102
+ application.connectKey = "application(/)(en)";
103
+ caselist.connectKey = "list(/books/books)(en)";
104
+ const store = mockStore({
105
+ modularui: {
106
+ "application(/)(en)": {
107
+ status: "FINISHED",
108
+ model: application,
109
+ lastModification: 0,
110
+ },
111
+ "list(/books/books)(en)": {
112
+ status: "FINISHED",
113
+ model: caselist,
114
+ lastModification: 0,
115
+ },
116
+ },
117
+ });
118
+
119
+ const wrapper = ({ children }) => (
120
+ <Provider store={store}>{children}</Provider>
121
+ );
122
+
123
+ const { result } = renderHook(() => useModels(), {
124
+ wrapper,
125
+ });
126
+
127
+ expect(typeof result.current.reloadWithFilter).toBe("function");
128
+
129
+ result.current.reloadWithFilter((model) =>
130
+ model.selfhref.equals(new Href("/books/books")),
131
+ );
132
+ expect(store.getActions()).toStrictEqual([
133
+ {
134
+ type: "MODULARUI/STATUS",
135
+ payload: { key: "list(/books/books)(en)", status: "LOADING" },
136
+ },
137
+ { type: "START_PROGRESS" },
138
+ {
139
+ type: "MODULARUI/FETCH",
140
+ payload: expect.objectContaining({
141
+ href: caselist.selfhref,
142
+ locale: "en",
143
+ }),
144
+ },
145
+ ]);
146
+ });
52
147
  });
@@ -1,19 +1,34 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.useModels = void 0;
8
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
9
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
10
+ var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
7
11
  var _reactRedux = require("react-redux");
8
12
  var _ModularUIActions = require("../redux/_modularui/ModularUIActions");
13
+ var _Constants = require("../constants/Constants");
9
14
  /**
10
15
  * Hook that contains the reload property that can be used to reload a model
11
16
  */
12
17
  const useModels = () => {
13
18
  const dispatch = (0, _reactRedux.useDispatch)();
19
+ const modularuiModels = (0, _reactRedux.useSelector)(state => {
20
+ var _context, _context2;
21
+ return (0, _map.default)(_context = (0, _filter.default)(_context2 = (0, _values.default)(state.modularui)).call(_context2, model => model.status === _Constants.MODULARUI_STATUS.FINISHED)).call(_context, model => model.model);
22
+ });
14
23
  return {
15
24
  reload: (model, options) => {
16
25
  dispatch((0, _ModularUIActions.reloadModel)(model, options));
26
+ },
27
+ reloadWithFilter: (callbackFn, options) => {
28
+ const modelsToReload = (0, _filter.default)(modularuiModels).call(modularuiModels, callbackFn);
29
+ for (const modelToReload of modelsToReload) {
30
+ dispatch((0, _ModularUIActions.reloadModel)(modelToReload, options));
31
+ }
17
32
  }
18
33
  };
19
34
  };
@@ -1,12 +1,16 @@
1
1
  // @flow
2
- import { useDispatch } from "react-redux";
2
+ import { useSelector, useDispatch } from "react-redux";
3
3
 
4
4
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
5
+ import { MODULARUI_STATUS } from "../constants/Constants";
5
6
 
6
7
  import type { ModularUIModel } from "../models/types";
7
8
 
9
+ type ReloadCallback = (model: ModularUIModel) => boolean;
10
+
8
11
  type UseModels = () => {
9
12
  reload: (model: ModularUIModel, options?: any) => void,
13
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,
10
14
  };
11
15
 
12
16
  /**
@@ -14,9 +18,21 @@ type UseModels = () => {
14
18
  */
15
19
  export const useModels: UseModels = () => {
16
20
  const dispatch = useDispatch();
21
+ const modularuiModels = useSelector((state) =>
22
+ Object.values(state.modularui)
23
+ .filter((model) => model.status === MODULARUI_STATUS.FINISHED)
24
+ .map((model) => model.model),
25
+ );
26
+
17
27
  return {
18
28
  reload: (model: ModularUIModel, options?: Object) => {
19
29
  dispatch(reloadModel(model, options));
20
30
  },
31
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {
32
+ const modelsToReload = modularuiModels.filter(callbackFn);
33
+ for (const modelToReload of modelsToReload) {
34
+ dispatch(reloadModel(modelToReload, options));
35
+ }
36
+ },
21
37
  };
22
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModels.js","names":["_reactRedux","require","_ModularUIActions","useModels","dispatch","useDispatch","reload","model","options","reloadModel","exports"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport { reloadModel } from \"../redux/_modularui/ModularUIActions\";\n\nimport type { ModularUIModel } from \"../models/types\";\n\ntype UseModels = () => {\n reload: (model: ModularUIModel, options?: any) => void,\n};\n\n/**\n * Hook that contains the reload property that can be used to reload a model\n */\nexport const useModels: UseModels = () => {\n const dispatch = useDispatch();\n return {\n reload: (model: ModularUIModel, options?: Object) => {\n dispatch(reloadModel(model, options));\n },\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AAQA;AACA;AACA;AACO,MAAME,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAC9B,OAAO;IACLC,MAAM,EAAEA,CAACC,KAAqB,EAAEC,OAAgB,KAAK;MACnDJ,QAAQ,CAAC,IAAAK,6BAAW,EAACF,KAAK,EAAEC,OAAO,CAAC,CAAC;IACvC;EACF,CAAC;AACH,CAAC;AAACE,OAAA,CAAAP,SAAA,GAAAA,SAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModels.js","names":["_reactRedux","require","_ModularUIActions","_Constants","useModels","dispatch","useDispatch","modularuiModels","useSelector","state","_context","_context2","_map","default","_filter","_values","modularui","call","model","status","MODULARUI_STATUS","FINISHED","reload","options","reloadModel","reloadWithFilter","callbackFn","modelsToReload","modelToReload","exports"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { reloadModel } from \"../redux/_modularui/ModularUIActions\";\nimport { MODULARUI_STATUS } from \"../constants/Constants\";\n\nimport type { ModularUIModel } from \"../models/types\";\n\ntype ReloadCallback = (model: ModularUIModel) => boolean;\n\ntype UseModels = () => {\n reload: (model: ModularUIModel, options?: any) => void,\n reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,\n};\n\n/**\n * Hook that contains the reload property that can be used to reload a model\n */\nexport const useModels: UseModels = () => {\n const dispatch = useDispatch();\n const modularuiModels = useSelector((state) =>\n Object.values(state.modularui)\n .filter((model) => model.status === MODULARUI_STATUS.FINISHED)\n .map((model) => model.model),\n );\n\n return {\n reload: (model: ModularUIModel, options?: Object) => {\n dispatch(reloadModel(model, options));\n },\n reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {\n const modelsToReload = modularuiModels.filter(callbackFn);\n for (const modelToReload of modelsToReload) {\n dispatch(reloadModel(modelToReload, options));\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAWA;AACA;AACA;AACO,MAAMG,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAC9B,MAAMC,eAAe,GAAG,IAAAC,uBAAW,EAAEC,KAAK;IAAA,IAAAC,QAAA,EAAAC,SAAA;IAAA,OACxC,IAAAC,IAAA,CAAAC,OAAA,EAAAH,QAAA,OAAAI,OAAA,CAAAD,OAAA,EAAAF,SAAA,OAAAI,OAAA,CAAAF,OAAA,EAAcJ,KAAK,CAACO,SAAS,CAAC,EAAAC,IAAA,CAAAN,SAAA,EACnBO,KAAK,IAAKA,KAAK,CAACC,MAAM,KAAKC,2BAAgB,CAACC,QAAQ,CAAC,EAAAJ,IAAA,CAAAP,QAAA,EACxDQ,KAAK,IAAKA,KAAK,CAACA,KAAK,CAAC;EAAA,CAChC,CAAC;EAED,OAAO;IACLI,MAAM,EAAEA,CAACJ,KAAqB,EAAEK,OAAgB,KAAK;MACnDlB,QAAQ,CAAC,IAAAmB,6BAAW,EAACN,KAAK,EAAEK,OAAO,CAAC,CAAC;IACvC,CAAC;IACDE,gBAAgB,EAAEA,CAACC,UAA0B,EAAEH,OAAgB,KAAK;MAClE,MAAMI,cAAc,GAAG,IAAAb,OAAA,CAAAD,OAAA,EAAAN,eAAe,EAAAU,IAAA,CAAfV,eAAe,EAAQmB,UAAU,CAAC;MACzD,KAAK,MAAME,aAAa,IAAID,cAAc,EAAE;QAC1CtB,QAAQ,CAAC,IAAAmB,6BAAW,EAACI,aAAa,EAAEL,OAAO,CAAC,CAAC;MAC/C;IACF;EACF,CAAC;AACH,CAAC;AAACM,OAAA,CAAAzB,SAAA,GAAAA,SAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.42.2",
3
+ "version": "1.43.0",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
4
4
  import configureMockStore from "redux-mock-store";
5
5
 
6
6
  import application from "../../models/application/__mock__/application";
7
+ import caselist from "../../models/list/__mock__/caselist";
8
+
7
9
  import thunk from "redux-thunk";
8
10
  import { Href } from "../../models";
9
11
 
@@ -11,7 +13,7 @@ const middlewares = [thunk];
11
13
  const mockStore = configureMockStore(middlewares);
12
14
 
13
15
  describe("model hooks", () => {
14
- it("useModels", () => {
16
+ it("useModels.reload", () => {
15
17
  application.connectKey = "application(/)(en)";
16
18
  const store = mockStore({
17
19
  modularui: {
@@ -49,4 +51,97 @@ describe("model hooks", () => {
49
51
  },
50
52
  ]);
51
53
  });
54
+
55
+ it("useModels.reloadWithFilter - only root", () => {
56
+ application.connectKey = "application(/)(en)";
57
+ const store = mockStore({
58
+ modularui: {
59
+ "application(/)(en)": {
60
+ status: "FINISHED",
61
+ model: application,
62
+ lastModification: 0,
63
+ },
64
+ "list(/books/books)(en)": {
65
+ status: "FINISHED",
66
+ model: caselist,
67
+ lastModification: 0,
68
+ },
69
+ },
70
+ });
71
+
72
+ const wrapper = ({ children }) => (
73
+ <Provider store={store}>{children}</Provider>
74
+ );
75
+
76
+ const { result } = renderHook(() => useModels(), {
77
+ wrapper,
78
+ });
79
+
80
+ expect(typeof result.current.reloadWithFilter).toBe("function");
81
+
82
+ result.current.reloadWithFilter((model) =>
83
+ model.selfhref.equals(new Href("/")),
84
+ );
85
+ expect(store.getActions()).toStrictEqual([
86
+ {
87
+ type: "MODULARUI/STATUS",
88
+ payload: { key: "application(/)(en)", status: "LOADING" },
89
+ },
90
+ { type: "START_PROGRESS" },
91
+ {
92
+ type: "MODULARUI/FETCH",
93
+ payload: expect.objectContaining({
94
+ href: new Href("/", "Application"),
95
+ locale: "en",
96
+ }),
97
+ },
98
+ ]);
99
+ });
100
+
101
+ it("useModels.reloadWithFilter - only tab", () => {
102
+ application.connectKey = "application(/)(en)";
103
+ caselist.connectKey = "list(/books/books)(en)";
104
+ const store = mockStore({
105
+ modularui: {
106
+ "application(/)(en)": {
107
+ status: "FINISHED",
108
+ model: application,
109
+ lastModification: 0,
110
+ },
111
+ "list(/books/books)(en)": {
112
+ status: "FINISHED",
113
+ model: caselist,
114
+ lastModification: 0,
115
+ },
116
+ },
117
+ });
118
+
119
+ const wrapper = ({ children }) => (
120
+ <Provider store={store}>{children}</Provider>
121
+ );
122
+
123
+ const { result } = renderHook(() => useModels(), {
124
+ wrapper,
125
+ });
126
+
127
+ expect(typeof result.current.reloadWithFilter).toBe("function");
128
+
129
+ result.current.reloadWithFilter((model) =>
130
+ model.selfhref.equals(new Href("/books/books")),
131
+ );
132
+ expect(store.getActions()).toStrictEqual([
133
+ {
134
+ type: "MODULARUI/STATUS",
135
+ payload: { key: "list(/books/books)(en)", status: "LOADING" },
136
+ },
137
+ { type: "START_PROGRESS" },
138
+ {
139
+ type: "MODULARUI/FETCH",
140
+ payload: expect.objectContaining({
141
+ href: caselist.selfhref,
142
+ locale: "en",
143
+ }),
144
+ },
145
+ ]);
146
+ });
52
147
  });
@@ -1,12 +1,16 @@
1
1
  // @flow
2
- import { useDispatch } from "react-redux";
2
+ import { useSelector, useDispatch } from "react-redux";
3
3
 
4
4
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
5
+ import { MODULARUI_STATUS } from "../constants/Constants";
5
6
 
6
7
  import type { ModularUIModel } from "../models/types";
7
8
 
9
+ type ReloadCallback = (model: ModularUIModel) => boolean;
10
+
8
11
  type UseModels = () => {
9
12
  reload: (model: ModularUIModel, options?: any) => void,
13
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,
10
14
  };
11
15
 
12
16
  /**
@@ -14,9 +18,21 @@ type UseModels = () => {
14
18
  */
15
19
  export const useModels: UseModels = () => {
16
20
  const dispatch = useDispatch();
21
+ const modularuiModels = useSelector((state) =>
22
+ Object.values(state.modularui)
23
+ .filter((model) => model.status === MODULARUI_STATUS.FINISHED)
24
+ .map((model) => model.model),
25
+ );
26
+
17
27
  return {
18
28
  reload: (model: ModularUIModel, options?: Object) => {
19
29
  dispatch(reloadModel(model, options));
20
30
  },
31
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {
32
+ const modelsToReload = modularuiModels.filter(callbackFn);
33
+ for (const modelToReload of modelsToReload) {
34
+ dispatch(reloadModel(modelToReload, options));
35
+ }
36
+ },
21
37
  };
22
38
  };