@truedat/core 5.20.1 → 5.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/core",
3
- "version": "5.20.1",
3
+ "version": "5.20.3",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -117,5 +117,5 @@
117
117
  "react-dom": ">= 16.8.6 < 17",
118
118
  "semantic-ui-react": ">= 2.0.3 < 2.2"
119
119
  },
120
- "gitHead": "a7197e02a1b1a88c375fe044dee65c7e96ccd618"
120
+ "gitHead": "11ee6981b87a3c8f2b99c7101b42cafc29dc4896"
121
121
  }
@@ -38,6 +38,8 @@ describe("<SelectedFilters/>", () => {
38
38
  const messages = {
39
39
  "search.clear_filters": "clean filters",
40
40
  "search.save_filters": "save filters",
41
+ "search.applied_filters": "applied filters",
42
+ "filter.empty": "empty",
41
43
  };
42
44
 
43
45
  const renderOptions = {
@@ -1,3 +1,4 @@
1
+ import _ from "lodash/fp";
1
2
  import { compile } from "path-to-regexp";
2
3
  import useSWR from "swr";
3
4
  import useSWRMutations from "swr/mutation";
@@ -8,21 +9,27 @@ import {
8
9
  apiJsonPatch,
9
10
  apiJsonPost,
10
11
  } from "../services/api";
11
- import _ from "lodash/fp";
12
12
 
13
- export const useLocales = () => {
14
- const { data, error, mutate } = useSWR(API_LOCALES, apiJson);
13
+ const toApiLocalesPath = compile(API_LOCALES);
14
+
15
+ export const useLocales = (includeMessages = true) => {
16
+ const url = toApiLocalesPath() + "?includeMessages=" + includeMessages;
17
+ const { data, error, mutate, isValidating } = useSWR(url, apiJson);
18
+
15
19
  const locales = data?.data?.data;
16
- return { locales, error, loading: !error && !data, mutate };
20
+ return { locales, error, loading: !error && !data, mutate, isValidating };
17
21
  };
18
22
 
19
23
  export const useLocalesUpdate = (id) => {
20
24
  const toApiPath = compile(API_LOCALE);
21
25
  const url = toApiPath({ id });
22
26
  return useSWRMutations(url, (url, { arg }) => {
23
- const { mutateData } = arg;
27
+ const { mutateData, handleDimmer } = arg;
24
28
  const payload = { id: arg.id, locale: arg };
25
- apiJsonPatch(url, payload).then(() => mutateData());
29
+ apiJsonPatch(url, payload).then(() => {
30
+ mutateData();
31
+ handleDimmer(false);
32
+ });
26
33
  });
27
34
  };
28
35
 
@@ -1,13 +1,15 @@
1
- import React, { useEffect, useState } from "react";
2
- import PropTypes from "prop-types";
3
- import { useIntl, FormattedMessage } from "react-intl";
4
1
  import _ from "lodash/fp";
2
+ import React, { useState } from "react";
3
+ import PropTypes from "prop-types";
4
+ import { useIntl } from "react-intl";
5
5
  import {
6
6
  Button,
7
+ Dimmer,
7
8
  Dropdown,
8
9
  Form,
9
10
  Icon,
10
11
  Input,
12
+ Loader,
11
13
  Table,
12
14
  TableBody,
13
15
  TableCell,
@@ -20,9 +22,10 @@ import {
20
22
  useLocalesCreate,
21
23
  useLocalesDelete,
22
24
  useLocalesUpdate,
25
+ useLocales,
23
26
  } from "../../hooks/useLocales";
24
27
 
25
- const LanguajeRow = ({ code, local, name, config, mutate }) => {
28
+ const LanguajeRow = ({ code, local, name, config, mutate, handleDimmer }) => {
26
29
  const { formatMessage } = useIntl();
27
30
  const { trigger } = useLocalesUpdate(config.id);
28
31
  const { trigger: triggerDelete } = useLocalesDelete(config.id);
@@ -33,7 +36,8 @@ const LanguajeRow = ({ code, local, name, config, mutate }) => {
33
36
  ...config,
34
37
  [name]: !checked,
35
38
  };
36
- trigger({ ...newConfig, mutateData: mutate });
39
+ handleDimmer(true);
40
+ trigger({ ...newConfig, mutateData: mutate, handleDimmer: handleDimmer });
37
41
  };
38
42
 
39
43
  const handleDelete = () => {
@@ -95,13 +99,34 @@ LanguajeRow.propTypes = {
95
99
  name: PropTypes.string,
96
100
  config: PropTypes.object,
97
101
  mutate: PropTypes.func,
102
+ handleDimmer: PropTypes.func,
98
103
  };
99
104
 
100
- const Languages = ({ config, langs, mutate }) => {
105
+ const Languages = () => {
106
+ const includeMessages = false;
107
+ const {
108
+ locales,
109
+ loading: loadingUseLocales,
110
+ mutate,
111
+ isValidating,
112
+ } = useLocales(includeMessages);
113
+ const langs = _.map("lang")(locales);
114
+
101
115
  const { formatMessage } = useIntl();
102
116
  const { all_locales, loading, error } = useAllLocales();
103
117
  const [newLocales, setNewLocales] = useState([]);
104
118
  const { trigger } = useLocalesCreate();
119
+ const [dimmerState, setDimmerState] = useState(false);
120
+
121
+ const handleDimmer = (isMutating) => {
122
+ setDimmerState(isMutating);
123
+ };
124
+
125
+ const langsConfig = _.flow(
126
+ _.map((locale) => _.omit("messages")(locale)),
127
+ _.groupBy("lang"),
128
+ _.mapValues(_.first)
129
+ )(locales);
105
130
 
106
131
  const options = _.flow(
107
132
  _.filter(({ code }) => {
@@ -157,49 +182,50 @@ const Languages = ({ config, langs, mutate }) => {
157
182
  })}
158
183
  </Button>
159
184
  </Form>
160
- <Table collapsing striped>
161
- <TableHeader>
162
- <TableRow>
163
- <TableCell></TableCell>
164
- <TableCell textAlign="center">
165
- {formatMessage({
166
- id: "i18n.messages.locale.required",
167
- })}
168
- </TableCell>
169
- <TableCell textAlign="center">
170
- {formatMessage({
171
- id: "i18n.messages.locale.default",
172
- })}
173
- </TableCell>
174
- <TableCell></TableCell>
175
- </TableRow>
176
- </TableHeader>
177
- <TableBody>
178
- {_.flow(
179
- _.filter((locale) => _.includes(locale.code)(langs)),
180
- _.map(({ code, local, name }) => {
181
- return (
182
- <LanguajeRow
183
- key={code}
184
- code={code}
185
- local={local}
186
- name={name}
187
- config={config[code]}
188
- mutate={mutate}
189
- />
190
- );
191
- })
192
- )(all_locales)}
193
- </TableBody>
194
- </Table>
185
+
186
+ <Dimmer.Dimmable dimmed={isValidating || dimmerState}>
187
+ <Dimmer active={isValidating || dimmerState} inverted>
188
+ <Loader />
189
+ </Dimmer>
190
+ <Table collapsing striped>
191
+ <TableHeader>
192
+ <TableRow>
193
+ <TableCell></TableCell>
194
+ <TableCell textAlign="center">
195
+ {formatMessage({
196
+ id: "i18n.messages.locale.required",
197
+ })}
198
+ </TableCell>
199
+ <TableCell textAlign="center">
200
+ {formatMessage({
201
+ id: "i18n.messages.locale.default",
202
+ })}
203
+ </TableCell>
204
+ <TableCell></TableCell>
205
+ </TableRow>
206
+ </TableHeader>
207
+ <TableBody>
208
+ {_.flow(
209
+ _.filter((locale) => _.includes(locale.code)(langs)),
210
+ _.map(({ code, local, name }) => {
211
+ return (
212
+ <LanguajeRow
213
+ key={code}
214
+ code={code}
215
+ local={local}
216
+ name={name}
217
+ config={langsConfig[code]}
218
+ mutate={mutate}
219
+ handleDimmer={handleDimmer}
220
+ />
221
+ );
222
+ })
223
+ )(all_locales)}
224
+ </TableBody>
225
+ </Table>
226
+ </Dimmer.Dimmable>
195
227
  </>
196
228
  );
197
229
  };
198
230
 
199
- Languages.propTypes = {
200
- config: PropTypes.array,
201
- langs: PropTypes.object,
202
- mutate: PropTypes.func,
203
- };
204
-
205
231
  export default Languages;
@@ -1,5 +1,6 @@
1
1
  import _ from "lodash/fp";
2
2
  import React, { useState } from "react";
3
+ import PropTypes from "prop-types";
3
4
  import { useIntl, FormattedMessage } from "react-intl";
4
5
  import {
5
6
  Button,
@@ -22,15 +23,13 @@ import Languages from "./Languages";
22
23
 
23
24
  const ITEMS_PER_PAGE = 30;
24
25
 
25
- export function MessagesContent({ locales, loading, mutate }) {
26
+ export function MessagesContent({ locales, loading }) {
26
27
  const langs = _.map("lang")(locales);
27
28
 
28
- const langsConfig = _.flow(
29
- _.map((locale) => _.omit("messages")(locale)),
30
- _.groupBy("lang"),
31
- _.mapValues(_.first)
32
- )(locales);
33
- const [selectedLang, setSelectedLang] = useState(_.head(langs));
29
+ const [selectedLang, setSelectedLang] = useState(
30
+ _.head(_.filter((lang) => lang === "en" || lang === "es")(langs))
31
+ );
32
+
34
33
  const [selectedManageView, setSelectedManageView] = useState(false);
35
34
  const [page, setPage] = useState(1);
36
35
  const [filter, setFilter] = useState("");
@@ -108,15 +107,21 @@ export function MessagesContent({ locales, loading, mutate }) {
108
107
  />
109
108
  </>
110
109
  ) : (
111
- <Languages langs={langs} config={langsConfig} mutate={mutate} />
110
+ <Languages />
112
111
  )}
113
112
  </>
114
113
  );
115
114
  }
116
115
 
116
+ MessagesContent.propTypes = {
117
+ locales: PropTypes.array,
118
+ loading: PropTypes.bool,
119
+ };
120
+
117
121
  export default function Messages() {
118
122
  const { formatMessage } = useIntl();
119
- const { locales, loading, mutate } = useLocales();
123
+
124
+ const { locales, loading } = useLocales();
120
125
 
121
126
  return (
122
127
  <Segment>
@@ -144,11 +149,7 @@ export default function Messages() {
144
149
  to={I18N_MESSAGES_NEW}
145
150
  />
146
151
  {!loading ? (
147
- <MessagesContent
148
- locales={locales}
149
- loading={loading}
150
- mutate={mutate}
151
- />
152
+ <MessagesContent locales={locales} loading={loading} />
152
153
  ) : null}
153
154
  </Segment>
154
155
  </Segment>
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import userEvent from "@testing-library/user-event";
3
2
  import { render } from "@truedat/test/render";
4
3
  import messages from "@truedat/core/messages";
5
4
  import MessageForm from "../MessageForm";