@beinformed/ui 1.42.2 → 1.43.1

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,20 @@
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.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.43.0...v1.43.1) (2024-03-11)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **models:** memoize retrieval of models from modularui ([b2c6b95](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/b2c6b95ba969e8b97553f3bbe4af183f6f02006a))
11
+
12
+ ## [1.43.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.42.2...v1.43.0) (2024-03-11)
13
+
14
+
15
+ ### Features
16
+
17
+ * **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))
18
+
5
19
  ## [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
20
 
7
21
 
@@ -1,13 +1,30 @@
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 { createSelector } from "reselect";
5
+ import { useSelector, useDispatch } from "react-redux";
2
6
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
7
+ import { MODULARUI_STATUS } from "../constants/Constants";
3
8
  /**
4
9
  * Hook that contains the reload property that can be used to reload a model
5
10
  */
6
11
  export const useModels = () => {
7
12
  const dispatch = useDispatch();
13
+ const selectModularUI = state => state.modularui;
14
+ const selector = createSelector([selectModularUI], modularui => {
15
+ var _context, _context2;
16
+ return _mapInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$values(modularui)).call(_context2, model => model.status === MODULARUI_STATUS.FINISHED)).call(_context, model => model.model);
17
+ });
18
+ const modularuiModels = useSelector(selector);
8
19
  return {
9
20
  reload: (model, options) => {
10
21
  dispatch(reloadModel(model, options));
22
+ },
23
+ reloadWithFilter: (callbackFn, options) => {
24
+ const modelsToReload = _filterInstanceProperty(modularuiModels).call(modularuiModels, callbackFn);
25
+ for (const modelToReload of modelsToReload) {
26
+ dispatch(reloadModel(modelToReload, options));
27
+ }
11
28
  }
12
29
  };
13
30
  };
@@ -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":["createSelector","useSelector","useDispatch","reloadModel","MODULARUI_STATUS","useModels","dispatch","selectModularUI","state","modularui","selector","_context","_context2","_mapInstanceProperty","_filterInstanceProperty","_Object$values","call","model","status","FINISHED","modularuiModels","reload","options","reloadWithFilter","callbackFn","modelsToReload","modelToReload"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { createSelector } from \"reselect\";\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\";\nimport type { ReduxState } from \"../redux\";\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\n const selectModularUI = (state: ReduxState) => state.modularui;\n const selector = createSelector([selectModularUI], (modularui) =>\n Object.values(modularui)\n .filter((model) => model.status === MODULARUI_STATUS.FINISHED)\n .map((model) => model.model),\n );\n const modularuiModels = useSelector(selector);\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,cAAc,QAAQ,UAAU;AACzC,SAASC,WAAW,EAAEC,WAAW,QAAQ,aAAa;AAEtD,SAASC,WAAW,QAAQ,sCAAsC;AAClE,SAASC,gBAAgB,QAAQ,wBAAwB;AAYzD;AACA;AACA;AACA,OAAO,MAAMC,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAGJ,WAAW,CAAC,CAAC;EAE9B,MAAMK,eAAe,GAAIC,KAAiB,IAAKA,KAAK,CAACC,SAAS;EAC9D,MAAMC,QAAQ,GAAGV,cAAc,CAAC,CAACO,eAAe,CAAC,EAAGE,SAAS;IAAA,IAAAE,QAAA,EAAAC,SAAA;IAAA,OAC3DC,oBAAA,CAAAF,QAAA,GAAAG,uBAAA,CAAAF,SAAA,GAAAG,cAAA,CAAcN,SAAS,CAAC,EAAAO,IAAA,CAAAJ,SAAA,EACbK,KAAK,IAAKA,KAAK,CAACC,MAAM,KAAKd,gBAAgB,CAACe,QAAQ,CAAC,EAAAH,IAAA,CAAAL,QAAA,EACxDM,KAAK,IAAKA,KAAK,CAACA,KAAK,CAAC;EAAA,CAChC,CAAC;EACD,MAAMG,eAAe,GAAGnB,WAAW,CAACS,QAAQ,CAAC;EAE7C,OAAO;IACLW,MAAM,EAAEA,CAACJ,KAAqB,EAAEK,OAAgB,KAAK;MACnDhB,QAAQ,CAACH,WAAW,CAACc,KAAK,EAAEK,OAAO,CAAC,CAAC;IACvC,CAAC;IACDC,gBAAgB,EAAEA,CAACC,UAA0B,EAAEF,OAAgB,KAAK;MAClE,MAAMG,cAAc,GAAGX,uBAAA,CAAAM,eAAe,EAAAJ,IAAA,CAAfI,eAAe,EAAQI,UAAU,CAAC;MACzD,KAAK,MAAME,aAAa,IAAID,cAAc,EAAE;QAC1CnB,QAAQ,CAACH,WAAW,CAACuB,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,37 @@
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"));
11
+ var _reselect = require("reselect");
7
12
  var _reactRedux = require("react-redux");
