@truedat/qx 8.2.1 → 8.2.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/qx",
3
- "version": "8.2.1",
3
+ "version": "8.2.3",
4
4
  "description": "Truedat Web Quality Experience package",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -53,7 +53,7 @@
53
53
  "@testing-library/jest-dom": "^6.6.3",
54
54
  "@testing-library/react": "^16.3.0",
55
55
  "@testing-library/user-event": "^14.6.1",
56
- "@truedat/test": "8.2.1",
56
+ "@truedat/test": "8.2.3",
57
57
  "identity-obj-proxy": "^3.0.0",
58
58
  "jest": "^29.7.0",
59
59
  "redux-saga-test-plan": "^4.0.6"
@@ -86,5 +86,5 @@
86
86
  "semantic-ui-react": "^3.0.0-beta.2",
87
87
  "swr": "^2.3.3"
88
88
  },
89
- "gitHead": "3008f4a5a734dc1f12e9f25a790542b56aed61d2"
89
+ "gitHead": "8e3f74fa7c3c0e071d3c46d161dde80454c26a15"
90
90
  }
@@ -119,7 +119,6 @@ export default function QualityControlActions() {
119
119
  "update_main",
120
120
  "execute",
121
121
  "link_to_business_concept",
122
- ,
123
122
  "link_to_data_structure",
124
123
  ])
125
124
  ),
@@ -12,7 +12,6 @@ import {
12
12
  QUALITY_CONTROL_HISTORY,
13
13
  QUALITY_CONTROL_SCORES,
14
14
  } from "@truedat/core/routes";
