orc-shared 5.10.1-dev.6 → 5.10.1-dev.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.
Files changed (42) hide show
  1. package/dist/components/AppFrame/MenuItem.js +3 -12
  2. package/dist/components/MaterialUI/DataDisplay/Table.js +2 -1
  3. package/dist/components/MaterialUI/DataDisplay/TableProps.js +3 -1
  4. package/dist/components/MaterialUI/Surfaces/SectionExpansionPanel.js +3 -2
  5. package/dist/components/ToastList.js +95 -64
  6. package/dist/getTheme.js +0 -5
  7. package/dist/utils/toastHelper.js +52 -0
  8. package/package.json +1 -1
  9. package/src/components/AppFrame/MenuItem.js +1 -9
  10. package/src/components/MaterialUI/DataDisplay/Table.js +6 -1
  11. package/src/components/MaterialUI/DataDisplay/Table.test.js +20 -0
  12. package/src/components/MaterialUI/DataDisplay/TableProps.js +2 -0
  13. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +20 -2
  14. package/src/components/MaterialUI/Surfaces/SectionExpansionPanel.js +2 -1
  15. package/src/components/ToastList.js +79 -90
  16. package/src/components/ToastList.test.js +29 -103
  17. package/src/getTheme.js +0 -5
  18. package/src/utils/toastHelper.js +8 -0
  19. package/src/utils/toastHelper.test.js +41 -0
  20. package/dist/components/CategoryList.js +0 -197
  21. package/dist/components/List/DataCell.js +0 -129
  22. package/dist/components/List/HeadCell.js +0 -125
  23. package/dist/components/List/HeadRow.js +0 -73
  24. package/dist/components/List/List.js +0 -274
  25. package/dist/components/List/Row.js +0 -109
  26. package/dist/components/List/enhanceColumnDefs.js +0 -111
  27. package/dist/components/List/index.js +0 -59
  28. package/src/components/CategoryList.js +0 -140
  29. package/src/components/CategoryList.test.js +0 -667
  30. package/src/components/List/DataCell.js +0 -77
  31. package/src/components/List/DataCell.test.js +0 -357
  32. package/src/components/List/HeadCell.js +0 -105
  33. package/src/components/List/HeadCell.test.js +0 -331
  34. package/src/components/List/HeadRow.js +0 -21
  35. package/src/components/List/HeadRow.test.js +0 -27
  36. package/src/components/List/List.js +0 -162
  37. package/src/components/List/List.test.js +0 -705
  38. package/src/components/List/Row.js +0 -72
  39. package/src/components/List/Row.test.js +0 -194
  40. package/src/components/List/enhanceColumnDefs.js +0 -54
  41. package/src/components/List/enhanceColumnDefs.test.js +0 -179
  42. package/src/components/List/index.js +0 -6
