@truedat/df 5.0.0 → 5.0.2

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 (25) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +5 -5
  3. package/src/api/hierarchies.js +4 -0
  4. package/src/components/hierarchies/Hierarchies.js +43 -0
  5. package/src/components/hierarchies/HierarchiesView.js +32 -0
  6. package/src/components/hierarchies/Hierarchy.js +301 -0
  7. package/src/components/hierarchies/HierarchyCrumbs.js +22 -0
  8. package/src/components/hierarchies/HierarchyRoutes.js +105 -0
  9. package/src/components/hierarchies/HierarchyView.js +261 -0
  10. package/src/components/hierarchies/__tests__/Hierarchies.spec.js +34 -0
  11. package/src/components/hierarchies/__tests__/HierarchiesView.spec.js +34 -0
  12. package/src/components/hierarchies/__tests__/Hierarchy.spec.js +42 -0
  13. package/src/components/hierarchies/__tests__/HierarchyCrumbs.spec.js +11 -0
  14. package/src/components/hierarchies/__tests__/HierarchyView.spec.js +36 -0
  15. package/src/components/hierarchies/__tests__/__snapshots__/Hierarchies.spec.js.snap +48 -0
  16. package/src/components/hierarchies/__tests__/__snapshots__/HierarchiesView.spec.js.snap +81 -0
  17. package/src/components/hierarchies/__tests__/__snapshots__/Hierarchy.spec.js.snap +186 -0
  18. package/src/components/hierarchies/__tests__/__snapshots__/HierarchyCrumbs.spec.js.snap +102 -0
  19. package/src/components/hierarchies/__tests__/__snapshots__/HierarchyView.spec.js.snap +145 -0
  20. package/src/components/hierarchies/index.js +3 -0
  21. package/src/components/index.js +1 -0
  22. package/src/hooks/useHierarchies.js +111 -0
  23. package/src/messages/en.js +94 -72
  24. package/src/messages/es.js +99 -77
  25. package/src/styles/hierarchy.less +91 -0