15
-
16
15
  import {
17
16
  useQualityControlsSearch,
18
17
  useQualityControlsFilters,
@@ -9,9 +9,14 @@ export default function QualityControlRow({
9
9
  withCheck = false,
10
10
  onChange,
11
11
  checked,
12
+ onClick,
13
+ active,
12
14
  }) {
13
15
  return _.isEmpty(columns) || _.isEmpty(qualityControl) ? null : (
14
- <Table.Row>
16
+ <Table.Row
17
+ active={active}
18
+ onClick={() => onClick && onClick(qualityControl)}
19
+ >
15
20
  {withCheck ? (
16
21
  <Table.Cell collapsing width="1" textAlign="center">
17
22
  <Checkbox
@@ -38,4 +43,6 @@ QualityControlRow.propTypes = {
38
43
  withCheck: PropTypes.bool,
39
44
  onChange: PropTypes.func,
40
45
  checked: PropTypes.bool,
46
+ onClick: PropTypes.func,
47
+ active: PropTypes.bool,
41
48
  };
@@ -0,0 +1,88 @@
1
+ import _ from "lodash/fp";
2
+ import { useState, useEffect } from "react";
3
+ import PropTypes from "prop-types";
4
+ import { Segment } from "semantic-ui-react";
5
+ import SearchWidget from "@truedat/core/search/SearchWidget";
6
+ import {
7
+ SearchContextProvider,
8
+ useSearchContext,
9
+ } from "@truedat/core/search/SearchContext";
10
+ import {
11
+ useQualityControlsSearch,
12
+ useQualityControlsFilters,
13
+ } from "../../hooks/useQualityControls";
14
+ import QualityControlsTable from "./QualityControlsTable";
15
+ import QualityControlsPagination from "./QualityControlsPagination";
16
+
17
+ function QualityControlSelectorContent({
18
+ selectedQualityControl: qualityControl,
19
+ onSelect,
20
+ disabled,
21
+ }) {
22
+ const [selectedQualityControl, setSelectedQualityControl] = useState(null);
23
+ const { searchData } = useSearchContext();
24
+
25
+ const qualityControls = searchData?.data;
26
+
27
+ useEffect(() => {
28
+ setSelectedQualityControl(qualityControl);
29
+ }, [qualityControl]);
30
+
31
+ const handleSelect = (qualityControl) => {
32
+ if (disabled) return;
33
+ const selectedQualityControl = _.find(
34
+ (qc) => qc.quality_control_id === qualityControl.quality_control_id
35
+ )(qualityControls);
36
+ setSelectedQualityControl(qualityControl);
37
+ onSelect && onSelect(selectedQualityControl || qualityControl);
38
+ };
39
+
40
+ return (
41
+ <Segment>
42
+ <SearchWidget />
43
+ <QualityControlsTable
44
+ onSelect={handleSelect}
45
+ selectedQualityControl={selectedQualityControl}
46
+ selectable={true}
47
+ placeToTop={true}
48
+ />
49
+ <QualityControlsPagination />
50
+ </Segment>
51
+ );
52
+ }
53
+
54
+ QualityControlSelectorContent.propTypes = {
55
+ onSelect: PropTypes.func,
56
+ selectedQualityControl: PropTypes.object,
57
+ disabled: PropTypes.bool,
58
+ };
59
+
60
+ export const QualityControlSelector = (props) => {
61
+ const defaultFilters = _.propOr({}, "defaultFilters")(props);
62
+ const pageSize = _.propOr(10, "pageSize")(props);
63
+
64
+ const searchProps = {
65
+ initialSortColumn: "name.raw",
66
+ initialSortDirection: "ascending",
67
+ useSearch: useQualityControlsSearch,
68
+ useFilters: useQualityControlsFilters,
69
+ pageSize,
70
+ defaultFilters,
71
+ };
72
+
73
+ return (
74
+ <SearchContextProvider {...searchProps}>
75
+ <QualityControlSelectorContent {...props} />
76
+ </SearchContextProvider>
77
+ );
78
+ };
79
+
80
+ QualityControlSelector.propTypes = {
81
+ pageSize: PropTypes.number,
82
+ defaultFilters: PropTypes.object,
83
+ selectedQualityControl: PropTypes.object,
84
+ onSelect: PropTypes.func,
85
+ disabled: PropTypes.bool,
86
+ };
87
+
88
+ export default QualityControlSelector;
@@ -84,6 +84,10 @@ export default function QualityControlsTable({
84
84
  checkRow,
85
85
  executeQualityControlOn,
86
86
  isRowChecked,
87
+ onSelect,
88
+ selectedQualityControl,
89
+ selectable = false,
90
+ placeToTop = false,
87
91
  }) {
88
92
  const {
89
93
  searchData,
@@ -94,12 +98,23 @@ export default function QualityControlsTable({
94
98
  } = useSearchContext();
95
99
  const { formatMessage } = useIntl();
96
100
 
97
- const qualityControls = searchData?.data;
101
+ const qualityControls = searchData?.data || [];
102
+
103
+ // Place selectedQualityControl at top if it's not already in the current page
104
+ const tableData =
105
+ _.has("quality_control_id")(selectedQualityControl) && placeToTop
106
+ ? _.any(
107
+ (qc) =>
108
+ qc.quality_control_id === selectedQualityControl.quality_control_id
109
+ )(qualityControls)
110
+ ? qualityControls
111
+ : [selectedQualityControl, ...qualityControls]
112
+ : qualityControls;
98
113
 
99
114
  return (
100
115
  <>
101
- {!_.isEmpty(qualityControls) && (
102
- <Table sortable>
116
+ {!_.isEmpty(tableData) && (
117
+ <Table sortable selectable={selectable}>
103
118
  <Table.Header>
104
119
  <Table.Row>
105
120
  {executeQualityControlOn ? (
@@ -137,7 +152,7 @@ export default function QualityControlsTable({
137
152
  </Table.Row>
138
153
  </Table.Header>
139
154
  <Table.Body>
140
- {qualityControls.map((qc, i) => (
155
+ {tableData.map((qc, i) => (
141
156
  <QualityControlRow
142
157
  key={i}
143
158
  checked={isRowChecked && isRowChecked(qc)}
@@ -145,12 +160,18 @@ export default function QualityControlsTable({
145
160
  columns={columns}
146
161
  onChange={() => checkRow && checkRow(qc)}
147
162
  withCheck={executeQualityControlOn}
163
+ onClick={onSelect}
164
+ active={
165
+ selectedQualityControl &&
166
+ selectedQualityControl.quality_control_id ===
167
+ qc.quality_control_id
168
+ }
148
169
  />
149
170
  ))}
150
171
  </Table.Body>
151
172
  </Table>
152
173
  )}
153
- {_.isEmpty(qualityControls) && !loading && (
174
+ {_.isEmpty(tableData) && !loading && (
154
175
  <Header as="h4">
155
176
  <Icon name="search" />
156
177
  <Header.Content>
@@ -168,4 +189,8 @@ QualityControlsTable.propTypes = {
168
189
  checkRow: PropTypes.func,
169
190
  executeQualityControlOn: PropTypes.bool,
170
191
  isRowChecked: PropTypes.func,
192
+ onSelect: PropTypes.func,
193
+ selectedQualityControl: PropTypes.object,
194
+ selectable: PropTypes.bool,
195
+ placeToTop: PropTypes.bool,
171
196
  };
@@ -0,0 +1,265 @@
1
+ import userEvent from "@testing-library/user-event";
2
+ import { render, waitForLoad } from "@truedat/test/render";
3
+ import { QualityControlSelector } from "../QualityControlSelector";
4
+ import { qualityControlData } from "./__fixtures__/qualityControlHelper";
5
+
6
+ const qualityControls = [
7
+ qualityControlData({ id: 8, name: "Test QC 1", quality_control_id: 8 }),
8
+ qualityControlData({ id: 9, name: "Test QC 2", quality_control_id: 9 }),
9
+ qualityControlData({ id: 10, name: "Test QC 3", quality_control_id: 10 }),
10
+ ];
11
+
12
+ const data = {
13
+ _actions: {},
14
+ data: qualityControls,
15
+ headers: { "x-total-count": 3 },
16
+ };
17
+
18
+ const filterData = {
19
+ data: {
20
+ status: {
21
+ values: ["draft", "published"],
22
+ },
23
+ },
24
+ };
25
+
26
+ jest.mock("@truedat/core/search/SearchContext", () => {
27
+ const originalModule = jest.requireActual(
28
+ "@truedat/core/search/SearchContext"
29
+ );
30
+
31
+ return {
32
+ __esModule: true,
33
+ ...originalModule,
34
+ useSearchContext: jest.fn(),
35
+ };
36
+ });
37
+
38
+ jest.mock("../../../hooks/useQualityControls", () => {
39
+ const originalModule = jest.requireActual("../../../hooks/useQualityControls");
40
+
41
+ return {
42
+ __esModule: true,
43
+ ...originalModule,
44
+ useQualityControlsFilters: jest.fn(),
45
+ useQualityControlsSearch: jest.fn(),
46
+ };
47
+ });
48
+
49
+ jest.mock("@truedat/core/search/SearchWidget", () => {
50
+ return function SearchWidget() {
51
+ return <div data-testid="search-widget">SearchWidget</div>;
52
+ };
53
+ });
54
+
55
+ jest.mock("../QualityControlsTable", () => {
56
+ return function QualityControlsTable({
57
+ onSelect,
58
+ selectedQualityControl,
59
+ selectable,
60
+ placeToTop,
61
+ }) {
62
+ return (
63
+ <div data-testid="quality-controls-table">
64
+ <div data-testid="selectable">{selectable ? "true" : "false"}</div>
65
+ <div data-testid="place-to-top">{placeToTop ? "true" : "false"}</div>
66
+ {selectedQualityControl && (
67
+ <div data-testid="selected-quality-control">
68
+ {selectedQualityControl.quality_control_id}
69
+ </div>
70
+ )}
71
+ <button
72
+ data-testid="select-qc-8"
73
+ onClick={() =>
74
+ onSelect &&
75
+ onSelect({
76
+ quality_control_id: 8,
77
+ name: "Test QC 1",
78
+ })
79
+ }
80
+ >
81
+ Select QC 8
82
+ </button>
83
+ <button
84
+ data-testid="select-qc-9"
85
+ onClick={() =>
86
+ onSelect &&
87
+ onSelect({
88
+ quality_control_id: 9,
89
+ name: "Test QC 2",
90
+ })
91
+ }
92
+ >
93
+ Select QC 9
94
+ </button>
95
+ </div>
96
+ );
97
+ };
98
+ });
99
+
100
+ jest.mock("../QualityControlsPagination", () => {
101
+ return function QualityControlsPagination() {
102
+ return <div data-testid="quality-controls-pagination">Pagination</div>;
103
+ };
104
+ });
105
+
106
+ import { useSearchContext } from "@truedat/core/search/SearchContext";
107
+ import {
108
+ useQualityControlsFilters,
109
+ useQualityControlsSearch,
110
+ } from "../../../hooks/useQualityControls";
111
+
112
+ describe("<QualityControlSelector />", () => {
113
+ const mockUseSearchContext = useSearchContext;
114
+ const mockUseQualityControlsFilters = useQualityControlsFilters;
115
+ const mockUseQualityControlsSearch = useQualityControlsSearch;
116
+
117
+ beforeEach(() => {
118
+ mockUseQualityControlsFilters.mockReturnValue({
119
+ trigger: jest.fn(() => ({
120
+ then: (callback) =>
121
+ callback({
122
+ data: filterData,
123
+ }),
124
+ })),
125
+ });
126
+
127
+ mockUseQualityControlsSearch.mockReturnValue({
128
+ trigger: jest.fn(() => ({
129
+ then: (callback) =>
130
+ callback({
131
+ data,
132
+ headers: {},
133
+ }),
134
+ })),
135
+ });
136
+
137
+ mockUseSearchContext.mockReturnValue({
138
+ searchData: {
139
+ data: qualityControls,
140
+ scroll_id: null,
141
+ },
142
+ loading: false,
143
+ searchMust: {},
144
+ setOnSearchChange: jest.fn(),
145
+ handleSortSelection: jest.fn(),
146
+ sortColumn: "name.raw",
147
+ sortDirection: "ascending",
148
+ count: 3,
149
+ size: 10,
150
+ page: 1,
151
+ selectPage: jest.fn(),
152
+ });
153
+ });
154
+
155
+ afterEach(() => {
156
+ jest.clearAllMocks();
157
+ });
158
+
159
+ it("matches the latest snapshot", async () => {
160
+ const rendered = render(<QualityControlSelector />);
161
+ await waitForLoad(rendered);
162
+ expect(rendered.container).toMatchSnapshot();
163
+ });
164
+
165
+ it("renders SearchWidget, QualityControlsTable, and QualityControlsPagination", async () => {
166
+ const rendered = render(<QualityControlSelector />);
167
+ await waitForLoad(rendered);
168
+
169
+ expect(rendered.getByTestId("search-widget")).toBeInTheDocument();
170
+ expect(rendered.getByTestId("quality-controls-table")).toBeInTheDocument();
171
+ expect(
172
+ rendered.getByTestId("quality-controls-pagination")
173
+ ).toBeInTheDocument();
174
+ });
175
+
176
+ it("passes selectable and placeToTop props to QualityControlsTable", async () => {
177
+ const rendered = render(<QualityControlSelector />);
178
+ await waitForLoad(rendered);
179
+
180
+ expect(rendered.getByTestId("selectable")).toHaveTextContent("true");
181
+ expect(rendered.getByTestId("place-to-top")).toHaveTextContent("true");
182
+ });
183
+
184
+ it("calls onSelect when a quality control is selected", async () => {
185
+ const onSelect = jest.fn();
186
+ const rendered = render(<QualityControlSelector onSelect={onSelect} />);
187
+ await waitForLoad(rendered);
188
+
189
+ const user = userEvent.setup({ delay: null });
190
+
191
+ await user.click(rendered.getByTestId("select-qc-8"));
192
+
193
+ expect(onSelect).toHaveBeenCalledTimes(1);
194
+ expect(onSelect).toHaveBeenCalledWith(
195
+ expect.objectContaining({
196
+ quality_control_id: 8,
197
+ name: "Test QC 1",
198
+ })
199
+ );
200
+ });
201
+
202
+ it("does not call onSelect when disabled", async () => {
203
+ const onSelect = jest.fn();
204
+ const rendered = render(
205
+ <QualityControlSelector onSelect={onSelect} disabled={true} />
206
+ );
207
+ await waitForLoad(rendered);
208
+
209
+ const user = userEvent.setup({ delay: null });
210
+
211
+ await user.click(rendered.getByTestId("select-qc-8"));
212
+
213
+ expect(onSelect).not.toHaveBeenCalled();
214
+ });
215
+
216
+ it("displays selected quality control when provided", async () => {
217
+ const selectedQualityControl = {
218
+ quality_control_id: 8,
219
+ name: "Test QC 1",
220
+ };
221
+
222
+ const rendered = render(
223
+ <QualityControlSelector selectedQualityControl={selectedQualityControl} />
224
+ );
225
+ await waitForLoad(rendered);
226
+
227
+ expect(rendered.getByTestId("selected-quality-control")).toHaveTextContent(
228
+ "8"
229
+ );
230
+ });
231
+
232
+ it("updates selected quality control when prop changes", async () => {
233
+ const selectedQualityControl = {
234
+ quality_control_id: 9,
235
+ name: "Test QC 2",
236
+ };
237
+
238
+ const rendered = render(
239
+ <QualityControlSelector selectedQualityControl={selectedQualityControl} />
240
+ );
241
+ await waitForLoad(rendered);
242
+
243
+ expect(rendered.getByTestId("selected-quality-control")).toHaveTextContent(
244
+ "9"
245
+ );
246
+ });
247
+
248
+ it("uses custom pageSize when provided", async () => {
249
+ const rendered = render(<QualityControlSelector pageSize={7} />);
250
+ await waitForLoad(rendered);
251
+
252
+ expect(mockUseQualityControlsSearch).toHaveBeenCalled();
253
+ });
254
+
255
+ it("uses defaultFilters when provided", async () => {
256
+ const defaultFilters = { status: ["published"] };
257
+ const rendered = render(
258
+ <QualityControlSelector defaultFilters={defaultFilters} />
259
+ );
260
+ await waitForLoad(rendered);
261
+
262
+ expect(mockUseQualityControlsSearch).toHaveBeenCalled();
263
+ });
264
+ });
265
+
@@ -0,0 +1,44 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<QualityControlSelector /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui segment"
7
+ >
8
+ <div
9
+ data-testid="search-widget"
10
+ >
11
+ SearchWidget
12
+ </div>
13
+ <div
14
+ data-testid="quality-controls-table"
15
+ >
16
+ <div
17
+ data-testid="selectable"
18
+ >
19
+ true
20
+ </div>
21
+ <div
22
+ data-testid="place-to-top"
23
+ >
24
+ true
25
+ </div>
26
+ <button
27
+ data-testid="select-qc-8"
28
+ >
29
+ Select QC 8
30
+ </button>
31
+ <button
32
+ data-testid="select-qc-9"
33
+ >
34
+ Select QC 9
35
+ </button>
36
+ </div>
37
+ <div
38
+ data-testid="quality-controls-pagination"
39
+ >
40
+ Pagination
41
+ </div>
42
+ </div>
43
+ </div>
44
+ `;