@truedat/core 6.13.4 → 6.13.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/core",
3
- "version": "6.13.4",
3
+ "version": "6.13.5",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -118,5 +118,5 @@
118
118
  "react-dom": ">= 16.8.6 < 17",
119
119
  "semantic-ui-react": ">= 2.0.3 < 2.2"
120
120
  },
121
- "gitHead": "3fd777c739ce6c9c78d505a85877e0ef6059b19c"
121
+ "gitHead": "8a56d5172d91597712cdeab607983c2b3282eb25"
122
122
  }
@@ -3,7 +3,6 @@ import AdminMenu from "./AdminMenu";
3
3
  import Alert from "./Alert";
4
4
  import Authorized from "./Authorized";
5
5
  import AvailableFilters from "./AvailableFilters";
6
- import BranchViewer from "./BranchViewer";
7
6
  import CardGroupsAccordion from "./CardGroupsAccordion";
8
7
  import CatalogMenu from "./CatalogMenu";
9
8
  import Comments from "./Comments";
@@ -60,7 +59,6 @@ export {
60
59
  Alert,
61
60
  Authorized,
62
61
  AvailableFilters,
63
- BranchViewer,
64
62
  CardGroupsAccordion,
65
63
  CatalogMenu,
66
64
  Comments,
@@ -4,6 +4,7 @@ import { IntlProvider } from "react-intl";
4
4
  import { Loading } from "@truedat/core/components";
5
5
  import { useLocales } from "../../hooks/useLocales";
6
6
  import { useMessages } from "../../hooks/useMessages";
7
+ import { getNavigatorLanguage } from "../../services/i18n";
7
8
 
8
9
  const LangProvider = ({ children, defaultMessages }) => {
9
10
  const { locales } = useLocales(false);
@@ -18,19 +19,9 @@ const LangProvider = ({ children, defaultMessages }) => {
18
19
  )(locales || []);
19
20
  }, [locales, setEnabledLocales]);
20
21
  useEffect(() => {
21
- const language =
22
- (navigator.languages && navigator.languages[0]) ||
23
- navigator.language ||
24
- navigator.userLanguage ||
25
- "en-US";
26
- const mapLocale = _.cond([
27
- [() => _.size(enabledLocales) === 1, () => _.first(enabledLocales)],
28
- [(l) => _.includes(l)(enabledLocales), (l) => l],
29
- [(l) => _.includes(l)(["es", "ca", "eu", "gl"]), _.constant("es")],
30
- [_.stubTrue, _.constant("en")],
31
- ]);
32
- _.flow(_.split("-"), _.head, mapLocale, setLang)(language);
33
- }, [navigator, enabledLocales, setLang]);
22
+ const navigatorLang = getNavigatorLanguage(enabledLocales);
23
+ if (navigatorLang !== lang) setLang(navigatorLang);
24
+ }, [enabledLocales, setLang, lang]);
34
25
 
