@beinformed/ui 1.54.1 → 1.54.3

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,21 @@
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.54.3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.2...v1.54.3) (2024-09-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **layouthint-config:** merge duplicate hint entries ([6dfefa3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/6dfefa36c7c00c4d7f139eff313c3a4c24853968))
11
+ * **modularui-connector:** make it possible to set removeOnUnmount with a property ([959ce04](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/959ce0447fce2d725c7bd8316a2c1cc4477cc1d1))
12
+
13
+ ## [1.54.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.1...v1.54.2) (2024-09-17)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **layouthint-config:** merge duplicate hint entries ([29b837c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/29b837c83d991d6f5dada5f6cd0eb165abdbd2eb))
19
+
5
20
  ## [1.54.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.0...v1.54.1) (2024-09-17)
6
21
 
7
22
 
@@ -1,5 +1,5 @@
1
1
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
2
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
2
+ import _Set from "@babel/runtime-corejs3/core-js-stable/set";
3
3
  import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
4
4
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
5
5
  const path = require("path");
@@ -9,6 +9,7 @@ const {
9
9
  readFileSync,
10
10
  writeFileSync
11
11
  } = require("fs");
12
+ const mergeWith = require("lodash/mergeWith");
12
13
  const {
13
14
  LayoutHintConfiguration
14
15
  } = require("../constants/LayoutHintConfig");
@@ -42,7 +43,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
42
43
  const content = readFileSync(file, "utf-8");
43
44
  return JSON.parse(content);
44
45
  });
45
- const newConfig = _Object$assign(LayoutHintConfiguration, ...jsons);
46
+
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue, srcValue) => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new _Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
46
54
  writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), _JSON$stringify(newConfig));
47
55
  return _Promise.resolve();
48
56
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","newConfig","_Object$assign","_JSON$stringify","_Promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAM;EAAEK;AAAwB,CAAC,GAAGL,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMM,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGR,WAAW,CAACM,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGZ,IAAI,CAACa,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIR,QAAQ,CAACS,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGjB,IAAI,CAACkB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAGC,oBAAA,CAAAhB,KAAK,EAAAiB,IAAA,CAALjB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMiB,OAAO,GAAGxB,YAAY,CAACO,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOkB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;EAEF,MAAMG,SAAS,GAAGC,cAAA,CAAc1B,uBAAuB,EAAE,GAAGmB,KAAK,CAAC;EAElEpB,aAAa,CACXL,IAAI,CAACa,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChDW,eAAA,CAAeF,SAAS,CAC1B,CAAC;EAED,OAAOG,QAAA,CAAQC,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_Set","newConfig","_JSON$stringify","_Promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,K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ACjD;EACF,CAAC;EAED,MAAMI,SAAS,GAAGhC,SAAS,CAACC,uBAAuB,EAAE,GAAGmB,KAAK,EAAEM,UAAU,CAAC;EAE1E3B,aAAa,CACXL,IAAI,CAACc,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChDgB,eAAA,CAAeD,SAAS,CAC1B,CAAC;EAED,OAAOE,QAAA,CAAQC,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
@@ -41,6 +41,8 @@ const modularUIConnector = function (name, resource) {
41
41
  } = options;
