orc-shared 5.10.2 → 5.99.0-dev.10

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 (234) hide show
  1. package/dist/components/AppFrame/About.js +13 -13
  2. package/dist/components/AppFrame/Anchor.js +7 -7
  3. package/dist/components/AppFrame/AppFrame.js +3 -3
  4. package/dist/components/AppFrame/Help.js +4 -4
  5. package/dist/components/AppFrame/MenuItem.js +17 -26
  6. package/dist/components/AppFrame/Preferences.js +14 -14
  7. package/dist/components/AppFrame/Sidebar.js +6 -6
  8. package/dist/components/AppFrame/Topbar.js +6 -6
  9. package/dist/components/ApplicationModuleLoader.js +3 -2
  10. package/dist/components/Authenticate.js +29 -22
  11. package/dist/components/DropMenu/Menu.js +9 -9
  12. package/dist/components/ErrorPlaceholder.js +8 -24
  13. package/dist/components/Form/Field.js +4 -4
  14. package/dist/components/Form/Inputs/Button.js +2 -2
  15. package/dist/components/Form/Inputs/MultiSelector.js +137 -0
  16. package/dist/components/Form/Inputs/Selector.js +13 -10
  17. package/dist/components/Form/Inputs/index.js +1 -1
  18. package/dist/components/InternetExplorerWarningMessage.js +15 -15
  19. package/dist/components/LoadingIcon.js +38 -17
  20. package/dist/components/MaterialUI/DataDisplay/Modal.js +3 -3
  21. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  22. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +1 -1
  23. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/TableInfoBar.js +1 -1
  24. package/dist/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  25. package/dist/components/MaterialUI/DataDisplay/Table.js +2 -1
  26. package/dist/components/MaterialUI/DataDisplay/TableProps.js +3 -1
  27. package/dist/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  28. package/dist/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  29. package/dist/components/MaterialUI/Inputs/DatePicker.js +1 -1
  30. package/dist/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  31. package/dist/components/MaterialUI/Inputs/Select.js +175 -109
  32. package/dist/components/MaterialUI/Inputs/SelectProps.js +11 -1
  33. package/dist/components/MaterialUI/Inputs/Switch.js +1 -1
  34. package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
  35. package/dist/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -1
  36. package/dist/components/MaterialUI/ScopeSelector/TreeItem.js +27 -42
  37. package/dist/components/MaterialUI/Surfaces/Paper.js +1 -1
  38. package/dist/components/MaterialUI/Surfaces/SectionExpansionPanel.js +3 -2
  39. package/dist/components/MaterialUI/muiThemes.js +3 -1
  40. package/dist/components/Provision.js +30 -13
  41. package/dist/components/Routing/SegmentPage.js +117 -56
  42. package/dist/components/Scope/ScopeNode.js +62 -57
  43. package/dist/components/Sidepanel.js +59 -23
  44. package/dist/components/Spritesheet.js +35 -17
  45. package/dist/components/Text.js +1 -60
  46. package/dist/components/ToastList.js +95 -64
  47. package/dist/components/Treeview/Branch.js +82 -20
  48. package/dist/components/Treeview/Label.js +108 -31
  49. package/dist/components/Treeview/Leaf.js +56 -12
  50. package/dist/components/Treeview/Node.js +22 -9
  51. package/dist/components/Treeview/index.js +7 -1
  52. package/dist/components/Treeview/settings.js +17 -6
  53. package/dist/{components/Modal/index.js → hooks/useWindowSize.js} +38 -36
  54. package/dist/sharedMessages.js +8 -0
  55. package/dist/utils/index.js +0 -4
  56. package/dist/utils/testUtils.js +1 -12
  57. package/dist/{components/Modal/Background.js → utils/toastHelper.js} +11 -14
  58. package/package.json +2 -2
  59. package/src/components/AppFrame/About.js +13 -13
  60. package/src/components/AppFrame/Anchor.js +7 -7
  61. package/src/components/AppFrame/AppFrame.js +3 -3
  62. package/src/components/AppFrame/Help.js +4 -4
  63. package/src/components/AppFrame/MenuItem.js +15 -23
  64. package/src/components/AppFrame/Preferences.js +14 -14
  65. package/src/components/AppFrame/Sidebar.js +6 -6
  66. package/src/components/AppFrame/Topbar.js +6 -6
  67. package/src/components/ApplicationModuleLoader.js +2 -2
  68. package/src/components/ApplicationModuleLoader.test.js +15 -28
  69. package/src/components/Authenticate.js +21 -23
  70. package/src/components/Authenticate.test.js +19 -27
  71. package/src/components/DropMenu/Menu.js +9 -9
  72. package/src/components/ErrorPlaceholder.js +4 -21
  73. package/src/components/ErrorPlaceholder.test.js +7 -14
  74. package/src/components/Form/Field.js +4 -4
  75. package/src/components/Form/InputField.test.js +2 -1
  76. package/src/components/Form/Inputs/Button.js +2 -2
  77. package/src/components/Form/Inputs/MultiSelector.js +73 -0
  78. package/src/components/Form/Inputs/MultiSelector.test.js +332 -0
  79. package/src/components/Form/Inputs/Selector.js +12 -4
  80. package/src/components/Form/Inputs/Selector.test.js +27 -12
  81. package/src/components/Form/Inputs/index.js +1 -1
  82. package/src/components/InternetExplorerWarningMessage.js +15 -15
  83. package/src/components/Loader.test.js +50 -59
  84. package/src/components/LoadingIcon.js +27 -14
  85. package/src/components/LoadingIcon.test.js +11 -15
  86. package/src/components/MaterialUI/DataDisplay/Modal.js +3 -3
  87. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  88. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +1 -1
  89. package/src/components/MaterialUI/DataDisplay/PredefinedElements/TableInfoBar.js +1 -1
  90. package/src/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  91. package/src/components/MaterialUI/DataDisplay/Table.js +6 -1
  92. package/src/components/MaterialUI/DataDisplay/Table.test.js +21 -1
  93. package/src/components/MaterialUI/DataDisplay/TableProps.js +2 -0
  94. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +20 -2
  95. package/src/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  96. package/src/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  97. package/src/components/MaterialUI/Inputs/DatePicker.js +1 -1
  98. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  99. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.test.js +1 -1
  100. package/src/components/MaterialUI/Inputs/Select.js +143 -83
  101. package/src/components/MaterialUI/Inputs/Select.test.js +199 -14
  102. package/src/components/MaterialUI/Inputs/SelectProps.js +10 -0
  103. package/src/components/MaterialUI/Inputs/SelectProps.test.js +10 -0
  104. package/src/components/MaterialUI/Inputs/Switch.js +1 -1
  105. package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
  106. package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
  107. package/src/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -2
  108. package/src/components/MaterialUI/ScopeSelector/TreeItem.js +8 -31
  109. package/src/components/MaterialUI/Surfaces/Paper.js +1 -1
  110. package/src/components/MaterialUI/Surfaces/SectionExpansionPanel.js +2 -1
  111. package/src/components/MaterialUI/muiThemes.js +4 -1
  112. package/src/components/Navigation/Navigation.test.js +0 -5
  113. package/src/components/Navigation/useNavigationState.test.js +79 -222
  114. package/src/components/Provision.js +36 -42
  115. package/src/components/Provision.test.js +10 -26
  116. package/src/components/Routing/SegmentPage.js +68 -52
  117. package/src/components/Routing/SegmentPage.test.js +4 -12
  118. package/src/components/Scope/ScopeNode.js +44 -55
  119. package/src/components/Scope/ScopeNode.test.js +84 -163
  120. package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
  121. package/src/components/Sidepanel.js +38 -32
  122. package/src/components/Sidepanel.test.js +54 -27
  123. package/src/components/Spritesheet.js +23 -21
  124. package/src/components/Spritesheet.test.js +10 -10
  125. package/src/components/Text.js +0 -49
  126. package/src/components/ToastList.js +79 -90
  127. package/src/components/ToastList.test.js +29 -103
  128. package/src/components/Treeview/Branch.js +65 -47
  129. package/src/components/Treeview/Branch.test.js +2 -43
  130. package/src/components/Treeview/Label.js +68 -54
  131. package/src/components/Treeview/Label.test.js +55 -63
  132. package/src/components/Treeview/Leaf.js +41 -22
  133. package/src/components/Treeview/Leaf.test.js +1 -15
  134. package/src/components/Treeview/Node.js +16 -9
  135. package/src/components/Treeview/Node.test.js +269 -200
  136. package/src/components/Treeview/Treeview.test.js +248 -248
  137. package/src/components/Treeview/index.js +6 -0
  138. package/src/components/Treeview/settings.js +10 -6
  139. package/src/hooks/useMultipleFieldEditState.test.js +0 -1
  140. package/src/hooks/useWindowSize.js +39 -0
  141. package/src/hooks/useWindowSize.test.js +68 -0
  142. package/src/sharedMessages.js +8 -0
  143. package/src/translations/en-US.json +2 -0
  144. package/src/translations/fr-CA.json +2 -0
  145. package/src/utils/index.js +0 -4
  146. package/src/utils/testUtils.js +0 -10
  147. package/src/utils/testUtils.test.js +0 -68
  148. package/src/utils/toastHelper.js +8 -0
  149. package/src/utils/toastHelper.test.js +41 -0
  150. package/dist/components/Button.js +0 -70
  151. package/dist/components/CategoryList.js +0 -197
  152. package/dist/components/Checkbox.js +0 -103
  153. package/dist/components/Icon.js +0 -69
  154. package/dist/components/IconButton.js +0 -80
  155. package/dist/components/Input.js +0 -101
  156. package/dist/components/List/DataCell.js +0 -129
  157. package/dist/components/List/HeadCell.js +0 -125
  158. package/dist/components/List/HeadRow.js +0 -73
  159. package/dist/components/List/List.js +0 -274
  160. package/dist/components/List/Row.js +0 -109
  161. package/dist/components/List/enhanceColumnDefs.js +0 -111
  162. package/dist/components/List/index.js +0 -59
  163. package/dist/components/Modal/Dialog.js +0 -75
  164. package/dist/components/Modal/Wrapper.js +0 -69
  165. package/dist/components/MultiSelector.js +0 -187
  166. package/dist/components/Navigation/Bar.js +0 -293
  167. package/dist/components/Navigation/Tab.js +0 -182
  168. package/dist/components/Placeholder.js +0 -114
  169. package/dist/components/Scope/Selector.js +0 -123
  170. package/dist/components/Selector.js +0 -185
  171. package/dist/components/Switch.js +0 -128
  172. package/dist/components/Toolbar.js +0 -227
  173. package/dist/components/Tooltip.js +0 -66
  174. package/dist/getTheme.js +0 -158
  175. package/dist/getThemeOverrides.js +0 -93
  176. package/dist/hocs/withAuthentication.js +0 -72
  177. package/dist/utils/styledPropFuncs.js +0 -88
  178. package/src/components/Button.js +0 -90
  179. package/src/components/Button.test.js +0 -49
  180. package/src/components/CategoryList.js +0 -140
  181. package/src/components/CategoryList.test.js +0 -667
  182. package/src/components/Checkbox.js +0 -63
  183. package/src/components/Checkbox.test.js +0 -122
  184. package/src/components/Icon.js +0 -18
  185. package/src/components/IconButton.js +0 -30
  186. package/src/components/IconButton.test.js +0 -61
  187. package/src/components/Input.js +0 -35
  188. package/src/components/Input.test.js +0 -34
  189. package/src/components/List/DataCell.js +0 -77
  190. package/src/components/List/DataCell.test.js +0 -357
  191. package/src/components/List/HeadCell.js +0 -105
  192. package/src/components/List/HeadCell.test.js +0 -331
  193. package/src/components/List/HeadRow.js +0 -21
  194. package/src/components/List/HeadRow.test.js +0 -27
  195. package/src/components/List/List.js +0 -162
  196. package/src/components/List/List.test.js +0 -705
  197. package/src/components/List/Row.js +0 -72
  198. package/src/components/List/Row.test.js +0 -194
  199. package/src/components/List/enhanceColumnDefs.js +0 -54
  200. package/src/components/List/enhanceColumnDefs.test.js +0 -179
  201. package/src/components/List/index.js +0 -6
  202. package/src/components/Modal/Background.js +0 -10
  203. package/src/components/Modal/Dialog.js +0 -27
  204. package/src/components/Modal/Dialog.test.js +0 -20
  205. package/src/components/Modal/Modal.test.js +0 -52
  206. package/src/components/Modal/Wrapper.js +0 -32
  207. package/src/components/Modal/Wrapper.test.js +0 -55
  208. package/src/components/Modal/index.js +0 -22
  209. package/src/components/MultiSelector.js +0 -104
  210. package/src/components/MultiSelector.test.js +0 -348
  211. package/src/components/Navigation/Bar.js +0 -212
  212. package/src/components/Navigation/Bar.test.js +0 -552
  213. package/src/components/Navigation/Tab.js +0 -156
  214. package/src/components/Navigation/Tab.test.js +0 -404
  215. package/src/components/Placeholder.js +0 -61
  216. package/src/components/Placeholder.test.js +0 -106
  217. package/src/components/Scope/Selector.js +0 -70
  218. package/src/components/Scope/Selector.test.js +0 -138
  219. package/src/components/Selector.js +0 -191
  220. package/src/components/Selector.test.js +0 -157
  221. package/src/components/Switch.js +0 -112
  222. package/src/components/Switch.test.js +0 -130
  223. package/src/components/Text.test.js +0 -132
  224. package/src/components/Toolbar.js +0 -178
  225. package/src/components/Toolbar.test.js +0 -478
  226. package/src/components/Tooltip.js +0 -51
  227. package/src/components/Tooltip.test.js +0 -21
  228. package/src/getTheme.js +0 -103
  229. package/src/getTheme.test.js +0 -92
  230. package/src/getThemeOverrides.js +0 -27
  231. package/src/hocs/withAuthentication.js +0 -18
  232. package/src/hocs/withAuthentication.test.js +0 -120
  233. package/src/utils/styledPropFuncs.js +0 -20
  234. package/src/utils/styledPropFuncs.test.js +0 -166
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.switchEnum = exports.ifFlag = exports.getThemeProp = void 0;
5
- var _safeGet = _interopRequireDefault(require("./safeGet"));
6
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
- (function () {
8
- var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
9
- enterModule && enterModule(module);
10
- })();
11
- (function () {
12
- var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
13
- enterModule && enterModule(module);
14
- })();
15
- var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
16
- return a;
17
- };
18
- var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
19
- return a;
20
- };
21
- var feedPropFunc = function feedPropFunc(props) {
22
- return function (value) {
23
- return typeof value === "function" ? value(props) : value;
24
- };
25
- };
26
-
27
- /* Safely gets a (potentially nested) theme property, can run a function on the resulting value */
28
- var getThemeProp = exports.getThemeProp = function getThemeProp(path, defaultValue, func) {
29
- if (func === void 0) {
30
- func = function func(x) {
31
- return x;
32
- };
33
- }
34
- return function (props) {
35
- return func(_safeGet.default.apply(void 0, [props, "theme"].concat(path.map(feedPropFunc(props)))) || feedPropFunc(props)(defaultValue));
36
- };
37
- };
38
-
39
- /* Use in styled components to check if a prop has a truthy value and
40
- return values based on that. */
41
- var ifFlag = exports.ifFlag = function ifFlag(name, thenVal, elseVal) {
42
- if (elseVal === void 0) {
43
- elseVal = "";
44
- }
45
- return function (props) {
46
- return props[name] ? feedPropFunc(props)(thenVal) : feedPropFunc(props)(elseVal);
47
- };
48
- };
49
-
50
- /* Creates a prop function that checks a field against a list of cases,
51
- and gives back a found case, or a default */
52
- var switchEnum = exports.switchEnum = function switchEnum(enumField, cases) {
53
- return function (props) {
54
- return cases[props[enumField]] || cases["default"];
55
- };
56
- };
57
- ;
58
- (function () {
59
- var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
60
- if (!reactHotLoader) {
61
- return;
62
- }
63
- reactHotLoader.register(feedPropFunc, "feedPropFunc", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
64
- reactHotLoader.register(getThemeProp, "getThemeProp", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
65
- reactHotLoader.register(ifFlag, "ifFlag", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
66
- reactHotLoader.register(switchEnum, "switchEnum", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
67
- })();
68
- ;
69
- (function () {
70
- var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
71
- leaveModule && leaveModule(module);
72
- })();
73
- ;
74
- (function () {
75
- var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
76
- if (!reactHotLoader) {
77
- return;
78
- }
79
- reactHotLoader.register(feedPropFunc, "feedPropFunc", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
80
- reactHotLoader.register(getThemeProp, "getThemeProp", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
81
- reactHotLoader.register(ifFlag, "ifFlag", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
82
- reactHotLoader.register(switchEnum, "switchEnum", "/home/vsts/work/1/s/src/utils/styledPropFuncs.js");
83
- })();
84
- ;
85
- (function () {
86
- var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
87
- leaveModule && leaveModule(module);
88
- })();
@@ -1,90 +0,0 @@
1
- import styled, { css } from "styled-components";
2
- import { getThemeProp, ifFlag } from "../utils";
3
- import { tint } from "polished";
4
-
5
- const borderColor = base => ifFlag("primary", getThemeProp(["colors", "application", "base"], base), base);
6
-
7
- const background = ifFlag(
8
- "primary",
9
- ifFlag(
10
- "active",
11
- css`
12
- color: #fff;
13
- background-image: linear-gradient(
14
- ${getThemeProp(["colors", "application", "base"], "#333", color => tint(0.05, color))},
15
- ${getThemeProp(["colors", "application", "base"], "#333")}
16
- );
17
- &:enabled:active {
18
- background-image: none;
19
- background-color: #fff;
20
- color: ${getThemeProp(["colors", "application", "base"], "#333")};
21
- }
22
- `,
23
- css`
24
- color: ${getThemeProp(["colors", "application", "base"], "#333")};
25
- background-image: none;
26
- background-color: #fff;
27
- &:enabled:active {
28
- color: #fff;
29
- background-image: linear-gradient(
30
- ${getThemeProp(["colors", "application", "base"], "#333", color => tint(0.05, color))},
31
- ${getThemeProp(["colors", "application", "base"], "#333")}
32
- );
33
- }
34
- `,
35
- ),
36
- ifFlag(
37
- "active",
38
- css`
39
- background-image: none;
40
- background-color: ${getThemeProp(["colors", "bgLight"], "#efefef")};
41
- &:enabled:active {
42
- background-color: #f7f7f7;
43
- }
44
- `,
45
- css`
46
- background-image: none;
47
- background-color: #f7f7f7;
48
- &:enabled:active {
49
- background-color: ${getThemeProp(["colors", "bgLight"], "#efefef")};
50
- }
51
- `,
52
- ),
53
- );
54
-
55
- const Button = styled.button`
56
- display: inline-block;
57
- margin: 0;
58
- font-weight: 400;
59
- text-align: center;
60
- vertical-align: middle;
61
- cursor: pointer;
62
- white-space: nowrap;
63
- padding: 6px 10px;
64
- font-size: 13px;
65
- line-height: 1.42857;
66
- border-radius: 4px;
67
- user-select: none;
68
- height: 30px;
69
- border: 1px solid ${borderColor(getThemeProp(["colors", "borderLight"], "#cccccc"))};
70
- outline: none;
71
- font-family: ${getThemeProp(["fonts", "header"], "sans-serif")};
72
- text-transform: uppercase;
73
- min-width: 50px;
74
- box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
75
- ${background};
76
-
77
- &:enabled:active,
78
- &:enabled:focus,
79
- &:enabled:hover {
80
- border-color: ${borderColor("#4fa1f0")};
81
- box-shadow: 0 0 4px #4fa1f0;
82
- outline: none;
83
- }
84
- &:disabled {
85
- opacity: 0.6;
86
- cursor: default;
87
- }
88
- `;
89
-
90
- export default Button;
@@ -1,49 +0,0 @@
1
- import React from "react";
2
- import Button from "./Button";
3
-
4
- describe("Button", () => {
5
- let onClick;
6
- beforeEach(() => {
7
- onClick = () => {};
8
- });
9
-
10
- it("renders a button", () =>
11
- expect(
12
- <Button onClick={onClick}>Label</Button>,
13
- "when mounted",
14
- "to satisfy",
15
- <button onClick={onClick}>Label</button>,
16
- ));
17
-
18
- it("sets an inactive background-color", () =>
19
- expect(<Button />, "when mounted", "to have style rules satisfying", "to contain", "background-color: #f7f7f7;"));
20
-
21
- it("sets an active background-color", () =>
22
- expect(
23
- <Button active />,
24
- "when mounted",
25
- "to have style rules satisfying",
26
- "to contain",
27
- "background-color: #efefef;",
28
- ));
29
-
30
- describe("primary", () => {
31
- it("sets an inactive background gradient", () =>
32
- expect(
33
- <Button primary />,
34
- "when mounted",
35
- "to have style rules satisfying",
36
- "to contain",
37
- "background-color: #fff;",
38
- ));
39
-
40
- it("sets an active background-color", () =>
41
- expect(
42
- <Button primary active />,
43
- "when mounted",
44
- "to have style rules satisfying",
45
- "to contain",
46
- "background-image: linear-gradient( #3d3d3d,#333 )",
47
- ));
48
- });
49
- });
@@ -1,140 +0,0 @@
1
- /*
2
- Multiple lists with a single header, aligned with each other
3
- No virtualization or page loading
4
- Categories can be folded up to hide content
5
- Sortable, within categories
6
- */
7
- import React from "react";
8
- import styled, { css } from "styled-components";
9
- import { compose, setDisplayName } from "recompose";
10
- import { safeGet, ifFlag, getThemeProp } from "../utils";
11
- import withScrollBox from "../hocs/withScrollBox";
12
- import useViewState from "../hooks/useViewState";
13
- import Icon from "./Icon";
14
- import Row from "./List/Row";
15
- import HeadRow from "./List/HeadRow";
16
- import { useListState, Table, Placeholder, HEADER_HEIGHT } from "./List/List";
17
-
18
- const arrayToggle = (array, item) => (array.includes(item) ? array.filter(x => x !== item) : array.concat(item));
19
-
20
- export const CategoryRow = styled.tr``;
21
-
22
- export const CategoryHeader = styled.td`
23
- border: 0 solid ${getThemeProp(["colors", "borderLight"], "#cccccc")};
24
- border-top-width: 1px;
25
- tr:first-child & {
26
- border-top-width: 0;
27
- }
28
- tr:last-child & {
29
- border-bottom-width: 1px;
30
- }
31
-
32
- position: relative;
33
- padding: 11px 45px;
34
- background-color: #f1eae0;
35
- ${ifFlag(
36
- "closed",
37
- css`
38
- border-bottom: 1px solid ${getThemeProp(["colors", "borderLight"], "#cccccc")};
39
- `,
40
- )}
41
- cursor: pointer;
42
- `;
43
-
44
- export const CategoryIndicator = styled(Icon).attrs(props => ({
45
- id: ifFlag(
46
- "closed",
47
- getThemeProp(["icons", "indicators", "right"], "chevron-right"),
48
- getThemeProp(["icons", "indicators", "down"], "chevron-down"),
49
- )(props),
50
- }))`
51
- font-size: 12px;
52
- position: absolute;
53
- left: 22px;
54
- top: 15px;
55
- `;
56
-
57
- export const CategoryList = ({
58
- name,
59
- columnDefs = [],
60
- rows = [],
61
- rowOnClick,
62
- placeholder,
63
- keyField = ["id"],
64
- categoryField = ["category"],
65
- openAll = false,
66
- height,
67
- rowBackgroundGetter = () => {},
68
- }) => {
69
- const [enhancedColumnDefs, selection] = useListState(name, columnDefs);
70
- const [{ closedCategories = [] }, updateViewState] = useViewState(name);
71
- if (columnDefs.length === 0) return null;
72
- const rowIds = [],
73
- rowCategories = {};
74
- rows.forEach((row, index) => {
75
- const id = safeGet(row, ...keyField) + ""; // Ensure rowId is string
76
- const category = safeGet(row, ...categoryField) || "";
77
- rowIds.push(id);
78
- if (!rowCategories[category]) {
79
- rowCategories[category] = [];
80
- }
81
- rowCategories[category].push(
82
- <Row
83
- columnDefs={enhancedColumnDefs}
84
- key={id}
85
- rowId={id}
86
- row={row}
87
- rowOnClick={rowOnClick}
88
- selected={selection.indexOf(id) !== -1}
89
- bgColor={rowBackgroundGetter(row, index)}
90
- />,
91
- );
92
- });
93
- const rowElements = [];
94
- if (Object.keys(rowCategories).length === 0) {
95
- if (placeholder) {
96
- rowElements.push(
97
- <Placeholder key="placeholder" width={columnDefs.length} height={height - HEADER_HEIGHT}>
98
- {placeholder}
99
- </Placeholder>,
100
- );
101
- }
102
- } else {
103
- Object.entries(rowCategories).forEach(([key, rows]) => {
104
- const clickHandler = () => updateViewState("closedCategories", arrayToggle(closedCategories, key));
105
- const closed = !openAll && closedCategories.includes(key);
106
- rowElements.push(
107
- <CategoryRow key={"category_" + key}>
108
- <CategoryHeader
109
- data-test-id={"category_" + key}
110
- closed={closed}
111
- colSpan={columnDefs.length}
112
- onClick={clickHandler}
113
- >
114
- <CategoryIndicator closed={closed} />
115
- {key}
116
- </CategoryHeader>
117
- </CategoryRow>,
118
- );
119
- if (!closed) {
120
- rowElements.push(...rows);
121
- }
122
- });
123
- }
124
- return (
125
- <Table>
126
- <thead>
127
- <HeadRow
128
- columnDefs={enhancedColumnDefs}
129
- rowIds={rowIds}
130
- allSelected={rows.length === selection.length && rows.length !== 0}
131
- />
132
- </thead>
133
- <tbody>{rowElements}</tbody>
134
- </Table>
135
- );
136
- };
137
-
138
- const StatefulCategoryList = compose(setDisplayName("CategoryList"), withScrollBox)(CategoryList);
139
-
140
- export default StatefulCategoryList;