8
13
  var _ModularUIActions = require("../redux/_modularui/ModularUIActions");
14
+ var _Constants = require("../constants/Constants");
9
15
  /**
10
16
  * Hook that contains the reload property that can be used to reload a model
11
17
  */
12
18
  const useModels = () => {
13
19
  const dispatch = (0, _reactRedux.useDispatch)();
20
+ const selectModularUI = state => state.modularui;
21
+ const selector = (0, _reselect.createSelector)([selectModularUI], modularui => {
22
+ var _context, _context2;
23
+ return (0, _map.default)(_context = (0, _filter.default)(_context2 = (0, _values.default)(modularui)).call(_context2, model => model.status === _Constants.MODULARUI_STATUS.FINISHED)).call(_context, model => model.model);
24
+ });
25
+ const modularuiModels = (0, _reactRedux.useSelector)(selector);
14
26
  return {
15
27
  reload: (model, options) => {
16
28
  dispatch((0, _ModularUIActions.reloadModel)(model, options));
29
+ },
30
+ reloadWithFilter: (callbackFn, options) => {
31
+ const modelsToReload = (0, _filter.default)(modularuiModels).call(modularuiModels, callbackFn);
32
+ for (const modelToReload of modelsToReload) {
33
+ dispatch((0, _ModularUIActions.reloadModel)(modelToReload, options));
34
+ }
17
35
  }
18
36
  };
19
37
  };
@@ -1,12 +1,18 @@
1
1
  // @flow
2
- import { useDispatch } from "react-redux";
2
+ import { createSelector } from "reselect";
3
+ import { useSelector, useDispatch } from "react-redux";
3
4
 
4
5
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
6
+ import { MODULARUI_STATUS } from "../constants/Constants";
5
7
 
6
8
  import type { ModularUIModel } from "../models/types";
9
+ import type { ReduxState } from "../redux";
10
+
11
+ type ReloadCallback = (model: ModularUIModel) => boolean;
7
12
 
8
13
  type UseModels = () => {
9
14
  reload: (model: ModularUIModel, options?: any) => void,
15
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,
10
16
  };
11
17
 
12
18
  /**
@@ -14,9 +20,24 @@ type UseModels = () => {
14
20
  */
15
21
  export const useModels: UseModels = () => {
16
22
  const dispatch = useDispatch();
23
+
24
+ const selectModularUI = (state: ReduxState) => state.modularui;
25
+ const selector = createSelector([selectModularUI], (modularui) =>
26
+ Object.values(modularui)
27
+ .filter((model) => model.status === MODULARUI_STATUS.FINISHED)
28
+ .map((model) => model.model),
29
+ );
30
+ const modularuiModels = useSelector(selector);
31
+
17
32
  return {
18
33
  reload: (model: ModularUIModel, options?: Object) => {
19
34
  dispatch(reloadModel(model, options));
20
35
  },
36
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {
37
+ const modelsToReload = modularuiModels.filter(callbackFn);
38
+ for (const modelToReload of modelsToReload) {
39
+ dispatch(reloadModel(modelToReload, options));
40
+ }
41
+ },
21
42
  };
22
43
  };
