@beinformed/ui 1.59.10 → 1.59.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/esm/hooks/useModelCatalog.js +1 -4
  3. package/esm/hooks/useModelCatalog.js.map +1 -1
  4. package/esm/modularui/ModularUIRequest.js +14 -1
  5. package/esm/modularui/ModularUIRequest.js.map +1 -1
  6. package/esm/redux/_i18n/I18nReducer.js +7 -1
  7. package/esm/redux/_i18n/I18nReducer.js.map +1 -1
  8. package/esm/redux/_modularui/ModularUIActions.js +14 -1
  9. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  10. package/esm/utils/helpers/createHref.js.map +1 -1
  11. package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +1 -1
  12. package/lib/hooks/useModelCatalog.js +1 -4
  13. package/lib/hooks/useModelCatalog.js.flow +1 -4
  14. package/lib/hooks/useModelCatalog.js.map +1 -1
  15. package/lib/modularui/ModularUIRequest.js +14 -1
  16. package/lib/modularui/ModularUIRequest.js.flow +16 -1
  17. package/lib/modularui/ModularUIRequest.js.map +1 -1
  18. package/lib/redux/_i18n/I18nReducer.js +7 -1
  19. package/lib/redux/_i18n/I18nReducer.js.flow +8 -1
  20. package/lib/redux/_i18n/I18nReducer.js.map +1 -1
  21. package/lib/redux/_modularui/ModularUIActions.js +14 -1
  22. package/lib/redux/_modularui/ModularUIActions.js.flow +16 -1
  23. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  24. package/lib/utils/helpers/createHref.js.flow +1 -1
  25. package/lib/utils/helpers/createHref.js.map +1 -1
  26. package/package.json +6 -6
  27. package/src/hooks/__tests__/useModelCatalog.spec.js +1 -1
  28. package/src/hooks/useModelCatalog.js +1 -4
  29. package/src/modularui/ModularUIRequest.js +16 -1
  30. package/src/redux/_i18n/I18nReducer.js +8 -1
  31. package/src/redux/_modularui/ModularUIActions.js +16 -1
  32. package/src/utils/helpers/createHref.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.59.10",
3
+ "version": "1.59.12",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -110,7 +110,7 @@
110
110
  "@babel/preset-env": "^7.26.0",
111
111
  "@babel/preset-flow": "^7.25.9",
112
112
  "@babel/preset-react": "^7.26.3",
113
- "@commitlint/cli": "^19.6.0",
113
+ "@commitlint/cli": "^19.6.1",
114
114
  "@commitlint/config-conventional": "^19.6.0",
115
115
  "@testing-library/react": "^16.1.0",
116
116
  "auditjs": "^4.0.46",
@@ -125,9 +125,9 @@
125
125
  "eslint-plugin-babel": "^5.3.1",
126
126
  "eslint-plugin-ft-flow": "^3.0.11",
127
127
  "eslint-plugin-import": "^2.31.0",
128
- "eslint-plugin-jest": "^28.9.0",
129
- "eslint-plugin-jsdoc": "^50.6.0",
130
- "eslint-plugin-react": "^7.37.2",
128
+ "eslint-plugin-jest": "^28.10.0",
129
+ "eslint-plugin-jsdoc": "^50.6.1",
130
+ "eslint-plugin-react": "^7.37.3",
131
131
  "eslint-plugin-react-hooks": "^5.1.0",
132
132
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
133
133
  "flow-bin": "^0.200.1",
@@ -141,7 +141,7 @@
141
141
  "jest-junit": "^16.0.0",
142
142
  "jest-sonar-reporter": "^2.0.0",
143
143
  "jscodeshift": "^17.1.1",
144
- "lint-staged": "^15.2.10",
144
+ "lint-staged": "^15.3.0",
145
145
  "polished": "^4.0.0",
146
146
  "prettier": "^3.4.2",
147
147
  "react": "^18.3.1",