42
42
  return Component => {
43
43
  const WrappedComponent = props => {
44
+ // explicit property for removeOnMount overwrite the setting
45
+ const finalRemoveOnUnmount = props.removeOnUnmount === true ? true : removeOnUnmount;
44
46
  const dispatch = useDispatch();
45
47
  const location = useLocation();
46
48
  const url = useUrl(resource, {
@@ -50,7 +52,10 @@ const modularUIConnector = function (name, resource) {
50
52
  const displayName = getDisplayName(Component, name, props.contextId);
51
53
 
52
54
  // Load the model through the useModUI hook
53
- const modelEntry = useModularUI(displayName, url, otherOptions);
55
+ const modelEntry = useModularUI(displayName, url, {
56
+ ...otherOptions,
57
+ removeOnUnmount: finalRemoveOnUnmount
58
+ });
54
59
  const modelKey = modelEntry?.model?.connectKey;
55
60
 
56
61
  // handle manual reload of model
@@ -79,11 +84,11 @@ const modularUIConnector = function (name, resource) {
79
84
  // Remove model when hoc unloads
80
85
  useEffect(() => {
81
86
  return () => {
82
- if (removeOnUnmount) {
87
+ if (finalRemoveOnUnmount) {
83
88
  dispatch(removeModelByKey(modelKey));
84
89
  }
85
90
  };
86
- }, [dispatch, modelKey]);
91
+ }, [dispatch, modelKey, finalRemoveOnUnmount]);
87
92
 
88
93
  // Create new properties object to inject modularui properties to own props
89
94
  const locale = useLocale();
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","FormModel","jsx","_jsx","patchUpdateModelOption","oldOptions","updateModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (removeOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n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MAEvC;MACA1C,SAAS,CAAC,MAAM;QACd,OAAO,MAAM;UACX,IAAI+B,eAAe,EAAE;YACnBK,QAAQ,CAAC/B,gBAAgB,CAACqC,QAAQ,CAAC,CAAC;UACtC;QACF,CAAC;MACH,CAAC,EAAE,CAACN,QAAQ,EAAEM,QAAQ,CAAC,CAAC;;MAExB;MACA,MAAMY,MAAM,GAAG3C,SAAS,CAAC,CAAC;MAC1B,MAAM4C,QAAuB,GAAG;QAC9Bb,QAAQ;QACR,CAACZ,QAAQ,GAAGW,UAAU,GAAGA,UAAU,CAACE,KAAK,GAAG,IAAI;QAChDN,QAAQ;QACRmB,MAAM,EAAEf,UAAU,GAAGA,UAAU,CAACe,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEhB,UAAU,GAAGA,UAAU,CAACgB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAAClB,UAAU,CAAC;QAC7Ba,MAAM;QACNM,cAAc,EAAEb,WAAW;QAC3B3C,WAAW,EAAEyC;MACf,CAAC;MAED,oBAAO/B,IAAA,CAACmB,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAMoB;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDrB,gBAAgB,CAACK,WAAW,GAAG,gBAAgBhC,cAAc,CAC3D2B,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAED,eAAeX,kBAAkB","ignoreList":[]}
1
+ {"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","FormModel","jsx","_jsx","patchUpdateModelOption","oldOptions","updateModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","finalRemoveOnUnmount","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n // explicit property for removeOnMount overwrite the setting\n const finalRemoveOnUnmount =\n props.removeOnUnmount === true ? true : removeOnUnmount;\n\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, {\n ...otherOptions,\n removeOnUnmount: finalRemoveOnUnmount,\n });\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (finalRemoveOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey, finalRemoveOnUnmount]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,O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AC;QACH;MACF,CAAC,EAAE,CAACjB,QAAQ,EAAEgB,QAAQ,EAAEd,GAAG,EAAEI,QAAQ,CAAC,CAAC;;MAEvC;MACA3C,SAAS,CAAC,MAAM;QACd,OAAO,MAAM;UACX,IAAIoC,oBAAoB,EAAE;YACxBC,QAAQ,CAAChC,gBAAgB,CAACsC,QAAQ,CAAC,CAAC;UACtC;QACF,CAAC;MACH,CAAC,EAAE,CAACN,QAAQ,EAAEM,QAAQ,EAAEP,oBAAoB,CAAC,CAAC;;MAE9C;MACA,MAAMmB,MAAM,GAAG5C,SAAS,CAAC,CAAC;MAC1B,MAAM6C,QAAuB,GAAG;QAC9Bb,QAAQ;QACR,CAACb,QAAQ,GAAGY,UAAU,GAAGA,UAAU,CAACE,KAAK,GAAG,IAAI;QAChDN,QAAQ;QACRmB,MAAM,EAAEf,UAAU,GAAGA,UAAU,CAACe,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEhB,UAAU,GAAGA,UAAU,CAACgB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAAClB,UAAU,CAAC;QAC7Ba,MAAM;QACNM,cAAc,EAAEb,WAAW;QAC3B5C,WAAW,EAAE0C;MACf,CAAC;MAED,oBAAOhC,IAAA,CAACmB,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAMqB;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDtB,gBAAgB,CAACM,WAAW,GAAG,gBAAgBjC,cAAc,CAC3D2B,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAED,eAAeX,kBAAkB","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
2
2
  import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
3
3
  const fs = require("fs");
4
+
4
5
  //
5
6
  const projectJson1 = {
6
7
  MOCK: {
@@ -26,6 +27,18 @@ const projectJson2 = {
26
27
  },
27
28
  };
28
29
 
30
+ const projectMerge = {
31
+ MERGE: {
32
+ hint: "merge",
33
+ description: {
34
+ NL: "merge with extra component",
35
+ EN: "merge with extra component",
36
+ },
37
+ link: "",
38
+ component: ["component1", "component2", "component3"],
39
+ },
40
+ };
41
+
29
42
  jest.mock("fs", () => ({
30
43
  ...jest.requireActual("fs"),
31
44
  writeFileSync: jest.fn(),
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
33
46
 
34
47
  describe("mergeLayoutHintConfigurations", () => {
35
48
  it("generates layouthint.json", async () => {
36
- expect.assertions(1);
49
+ expect.assertions(2);
37
50
 
38
51
  const expectedJson = {
39
52
  ...LayoutHintConfiguration,
40
53
  ...projectJson1,
41
54
  ...projectJson2,
55
+ ...projectMerge,
42
56
  };
43
57
 
44
58
  await mergeLayoutHintConfigurations("./src", "/output");
45
59
 
46
60
  expect(fs.writeFileSync).toHaveBeenCalledWith(
47
61
  expect.stringContaining("LayoutHintConfig.json"),
48
- JSON.stringify(expectedJson),
62
+ expect.any(String),
49
63
  );
64
+
65
+ // Check that the JSON written matches the expected JSON
66
+ const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
67
+
68
+ // Compare objects using deep comparison to ensure they are equal
69
+ expect(actualJson).toEqual(expectedJson);
50
70
  });
51
71
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
4
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
5
- var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
5
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
6
6
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
7
7
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
8
8
  const path = require("path");
@@ -12,6 +12,7 @@ const {
12
12
  readFileSync,
13
13
  writeFileSync
14
14
  } = require("fs");
15
+ const mergeWith = require("lodash/mergeWith");
15
16
  const {
16
17
  LayoutHintConfiguration
17
18
  } = require("../constants/LayoutHintConfig");
@@ -45,7 +46,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
45
46
  const content = readFileSync(file, "utf-8");
46
47
  return JSON.parse(content);
47
48
  });
48
- const newConfig = (0, _assign.default)(LayoutHintConfiguration, ...jsons);
49
+
50
+ // Function to merge arrays during merging
51
+ const customizer = (objValue, srcValue) => {
52
+ if (Array.isArray(objValue)) {
53
+ return [...new _set.default([...objValue, ...srcValue])];
54
+ }
55
+ };
56
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
49
57
  writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), (0, _stringify.default)(newConfig));
50
58
  return _promise.default.resolve();
51
59
  };
@@ -2,6 +2,7 @@
2
2
  const path = require("path");
3
3
  const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
4
4
 
5
+ const mergeWith = require("lodash/mergeWith");
5
6
  const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
6
7
 
7
8
  const findFiles = (dir: string): Array<string> => {
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
43
44
  return JSON.parse(content);
44
45
  });
45
46
 
46
- const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue: Object, srcValue: Object): Object => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+
54
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
47
55
 
48
56
  writeFileSync(
49
57
  path.join(outputFolder, "LayoutHintConfig.json"),
@@ -1 +1 @@
1
- {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","newConfig","_assign","_stringify","_promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAM;EAAEK;AAAwB,CAAC,GAAGL,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAA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AACS,YAAY,EAAE,uBAAuB,CAAC,EAChD,IAAAY,UAAA,CAAAP,OAAA,EAAeK,SAAS,CAC1B,CAAC;EAED,OAAOG,QAAA,CAAAR,OAAA,CAAQS,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_set","newConfig","_stringify","_promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGT,WAAW,CAACO,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGb,IAAI,CAACc,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIT,QAAQ,CAACU,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGlB,IAAI,CAACmB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAG,IAAAC,IAAA,CAAAC,OAAA,EAAAjB,KAAK,EAAAkB,IAAA,CAALlB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMkB,OAAO,GAAG1B,YAAY,CAACQ,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOmB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;;EAEF;EACA,MAAMG,UAAU,GAAGA,CAACC,QAAgB,EAAEC,QAAgB,KAAa;IACjE,IAAIC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,EAAE;MAC3B,OAAO,CAAC,GAAG,IAAAI,IAAA,CAAAV,OAAA,CAAQ,CAAC,GAAGM,QAAQ,EAAE,GAAGC,QAAQ,CAAC,CAAC,CAAC;IACjD;EACF,CAAC;EAED,MAAMI,SAAS,GAAGjC,SAAS,CAACC,uBAAuB,EAAE,GAAGmB,KAAK,EAAEO,UAAU,CAAC;EAE1E5B,aAAa,CACXL,IAAI,CAACc,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChD,IAAAiB,UAAA,CAAAZ,OAAA,EAAeW,SAAS,CAC1B,CAAC;EAED,OAAOE,QAAA,CAAAb,OAAA,CAAQc,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
@@ -48,6 +48,8 @@ const modularUIConnector = function (name, resource) {
48
48
  } = options;
49
49
  return Component => {
50
50
  const WrappedComponent = props => {
51
+ // explicit property for removeOnMount overwrite the setting
52
+ const finalRemoveOnUnmount = props.removeOnUnmount === true ? true : removeOnUnmount;
51
53
  const dispatch = (0, _reactRedux.useDispatch)();
52
54
  const location = (0, _reactRouter.useLocation)();
53
55
  const url = (0, _ModularUIUtils.useUrl)(resource, {
@@ -57,7 +59,10 @@ const modularUIConnector = function (name, resource) {
57
59
  const displayName = (0, _utils.getDisplayName)(Component, name, props.contextId);
58
60
 
59
61
  // Load the model through the useModUI hook
60
- const modelEntry = (0, _useModularUI.useModularUI)(displayName, url, otherOptions);
62
+ const modelEntry = (0, _useModularUI.useModularUI)(displayName, url, {
63
+ ...otherOptions,
64
+ removeOnUnmount: finalRemoveOnUnmount
65
+ });
61
66
  const modelKey = modelEntry?.model?.connectKey;
62
67
 
63
68
  // handle manual reload of model
@@ -86,11 +91,11 @@ const modularUIConnector = function (name, resource) {
86
91
  // Remove model when hoc unloads
87
92
  (0, _react.useEffect)(() => {
88
93
  return () => {
89
- if (removeOnUnmount) {
94
+ if (finalRemoveOnUnmount) {
90
95
  dispatch((0, _ModularUIActions.removeModelByKey)(modelKey));
91
96
  }
92
97
  };
93
- }, [dispatch, modelKey]);
98
+ }, [dispatch, modelKey, finalRemoveOnUnmount]);
94
99
 
95
100
  // Create new properties object to inject modularui properties to own props
96
101
  const locale = (0, _useI18n.useLocale)();
@@ -71,6 +71,10 @@ const modularUIConnector = (
71
71
 
72
72
  return (Component: ComponentType<any>) => {
73
73
  const WrappedComponent = (props: any) => {
74
+ // explicit property for removeOnMount overwrite the setting
75
+ const finalRemoveOnUnmount =
76
+ props.removeOnUnmount === true ? true : removeOnUnmount;
77
+
74
78
  const dispatch = useDispatch();
75
79
  const location = useLocation();
76
80
 
@@ -78,7 +82,10 @@ const modularUIConnector = (
78
82
  const displayName = getDisplayName(Component, name, props.contextId);
79
83
 
80
84
  // Load the model through the useModUI hook
81
- const modelEntry = useModularUI(displayName, url, otherOptions);
85
+ const modelEntry = useModularUI(displayName, url, {
86
+ ...otherOptions,
87
+ removeOnUnmount: finalRemoveOnUnmount,
88
+ });
82
89
  const modelKey = modelEntry?.model?.connectKey;
83
90
 
84
91
  // handle manual reload of model
@@ -114,11 +121,11 @@ const modularUIConnector = (
114
121
  // Remove model when hoc unloads
115
122
  useEffect(() => {
116
123
  return () => {
117
- if (removeOnUnmount) {
124
+ if (finalRemoveOnUnmount) {
118
125
  dispatch(removeModelByKey(modelKey));
119
126
  }
120
127
  };
121
- }, [dispatch, modelKey]);
128
+ }, [dispatch, modelKey, finalRemoveOnUnmount]);
122
129
 
123
130
  // Create new properties object to inject modularui properties to own props
124
131
  const locale = useLocale();
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_FormModel","_jsxRuntime","patchUpdateModelOption","oldOptions","updateModel","FormModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (removeOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAMA,IAAAI,KAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AAMA,IAAAU,UAAA,GAAAL,sBAAA,CAAAL,OAAA;AAAoD,IAAAW,WAAA,GAAAX,OAAA;AAcpD,MAAMY,sBAAsB,GAAIC,UAAkB,IAAK;EACrD,IACE,aAAa,IAAIA,UAAU,IAC3BA,UAAU,CAACC,WAAW,YAAYC,kBAAS,EAC3C;IACA,OAAO;MACL,GAAGF,UAAU;MACbG,aAAa,EAAGC,QAAwB,IAAqB;QAC3D,IAAIA,QAAQ,YAAYF,kBAAS,EAAE;UACjC;UACA,MAAMG,WAAsB,GAAGL,UAAU,CAACC,WAAW,CAACK,KAAK,CAAC,CAAC;UAC7DD,WAAW,CAACE,MAAM,CAACH,QAAQ,CAAC;UAC5B,OAAOC,WAAW;QACpB;QACA,OAAOD,QAAQ;MACjB;IACF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Q,CAAG,CAAC;IAC/C,CAAC;IAEDhC,gBAAgB,CAACQ,WAAW,GAAG,gBAAgB,IAAAC,qBAAc,EAC3DT,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAAC,IAAAuC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEapD,kBAAkB","ignoreList":[]}
1
+ {"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_FormModel","_jsxRuntime","patchUpdateModelOption","oldOptions","updateModel","FormModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","finalRemoveOnUnmount","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n // explicit property for removeOnMount overwrite the setting\n const finalRemoveOnUnmount =\n props.removeOnUnmount === true ? true : removeOnUnmount;\n\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, {\n ...otherOptions,\n removeOnUnmount: finalRemoveOnUnmount,\n });\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (finalRemoveOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey, finalRemoveOnUnmount]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAMA,IAAAI,KAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AAMA,IAAAU,UAAA,GAAAL,sBAAA,CAAAL,OAAA;AAAoD,IAAAW,WAAA,GAAAX,OAAA;AAcpD,MAAMY,sBAAsB,GAAIC,UAAkB,IAAK;EACrD,IACE,aAAa,IAAIA,UAAU,IAC3BA,UAAU,CAACC,WAAW,YAAYC,kBAAS,EAC3C;IACA,OAAO;MACL,GAAGF,UAAU;MACbG,aAAa,EAAGC,QAAwB,IAAqB;QAC3D,IAAIA,QAAQ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V,QAAQ;QACR6B,MAAM,EAAEtB,UAAU,GAAGA,UAAU,CAACsB,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEvB,UAAU,GAAGA,UAAU,CAACuB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAACzB,UAAU,CAAC;QAC7BmB,MAAM;QACNO,cAAc,EAAElB,WAAW;QAC3BD,WAAW,EAAEF;MACf,CAAC;MAED,oBAAO,IAAAtC,WAAA,CAAA4D,GAAA,EAACxC,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAMgC;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDjC,gBAAgB,CAACS,WAAW,GAAG,gBAAgB,IAAAC,qBAAc,EAC3DV,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAAC,IAAAwC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEarD,kBAAkB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.54.1",
3
+ "version": "1.54.3",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -7,5 +7,14 @@
7
7
  },
8
8
  "link": "",
9
9
  "component": ["attribute"]
10
+ },
11
+ "MERGE": {
12
+ "hint": "merge",
13
+ "description": {
14
+ "NL": "merge with extra component",
15
+ "EN": "merge with extra component"
16
+ },
17
+ "link": "",
18
+ "component": ["component1", "component2"]
10
19
  }
11
20
  }
@@ -1,6 +1,7 @@
1
1
  import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
2
2
  import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
3
3
  const fs = require("fs");
4
+
4
5
  //
5
6
  const projectJson1 = {
6
7
  MOCK: {
@@ -26,6 +27,18 @@ const projectJson2 = {
26
27
  },
27
28
  };
28
29
 
30
+ const projectMerge = {
31
+ MERGE: {
32
+ hint: "merge",
33
+ description: {
34
+ NL: "merge with extra component",
35
+ EN: "merge with extra component",
36
+ },
37
+ link: "",
38
+ component: ["component1", "component2", "component3"],
39
+ },
40
+ };
41
+
29
42
  jest.mock("fs", () => ({
30
43
  ...jest.requireActual("fs"),
31
44
  writeFileSync: jest.fn(),
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
33
46
 
34
47
  describe("mergeLayoutHintConfigurations", () => {
35
48
  it("generates layouthint.json", async () => {
36
- expect.assertions(1);
49
+ expect.assertions(2);
37
50
 
38
51
  const expectedJson = {
39
52
  ...LayoutHintConfiguration,
40
53
  ...projectJson1,
41
54
  ...projectJson2,
55
+ ...projectMerge,
42
56
  };
43
57
 
44
58
  await mergeLayoutHintConfigurations("./src", "/output");
45
59
 
46
60
  expect(fs.writeFileSync).toHaveBeenCalledWith(
47
61
  expect.stringContaining("LayoutHintConfig.json"),
48
- JSON.stringify(expectedJson),
62
+ expect.any(String),
49
63
  );
64
+
65
+ // Check that the JSON written matches the expected JSON
66
+ const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
67
+
68
+ // Compare objects using deep comparison to ensure they are equal
69
+ expect(actualJson).toEqual(expectedJson);
50
70
  });
51
71
  });
@@ -7,5 +7,14 @@
7
7
  },
8
8
  "link": "",
9
9
  "component": ["attribute"]
10
+ },
11
+ "MERGE": {
12
+ "hint": "merge",
13
+ "description": {
14
+ "NL": "merge with extra component",
15
+ "EN": "merge with extra component"
16
+ },
17
+ "link": "",
18
+ "component": ["component1", "component3"]
10
19
  }
11
20
  }
@@ -2,6 +2,7 @@
2
2
  const path = require("path");
3
3
  const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
4
4
 
5
+ const mergeWith = require("lodash/mergeWith");
5
6
  const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
6
7
 
7
8
  const findFiles = (dir: string): Array<string> => {
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
43
44
  return JSON.parse(content);
44
45
  });
45
46
 
46
- const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue: Object, srcValue: Object): Object => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+
54
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
47
55
 
48
56
  writeFileSync(
49
57
  path.join(outputFolder, "LayoutHintConfig.json"),
@@ -71,6 +71,10 @@ const modularUIConnector = (
71
71
 
72
72
  return (Component: ComponentType<any>) => {
73
73
  const WrappedComponent = (props: any) => {
74
+ // explicit property for removeOnMount overwrite the setting
75
+ const finalRemoveOnUnmount =
76
+ props.removeOnUnmount === true ? true : removeOnUnmount;
77
+
74
78
  const dispatch = useDispatch();
75
79
  const location = useLocation();
76
80
 
@@ -78,7 +82,10 @@ const modularUIConnector = (
78
82
  const displayName = getDisplayName(Component, name, props.contextId);
79
83
 
80
84
  // Load the model through the useModUI hook
81
- const modelEntry = useModularUI(displayName, url, otherOptions);
85
+ const modelEntry = useModularUI(displayName, url, {
86
+ ...otherOptions,
87
+ removeOnUnmount: finalRemoveOnUnmount,
88
+ });
82
89
  const modelKey = modelEntry?.model?.connectKey;
83
90
 
84
91
  // handle manual reload of model
@@ -114,11 +121,11 @@ const modularUIConnector = (
114
121
  // Remove model when hoc unloads
115
122
  useEffect(() => {
116
123
  return () => {
117
- if (removeOnUnmount) {
124
+ if (finalRemoveOnUnmount) {
118
125
  dispatch(removeModelByKey(modelKey));
119
126
  }
120
127
  };
121
- }, [dispatch, modelKey]);
128
+ }, [dispatch, modelKey, finalRemoveOnUnmount]);
122
129
 
123
130
  // Create new properties object to inject modularui properties to own props
124
131
  const locale = useLocale();