@@ -0,0 +1,186 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<Hierarchy /> matches snapshot with edition mode 1`] = `
4
+ <div>
5
+ <div
6
+ class="column"
7
+ >
8
+ <div
9
+ class="row"
10
+ >
11
+ <div
12
+ style="display: flex; flex-direction: row; align-items: self-start;"
13
+ >
14
+ <div
15
+ class="ui input"
16
+ >
17
+ <input
18
+ placeholder="Hierarchy name"
19
+ type="text"
20
+ value="Baggins"
21
+ />
22
+ </div>
23
+ <div
24
+ class="description_wrapper"
25
+ >
26
+ <div
27
+ class="description"
28
+ >
29
+ bar
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ <ul
35
+ class="wtree expanded"
36
+ >
37
+ <li>
38
+ <i
39
+ aria-hidden="true"
40
+ class="cut large icon li_trash"
41
+ style="cursor: pointer; visibility: hidden;"
42
+ title="Delete node"
43
+ />
44
+ <div
45
+ style="display: flex; flex-direction: row; align-items: self-start;"
46
+ >
47
+ <div>
48
+ <div
49
+ class="ui left labeled input"
50
+ >
51
+ <div
52
+ class="ui basic label"
53
+ title="Expand"
54
+ >
55
+ <i
56
+ aria-hidden="true"
57
+ class="circle fitted icon"
58
+ style="cursor: pointer;"
59
+ />
60
+ </div>
61
+ <input
62
+ placeholder="Node"
63
+ type="text"
64
+ value="Fosco"
65
+ />
66
+ </div>
67
+ </div>
68
+ <div
69
+ class="description_wrapper"
70
+ >
71
+ <div
72
+ class="description"
73
+ >
74
+ Add description
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </li>
79
+ <li
80
+ class="add_node"
81
+ >
82
+ <div>
83
+ <form
84
+ class="ui form"
85
+ >
86
+ <div
87
+ class="ui input"
88
+ >
89
+ <input
90
+ placeholder="New node"
91
+ type="text"
92
+ value=""
93
+ />
94
+ </div>
95
+ </form>
96
+ </div>
97
+ </li>
98
+ </ul>
99
+ </div>
100
+ </div>
101
+ `;
102
+
103
+ exports[`<Hierarchy /> matches the last snapshot with edition mode false 1`] = `
104
+ <div>
105
+ <div
106
+ class="column"
107
+ >
108
+ <div
109
+ class="row"
110
+ >
111
+ <div
112
+ style="display: flex; flex-direction: row; align-items: self-start;"
113
+ >
114
+ <div
115
+ class="ui disabled input"
116
+ style="opacity: 1;"
117
+ >
118
+ <input
119
+ disabled=""
120
+ placeholder="Hierarchy name"
121
+ tabindex="-1"
122
+ type="text"
123
+ value="Baggins"
124
+ />
125
+ </div>
126
+ <div
127
+ class="description_wrapper"
128
+ >
129
+ <div
130
+ class="description disabled"
131
+ >
132
+ bar
133
+ </div>
134
+ </div>
135
+ </div>
136
+ </div>
137
+ <ul
138
+ class="wtree expanded"
139
+ >
140
+ <li>
141
+ <i
142
+ aria-hidden="true"
143
+ class="cut large icon li_trash"
144
+ style="cursor: pointer; visibility: hidden;"
145
+ title="Delete node"
146
+ />
147
+ <div
148
+ style="display: flex; flex-direction: row; align-items: self-start;"
149
+ >
150
+ <div>
151
+ <div
152
+ class="ui disabled left labeled input"
153
+ style="opacity: 1;"
154
+ >
155
+ <div
156
+ class="ui basic label"
157
+ title="Expand"
158
+ >
159
+ <i
160
+ aria-hidden="true"
161
+ class="circle fitted icon"
162
+ style="cursor: pointer;"
163
+ />
164
+ </div>
165
+ <input
166
+ disabled=""
167
+ placeholder="Node"
168
+ tabindex="-1"
169
+ type="text"
170
+ value="Fosco"
171
+ />
172
+ </div>
173
+ </div>
174
+ <div
175
+ class="description_wrapper"
176
+ >
177
+ <div
178
+ class="description disabled"
179
+ />
180
+ </div>
181
+ </div>
182
+ </li>
183
+ </ul>
184
+ </div>
185
+ </div>
186
+ `;
@@ -0,0 +1,102 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<HierarchyCrumbs /> matches the latest snapshot 1`] = `
4
+ Object {
5
+ "asFragment": [Function],
6
+ "baseElement": <body>
7
+ <div>
8
+ <div
9
+ class="ui breadcrumb"
10
+ >
11
+ <a
12
+ class="section"
13
+ href="/hierarchies"
14
+ >
15
+ Hierarchies
16
+ </a>
17
+ <i
18
+ aria-hidden="true"
19
+ class="right angle icon divider"
20
+ />
21
+ <div
22
+ class="active section"
23
+ >
24
+ foo
25
+ </div>
26
+ </div>
27
+ </div>
28
+ </body>,
29
+ "container": <div>
30
+ <div
31
+ class="ui breadcrumb"
32
+ >
33
+ <a
34
+ class="section"
35
+ href="/hierarchies"
36
+ >
37
+ Hierarchies
38
+ </a>
39
+ <i
40
+ aria-hidden="true"
41
+ class="right angle icon divider"
42
+ />
43
+ <div
44
+ class="active section"
45
+ >
46
+ foo
47
+ </div>
48
+ </div>
49
+ </div>,
50
+ "debug": [Function],
51
+ "findAllByAltText": [Function],
52
+ "findAllByDisplayValue": [Function],
53
+ "findAllByLabelText": [Function],
54
+ "findAllByPlaceholderText": [Function],
55
+ "findAllByRole": [Function],
56
+ "findAllByTestId": [Function],
57
+ "findAllByText": [Function],
58
+ "findAllByTitle": [Function],
59
+ "findByAltText": [Function],
60
+ "findByDisplayValue": [Function],
61
+ "findByLabelText": [Function],
62
+ "findByPlaceholderText": [Function],
63
+ "findByRole": [Function],
64
+ "findByTestId": [Function],
65
+ "findByText": [Function],
66
+ "findByTitle": [Function],
67
+ "getAllByAltText": [Function],
68
+ "getAllByDisplayValue": [Function],
69
+ "getAllByLabelText": [Function],
70
+ "getAllByPlaceholderText": [Function],
71
+ "getAllByRole": [Function],
72
+ "getAllByTestId": [Function],
73
+ "getAllByText": [Function],
74
+ "getAllByTitle": [Function],
75
+ "getByAltText": [Function],
76
+ "getByDisplayValue": [Function],
77
+ "getByLabelText": [Function],
78
+ "getByPlaceholderText": [Function],
79
+ "getByRole": [Function],
80
+ "getByTestId": [Function],
81
+ "getByText": [Function],
82
+ "getByTitle": [Function],
83
+ "queryAllByAltText": [Function],
84
+ "queryAllByDisplayValue": [Function],
85
+ "queryAllByLabelText": [Function],
86
+ "queryAllByPlaceholderText": [Function],
87
+ "queryAllByRole": [Function],
88
+ "queryAllByTestId": [Function],
89
+ "queryAllByText": [Function],
90
+ "queryAllByTitle": [Function],
91
+ "queryByAltText": [Function],
92
+ "queryByDisplayValue": [Function],
93
+ "queryByLabelText": [Function],
94
+ "queryByPlaceholderText": [Function],
95
+ "queryByRole": [Function],
96
+ "queryByTestId": [Function],
97
+ "queryByText": [Function],
98
+ "queryByTitle": [Function],
99
+ "rerender": [Function],
100
+ "unmount": [Function],
101
+ }
102
+ `;
@@ -0,0 +1,145 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<HierarchyView /> matches the last snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui breadcrumb"
7
+ >
8
+ <a
9
+ class="section"
10
+ href="/hierarchies"
11
+ >
12
+ Hierarchies
13
+ </a>
14
+ <i
15
+ aria-hidden="true"
16
+ class="right angle icon divider"
17
+ />
18
+ <div
19
+ class="active section"
20
+ >
21
+ Baggins
22
+ </div>
23
+ </div>
24
+ <div
25
+ class="ui segment"
26
+ >
27
+ <h2
28
+ class="ui header"
29
+ >
30
+ <div
31
+ class="actions_wrapper"
32
+ >
33
+ <div
34
+ class="actions"
35
+ >
36
+ <a
37
+ class="ui primary right floated button"
38
+ href="/hierarchies/1/edit"
39
+ role="button"
40
+ >
41
+ Edit
42
+ </a>
43
+ <button
44
+ class="ui secondary right floated button"
45
+ >
46
+ Delete
47
+ </button>
48
+ </div>
49
+ </div>
50
+ <i
51
+ aria-hidden="true"
52
+ class="tree circular icon"
53
+ />
54
+ <div
55
+ class="content"
56
+ >
57
+ Baggins
58
+ <div
59
+ class="sub header"
60
+ />
61
+ </div>
62
+ </h2>
63
+ <div
64
+ class="ui bottom attached segment"
65
+ >
66
+ <div
67
+ class="column"
68
+ >
69
+ <div
70
+ class="row"
71
+ >
72
+ <div
73
+ style="display: flex; flex-direction: row; align-items: self-start;"
74
+ >
75
+ <div
76
+ class="ui disabled input"
77
+ style="opacity: 1;"
78
+ >
79
+ <input
80
+ disabled=""
81
+ placeholder="Hierarchy name"
82
+ tabindex="-1"
83
+ type="text"
84
+ value="Baggins"
85
+ />
86
+ </div>
87
+ <div
88
+ class="description_wrapper"
89
+ >
90
+ <div
91
+ class="description disabled"
92
+ />
93
+ </div>
94
+ </div>
95
+ </div>
96
+ <ul
97
+ class="wtree expanded"
98
+ >
99
+ <li>
100
+ <i
101
+ aria-hidden="true"
102
+ class="cut large icon li_trash"
103
+ style="cursor: pointer; visibility: hidden;"
104
+ title="Delete node"
105
+ />
106
+ <div
107
+ style="display: flex; flex-direction: row; align-items: self-start;"
108
+ >
109
+ <div>
110
+ <div
111
+ class="ui disabled left labeled input"
112
+ style="opacity: 1;"
113
+ >
114
+ <div
115
+ class="ui basic label"
116
+ >
117
+ <i
118
+ aria-hidden="true"
119
+ class="circle outline fitted icon"
120
+ />
121
+ </div>
122
+ <input
123
+ disabled=""
124
+ placeholder="Node"
125
+ tabindex="-1"
126
+ type="text"
127
+ value="Fosco"
128
+ />
129
+ </div>
130
+ </div>
131
+ <div
132
+ class="description_wrapper"
133
+ >
134
+ <div
135
+ class="description disabled"
136
+ />
137
+ </div>
138
+ </div>
139
+ </li>
140
+ </ul>
141
+ </div>
142
+ </div>
143
+ </div>
144
+ </div>
145
+ `;
@@ -0,0 +1,3 @@
1
+ import HierarchyRoutes from "./HierarchyRoutes";
2
+
3
+ export { HierarchyRoutes };
@@ -1 +1,2 @@
1
1
  export * from "../templates/components";
2
+ export * from "./hierarchies";
@@ -0,0 +1,111 @@
1
+ import _ from "lodash/fp";
2
+ import { compile } from "path-to-regexp";
3
+ import { mutate } from "swr";
4
+ import useSWR from "swr";
5
+ import useSWRMutations from "swr/mutation";
6
+ import {
7
+ apiJson,
8
+ apiJsonPatch,
9
+ apiJsonPost,
10
+ apiJsonDelete,
11
+ } from "@truedat/core/services/api";
12
+ import { API_HIERARCHIES, API_HIERARCHY } from "../api/hierarchies";
13
+
14
+ const newHierarchy = {
15
+ name: "",
16
+ description: null,
17
+ nodes: [],
18
+ };
19
+
20
+ export const useHierarchies = () => {
21
+ const toApiPath = compile(API_HIERARCHIES);
22
+ const url = toApiPath();
23
+ const { data, error } = useSWR(url, apiJson);
24
+ return { data: data?.data?.data, error, loading: !error && !data };
25
+ };
26
+
27
+ export const useInitialHiearchy = () => {
28
+ return {
29
+ data: newHierarchy,
30
+ error: null,
31
+ loading: false,
32
+ };
33
+ };
34
+
35
+ export const useHierarchy = (id) => {
36
+ const toApiPath = compile(API_HIERARCHY);
37
+ const url = toApiPath({ id: id });
38
+ const { data, error } = useSWR(url, apiJson);
39
+ const back_hierarchy = data?.data?.data;
40
+ const front_hierarchy = toFront(back_hierarchy);
41
+ return { data: front_hierarchy, error, loading: !error && !data };
42
+ };
43
+
44
+ export const useHierarchyPatch = (id, callback) => {
45
+ const toApiPath = compile(API_HIERARCHY);
46
+ const url = toApiPath({ id });
47
+ return useSWRMutations(url, (url, { arg }) =>
48
+ apiJsonPatch(url, toBack(arg)).then(
49
+ ({ data }) =>
50
+ mutate(API_HIERARCHIES) && mutate(url, data) && callback(data?.data)
51
+ )
52
+ );
53
+ };
54
+
55
+ export const useHierarchyPost = (callback) => {
56
+ return useSWRMutations(API_HIERARCHIES, (url, { arg }) =>
57
+ apiJsonPost(url, toBack(arg)).then(
58
+ ({ data }) => mutate(API_HIERARCHIES) && callback(data?.data)
59
+ )
60
+ );
61
+ };
62
+
63
+ export const useHierarchyDelete = (id, callback) => {
64
+ const toApiPath = compile(API_HIERARCHY);
65
+ const url = toApiPath({ id });
66
+ return useSWRMutations(url, (url, { arg }) =>
67
+ apiJsonDelete(url, toBack(arg)).then(
68
+ ({ data }) => mutate(API_HIERARCHIES) && callback(data?.data)
69
+ )
70
+ );
71
+ };
72
+
73
+ const toFront = (hierarchy) => {
74
+ return hierarchy
75
+ ? {
76
+ ...hierarchy,
77
+ nodes: _.flow(
78
+ _.pathOr([], "nodes"),
79
+ _.map((node) => {
80
+ return {
81
+ id: node.node_id,
82
+ parentId: node.parent_id,
83
+ name: node.name,
84
+ description: node.description,
85
+ };
86
+ })
87
+ )(hierarchy),
88
+ }
89
+ : hierarchy;
90
+ };
91
+
92
+ const toBack = (hierarchy) => {
93
+ return hierarchy
94
+ ? {
95
+ hierarchy: {
96
+ ...hierarchy,
97
+ nodes: _.flow(
98
+ _.pathOr([], "nodes"),
99
+ _.map((node) => {
100
+ return {
101
+ node_id: node.id,
102
+ parent_id: node.parentId,
103
+ name: node.name,
104
+ description: node.description,
105
+ };
106
+ })
107
+ )(hierarchy),
108
+ },
109
+ }
110
+ : hierarchy;
111
+ };