35
26
  return loading ? (
36
27
  <Loading />
@@ -47,7 +47,6 @@ export default {
47
47
  "dateFilter.weeks": "weeks ago",
48
48
  "dateFilter.months": "months ago",
49
49
  "dateFilter.years": "years ago",
50
- "domains.notExist": "There are no domains",
51
50
  emptyBucket: "(Empty)",
52
51
  "error.content": "Please report this error to the Truedat team.",
53
52
  "error.duplicated": "duplicated",
@@ -48,7 +48,6 @@ export default {
48
48
  "dateFilter.weeks": "semanas",
49
49
  "dateFilter.months": "meses",
50
50
  "dateFilter.years": "años",
51
- "domains.notExist": "No existen dominios",
52
51
  emptyBucket: "(Vacío)",
53
52
  "error.content": "Por favor, coméntaselo al equipo de Truedat.",
54
53
  "error.duplicated": "duplicado",
@@ -64,6 +63,7 @@ export default {
64
63
  "hierarchy.multiple.placeholder": "Seleccionar Jerarquías",
65
64
  "hierarchy.selector.placeholder": "Seleccionar Jerarquía",
66
65
  "i18n.actions.createMessage": "Crear mensaje",
66
+
67
67
  "i18n.message.form.messageId.placeholder": "Id del mensaje",
68
68
  "i18n.message.form.definition.placeholder": "Definición",
69
69
  "i18n.message.form.description.placeholder": "Descripción",
@@ -1,6 +1,7 @@
1
1
  import _ from "lodash/fp";
2
2
  import axios from "axios";
3
3
  import { clearToken, readToken } from "./storage";
4
+ import { getNavigatorLanguage } from "./i18n";
4
5
 
5
6
  // If no authorization header is present and token exists in local storage, put
6
7
  // the bearer token authorization header
@@ -21,6 +22,18 @@ const maybePutAuthorization = (config) => {
21
22
  }
22
23
  };
23
24
 
25
+ const putLanguage = (config) => {
26
+ const lang = getNavigatorLanguage();
27
+
28
+ return {
29
+ ...config,
30
+ headers: {
31
+ ...config.headers,
32
+ "Accept-Language": lang,
33
+ },
34
+ };
35
+ };
36
+
24
37
  // If an unauthorized response is received, remove token from local storage
25
38
  const maybeClearToken = (error) => {
26
39
  if (error?.response?.status === 401) {
@@ -30,6 +43,7 @@ const maybeClearToken = (error) => {
30
43
  };
31
44
 
32
45
  axios.interceptors.request.use(maybePutAuthorization, Promise.reject);
46
+ axios.interceptors.request.use(putLanguage, Promise.reject);
33
47
  axios.interceptors.response.use(_.identity, maybeClearToken);
34
48
 
35
49
  export default axios;
@@ -3,6 +3,7 @@ import { setContext } from "@apollo/client/link/context";
3
3
  import { onError } from "@apollo/client/link/error";
4
4
  import { unauthorized, logError } from "../routines";
5
5
  import { readToken } from "./storage";
6
+ import { getNavigatorLanguage } from "./i18n";
6
7
 
7
8
  const authLink = setContext((_, { headers }) => {
8
9
  const token = readToken();
@@ -16,6 +17,17 @@ const authLink = setContext((_, { headers }) => {
16
17
  : { headers };
17
18
  });
18
19
 
20
+ const langLink = setContext((_, { headers }) => {
21
+ const lang = getNavigatorLanguage();
22
+
23
+ return {
24
+ headers: {
25
+ ...headers,
26
+ "Accept-Language": lang,
27
+ },
28
+ };
29
+ });
30
+
19
31
  const httpLink = createHttpLink({ uri: "/api/v2" });
20
32
 
21
33
  const errorLink = ({ dispatch }) =>
@@ -32,5 +44,5 @@ const errorLink = ({ dispatch }) =>
32
44
  export const createClient = (store) =>
33
45
  new ApolloClient({
34
46
  cache: new InMemoryCache({}),
35
- link: authLink.concat(errorLink(store)).concat(httpLink),
47
+ link: authLink.concat(langLink).concat(errorLink(store)).concat(httpLink),
36
48
  });
@@ -10,3 +10,18 @@ export const makeOption = (translations, filter) => (value) =>
10
10
  value: value,
11
11
  text: translate(translations, filter)(value),
12
12
  };
13
+
14
+ export const getNavigatorLanguage = (localesAllowed = []) => {
15
+ const language =
16
+ (navigator.languages && navigator.languages[0]) ||
17
+ navigator.language ||
18
+ navigator.userLanguage ||
19
+ "en-US";
20
+ const mapLocale = _.cond([
21
+ [() => _.size(localesAllowed) === 1, () => _.first(localesAllowed)],
22
+ [(l) => _.includes(l)(localesAllowed), (l) => l],
23
+ [(l) => _.includes(l)(["es", "ca", "eu", "gl"]), _.constant("es")],
24
+ [_.stubTrue, _.constant("en")],
25
+ ]);
26
+ return _.flow(_.split("-"), _.head, mapLocale)(language);
27
+ };
@@ -1,289 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React, { useState, useEffect } from "react";
3
- import PropTypes from "prop-types";
4
- import { Link } from "react-router-dom";
5
- import { linkTo } from "@truedat/core/routes";
6
- import {
7
- Card,
8
- Grid,
9
- Header,
10
- Icon,
11
- Input,
12
- Label,
13
- Segment,
14
- } from "semantic-ui-react";
15
- import { FormattedMessage, useIntl } from "react-intl";
16
- import { LocalSearchInput } from "./LocalSearchInput";
17
- import { LocalCustomSearch } from "./LocalCustomSearch";
18
-
19
- import "../styles/BranchViewer.less";
20
-
21
- const organizeBranches = (branches) => {
22
- const grouped = branches.reduce((acc, branch) => {
23
- const { parent_id } = branch;
24
-
25
- return {
26
- ...acc,
27
- [parent_id]: [
28
- ...(acc[parent_id] || []),
29
- {
30
- ...branch,
31
- parents: [],
32
- },
33
- ],
34
- };
35
- }, {});
36
-
37
- const buildParents = (branch, accParents = []) => {
38
- if (branch.parent_id === null) {
39
- return [...accParents];
40
- }
41
-
42
- const parentBranch = Object.values(grouped)
43
- .flat()
44
- .find((b) => b.id === branch.parent_id);
45
-
46
- return parentBranch
47
- ? buildParents(parentBranch, [branch.parent_id, ...accParents])
48
- : accParents;
49
- };
50
-
51
- const buildBranch = (parentId) => {
52
- const children = grouped[parentId] || [];
53
-
54
- return children.map((element) => {
55
- const parents = buildParents(element);
56
- const childs = buildBranch(element.id);
57
-
58
- const child = {
59
- ...element,
60
- parents,
61
- childs,
62
- };
63
-
64
- return { ...child, path: createPathDescription(child) };
65
- });
66
- };
67
-
68
- const createPathDescription = (branch) => {
69
- const results = [];
70
- const { parents } = branch;
71
-
72
- for (const parent_id of parents) {
73
- const { name } = branches.find((branch) => branch.id === parent_id);
74
- results.push(name);
75
- }
76
-
77
- return results.length == 0 ? "" : results.join(" > ");
78
- };
79
-
80
- return buildBranch(null);
81
- };
82
-
83
- const ListBranchItem = ({ branch, handleRedirect, selectedBranch }) => {
84
- const { id, name } = branch;
85
- const [expanded, setExpanded] = useState(false);
86
- const generation = branch.childs;
87
- const hasChildren = !generation.length == 0;
88
-
89
- useEffect(() => {
90
- if (selectedBranch?.parents?.includes(id)) {
91
- setExpanded(!expanded);
92
- }
93
-
94
- if (id === selectedBranch?.id) {
95
- setExpanded(true);
96
- }
97
- }, []);
98
-
99
- return (
100
- <li key={id}>
101
- <div
102
- style={{
103
- display: "flex",
104
- flexDirection: "row",
105
- alignItems: "self-start",
106
- }}
107
- onClick={() => handleRedirect(id)}
108
- >
109
- <Input
110
- labelPosition="left"
111
- type="text"
112
- value={name == null ? "" : name}
113
- className="hierarchyNode"
114
- disabled={true}
115
- >
116
- {hasChildren ? (
117
- <Label
118
- basic
119
- onClick={(e) => {
120
- e.stopPropagation();
121
- setExpanded(!expanded);
122
- }}
123
- style={{ cursor: "pointer" }}
124
- >
125
- <Icon fitted name={expanded ? "dot circle outline" : "circle"} />
126
- </Label>
127
- ) : null}
128
- <input
129
- className={id === selectedBranch?.id ? "selectedBranch" : " "}
130
- />
131
- </Input>
132
- </div>
133
- {generation.length == 0 || !expanded ? null : (
134
- <ListBranch
135
- childs={branch.childs}
136
- parentId={id}
137
- handleRedirect={handleRedirect}
138
- selectedBranch={selectedBranch}
139
- />
140
- )}
141
- </li>
142
- );
143
- };
144
-
145
- ListBranchItem.propTypes = {
146
- key: PropTypes.number,
147
- branch: PropTypes.object,
148
- handleRedirect: PropTypes.func.isRequired,
149
- selectedBranch: PropTypes.object,
150
- };
151
-
152
- const ListBranch = ({ childs, handleRedirect, selectedBranch }) => {
153
- return _.isEmpty(childs) ? null : (
154
- <ul className="wtree expanded">
155
- {childs.map((child) => {
156
- return (
157
- <ListBranchItem
158
- key={child.id}
159
- branch={child}
160
- handleRedirect={handleRedirect}
161
- selectedBranch={selectedBranch}
162
- />
163
- );
164
- })}
165
- </ul>
166
- );
167
- };
168
-
169
- ListBranch.propTypes = {
170
- childs: PropTypes.object,
171
- handleRedirect: PropTypes.func.isRequired,
172
- selectedBranch: PropTypes.object,
173
- };
174
-
175
- export const BranchViewer = ({
176
- branches = [],
177
- handleRedirect,
178
- idSelectedBranch,
179
- }) => {
180
- useIntl();
181
-
182
- const [filteredBranches, setFilteredBranches] = useState([]);
183
- const [selectedBranch, setSelectedBranch] = useState({});
184
- const organizedBranches = _.isNull(branches)
185
- ? []
186
- : organizeBranches(branches);
187
- const searchFields = ["name", "childs"];
188
-
189
- const checkSearchEnabled = () => {
190
- return !_.equals(organizedBranches, filteredBranches);
191
- };
192
-
193
- useEffect(() => {
194
- if (_.isEmpty(filteredBranches) && checkSearchEnabled()) {
195
- setFilteredBranches(organizedBranches);
196
- }
197
-
198
- if (!_.isUndefined(idSelectedBranch)) {
199
- LocalCustomSearch(
200
- organizedBranches,
201
- idSelectedBranch,
202
- setSelectedBranch,
203
- ["id", "childs"],
204
- true
205
- );
206
- }
207
- }, [branches]);
208
-
209
- return (
210
- <Segment
211
- style={{
212
- overflow: "auto",
213
- }}
214
- >
215
- <Grid>
216
- <Grid.Row>
217
- <Grid.Column width={16}>
218
- <LocalSearchInput
219
- collection={organizedBranches}
220
- callback={setFilteredBranches}
221
- searchFields={searchFields}
222
- searchFunction={LocalCustomSearch}
223
- enabled={checkSearchEnabled()}
224
- />
225
- </Grid.Column>
226
- </Grid.Row>
227
- <Grid.Row>
228
- <Grid.Column width={16}>
229
- {!_.isEmpty(branches) ? (
230
- filteredBranches.map((branch) => (
231
- <Grid.Column key={branch.id}>
232
- <Grid.Row>
233
- <ul
234
- style={{
235
- listStyleType: "none",
236
- padding: 0,
237
- }}
238
- >
239
- {checkSearchEnabled(branches) ? (
240
- <Card
241
- key={branch.id}
242
- link
243
- as={Link}
244
- to={linkTo.DOMAIN_MEMBERS({
245
- id: _.get("id")(branch),
246
- })}
247
- >
248
- <Card.Content>
249
- <Card.Header className="brancheViewerSearchResultHeader">
250
- {_.get("name")(branch)}
251
- </Card.Header>
252
- <Card.Meta className="brancheViewerSearchResultMeta">
253
- {_.get("path")(branch)}
254
- </Card.Meta>
255
- </Card.Content>
256
- </Card>
257
- ) : (
258
- <ListBranchItem
259
- branch={branch}
260
- handleRedirect={handleRedirect}
261
- selectedBranch={selectedBranch}
262
- />
263
- )}
264
- </ul>
265
- </Grid.Row>
266
- </Grid.Column>
267
- ))
268
- ) : (
269
- <Header as="h4">
270
- <Icon name="cube" />
271
- <Header.Content>
272
- <FormattedMessage id="domains.notExist" />
273
- </Header.Content>
274
- </Header>
275
- )}
276
- </Grid.Column>
277
- </Grid.Row>
278
- </Grid>
279
- </Segment>
280
- );
281
- };
282
-
283
- BranchViewer.propTypes = {
284
- branches: PropTypes.array,
285
- handleRedirect: PropTypes.func.isRequired,
286
- idSelectedBranch: PropTypes.number,
287
- };
288
-
289
- export default BranchViewer;
@@ -1,58 +0,0 @@
1
- import _ from "lodash/fp";
2
- import PropTypes from "prop-types";
3
-
4
- export const LocalCustomSearch = (
5
- collection,
6
- searchString = "",
7
- callback,
8
- searchFields,
9
- getOneOrMany = false
10
- ) => {
11
- const results = [];
12
-
13
- const recursiveSearch = (item) => {
14
- if (_.isObject(item) && !_.isNull(item)) {
15
- for (const field of searchFields) {
16
- const value = item[field];
17
- if (_.isArray(value) && !_.isEmpty(value)) {
18
- value.forEach(recursiveSearch);
19
- } else if (_.isNumber(value) && searchString == value) {
20
- results.push(item);
21
- } else if (
22
- _.isString(value) &&
23
- value.toLowerCase().includes(searchString.toString().toLowerCase())
24
- ) {
25
- results.push(item);
26
- }
27
- }
28
- }
29
- };
30
-
31
- const applyFilter = (data) => {
32
- callback(getOneOrMany ? _.head(data) : data);
33
- };
34
-
35
- if (
36
- searchFields === undefined ||
37
- searchFields === null ||
38
- searchFields.length === 0
39
- ) {
40
- return -1;
41
- } else if (_.isEmpty(searchString.toString())) {
42
- applyFilter(collection);
43
- return collection.length;
44
- } else {
45
- collection.forEach(recursiveSearch);
46
- applyFilter(results);
47
- return results.length;
48
- }
49
- };
50
-
51
- LocalCustomSearch.propTypes = {
52
- collection: PropTypes.array,
53
- query: PropTypes.string,
54
- callback: PropTypes.func,
55
- searchFields: PropTypes.array,
56
- getOneOrMany: PropTypes.bool,
57
- };
58
- export default LocalCustomSearch;
@@ -1,67 +0,0 @@
1
- import React, { useState } from "react";
2
- import PropTypes from "prop-types";
3
- import { Header, Icon, Input } from "semantic-ui-react";
4
- import { FormattedMessage, useIntl } from "react-intl";
5
-
6
- import "../styles/LocalSearchInput.less";
7
-
8
- export const LocalSearchInput = ({
9
- loading,
10
- query,
11
- collection,
12
- callback,
13
- searchFields,
14
- searchFunction,
15
- enabled,
16
- }) => {
17
- const { formatMessage } = useIntl();
18
- const [countSearch, setCountSearch] = useState(0);
19
-
20
- const onChange = (value) => {
21
- setCountSearch(searchFunction(collection, value, callback, searchFields));
22
- };
23
-
24
- return (
25
- <>
26
- <Input
27
- value={query}
28
- className="searchbox"
29
- onChange={(_e, { value }) => onChange(value)}
30
- icon={{ name: "search", link: true }}
31
- loading={loading}
32
- placeholder={formatMessage({ id: "search.input.placeholder" })}
33
- />
34
- {enabled ? (
35
- <Header as="h4">
36
- <Icon name="search" />
37
- <Header.Content>
38
- {countSearch == -1 && (
39
- <FormattedMessage id="domains.search.error.fields" />
40
- )}
41
- {countSearch == 0 && (
42
- <FormattedMessage id="domains.search.results.empty" />
43
- )}
44
- {countSearch > 0 && (
45
- <FormattedMessage
46
- id="domains.search.results.count"
47
- values={{ count: countSearch }}
48
- />
49
- )}
50
- </Header.Content>
51
- </Header>
52
- ) : null}
53
- </>
54
- );
55
- };
56
-
57
- LocalSearchInput.propTypes = {
58
- loading: PropTypes.bool,
59
- query: PropTypes.string,
60
- collection: PropTypes.array,
61
- callback: PropTypes.func,
62
- searchFields: PropTypes.array,
63
- searchFunction: PropTypes.func,
64
- enabled: PropTypes.bool,
65
- };
66
-
67
- export default LocalSearchInput;