@truedat/core 5.9.6 → 5.9.8
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.9.
|
|
3
|
+
"version": "5.9.8",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@testing-library/jest-dom": "^5.16.5",
|
|
36
36
|
"@testing-library/react": "^12.0.0",
|
|
37
37
|
"@testing-library/user-event": "^13.2.1",
|
|
38
|
-
"@truedat/test": "5.9.
|
|
38
|
+
"@truedat/test": "5.9.7",
|
|
39
39
|
"babel-jest": "^28.1.0",
|
|
40
40
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
41
41
|
"babel-plugin-lodash": "^3.3.4",
|
|
@@ -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": "
|
|
120
|
+
"gitHead": "ea466759ff38b111f12c743f430779586c28f37d"
|
|
121
121
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Label, Popup } from "semantic-ui-react";
|
|
5
|
+
|
|
6
|
+
const ArrayDecorator = (limit, concatenator) => (list) => {
|
|
7
|
+
const itemsToShow = _.flow(_.take(limit), _.join(concatenator))(list);
|
|
8
|
+
const hiddenItems = _.slice(limit, Infinity)(list);
|
|
9
|
+
return ArrayDecoratorComponent({ itemsToShow, hiddenItems });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const ArrayDecoratorComponent = ({ itemsToShow, hiddenItems }) => {
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
{itemsToShow + " "}
|
|
16
|
+
{_.isEmpty(hiddenItems) ? null : (
|
|
17
|
+
<Popup
|
|
18
|
+
content=<ul>
|
|
19
|
+
{_.map((item) => <li key={item}>{item}</li>)(hiddenItems)}
|
|
20
|
+
</ul>
|
|
21
|
+
trigger={<Label>+{_.size(hiddenItems)}</Label>}
|
|
22
|
+
/>
|
|
23
|
+
)}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
ArrayDecoratorComponent.propTypes = {
|
|
29
|
+
itemsToShow: PropTypes.array,
|
|
30
|
+
hiddenItems: PropTypes.array,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
ArrayDecorator.propTypes = {
|
|
34
|
+
limit: PropTypes.number,
|
|
35
|
+
concatenator: PropTypes.string,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default ArrayDecorator;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { render } from "@truedat/test/render";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import ArrayDecorator from "../ArrayDecorator";
|
|
5
|
+
|
|
6
|
+
describe("<ArrayDecorator />", () => {
|
|
7
|
+
it("without parameters generate an empty text", () => {
|
|
8
|
+
const { queryByText } = render(ArrayDecorator());
|
|
9
|
+
expect(queryByText(",")).not.toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("show list wiht limit 1", () => {
|
|
13
|
+
const list = ["foo", "bar", "rab", "oof"];
|
|
14
|
+
const { queryByText } = render(ArrayDecorator(1, ",")(list));
|
|
15
|
+
expect(queryByText("foo")).toBeInTheDocument();
|
|
16
|
+
expect(queryByText("bar")).not.toBeInTheDocument();
|
|
17
|
+
expect(queryByText("+3")).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("show list wiht limit 3", () => {
|
|
21
|
+
const list = ["foo", "bar", "rab", "oof"];
|
|
22
|
+
const { queryByText } = render(ArrayDecorator(3, ", ")(list));
|
|
23
|
+
expect(queryByText("foo, bar, rab")).toBeInTheDocument();
|
|
24
|
+
expect(queryByText("oof")).not.toBeInTheDocument();
|
|
25
|
+
expect(queryByText("+1")).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("show a popup with hidden items", async () => {
|
|
29
|
+
const showableItems = ["showable_item_1", "showable_item_2"];
|
|
30
|
+
const hiddenItems = ["hidden_item_1", "hidden_item_2"];
|
|
31
|
+
const concatenator = ", ";
|
|
32
|
+
const list = [...showableItems, ...hiddenItems];
|
|
33
|
+
const { getByText, getByRole, queryAllByRole } = render(
|
|
34
|
+
ArrayDecorator(showableItems.length, concatenator)(list)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(queryAllByRole("listitem")).toEqual([]);
|
|
38
|
+
expect(getByText(showableItems.join(concatenator))).toBeInTheDocument();
|
|
39
|
+
userEvent.hover(await getByText("+2"));
|
|
40
|
+
await waitFor(() => expect(getByRole("list")).toBeInTheDocument());
|
|
41
|
+
const listItems = queryAllByRole("listitem");
|
|
42
|
+
expect(listItems.length).toBe(2);
|
|
43
|
+
const hiddenNames = listItems.map((item) => item.textContent);
|
|
44
|
+
expect(hiddenNames).toEqual(hiddenItems);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("does not show the popup label whith no hidden items", async () => {
|
|
48
|
+
const showableItems = ["showable_item_1", "showable_item_2"];
|
|
49
|
+
const { queryByText } = render(
|
|
50
|
+
ArrayDecorator(showableItems.length, ",")(showableItems)
|
|
51
|
+
);
|
|
52
|
+
expect(queryByText("+0")).not.toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/messages/en.js
CHANGED
|
@@ -47,6 +47,7 @@ export default {
|
|
|
47
47
|
"dateFilter.weeks": "weeks ago",
|
|
48
48
|
"dateFilter.months": "months ago",
|
|
49
49
|
"dateFilter.years": "years ago",
|
|
50
|
+
emptyBucket: "(Empty)",
|
|
50
51
|
"error.content": "Please report this error to the Truedat team.",
|
|
51
52
|
"error.duplicated": "duplicated",
|
|
52
53
|
"error.header": "Eek! Something went wrong...",
|
package/src/messages/es.js
CHANGED
|
@@ -48,6 +48,7 @@ export default {
|
|
|
48
48
|
"dateFilter.weeks": "semanas",
|
|
49
49
|
"dateFilter.months": "meses",
|
|
50
50
|
"dateFilter.years": "años",
|
|
51
|
+
emptyBucket: "(Vacío)",
|
|
51
52
|
"error.content": "Por favor, coméntaselo al equipo de Truedat.",
|
|
52
53
|
"error.duplicated": "duplicado",
|
|
53
54
|
"error.header": "Se ha producido un error inesperado",
|