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,331 +0,0 @@
1
- import React from "react";
2
- import { Provider } from "react-redux";
3
- import { IntlProvider } from "react-intl";
4
- import sinon from "sinon";
5
- import Checkbox from "../Checkbox";
6
- import HeadCell, { SortMark, UpMark, DownMark, MarkBox, HeadBox, TableHeader } from "./HeadCell";
7
-
8
- describe("HeadCell", () => {
9
- it("renders a header cell with the column label", () => {
10
- const columnDef = {
11
- fieldName: "a",
12
- label: "Test column",
13
- width: 42,
14
- };
15
- return expect(
16
- <Provider
17
- store={{
18
- subscribe: () => {},
19
- dispatch: () => {},
20
- getState: () => ({}),
21
- }}
22
- >
23
- <table>
24
- <thead>
25
- <tr>
26
- <HeadCell columnDef={columnDef} />
27
- </tr>
28
- </thead>
29
- </table>
30
- </Provider>,
31
- "when mounted",
32
- "to satisfy",
33
- <Provider
34
- store={{
35
- subscribe: () => {},
36
- dispatch: () => {},
37
- getState: () => ({}),
38
- }}
39
- >
40
- <table>
41
- <thead>
42
- <tr>
43
- <TableHeader width={42}>
44
- <HeadBox>Test column</HeadBox>
45
- </TableHeader>
46
- </tr>
47
- </thead>
48
- </table>
49
- </Provider>,
50
- );
51
- });
52
-
53
- it("renders a header cell with no label", () => {
54
- const columnDef = {
55
- fieldName: "a",
56
- };
57
- return expect(
58
- <table>
59
- <thead>
60
- <tr>
61
- <HeadCell columnDef={columnDef} />
62
- </tr>
63
- </thead>
64
- </table>,
65
- "when mounted",
66
- "to satisfy",
67
- <table>
68
- <thead>
69
- <tr>
70
- <TableHeader>
71
- <HeadBox />
72
- </TableHeader>
73
- </tr>
74
- </thead>
75
- </table>,
76
- );
77
- });
78
-
79
- it("renders a header cell for a select column", () => {
80
- const columnDef = {
81
- type: "select",
82
- onChange: sinon.spy().named("onChange"),
83
- };
84
- const rowIds = ["a", "b", "c"];
85
- return expect(
86
- <table>
87
- <thead>
88
- <tr>
89
- <HeadCell columnDef={columnDef} rowIds={rowIds} />
90
- </tr>
91
- </thead>
92
- </table>,
93
- "when mounted",
94
- "with event",
95
- { type: "change", target: "input" },
96
- "to satisfy",
97
- <table>
98
- <thead>
99
- <tr>
100
- <TableHeader select>
101
- <HeadBox>
102
- <Checkbox id="select_headRow" value={false} />
103
- </HeadBox>
104
- </TableHeader>
105
- </tr>
106
- </thead>
107
- </table>,
108
- ).then(() => expect(columnDef.onChange, "to have calls satisfying", [{ args: [rowIds] }]));
109
- });
110
-
111
- it("renders a header cell for a select column with all rows selected", () => {
112
- const columnDef = {
113
- type: "select",
114
- onChange: sinon.spy().named("onChange"),
115
- };
116
- const rowIds = ["a", "b", "c"];
117
- return expect(
118
- <table>
119
- <thead>
120
- <tr>
121
- <HeadCell columnDef={columnDef} rowIds={rowIds} allSelected />
122
- </tr>
123
- </thead>
124
- </table>,
125
- "when mounted",
126
- "with event",
127
- { type: "change", target: "input" },
128
- "to satisfy",
129
- <table>
130
- <thead>
131
- <tr>
132
- <TableHeader select>
133
- <HeadBox>
134
- <Checkbox id="select_headRow" value={true} />
135
- </HeadBox>
136
- </TableHeader>
137
- </tr>
138
- </thead>
139
- </table>,
140
- ).then(() => expect(columnDef.onChange, "to have calls satisfying", [{ args: [[]] }]));
141
- });
142
-
143
- it("renders a sortable header cell", () => {
144
- const columnDef = {
145
- fieldName: "a",
146
- label: { id: "test.label", defaultMessage: "Test column" },
147
- sort: () => {},
148
- };
149
- return expect(
150
- <Provider
151
- store={{
152
- subscribe: () => {},
153
- dispatch: () => {},
154
- getState: () => ({}),
155
- }}
156
- >
157
- <IntlProvider locale="en">
158
- <table>
159
- <thead>
160
- <tr>
161
- <HeadCell columnDef={columnDef} />
162
- </tr>
163
- </thead>
164
- </table>
165
- </IntlProvider>
166
- </Provider>,
167
- "when mounted",
168
- "to satisfy",
169
- <Provider
170
- store={{
171
- subscribe: () => {},
172
- dispatch: () => {},
173
- getState: () => ({}),
174
- }}
175
- >
176
- <table>
177
- <thead>
178
- <tr>
179
- <TableHeader onClick={columnDef.sort}>
180
- <HeadBox>
181
- Test column
182
- <SortMark />
183
- </HeadBox>
184
- </TableHeader>
185
- </tr>
186
- </thead>
187
- </table>
188
- </Provider>,
189
- );
190
- });
191
-
192
- it("renders a sortable header cell sorted ascending", () => {
193
- const columnDef = {
194
- fieldName: "a",
195
- label: { id: "test.label", defaultMessage: "Test column" },
196
- sort: () => {},
197
- sortDirection: "asc",
198
- };
199
- return expect(
200
- <Provider
201
- store={{
202
- subscribe: () => {},
203
- dispatch: () => {},
204
- getState: () => ({}),
205
- }}
206
- >
207
- <IntlProvider locale="en">
208
- <table>
209
- <thead>
210
- <tr>
211
- <HeadCell columnDef={columnDef} />
212
- </tr>
213
- </thead>
214
- </table>
215
- </IntlProvider>
216
- </Provider>,
217
- "when mounted",
218
- "to satisfy",
219
- <Provider
220
- store={{
221
- subscribe: () => {},
222
- dispatch: () => {},
223
- getState: () => ({}),
224
- }}
225
- >
226
- <table>
227
- <thead>
228
- <tr>
229
- <TableHeader>
230
- <HeadBox>
231
- Test column
232
- <SortMark direction="asc" />
233
- </HeadBox>
234
- </TableHeader>
235
- </tr>
236
- </thead>
237
- </table>
238
- </Provider>,
239
- );
240
- });
241
-
242
- it("renders a sortable header cell sorted descending", () => {
243
- const columnDef = {
244
- fieldName: "a",
245
- label: { id: "test.label", defaultMessage: "Test column" },
246
- sort: () => {},
247
- sortDirection: "desc",
248
- };
249
- return expect(
250
- <Provider
251
- store={{
252
- subscribe: () => {},
253
- dispatch: () => {},
254
- getState: () => ({}),
255
- }}
256
- >
257
- <IntlProvider locale="en">
258
- <table>
259
- <thead>
260
- <tr>
261
- <HeadCell columnDef={columnDef} />
262
- </tr>
263
- </thead>
264
- </table>
265
- </IntlProvider>
266
- </Provider>,
267
- "when mounted",
268
- "to satisfy",
269
- <Provider
270
- store={{
271
- subscribe: () => {},
272
- dispatch: () => {},
273
- getState: () => ({}),
274
- }}
275
- >
276
- <table>
277
- <thead>
278
- <tr>
279
- <TableHeader>
280
- <HeadBox>
281
- Test column
282
- <SortMark direction="desc" />
283
- </HeadBox>
284
- </TableHeader>
285
- </tr>
286
- </thead>
287
- </table>
288
- </Provider>,
289
- );
290
- });
291
- });
292
-
293
- describe("TableHeader", () => {
294
- // Switch components as <tr> warns when outside a table.
295
- it("sets a width if selection column", () =>
296
- expect(
297
- <TableHeader as="div" select />,
298
- "when mounted",
299
- "to have style rules satisfying",
300
- "to contain",
301
- "width: 56px;",
302
- ));
303
-
304
- it("sets a width if told to", () =>
305
- expect(
306
- <TableHeader as="div" width={"550px"} />,
307
- "when mounted",
308
- "to have style rules satisfying",
309
- "to contain",
310
- "width: 550px;",
311
- ));
312
- });
313
-
314
- describe("SortMark", () => {
315
- it("renders a downwards arrow when ascending", () =>
316
- expect(<SortMark direction="asc" />, "when mounted", "to satisfy", <UpMark />));
317
-
318
- it("renders an upwards arrow when descending", () =>
319
- expect(<SortMark direction="desc" />, "when mounted", "to satisfy", <DownMark />));
320
-
321
- it("renders bidirectional arrows when no direction set", () =>
322
- expect(
323
- <SortMark />,
324
- "when mounted",
325
- "to satisfy",
326
- <MarkBox>
327
- <UpMark />
328
- <DownMark />
329
- </MarkBox>,
330
- ));
331
- });
@@ -1,21 +0,0 @@
1
- import React from "react";
2
- import styled from "styled-components";
3
- import { TableRow, stringifyFieldName } from "./Row";
4
- import HeadCell from "./HeadCell";
5
-
6
- export const HeadTableRow = styled(TableRow)`
7
- border-width: 0;
8
- `;
9
-
10
- const HeadRow = ({ columnDefs, rowIds, allSelected }) => (
11
- <HeadTableRow>
12
- {columnDefs.map(columnDef => (
13
- <HeadCell
14
- key={columnDef.type === "select" ? "select" : stringifyFieldName(columnDef.fieldName)}
15
- {...{ columnDef, rowIds, allSelected }}
16
- />
17
- ))}
18
- </HeadTableRow>
19
- );
20
-
21
- export default HeadRow;
@@ -1,27 +0,0 @@
1
- import React from "react";
2
- import HeadRow, { HeadTableRow } from "./HeadRow";
3
- import HeadCell from "./HeadCell";
4
-
5
- describe("HeadRow", () => {
6
- it("renders a row of headers, one for each defined column", () => {
7
- const columnDefs = [{ fieldName: "a" }, { fieldName: "b" }, { fieldName: "c" }];
8
- return expect(
9
- <table>
10
- <thead>
11
- <HeadRow columnDefs={columnDefs} allSelected={false} />
12
- </thead>
13
- </table>,
14
- "when mounted",
15
- "to satisfy",
16
- <table>
17
- <thead>
18
- <HeadTableRow>
19
- <HeadCell key="a" columnDef={columnDefs[0]} allSelected={false} />
20
- <HeadCell key="b" columnDef={columnDefs[1]} allSelected={false} />
21
- <HeadCell key="c" columnDef={columnDefs[2]} allSelected={false} />
22
- </HeadTableRow>
23
- </thead>
24
- </table>,
25
- );
26
- });
27
- });
@@ -1,162 +0,0 @@
1
- import React from "react";
2
- import pt from "prop-types";
3
- import styled from "styled-components";
4
- import { compose, branch, setDisplayName } from "recompose";
5
- import { safeGet } from "../../utils";
6
- import withScrollBox from "../../hocs/withScrollBox";
7
- import withInfiniteScroll from "../../hocs/withInfiniteScroll";
8
- import Row from "./Row";
9
- import HeadRow from "./HeadRow";
10
- import useViewState from "../../hooks/useViewState";
11
- import enhanceColumnDefs from "./enhanceColumnDefs";
12
-
13
- export const PlaceholderCell = styled.div`
14
- height: ${/* istanbul ignore next*/ props => props.cssHeight || 100}px;
15
- display: flex;
16
- justify-content: center;
17
- `;
18
-
19
- export const PlaceholderBox = styled.div`
20
- padding-top: 30px;
21
- width: 100%;
22
- margin: auto;
23
- `;
24
-
25
- export const Placeholder = ({ width, height, children }) => (
26
- <tr>
27
- <td colSpan={width} style={{ padding: 0 }}>
28
- <PlaceholderCell cssHeight={height}>
29
- <PlaceholderBox>{children}</PlaceholderBox>
30
- </PlaceholderCell>
31
- </td>
32
- </tr>
33
- );
34
- Placeholder.displayName = "Placeholder";
35
-
36
- export const Table = styled.table`
37
- border-spacing: 0;
38
- table-layout: fixed;
39
- width: 100%;
40
- font-size: 13px;
41
- `;
42
-
43
- export const HEADER_HEIGHT = 41;
44
- export const ROW_HEIGHT = 51;
45
-
46
- const calculateVirtualization = (virtual, scrollTop, scrollBuffer, height, rows) => {
47
- let virtualFilter, heightAbove, heightBelow;
48
- if (virtual) {
49
- const correctedScrollTop = scrollTop - HEADER_HEIGHT; // Subtract header height
50
- const firstIn = Math.floor(correctedScrollTop / ROW_HEIGHT);
51
- const firstShow = Math.max(firstIn - scrollBuffer, 0);
52
- const lastIn = Math.ceil((correctedScrollTop + height) / ROW_HEIGHT);
53
- const lastShow = Math.min(lastIn + scrollBuffer, rows.length);
54
- virtualFilter = index => index >= firstShow && index < lastShow;
55
- heightAbove = firstShow * ROW_HEIGHT;
56
- heightBelow = (rows.length - lastShow) * ROW_HEIGHT;
57
- } else {
58
- virtualFilter = () => true;
59
- heightAbove = 0;
60
- heightBelow = 0;
61
- }
62
- return { virtualFilter, heightAbove, heightBelow };
63
- };
64
-
65
- export const useListState = (name, columnDefs) => {
66
- const [viewState, updateViewState] = useViewState(name);
67
- const { selection = [], sorting = {} } = viewState;
68
- const enhancedColumnDefs = enhanceColumnDefs(sorting, selection, updateViewState, columnDefs);
69
-
70
- return [enhancedColumnDefs, selection];
71
- };
72
-
73
- export const List = ({
74
- name,
75
- columnDefs = [],
76
- rows = [],
77
- rowOnClick,
78
- placeholder,
79
- keyField = ["id"],
80
- virtual = false,
81
- scrollTop = 0,
82
- height = 300, // Arbitrary, set this prop according to scroll viewport size
83
- scrollBuffer = 10,
84
- rowBackgroundGetter = () => {},
85
- }) => {
86
- const [enhancedColumnDefs, selection] = useListState(name, columnDefs);
87
- if (columnDefs.length === 0) return null;
88
- const rowIds = [],
89
- rowElements = [];
90
- const { virtualFilter, heightAbove, heightBelow } = calculateVirtualization(
91
- virtual,
92
- scrollTop,
93
- scrollBuffer,
94
- height,
95
- rows,
96
- );
97
- rows.forEach((row, index) => {
98
- const id = safeGet(row, ...keyField) + ""; // Ensure rowId is string
99
- rowIds.push(id);
100
- if (!virtualFilter(index)) return;
101
- rowElements.push(
102
- <Row
103
- columnDefs={enhancedColumnDefs}
104
- key={id}
105
- rowId={id}
106
- row={row}
107
- rowOnClick={rowOnClick}
108
- selected={selection.indexOf(id) !== -1}
109
- bgColor={rowBackgroundGetter(row, index)}
110
- />,
111
- );
112
- });
113
- if (virtual && heightAbove) {
114
- rowElements.unshift(<tr key="virtualAbove" style={{ height: heightAbove }} />);
115
- }
116
- if (virtual && heightBelow) {
117
- rowElements.push(<tr key="virtualBelow" style={{ height: heightBelow }} />);
118
- }
119
- if (rowElements.length === 0 && placeholder) {
120
- rowElements.push(
121
- <Placeholder key="placeholder" width={columnDefs.length} height={height - HEADER_HEIGHT}>
122
- {placeholder}
123
- </Placeholder>,
124
- );
125
- }
126
- return (
127
- <Table>
128
- <thead>
129
- <HeadRow
130
- columnDefs={columnDefs}
131
- rowIds={rowIds}
132
- allSelected={rows.length === selection.length && rows.length !== 0}
133
- />
134
- </thead>
135
- <tbody>{rowElements}</tbody>
136
- </Table>
137
- );
138
- };
139
-
140
- /* istanbul ignore next */
141
- const checkInfiniteScroll = branch(({ scrollLoader }) => !!scrollLoader, withInfiniteScroll);
142
-
143
- const StatefulList = compose(setDisplayName("List"), checkInfiniteScroll, withScrollBox)(List);
144
- StatefulList.propTypes = {
145
- columnDefs: pt.arrayOf(pt.object), // Each object must be a valid column definition
146
- rows: pt.arrayOf(pt.object),
147
- rowOnClick: pt.func, // Click handler for row.
148
- // Fires when row is clicked, excluding select or switch columns
149
- // Event target will have a 'rowId' data value which identifies the clicked row.
150
- placeholder: pt.node, // A React element to render as placeholder.
151
- keyField: pt.arrayOf(pt.string), // Path to identifying data field on each row.
152
- // Infinite/virtual scroll
153
- // If scrollLoader is present, below props will control the scrolling
154
- scrollLoader: pt.func, // Loader function. Called with page number to be loaded.
155
- onScroll: pt.func, // Optional scroll event handler
156
- loadTrigger: pt.number, // How many pixels from the bottom should the load be triggered. Default: 200
157
- length: pt.number, // How many elements are loaded, should equal rows.length
158
- latestPage: pt.number, // The latest page number loaded
159
- pageLength: pt.number, // The length of a page, in row items. Default: 20.
160
- };
161
-
162
- export default StatefulList;