@@ -1,72 +0,0 @@
1
- import React, { useCallback } from "react";
2
- import styled, { css } from "styled-components";
3
- import { ifFlag } from "../../utils";
4
- import DataCell from "./DataCell";
5
-
6
- export const stringifyFieldName = name => {
7
- if (Array.isArray(name)) {
8
- return name.join("_");
9
- } else {
10
- return name && name.toString();
11
- }
12
- };
13
-
14
- export const TableRow = styled.tr`
15
- ${ifFlag(
16
- "bgColor",
17
- props =>
18
- css`
19
- background-color: ${props.bgColor};
20
- `,
21
- css`
22
- transition: background-color 0.2s ease-in;
23
- &:hover {
24
- background-color: #f3f3f3;
25
- }
26
- `,
27
- )}
28
-
29
- ${ifFlag(
30
- "onClick",
31
- css`
32
- & td {
33
- cursor: pointer;
34
- }
35
- `,
36
- )}
37
- `;
38
-
39
- // Clicks on these elements will not be handled by the row onClick
40
- const formTags = ["INPUT", "SELECT", "LABEL"];
41
-
42
- export const Row = ({ columnDefs, row, rowId, selected, rowOnClick, bgColor }) => {
43
- const onClick = useCallback(
44
- event => {
45
- if (formTags.indexOf(event.target.tagName) === -1) {
46
- /* istanbul ignore else */
47
- if (!event.target.dataset["rowId"]) {
48
- event.target.dataset["rowId"] = rowId;
49
- }
50
- rowOnClick(event);
51
- }
52
- },
53
- [rowOnClick, rowId],
54
- );
55
- return (
56
- <TableRow onClick={rowOnClick ? onClick : undefined} bgColor={bgColor}>
57
- {columnDefs.map(columnDef => (
58
- <DataCell
59
- key={stringifyFieldName(columnDef.fieldName)}
60
- {...{
61
- rowId,
62
- row,
63
- columnDef,
64
- selected,
65
- }}
66
- />
67
- ))}
68
- </TableRow>
69
- );
70
- };
71
-
72
- export default Row;
@@ -1,194 +0,0 @@
1
- import React from "react";
2
- import { Provider } from "react-redux";
3
- import sinon from "sinon";
4
- import { Row, TableRow, stringifyFieldName } from "./Row";
5
- import DataCell from "./DataCell";
6
-
7
- const TestComp = () => (
8
- <div>
9
- <input />
10
- <select />
11
- <label />
12
- </div>
13
- );
14
-
15
- describe("Row", () => {
16
- let rowOnClick, columnDefs, row;
17
- beforeEach(() => {
18
- rowOnClick = sinon.spy().named("rowOnClick");
19
- columnDefs = [{ fieldName: "a" }, { fieldName: "b" }, { fieldName: "test", type: "custom", component: TestComp }];
20
- row = { a: "foo", b: "bar" };
21
- });
22
-
23
- it("it renders a data cell for each column definition", () =>
24
- expect(
25
- <Provider
26
- store={{
27
- subscribe: () => {},
28
- dispatch: () => {},
29
- getState: () => ({}),
30
- }}
31
- >
32
- <table>
33
- <tbody>
34
- <Row row={row} rowId="rowIdentifier" columnDefs={columnDefs} rowOnClick={rowOnClick} bgColor="#ff0000" />
35
- </tbody>
36
- </table>
37
- </Provider>,
38
- "when mounted",
39
- "with event",
40
- { type: "click", target: "tr" },
41
- "to satisfy",
42
- <Provider
43
- store={{
44
- subscribe: () => {},
45
- dispatch: () => {},
46
- getState: () => ({}),
47
- }}
48
- >
49
- <table>
50
- <tbody>
51
- <TableRow bgColor="#ff0000" onClick={() => {}}>
52
- <DataCell key="a" rowId="rowIdentifier" row={row} columnDef={columnDefs[0]} />
53
- <DataCell key="b" rowId="rowIdentifier" row={row} columnDef={columnDefs[1]} />
54
- <DataCell key="test" rowId="rowIdentifier" row={row} columnDef={columnDefs[2]} />
55
- </TableRow>
56
- </tbody>
57
- </table>
58
- </Provider>,
59
- ).then(() => expect(rowOnClick, "was called")));
60
-
61
- it("wraps row onClick handler to add rowId to event target, and not to fire if target is form element", () =>
62
- expect(
63
- <Provider
64
- store={{
65
- subscribe: () => {},
66
- dispatch: () => {},
67
- getState: () => ({}),
68
- }}
69
- >
70
- <table>
71
- <tbody>
72
- <Row row={row} rowId="rowIdentifier" columnDefs={columnDefs} rowOnClick={rowOnClick} />
73
- </tbody>
74
- </table>
75
- </Provider>,
76
- "when mounted",
77
- "with event",
78
- "click",
79
- "with event",
80
- {
81
- type: "click",
82
- target: "input",
83
- // don't fire
84
- },
85
- "with event",
86
- {
87
- type: "click",
88
- target: "select",
89
- // don't fire
90
- },
91
- "with event",
92
- {
93
- type: "click",
94
- target: "label",
95
- // don't fire
96
- },
97
- "with event",
98
- {
99
- type: "click",
100
- target: "tr",
101
- },
102
- "to contain",
103
- <TestComp />,
104
- ).then(() =>
105
- expect(rowOnClick, "to have calls satisfying", [
106
- {
107
- args: [
108
- {
109
- target: expect.it("to have attributes", {
110
- "data-row-id": "rowIdentifier",
111
- }),
112
- },
113
- ],
114
- },
115
- ]),
116
- ));
117
- });
118
-
119
- describe("TableRow", () => {
120
- it("renders with a hover transition", () =>
121
- expect(
122
- <table>
123
- <tbody>
124
- <TableRow />
125
- </tbody>
126
- </table>,
127
- "when mounted",
128
- "queried for first",
129
- "tr",
130
- "to have style rules satisfying",
131
- expect
132
- .it("to contain", "transition: background-color 0.2s ease-in;")
133
- .and("to contain", ":hover {background-color: #f3f3f3;}"),
134
- ));
135
-
136
- it("renders a specific background color when given", () =>
137
- expect(
138
- <table>
139
- <tbody>
140
- <TableRow bgColor="#ff0000" />
141
- </tbody>
142
- </table>,
143
- "when mounted",
144
- "queried for first",
145
- "tr",
146
- "to have style rules satisfying",
147
- "to contain",
148
- "background-color: #ff0000;",
149
- ));
150
-
151
- it("renders no transition if given a bgColor prop", () =>
152
- expect(
153
- <table>
154
- <tbody>
155
- <TableRow bgColor="#ff0000" />
156
- </tbody>
157
- </table>,
158
- "when mounted",
159
- "queried for first",
160
- "tr",
161
- "to have style rules satisfying",
162
- expect
163
- .it("not to match", /transition: background-color/)
164
- .and("not to match", /:hover \{[^}]*background-color:[^}]*\}/),
165
- ));
166
-
167
- it("sets cursor type if given click handler", () =>
168
- expect(
169
- <table>
170
- <tbody>
171
- <TableRow onClick={() => {}} />
172
- </tbody>
173
- </table>,
174
- "when mounted",
175
- "queried for first",
176
- "tr",
177
- "to have style rules satisfying",
178
- expect.it("to contain", "td {cursor: pointer;}"),
179
- ));
180
- });
181
-
182
- describe("stringifyFieldName", () => {
183
- it("does nothing to a string", () =>
184
- expect(stringifyFieldName, "when called with", ["FieldName"], "to equal", "FieldName"));
185
-
186
- it("converts an array to a string", () =>
187
- expect(stringifyFieldName, "when called with", [["fieldA", "foo"]], "to equal", "fieldA_foo"));
188
-
189
- it("handles arrays with non-string types", () =>
190
- expect(stringifyFieldName, "when called with", [["fieldA", 0, "foo"]], "to equal", "fieldA_0_foo"));
191
-
192
- it("returns undefined if given undefined", () =>
193
- expect(stringifyFieldName, "when called with", [undefined], "to equal", undefined));
194
- });
@@ -1,54 +0,0 @@
1
- const toggleInArray = (nameList, name) => {
2
- if (nameList.indexOf(name) !== -1) {
3
- return nameList.filter(n => n !== name);
4
- } else {
5
- return nameList.concat(name);
6
- }
7
- };
8
-
9
- const enhanceSelectColumn = (selection, updateViewState, def) => {
10
- return {
11
- fieldName: "selection",
12
- ...def,
13
- onChange: eventOrSelection => {
14
- if (Array.isArray(eventOrSelection)) {
15
- updateViewState("selection", eventOrSelection);
16
- } else {
17
- updateViewState("selection", toggleInArray(selection, eventOrSelection.target.dataset.rowId));
18
- eventOrSelection.stopPropagation();
19
- }
20
- },
21
- };
22
- };
23
-
24
- const enhanceSortableColumn = (sorting, updateViewState, def) => {
25
- const isSortColumn = sorting.column && def.fieldName && sorting.column.toString() === def.fieldName.toString();
26
- const isAscending = isSortColumn && sorting.direction === "asc";
27
- const newDef = {
28
- ...def,
29
- sort: () => {
30
- updateViewState("sorting", {
31
- column: def.fieldName,
32
- direction: isAscending ? "desc" : "asc",
33
- });
34
- def.sort(isAscending, def.fieldName, def.type);
35
- },
36
- };
37
- if (isSortColumn) {
38
- newDef.sortDirection = sorting.direction;
39
- }
40
- return newDef;
41
- };
42
-
43
- const enhanceColumnDef = (sorting, selection, updateViewState, columnDefs) =>
44
- columnDefs.map(def => {
45
- if (def.type === "select") {
46
- return enhanceSelectColumn(selection, updateViewState, def);
47
- }
48
- if (def.sort) {
49
- return enhanceSortableColumn(sorting, updateViewState, def);
50
- }
51
- return def;
52
- });
53
-
54
- export default enhanceColumnDef;
@@ -1,179 +0,0 @@
1
- import sinon from "sinon";
2
- import enhanceColumnDefs from "./enhanceColumnDefs";
3
-
4
- describe("enhanceColumnDefs", () => {
5
- let sorting, selection, updateViewState, columnDefs, mockEvent, stopPropagations;
6
- beforeEach(() => {
7
- sorting = {};
8
- selection = [];
9
- updateViewState = sinon.spy().named("updateViewState");
10
- columnDefs = [{ fieldName: "a" }];
11
- stopPropagations = {};
12
- mockEvent = id => {
13
- stopPropagations[id] = sinon.spy().named("stopPropagation:" + id);
14
- return {
15
- target: { dataset: { rowId: id } },
16
- stopPropagation: stopPropagations[id],
17
- };
18
- };
19
- });
20
-
21
- it("does not change column definitions without cause", () =>
22
- expect(enhanceColumnDefs, "called with", [sorting, selection, updateViewState, columnDefs], "to satisfy", [
23
- {
24
- fieldName: "a",
25
- },
26
- ]));
27
-
28
- describe("column selection", () => {
29
- beforeEach(() => {
30
- columnDefs = [{ type: "select" }, { fieldName: "a" }];
31
- selection = ["selectedRow"];
32
- });
33
-
34
- it("adds field name and onChange to select columns", () =>
35
- expect(
36
- enhanceColumnDefs,
37
- "called with",
38
- [sorting, selection, updateViewState, columnDefs],
39
- "to exhaustively satisfy",
40
- [
41
- {
42
- type: "select",
43
- fieldName: "selection",
44
- onChange: expect
45
- .it("to be a function")
46
- // Add name to selection
47
- .and("called with", [mockEvent("myRow")])
48
- // remove name from selection
49
- .and("called with", [mockEvent("selectedRow")])
50
- // Replace selection
51
- .and("called with", [["list", "of", "row", "ids"]]),
52
- },
53
- { fieldName: "a" },
54
- ],
55
- ).then(() => {
56
- expect(stopPropagations["myRow"], "was called");
57
- expect(stopPropagations["selectedRow"], "was called");
58
- expect(updateViewState, "to have calls satisfying", [
59
- {
60
- args: [
61
- // Add name to selection
62
- "selection",
63
- ["selectedRow", "myRow"],
64
- ],
65
- },
66
- {
67
- args: [
68
- // remove name from selection
69
- "selection",
70
- [],
71
- ],
72
- },
73
- {
74
- args: [
75
- // Replace selection
76
- "selection",
77
- ["list", "of", "row", "ids"],
78
- ],
79
- },
80
- ]);
81
- }));
82
-
83
- it("handles missing selection", () =>
84
- expect(enhanceColumnDefs, "called with", [sorting, [], updateViewState, columnDefs], "to exhaustively satisfy", [
85
- {
86
- type: "select",
87
- fieldName: "selection",
88
- onChange: expect.it("to be a function"),
89
- },
90
- { fieldName: "a" },
91
- ]));
92
- });
93
-
94
- describe("column sorting", () => {
95
- let sorterSpies;
96
- beforeEach(() => {
97
- sorting = { column: "b", direction: "asc" };
98
- sorterSpies = [sinon.spy().named("sorter-a"), sinon.spy().named("sorter-b"), sinon.spy().named("sorter-c")];
99
- columnDefs = [
100
- {
101
- fieldName: "a",
102
- sort: sorterSpies[0],
103
- type: "currency",
104
- onChange: () => {},
105
- },
106
- { fieldName: "b", sort: sorterSpies[1], type: "date" },
107
- { fieldName: "c", sort: sorterSpies[2], type: "switch" },
108
- ];
109
- });
110
-
111
- it("wraps sort functions to set view state", () =>
112
- expect(
113
- enhanceColumnDefs,
114
- "called with",
115
- [sorting, selection, updateViewState, columnDefs],
116
- "to exhaustively satisfy",
117
- [
118
- {
119
- fieldName: "a",
120
- sort: expect.it("to be a function").and("called"),
121
- type: "currency",
122
- onChange: expect.it("to be a function"),
123
- },
124
- {
125
- fieldName: "b",
126
- sort: expect.it("to be a function"),
127
- type: "date",
128
- sortDirection: "asc",
129
- },
130
- {
131
- fieldName: "c",
132
- sort: expect.it("to be a function"),
133
- type: "switch",
134
- },
135
- ],
136
- ).then(() => {
137
- expect(sorterSpies, "to have calls satisfying", [{ spy: sorterSpies[0], args: [false, "a", "currency"] }]);
138
- expect(updateViewState, "to have calls satisfying", [
139
- {
140
- args: ["sorting", { column: "a", direction: "asc" }],
141
- },
142
- ]);
143
- }));
144
-
145
- it("wraps sort functions to handle flipping sort direction", () =>
146
- expect(
147
- enhanceColumnDefs,
148
- "called with",
149
- [sorting, selection, updateViewState, columnDefs],
150
- "to exhaustively satisfy",
151
- [
152
- {
153
- fieldName: "a",
154
- sort: expect.it("to be a function"),
155
- type: "currency",
156
- onChange: expect.it("to be a function"),
157
- },
158
- {
159
- fieldName: "b",
160
- sort: expect.it("to be a function").and("called"),
161
- type: "date",
162
- sortDirection: "asc",
163
- },
164
- {
165
- fieldName: "c",
166
- sort: expect.it("to be a function"),
167
- type: "switch",
168
- },
169
- ],
170
- ).then(() => {
171
- expect(sorterSpies, "to have calls satisfying", [{ spy: sorterSpies[1], args: [true, "b", "date"] }]);
172
- expect(updateViewState, "to have calls satisfying", [
173
- {
174
- args: ["sorting", { column: "b", direction: "desc" }],
175
- },
176
- ]);
177
- }));
178
- });
179
- });
@@ -1,6 +0,0 @@
1
- import Loader from "../Loader";
2
-
3
- /* istanbul ignore next */
4
- const LoadableList = Loader(() => import("./List"));
5
-
6
- export default LoadableList;