@onehat/ui 0.2.73 → 0.2.74

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": "@onehat/ui",
3
- "version": "0.2.73",
3
+ "version": "0.2.74",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -35,6 +35,7 @@ import withMultiSelection from '../Hoc/withMultiSelection.js';
35
35
  import withSelection from '../Hoc/withSelection.js';
36
36
  import withWindowedEditor from '../Hoc/withWindowedEditor.js';
37
37
  import withInlineEditor from '../Hoc/withInlineEditor.js';
38
+ import getIconButtonFromConfig from '../../Functions/getIconButtonFromConfig.js';
38
39
  import testProps from '../../Functions/testProps.js';
39
40
  import nbToRgb from '../../Functions/nbToRgb.js';
40
41
  import GridHeaderRow from './GridHeaderRow.js';
@@ -52,7 +53,7 @@ import _ from 'lodash';
52
53
  // The default export is *with* the HOC. A separate *raw* component is
53
54
  // exported which can be combined with many HOCs for various functionality.
54
55
 
55
- export function GridComponent(props) {
56
+ function GridComponent(props) {
56
57
  const {
57
58
 
58
59
  columnsConfig = [], // json configurations for each column
@@ -217,42 +218,8 @@ export function GridComponent(props) {
217
218
  }
218
219
  },
219
220
  getFooterToolbarItems = () => {
220
- const
221
- iconButtonProps = {
222
- _hover: {
223
- bg: 'trueGray.400',
224
- },
225
- mx: 1,
226
- px: 3,
227
- },
228
- iconProps = {
229
- alignSelf: 'center',
230
- size: styles.GRID_TOOLBAR_ITEMS_ICON_SIZE,
231
- h: 20,
232
- w: 20,
233
- },
234
- items = _.map(additionalToolbarButtons, (config, ix) => {
235
- let {
236
- text,
237
- handler,
238
- icon = null,
239
- isDisabled = false,
240
- } = config;
241
- if (icon) {
242
- const thisIconProps = {
243
- color: isDisabled ? styles.GRID_TOOLBAR_ITEMS_DISABLED_COLOR : styles.GRID_TOOLBAR_ITEMS_COLOR,
244
- };
245
- icon = React.cloneElement(icon, {...iconProps, ...thisIconProps});
246
- }
247
- return <IconButton
248
- key={ix}
249
- {...iconButtonProps}
250
- onPress={handler}
251
- icon={icon}
252
- isDisabled={isDisabled}
253
- tooltip={text}
254
- />;
255
- });
221
+ const items = _.map(additionalToolbarButtons, getIconButtonFromConfig);
222
+
256
223
  if (canRowsReorder) {
257
224
  items.unshift(<IconButton
258
225
  key="reorderBtn"
@@ -851,21 +818,19 @@ export function GridComponent(props) {
851
818
 
852
819
  }
853
820
 
854
- const Grid = withAlert(
821
+ export const Grid = withAlert(
855
822
  withEvents(
856
823
  withData(
857
824
  withMultiSelection(
858
825
  withSelection(
859
- // withSideEditor(
860
- withFilters(
861
- withPresetButtons(
862
- withContextMenu(
863
- GridComponent
864
- ),
865
- true // isGrid
866
- )
826
+ withFilters(
827
+ withPresetButtons(
828
+ withContextMenu(
829
+ GridComponent
830
+ ),
831
+ true // isGrid
867
832
  )
868
- // )
833
+ )
869
834
  )
870
835
  )
871
836
  )
@@ -920,13 +885,13 @@ export const InlineGridEditor = withAlert(
920
885
  withMultiSelection(
921
886
  withSelection(
922
887
  withInlineEditor(
923
- withPresetButtons(
924
- withContextMenu(
925
- withFilters(
888
+ withFilters(
889
+ withPresetButtons(
890
+ withContextMenu(
926
891
  GridComponent
927
- ),
928
- true // isGrid
929
- )
892
+ )
893
+ ),
894
+ true // isGrid
930
895
  )
931
896
  )
932
897
  )
@@ -1,4 +1,9 @@
1
1
  import { useEffect, useState, } from 'react';
2
+ import {
3
+ Column,
4
+ Modal,
5
+ Text,
6
+ } from 'native-base';
2
7
  import {
3
8
  EDITOR_MODE__VIEW,
4
9
  EDITOR_MODE__ADD,
@@ -19,6 +24,7 @@ export default function withEditor(WrappedComponent) {
19
24
  disableDelete = false,
20
25
  disableDuplicate = false,
21
26
  disableView = false,
27
+ isTree = false,
22
28
  getRecordIdentifier = (selection) => {
23
29
  if (selection.length > 1) {
24
30
  return 'records?';
@@ -44,6 +50,7 @@ export default function withEditor(WrappedComponent) {
44
50
  [currentRecord, setCurrentRecord] = useState(null),
45
51
  [isEditorShown, setIsEditorShown] = useState(false),
46
52
  [isEditorViewOnly, setIsEditorViewOnly] = useState(false),
53
+ [isModalShown, setIsModalShown] = useState(false),
47
54
  [lastSelection, setLastSelection] = useState(),
48
55
  onAdd = async () => {
49
56
  const defaultValues = Repository.getSchema().model.defaultValues;
@@ -53,6 +60,13 @@ export default function withEditor(WrappedComponent) {
53
60
  addValues[selectorId] = selectorSelected.id;
54
61
  }
55
62
 
63
+ if (isTree) {
64
+ if (!selection[0]) {
65
+ throw Error('Must select a parent node.');
66
+ }
67
+ addValues.parentId = selection[0].id;
68
+ }
69
+
56
70
  // Set repository to sort by id DESC and switch to page 1, so this new entity is guaranteed to show up on the current page, even after saving
57
71
  const currentSorter = Repository.sorters[0];
58
72
  if (currentSorter.name !== Repository.schema.model.idProperty || currentSorter.direction !== 'DESC') {
@@ -195,33 +209,42 @@ export default function withEditor(WrappedComponent) {
195
209
  editorMode = calculateEditorMode();
196
210
  }
197
211
 
198
- return <WrappedComponent
199
- {...props}
200
- currentRecord={currentRecord}
201
- setCurrentRecord={setCurrentRecord}
202
- isEditorShown={isEditorShown}
203
- isEditorViewOnly={isEditorViewOnly}
204
- editorMode={editorMode}
205
- setEditorMode={setEditorMode}
206
- setIsEditorShown={setIsEditorShown}
207
- onAdd={(!userCanEdit || disableAdd) ? null : onAdd}
208
- onEdit={(!userCanEdit || disableEdit) ? null : onEdit}
209
- onDelete={(!userCanEdit || disableDelete || (editorMode === EDITOR_MODE__ADD && (selection[0]?.isPhantom || currentRecord?.isPhantom))) ? null : onDelete}
210
- onView={viewRecord}
211
- onDuplicate={duplicateRecord}
212
- onEditorSave={onEditorSave}
213
- onEditorCancel={onEditorCancel}
214
- onEditorDelete={(!userCanEdit || disableDelete || (editorMode === EDITOR_MODE__ADD && (selection[0]?.isPhantom || currentRecord?.isPhantom))) ? null : onEditorDelete}
215
- onEditorClose={onEditorClose}
216
- isEditor={true}
217
- useEditor={useEditor}
218
- userCanEdit={userCanEdit}
219
- userCanView={userCanView}
220
- disableAdd={disableAdd}
221
- disableEdit={disableEdit}
222
- disableDelete={disableDelete}
223
- disableDuplicate={disableDuplicate}
224
- disableView ={disableView}
225
- />;
212
+ return <>
213
+ <WrappedComponent
214
+ {...props}
215
+ currentRecord={currentRecord}
216
+ setCurrentRecord={setCurrentRecord}
217
+ isEditorShown={isEditorShown}
218
+ isEditorViewOnly={isEditorViewOnly}
219
+ editorMode={editorMode}
220
+ setEditorMode={setEditorMode}
221
+ setIsEditorShown={setIsEditorShown}
222
+ onAdd={(!userCanEdit || disableAdd) ? null : onAdd}
223
+ onEdit={(!userCanEdit || disableEdit) ? null : onEdit}
224
+ onDelete={(!userCanEdit || disableDelete || (editorMode === EDITOR_MODE__ADD && (selection[0]?.isPhantom || currentRecord?.isPhantom))) ? null : onDelete}
225
+ onView={viewRecord}
226
+ onDuplicate={duplicateRecord}
227
+ onEditorSave={onEditorSave}
228
+ onEditorCancel={onEditorCancel}
229
+ onEditorDelete={(!userCanEdit || disableDelete || (editorMode === EDITOR_MODE__ADD && (selection[0]?.isPhantom || currentRecord?.isPhantom))) ? null : onEditorDelete}
230
+ onEditorClose={onEditorClose}
231
+ isEditor={true}
232
+ useEditor={useEditor}
233
+ userCanEdit={userCanEdit}
234
+ userCanView={userCanView}
235
+ disableAdd={disableAdd}
236
+ disableEdit={disableEdit}
237
+ disableDelete={disableDelete}
238
+ disableDuplicate={disableDuplicate}
239
+ disableView ={disableView}
240
+ />
241
+ {isTree && isModalShown &&
242
+ <Modal
243
+ isOpen={true}
244
+ onClose={() => setIsModalShown(false)}
245
+ >
246
+
247
+ </Modal>}
248
+ </>;
226
249
  };
227
250
  }
@@ -34,6 +34,7 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
34
34
  {
35
35
  // for local use
36
36
  isEditor = false,
37
+ isTree = false,
37
38
  useEditor = true,
38
39
  disableAdd = !isEditor,
39
40
  disableEdit = !isEditor,
@@ -125,6 +126,9 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
125
126
  if (selectorId && !selectorSelected) {
126
127
  isDisabled = true;
127
128
  }
129
+ if (isTree && _.isEmpty(selection)) {
130
+ isDisabled = true;
131
+ }
128
132
  break;
129
133
  case 'edit':
130
134
  text = 'Edit';
@@ -6,7 +6,7 @@ import withEditor from './withEditor.js';
6
6
  import _ from 'lodash';
7
7
 
8
8
 
9
- export default function withSideEditor(WrappedComponent) {
9
+ export default function withSideEditor(WrappedComponent, isTree = false) {
10
10
  return withEditor((props) => {
11
11
  const {
12
12
  Editor,
@@ -19,7 +19,7 @@ export default function withSideEditor(WrappedComponent) {
19
19
  }
20
20
 
21
21
  return <Container
22
- center={<WrappedComponent {...props} />}
22
+ center={<WrappedComponent isTree={isTree} {...props} />}
23
23
  east={<Editor
24
24
  editorType={EDITOR_TYPE__SIDE}
25
25
  flex={sideFlex}
@@ -25,7 +25,7 @@ import _ from 'lodash';
25
25
  // then switch position to absolute, draggable area would be header of panel
26
26
  // const DraggableColumn = withAdditionalProps(withDraggable(Column));
27
27
 
28
- export default function withWindowedEditor(WrappedComponent) {
28
+ export default function withWindowedEditor(WrappedComponent, isTree = false) {
29
29
  return withEditor((props) => {
30
30
  const {
31
31
  useEditor = false,
@@ -40,7 +40,7 @@ export default function withWindowedEditor(WrappedComponent) {
40
40
  }
41
41
 
42
42
  return <>
43
- <WrappedComponent {...props} />
43
+ <WrappedComponent isTree={isTree} {...props} />
44
44
  {useEditor && isEditorShown &&
45
45
  <Modal
46
46
  isOpen={true}
@@ -32,6 +32,7 @@ import withPresetButtons from '../Hoc/withPresetButtons.js';
32
32
  import withMultiSelection from '../Hoc/withMultiSelection.js';
33
33
  import withSelection from '../Hoc/withSelection.js';
34
34
  import withWindowedEditor from '../Hoc/withWindowedEditor.js';
35
+ import getIconButtonFromConfig from '../../Functions/getIconButtonFromConfig.js';
35
36
  import testProps from '../../Functions/testProps.js';
36
37
  import nbToRgb from '../../Functions/nbToRgb.js';
37
38
  import TreeNode, { ReorderableTreeNode } from './TreeNode.js';
@@ -63,7 +64,7 @@ import _ from 'lodash';
63
64
  //////////////////////
64
65
 
65
66
 
66
- export function TreeComponent(props) {
67
+ function TreeComponent(props) {
67
68
  const {
68
69
  areRootsVisible = true,
69
70
  extraParams = {}, // Additional params to send with each request ( e.g. { order: 'Categories.name ASC' })
@@ -251,7 +252,7 @@ export function TreeComponent(props) {
251
252
  isDisabled: false,
252
253
  });
253
254
  }
254
- const items = _.map(buttons, getIconFromConfig);
255
+ const items = _.map(buttons, getIconButtonFromConfig);
255
256
 
256
257
  items.unshift(<Input // Add text input to beginning of header items
257
258
  key="searchNodes"
@@ -270,40 +271,7 @@ export function TreeComponent(props) {
270
271
  return items;
271
272
  },
272
273
  getFooterToolbarItems = () => {
273
- return _.map(additionalToolbarButtons, getIconFromConfig);
274
- },
275
- getIconFromConfig = (config, ix) => {
276
- const
277
- iconButtonProps = {
278
- _hover: {
279
- bg: 'trueGray.400',
280
- },
281
- mx: 1,
282
- px: 3,
283
- },
284
- _icon = {
285
- alignSelf: 'center',
286
- size: styles.TREE_TOOLBAR_ITEMS_ICON_SIZE,
287
- h: 20,
288
- w: 20,
289
- color: isDisabled ? styles.TREE_TOOLBAR_ITEMS_DISABLED_COLOR : styles.TREE_TOOLBAR_ITEMS_COLOR,
290
- };
291
- let {
292
- key,
293
- text,
294
- handler,
295
- icon = null,
296
- isDisabled = false,
297
- } = config;
298
- return <IconButton
299
- key={key || ix}
300
- onPress={handler}
301
- icon={icon}
302
- _icon={_icon}
303
- isDisabled={isDisabled}
304
- tooltip={text}
305
- {...iconButtonProps}
306
- />;
274
+ return _.map(additionalToolbarButtons, getIconButtonFromConfig);
307
275
  },
308
276
  buildTreeNodeDatum = (treeNode) => {
309
277
  // Build the data-representation of one node and its children,
@@ -1114,25 +1082,21 @@ export function TreeComponent(props) {
1114
1082
 
1115
1083
  }
1116
1084
 
1117
- const Tree = withAlert(
1118
- withEvents(
1119
- withData(
1120
- // withMultiSelection(
1121
- withSelection(
1122
- // withSideEditor(
1123
- withFilters(
1124
- // withPresetButtons(
1085
+ export const Tree = withAlert(
1086
+ withEvents(
1087
+ withData(
1088
+ // withMultiSelection(
1089
+ withSelection(
1090
+ withFilters(
1125
1091
  withContextMenu(
1126
1092
  TreeComponent
1127
1093
  )
1128
- // )
1094
+ )
1129
1095
  )
1130
1096
  // )
1131
1097
  )
1132
- // )
1133
- )
1134
- )
1135
- );
1098
+ )
1099
+ );
1136
1100
 
1137
1101
  export const SideTreeEditor = withAlert(
1138
1102
  withEvents(
@@ -1146,7 +1110,8 @@ export const SideTreeEditor = withAlert(
1146
1110
  TreeComponent
1147
1111
  )
1148
1112
  )
1149
- )
1113
+ ),
1114
+ true // isTree
1150
1115
  )
1151
1116
  )
1152
1117
  // )
@@ -1166,7 +1131,8 @@ export const WindowedTreeEditor = withAlert(
1166
1131
  TreeComponent
1167
1132
  )
1168
1133
  )
1169
- )
1134
+ ),
1135
+ true // isTree
1170
1136
  )
1171
1137
  )
1172
1138
  // )
@@ -63,9 +63,6 @@ const defaults = {
63
63
  GRID_ROW_HOVER_BG: 'hover',
64
64
  GRID_ROW_SELECTED_BG: 'selected',
65
65
  GRID_ROW_SELECTED_HOVER_BG: 'selectedHover',
66
- GRID_TOOLBAR_ITEMS_COLOR: 'trueGray.800',
67
- GRID_TOOLBAR_ITEMS_DISABLED_COLOR: 'disabled',
68
- GRID_TOOLBAR_ITEMS_ICON_SIZE: 'sm',
69
66
  ICON_BUTTON_BG: 'trueGray.200:alpha.0',
70
67
  ICON_BUTTON_BG_DISABLED: 'trueGray.200',
71
68
  ICON_BUTTON_BG_HOVER: '#000:alpha.20',
@@ -97,9 +94,9 @@ const defaults = {
97
94
  TREE_NODE_HOVER_BG: 'hover',
98
95
  TREE_NODE_SELECTED_BG: 'selected',
99
96
  TREE_NODE_SELECTED_HOVER_BG: 'selectedHover',
100
- TREE_TOOLBAR_ITEMS_COLOR: 'trueGray.800',
101
- TREE_TOOLBAR_ITEMS_DISABLED_COLOR: 'disabled',
102
- TREE_TOOLBAR_ITEMS_ICON_SIZE: 'sm',
97
+ TOOLBAR_ITEMS_COLOR: 'trueGray.800',
98
+ TOOLBAR_ITEMS_DISABLED_COLOR: 'disabled',
99
+ TOOLBAR_ITEMS_ICON_SIZE: 'sm',
103
100
  VIEWER_ANCILLARY_FONTSIZE: 22,
104
101
  };
105
102
 
@@ -0,0 +1,38 @@
1
+ import IconButton from '../Components/Buttons/IconButton.js';
2
+ import UiGlobals from '../UiGlobals.js';
3
+
4
+
5
+ export default function getIconButtonFromConfig($config, ix) {
6
+ const
7
+ styles = UiGlobals.styles,
8
+ iconButtonProps = {
9
+ _hover: {
10
+ bg: 'trueGray.400',
11
+ },
12
+ mx: 1,
13
+ px: 3,
14
+ },
15
+ _icon = {
16
+ alignSelf: 'center',
17
+ size: styles.TOOLBAR_ITEMS_ICON_SIZE,
18
+ h: 20,
19
+ w: 20,
20
+ color: isDisabled ? styles.TOOLBAR_ITEMS_DISABLED_COLOR : styles.TOOLBAR_ITEMS_COLOR,
21
+ };
22
+ let {
23
+ key,
24
+ text,
25
+ handler,
26
+ icon = null,
27
+ isDisabled = false,
28
+ } = config;
29
+ return <IconButton
30
+ key={key || ix}
31
+ onPress={handler}
32
+ icon={icon}
33
+ _icon={_icon}
34
+ isDisabled={isDisabled}
35
+ tooltip={text}
36
+ {...iconButtonProps}
37
+ />;
38
+ }