@truedat/core 4.46.5 → 4.46.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.46.6] 2022-06-20
4
+
5
+ ### Added
6
+
7
+ - [TD-4858] Group cards in CardGroupsAccordion component.
8
+
3
9
  ## [4.46.5] 2022-06-17
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/core",
3
- "version": "4.46.5",
3
+ "version": "4.46.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.4",
36
36
  "@testing-library/react": "^12.0.0",
37
37
  "@testing-library/user-event": "^13.2.1",
38
- "@truedat/test": "4.46.5",
38
+ "@truedat/test": "4.46.8",
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",
@@ -112,5 +112,5 @@
112
112
  "react-dom": ">= 16.8.6 < 17",
113
113
  "semantic-ui-react": ">= 0.88.2 < 2.1"
114
114
  },
115
- "gitHead": "cc6e42515345adf2926f47216622e0fc4f7a0d86"
115
+ "gitHead": "44f3e7aea8153415f773f7b4f9137c11ad128b1d"
116
116
  }
@@ -0,0 +1,145 @@
1
+ import React, { useState } from "react";
2
+ import PropTypes from "prop-types";
3
+ import _ from "lodash/fp";
4
+ import { useIntl } from "react-intl";
5
+
6
+ import { Accordion, Icon, Header, Card } from "semantic-ui-react";
7
+
8
+ import "../styles/CardGroupsAccordion.less";
9
+
10
+ /**
11
+ * Component to split Card.Groups into different folding sections
12
+ *
13
+ * If an element doesn't have a df_content.system_group, it must be appear
14
+ * under the "default" key.
15
+ *
16
+ * The objects that are inside the list of each group must contain the keys
17
+ * that will be passed as properties to cardComponent
18
+ *
19
+ * @component
20
+ * @example
21
+ *
22
+ * import { Card } from "semantic-ui-react";
23
+ *
24
+ *
25
+ * const groups = {
26
+ * foo: [
27
+ * {
28
+ * title: "hello foo",
29
+ * meta: "world foo",
30
+ * description: "Test description foo 1",
31
+ * },
32
+ * {
33
+ * title: "hello foo 2",
34
+ * meta: "world foo 2",
35
+ * description: "Test description foo 2",
36
+ * },
37
+ * ],
38
+ * bar: [
39
+ * {
40
+ * title: "hello bar",
41
+ * meta: "world bar",
42
+ * description: "Test description bar 1",
43
+ * },
44
+ * {
45
+ * title: "hello bar 2",
46
+ * meta: "world bar 2",
47
+ * description: "Test description bar 2",
48
+ * },
49
+ * ],
50
+ * }
51
+ *
52
+ * const CustomCard = (props) => (
53
+ * <Card>
54
+ * <Card.Content>
55
+ * <Card.Header>{props.title}</Card.Header>
56
+ * <Card.Meta>
57
+ * <span>{props.meta}</span>
58
+ * </Card.Meta>
59
+ * <Card.Description>{props.description}</Card.Description>
60
+ * </Card.Content>
61
+ * </Card>
62
+ * );
63
+ *
64
+ * return (
65
+ * <CardGroupsAccordion groups={groups} cardComponent={CustomCard} />
66
+ * )
67
+ */
68
+ const CardGroupsAccordion = ({ groups, cardComponent: CardComponent }) => {
69
+ const { formatMessage } = useIntl();
70
+
71
+ // State and lifecycle methods
72
+
73
+ const [cardGroups, setCardGroups] = _.flow(
74
+ _.toPairs,
75
+ _.reduce(
76
+ (acc, [groupName, members]) => ({
77
+ ...acc,
78
+ [groupName]: { members, active: true },
79
+ }),
80
+ {}
81
+ ),
82
+ useState
83
+ )(groups);
84
+
85
+ // Handlers
86
+
87
+ const handleClick = (e, { index: groupName }) =>
88
+ _.flow(
89
+ _.set(`${groupName}.active`, !cardGroups[groupName].active),
90
+ setCardGroups
91
+ )(cardGroups);
92
+
93
+ // Renders
94
+
95
+ const renderSection = (groupName, group) => (
96
+ <div key={groupName}>
97
+ <Accordion.Title
98
+ active={group.active}
99
+ index={groupName}
100
+ onClick={handleClick}
101
+ className="CardGroupTitle"
102
+ >
103
+ <Header as="h3" dividing>
104
+ <Icon name="dropdown" />
105
+ {groupName === "default"
106
+ ? formatMessage({
107
+ id: "components.CardGroupsAccordion.withoutGroups",
108
+ })
109
+ : groupName}
110
+ </Header>
111
+ </Accordion.Title>
112
+ <Accordion.Content active={group.active}>
113
+ <Card.Group>
114
+ {group.members.map((cardProps) => (
115
+ <CardComponent key={cardProps.id} {...cardProps} />
116
+ ))}
117
+ </Card.Group>
118
+ </Accordion.Content>
119
+ </div>
120
+ );
121
+
122
+ return (
123
+ <Accordion exclusive={false}>
124
+ {cardGroups?.default
125
+ ? renderSection("default", cardGroups.default)
126
+ : null}
127
+ {_.flow(
128
+ _.omit(["default"]),
129
+ _.toPairs,
130
+ _.sortBy(0),
131
+ _.map(([groupName, group]) => renderSection(groupName, group))
132
+ )(cardGroups)}
133
+ </Accordion>
134
+ );
135
+ };
136
+
137
+ CardGroupsAccordion.propTypes = {
138
+ /** Object where the key is the name of group and the value is an array with
139
+ * card props that will be used in cardComponent */
140
+ groups: PropTypes.object,
141
+ /** Component to render Card content using card props passed in groups */
142
+ cardComponent: PropTypes.func,
143
+ };
144
+
145
+ export default CardGroupsAccordion;
@@ -0,0 +1,142 @@
1
+ import React from "react";
2
+ import { waitFor, fireEvent } from "@testing-library/react";
3
+ import { render } from "@truedat/test/render";
4
+ import { Card } from "semantic-ui-react";
5
+ import { CardGroupsAccordion } from "..";
6
+
7
+ const groups_all_cards_grouped = {
8
+ foo: [
9
+ {
10
+ id: 1,
11
+ name: "hello foo",
12
+ ueueue: "world foo",
13
+ description: "Test description foo 1",
14
+ },
15
+ {
16
+ id: 2,
17
+ name: "hello foo 2",
18
+ meta: "world foo 2",
19
+ description: "Test description foo 2",
20
+ },
21
+ ],
22
+ bar: [
23
+ {
24
+ id: 3,
25
+ name: "hello bar",
26
+ meta: "world bar",
27
+ description: "Test description bar 1",
28
+ },
29
+ {
30
+ id: 4,
31
+ name: "hello bar 2",
32
+ meta: "world bar 2",
33
+ description: "Test description bar 2",
34
+ },
35
+ ],
36
+ };
37
+
38
+ const groups_any_cards_without_group = {
39
+ foo: [
40
+ {
41
+ id: 1,
42
+ name: "hello foo",
43
+ meta: "world foo",
44
+ description: "Test description foo 1",
45
+ },
46
+ {
47
+ id: 2,
48
+ name: "hello foo 2",
49
+ meta: "world foo 2",
50
+ description: "Test description foo 2",
51
+ },
52
+ ],
53
+ default: [
54
+ {
55
+ id: 3,
56
+ name: "hello bar",
57
+ meta: "world bar",
58
+ description: "Test description bar 1",
59
+ },
60
+ {
61
+ id: 4,
62
+ name: "hello bar 2",
63
+ meta: "world bar 2",
64
+ description: "Test description bar 2",
65
+ },
66
+ ],
67
+ };
68
+
69
+ const cardComponent = (props) => (
70
+ <Card>
71
+ <Card.Content>
72
+ <Card.Header>{props.name}</Card.Header>
73
+ <Card.Meta>
74
+ <span>{props.meta}</span>
75
+ </Card.Meta>
76
+ <Card.Description>{props.description}</Card.Description>
77
+ </Card.Content>
78
+ </Card>
79
+ );
80
+
81
+ describe("<CardGroupsAccordion />", () => {
82
+ it("matches the latest snapshot", () => {
83
+ const { container } = render(
84
+ <CardGroupsAccordion
85
+ groups={groups_all_cards_grouped}
86
+ cardComponent={cardComponent}
87
+ />
88
+ );
89
+ expect(container).toMatchSnapshot();
90
+ });
91
+
92
+ it("Data without group appear in without group section", async () => {
93
+ const { getByText } = render(
94
+ <CardGroupsAccordion
95
+ groups={groups_any_cards_without_group}
96
+ cardComponent={cardComponent}
97
+ />
98
+ );
99
+
100
+ await waitFor(() => {
101
+ expect(getByText("Without Groups")).toBeTruthy();
102
+ });
103
+ });
104
+
105
+ it("Data without group appear in first position", async () => {
106
+ const { container } = render(
107
+ <CardGroupsAccordion
108
+ groups={groups_any_cards_without_group}
109
+ cardComponent={cardComponent}
110
+ />
111
+ );
112
+
113
+ const firstGroup = container.getElementsByClassName("title")[0].innerHTML;
114
+
115
+ await waitFor(() => {
116
+ expect(firstGroup).toMatch("Without Groups");
117
+ });
118
+ });
119
+
120
+ it("CardGroupsAccordion fold and unfold when click in title", async () => {
121
+ const { container } = render(
122
+ <CardGroupsAccordion
123
+ groups={groups_any_cards_without_group}
124
+ cardComponent={cardComponent}
125
+ />
126
+ );
127
+
128
+ const firstTitle = container.querySelector(".title");
129
+
130
+ fireEvent.click(firstTitle);
131
+
132
+ await waitFor(() => {
133
+ expect(firstTitle.classList.contains("active")).toBeFalsy();
134
+ });
135
+
136
+ fireEvent.click(firstTitle);
137
+
138
+ await waitFor(() => {
139
+ expect(firstTitle.classList.contains("active")).toBeTruthy();
140
+ });
141
+ });
142
+ });
@@ -0,0 +1,154 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<CardGroupsAccordion /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="accordion ui"
7
+ >
8
+ <div>
9
+ <div
10
+ class="active title CardGroupTitle"
11
+ >
12
+ <h3
13
+ class="ui dividing header"
14
+ >
15
+ <i
16
+ aria-hidden="true"
17
+ class="dropdown icon"
18
+ />
19
+ bar
20
+ </h3>
21
+ </div>
22
+ <div
23
+ class="content active"
24
+ >
25
+ <div
26
+ class="ui cards"
27
+ >
28
+ <div
29
+ class="ui card"
30
+ >
31
+ <div
32
+ class="content"
33
+ >
34
+ <div
35
+ class="header"
36
+ >
37
+ hello bar
38
+ </div>
39
+ <div
40
+ class="meta"
41
+ >
42
+ <span>
43
+ world bar
44
+ </span>
45
+ </div>
46
+ <div
47
+ class="description"
48
+ >
49
+ Test description bar 1
50
+ </div>
51
+ </div>
52
+ </div>
53
+ <div
54
+ class="ui card"
55
+ >
56
+ <div
57
+ class="content"
58
+ >
59
+ <div
60
+ class="header"
61
+ >
62
+ hello bar 2
63
+ </div>
64
+ <div
65
+ class="meta"
66
+ >
67
+ <span>
68
+ world bar 2
69
+ </span>
70
+ </div>
71
+ <div
72
+ class="description"
73
+ >
74
+ Test description bar 2
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ <div>
82
+ <div
83
+ class="active title CardGroupTitle"
84
+ >
85
+ <h3
86
+ class="ui dividing header"
87
+ >
88
+ <i
89
+ aria-hidden="true"
90
+ class="dropdown icon"
91
+ />
92
+ foo
93
+ </h3>
94
+ </div>
95
+ <div
96
+ class="content active"
97
+ >
98
+ <div
99
+ class="ui cards"
100
+ >
101
+ <div
102
+ class="ui card"
103
+ >
104
+ <div
105
+ class="content"
106
+ >
107
+ <div
108
+ class="header"
109
+ >
110
+ hello foo
111
+ </div>
112
+ <div
113
+ class="meta"
114
+ >
115
+ <span />
116
+ </div>
117
+ <div
118
+ class="description"
119
+ >
120
+ Test description foo 1
121
+ </div>
122
+ </div>
123
+ </div>
124
+ <div
125
+ class="ui card"
126
+ >
127
+ <div
128
+ class="content"
129
+ >
130
+ <div
131
+ class="header"
132
+ >
133
+ hello foo 2
134
+ </div>
135
+ <div
136
+ class="meta"
137
+ >
138
+ <span>
139
+ world foo 2
140
+ </span>
141
+ </div>
142
+ <div
143
+ class="description"
144
+ >
145
+ Test description foo 2
146
+ </div>
147
+ </div>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+ </div>
153
+ </div>
154
+ `;
@@ -4,6 +4,7 @@ import MembersMenu from "./MembersMenu";
4
4
  import Alert from "./Alert";
5
5
  import Authorized from "./Authorized";
6
6
  import AvailableFilters from "./AvailableFilters";
7
+ import CardGroupsAccordion from "./CardGroupsAccordion";
7
8
  import CatalogMenu from "./CatalogMenu";
8
9
  import Comments from "./Comments";
9
10
  import CommentsLoader from "./CommentsLoader";
@@ -51,6 +52,7 @@ export {
51
52
  Alert,
52
53
  Authorized,
53
54
  AvailableFilters,
55
+ CardGroupsAccordion,
54
56
  CatalogMenu,
55
57
  Comments,
56
58
  CommentsLoader,
@@ -33,6 +33,7 @@ export default {
33
33
  "alert.status.504.header": "Gateway Timeout (504)",
34
34
  "comments.actions.new": "New comment",
35
35
  "comments.header": "Comments",
36
+ "components.CardGroupsAccordion.withoutGroups": "Without Groups",
36
37
  "confirmation.no": "No",
37
38
  "confirmation.yes": "Yes",
38
39
  "dateFilter.since": "less than",
@@ -34,6 +34,7 @@ export default {
34
34
  "alert.status.504.header": "Gateway Timeout (504)",
35
35
  "comments.actions.new": "Añadir comentario",
36
36
  "comments.header": "Comentarios",
37
+ "components.CardGroupsAccordion.withoutGroups": "Sin Agrupación",
37
38
  "confirmation.no": "No",
38
39
  "confirmation.yes": "Sí",
39
40
  "dateFilter.since": "hace menos de",
package/src/routes.js CHANGED
@@ -71,6 +71,8 @@ export const IMPLEMENTATION_EVENTS =
71
71
  export const IMPLEMENTATION_EDIT = "/implementations/:implementation_id/edit";
72
72
  export const IMPLEMENTATION_CLONE = "/implementations/:implementation_id/clone";
73
73
  export const IMPLEMENTATION_MOVE = "/implementations/:implementation_id/move";
74
+ export const IMPLEMENTATION_HISTORY =
75
+ "/implementations/:implementation_id/history";
74
76
  export const IMPLEMENTATION_RESULT_DETAILS =
75
77
  "/implementations/:implementation_id/results/:rule_result_id";
76
78
  export const IMPLEMENTATION_RESULT_SEGMENTS_RESULTS =
@@ -242,6 +244,7 @@ const routes = {
242
244
  IMPLEMENTATION_CONCEPT_LINKS_NEW,
243
245
  IMPLEMENTATION_EDIT,
244
246
  IMPLEMENTATION_EVENTS,
247
+ IMPLEMENTATION_HISTORY,
245
248
  IMPLEMENTATION_MOVE,
246
249
  IMPLEMENTATION_NEW,
247
250
  IMPLEMENTATION_NEW_RAW,
@@ -0,0 +1,3 @@
1
+ .CardGroupTitle {
2
+ margin-top: 1rem;
3
+ }