@@ -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":["_reselect","require","_reactRedux","_ModularUIActions","_Constants","useModels","dispatch","useDispatch","selectModularUI","state","modularui","selector","createSelector","_context","_context2","_map","default","_filter","_values","call","model","status","MODULARUI_STATUS","FINISHED","modularuiModels","useSelector","reload","options","reloadModel","reloadWithFilter","callbackFn","modelsToReload","modelToReload","exports"],"sources":["../../src/hooks/useModels.js"],"sourcesContent":["// @flow\nimport { createSelector } from \"reselect\";\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\";\nimport type { ReduxState } from \"../redux\";\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\n const selectModularUI = (state: ReduxState) => state.modularui;\n const selector = createSelector([selectModularUI], (modularui) =>\n Object.values(modularui)\n .filter((model) => model.status === MODULARUI_STATUS.FINISHED)\n .map((model) => model.model),\n );\n const modularuiModels = useSelector(selector);\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,SAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAYA;AACA;AACA;AACO,MAAMI,SAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAE9B,MAAMC,eAAe,GAAIC,KAAiB,IAAKA,KAAK,CAACC,SAAS;EAC9D,MAAMC,QAAQ,GAAG,IAAAC,wBAAc,EAAC,CAACJ,eAAe,CAAC,EAAGE,SAAS;IAAA,IAAAG,QAAA,EAAAC,SAAA;IAAA,OAC3D,IAAAC,IAAA,CAAAC,OAAA,EAAAH,QAAA,OAAAI,OAAA,CAAAD,OAAA,EAAAF,SAAA,OAAAI,OAAA,CAAAF,OAAA,EAAcN,SAAS,CAAC,EAAAS,IAAA,CAAAL,SAAA,EACbM,KAAK,IAAKA,KAAK,CAACC,MAAM,KAAKC,2BAAgB,CAACC,QAAQ,CAAC,EAAAJ,IAAA,CAAAN,QAAA,EACxDO,KAAK,IAAKA,KAAK,CAACA,KAAK,CAAC;EAAA,CAChC,CAAC;EACD,MAAMI,eAAe,GAAG,IAAAC,uBAAW,EAACd,QAAQ,CAAC;EAE7C,OAAO;IACLe,MAAM,EAAEA,CAACN,KAAqB,EAAEO,OAAgB,KAAK;MACnDrB,QAAQ,CAAC,IAAAsB,6BAAW,EAACR,KAAK,EAAEO,OAAO,CAAC,CAAC;IACvC,CAAC;IACDE,gBAAgB,EAAEA,CAACC,UAA0B,EAAEH,OAAgB,KAAK;MAClE,MAAMI,cAAc,GAAG,IAAAd,OAAA,CAAAD,OAAA,EAAAQ,eAAe,EAAAL,IAAA,CAAfK,eAAe,EAAQM,UAAU,CAAC;MACzD,KAAK,MAAME,aAAa,IAAID,cAAc,EAAE;QAC1CzB,QAAQ,CAAC,IAAAsB,6BAAW,EAACI,aAAa,EAAEL,OAAO,CAAC,CAAC;MAC/C;IACF;EACF,CAAC;AACH,CAAC;AAACM,OAAA,CAAA5B,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.1",
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,18 @@
1
1
  // @flow
2
- import { useDispatch } from "react-redux";
2
+ import { createSelector } from "reselect";
3
+ import { useSelector, useDispatch } from "react-redux";
3
4
 
4
5
  import { reloadModel } from "../redux/_modularui/ModularUIActions";
6
+ import { MODULARUI_STATUS } from "../constants/Constants";
5
7
 
6
8
  import type { ModularUIModel } from "../models/types";
9
+ import type { ReduxState } from "../redux";
10
+
11
+ type ReloadCallback = (model: ModularUIModel) => boolean;
7
12
 
8
13
  type UseModels = () => {
9
14
  reload: (model: ModularUIModel, options?: any) => void,
15
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: any) => void,
10
16
  };
11
17
 
12
18
  /**
@@ -14,9 +20,24 @@ type UseModels = () => {
14
20
  */
15
21
  export const useModels: UseModels = () => {
16
22
  const dispatch = useDispatch();
23
+
24
+ const selectModularUI = (state: ReduxState) => state.modularui;
25
+ const selector = createSelector([selectModularUI], (modularui) =>
26
+ Object.values(modularui)
27
+ .filter((model) => model.status === MODULARUI_STATUS.FINISHED)
28
+ .map((model) => model.model),
29
+ );
30
+ const modularuiModels = useSelector(selector);
31
+
17
32
  return {
18
33
  reload: (model: ModularUIModel, options?: Object) => {
19
34
  dispatch(reloadModel(model, options));
20
35
  },
36
+ reloadWithFilter: (callbackFn: ReloadCallback, options?: Object) => {
37
+ const modelsToReload = modularuiModels.filter(callbackFn);
38
+ for (const modelToReload of modelsToReload) {
39
+ dispatch(reloadModel(modelToReload, options));
40
+ }
41
+ },
21
42
  };
22
43
  };