@@ -156,7 +156,7 @@ describe("modelcatalog hooks", () => {
156
156
  assertTargetModel(
157
157
  () => useContentType("/contenttypes/contenttype"),
158
158
  "contenttypes",
159
- "/contenttypes/contenttype?entryDate=" + DateUtil.now(),
159
+ "/contenttypes/contenttype",
160
160
  ContentTypeModel,
161
161
  );
162
162
  });
@@ -142,10 +142,7 @@ export const useContentType = (
142
142
  key?: string = "contenttypes",
143
143
  options?: UseModularUIBasicOptions<ContentTypeModel>,
144
144
  ): ?ContentTypeModel => {
145
- const { entryDate } = useEntryDate();
146
-
147
- const href = createHref("contenttypes", contentType, entryDate, null, []);
148
-
145
+ const href = createHref("contenttypes", contentType, null, null, []);
149
146
  return useModularUIBasic(key, href, {
150
147
  expectedModels: ["ContentType"],
151
148
  targetModel: ContentTypeModel,
@@ -66,7 +66,7 @@ class ModularUIRequest {
66
66
  this._response = new ModularUIResponse();
67
67
 
68
68
  this.href = typeof href === "string" ? new Href(href) : href;
69
- this.locale = options.locale ?? "en";
69
+ this.locale = this.getRequestLocale(options.locale);
70
70
 
71
71
  // copy request parameters to response, to be able to use them in the models
72
72
  // self links are missing the request parameters
@@ -95,6 +95,21 @@ class ModularUIRequest {
95
95
  }
96
96
  }
97
97
 
98
+ /**
99
+ * Retrieve the preferred language for this request, falls back to the browser language or english
100
+ */
101
+ getRequestLocale(optionLocale: ?string): string {
102
+ if (optionLocale) {
103
+ return optionLocale;
104
+ }
105
+
106
+ if (navigator.language) {
107
+ return navigator.language.split("-")[0] || "en";
108
+ }
109
+
110
+ return "en";
111
+ }
112
+
98
113
  /**
99
114
  */
100
115
  get origin(): string {
@@ -46,10 +46,17 @@ const setLocales = (
46
46
  };
47
47
  };
48
48
 
49
+ const getDefaultLocale = () => {
50
+ if (navigator?.language) {
51
+ return navigator?.language.split("-")[0] || "en";
52
+ }
53
+ return "en";
54
+ };
55
+
49
56
  // REDUCER
50
57
  const initialState: I18nState = {
51
58
  locales: new Locales(),
52
- locale: "en",
59
+ locale: getDefaultLocale(),
53
60
  };
54
61
 
55
62
  /**
@@ -99,6 +99,21 @@ const loadModelSuccessAction = (
99
99
  return setModel(key, model);
100
100
  };
101
101
 
102
+ /**
103
+ * Retrieve the preferred language for this request, falls back to the browser language or english
104
+ */
105
+ const getRequestLocale = (optionLocale: ?string): string => {
106
+ if (optionLocale) {
107
+ return optionLocale;
108
+ }
109
+
110
+ if (navigator.language) {
111
+ return navigator.language.split("-")[0] || "en";
112
+ }
113
+
114
+ return "en";
115
+ };
116
+
102
117
  /**
103
118
  * This action is handled by the modularui middleware
104
119
  */
@@ -121,7 +136,7 @@ export const loadModel = (
121
136
  }),
122
137
  method: options?.method ?? HTTP_METHODS.GET,
123
138
  data: options?.data,
124
- locale: options?.locale ?? "en",
139
+ locale: getRequestLocale(options?.locale),
125
140
  childmodels: options?.childmodels,
126
141
  targetModel: options?.targetModel,
127
142
  forceTargetModel: options?.forceTargetModel,
@@ -77,7 +77,7 @@ export const filterParameters = (
77
77
  export const createHref = (
78
78
  context: string,
79
79
  dynamicPart: string | Href,
80
- entryDate?: ISO_DATE,
80
+ entryDate?: ?ISO_DATE,
81
81
  location?: ?Location,
82
82
  allowedParameters?: Array<string>,
83
83
  ): Href => {