@onehat/ui 0.2.78 → 0.2.79

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.78",
3
+ "version": "0.2.79",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -14,6 +14,7 @@ export default function Editor(props) {
14
14
  onEditorClose: onClose,
15
15
  onEditorDelete: onDelete,
16
16
  editorMode,
17
+ onEditMode,
17
18
 
18
19
  // withData
19
20
  Repository,
@@ -21,7 +22,7 @@ export default function Editor(props) {
21
22
  // withSelection
22
23
  selection,
23
24
 
24
- } = prop;
25
+ } = props;
25
26
 
26
27
  if (_.isEmpty(selection)) {
27
28
  return null;
@@ -33,7 +34,7 @@ export default function Editor(props) {
33
34
  record={selection[0]}
34
35
  onEditMode={isViewOnly ? null : onEditMode}
35
36
  onClose={onClose}
36
- // onDelete={onDelete}
37
+ onDelete={onDelete}
37
38
  />;
38
39
  }
39
40
 
@@ -20,7 +20,12 @@ export default function Viewer(props) {
20
20
  const {
21
21
  additionalViewButtons = [],
22
22
  ancillaryItems = [],
23
+ viewerCanDelete = false,
24
+
25
+ // withData
23
26
  record,
27
+
28
+ // withEditor
24
29
  onEditMode,
25
30
  onClose,
26
31
  onDelete,
@@ -80,19 +85,18 @@ export default function Viewer(props) {
80
85
  </Column>
81
86
  </ScrollView>
82
87
  <Footer justifyContent="flex-end">
83
- {onDelete && <Row flex={1} justifyContent="flex-start">
84
- <Button
85
- key="deleteBtn"
86
- onPress={() => {
87
- confirm('Are you sure you want to delete this record?', onDelete);
88
- }}
89
- bg="warning"
90
- _hover={{
91
- bg: 'warningHover',
92
- }}
93
- color="#fff"
94
- >Delete</Button>
95
- </Row>}
88
+ {onDelete && viewerCanDelete &&
89
+ <Row flex={1} justifyContent="flex-start">
90
+ <Button
91
+ key="deleteBtn"
92
+ onPress={onDelete}
93
+ bg="warning"
94
+ _hover={{
95
+ bg: 'warningHover',
96
+ }}
97
+ color="#fff"
98
+ >Delete</Button>
99
+ </Row>}
96
100
  <Button.Group space={2}>
97
101
  <Button
98
102
  key="closeBtn"
@@ -12,12 +12,15 @@ import {
12
12
  } from '../../../../Constants/UiModes.js';
13
13
  import UiGlobals from '../../../../UiGlobals.js';
14
14
  import Input from '../Input.js';
15
+ import withAlert from '../../../Hoc/withAlert.js';
15
16
  import withData from '../../../Hoc/withData.js';
16
17
  import withEvents from '../../../Hoc/withEvents.js';
18
+ import withPresetButtons from '../../../Hoc/withPresetButtons.js';
17
19
  import withSelection from '../../../Hoc/withSelection.js';
18
20
  import withValue from '../../../Hoc/withValue.js';
21
+ import withWindowedEditor from '../../../Hoc/withWindowedEditor.js';
19
22
  import emptyFn from '../../../../Functions/emptyFn.js';
20
- import { Grid } from '../../../Grid/Grid.js';
23
+ import { Grid, WindowedGridEditor } from '../../../Grid/Grid.js';
21
24
  import IconButton from '../../../Buttons/IconButton.js';
22
25
  import CaretDown from '../../../Icons/CaretDown.js';
23
26
  import _ from 'lodash';
@@ -26,7 +29,7 @@ import _ from 'lodash';
26
29
  // The default export is *with* the HOC. A separate *raw* component is
27
30
  // exported which can be combined with many HOCs for various functionality.
28
31
 
29
- export function Combo(props) {
32
+ export function ComboComponent(props) {
30
33
  const {
31
34
  additionalButtons,
32
35
  autoFocus = false,
@@ -36,7 +39,9 @@ export function Combo(props) {
36
39
  menuMinWidth = 150,
37
40
  disableDirectEntry = false,
38
41
  disablePagination = true,
42
+ hideMenuOnSelection = true,
39
43
  _input = {},
44
+ isEditor = false,
40
45
 
41
46
  // withValue
42
47
  value,
@@ -341,6 +346,8 @@ export function Combo(props) {
341
346
  if (tooltipRef) {
342
347
  refProps.ref = tooltipRef;
343
348
  }
349
+
350
+ const WhichGrid = isEditor ? WindowedGridEditor : Grid;
344
351
 
345
352
  let comboComponent = <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1} onLayout={() => setIsRendered(true)}>
346
353
  {disableDirectEntry ?
@@ -474,7 +481,7 @@ export function Combo(props) {
474
481
  borderTopWidth={0}
475
482
  p={0}
476
483
  >
477
- <Grid
484
+ <WhichGrid
478
485
  showHeaders={false}
479
486
  showHovers={true}
480
487
  shadow={1}
@@ -489,13 +496,16 @@ export function Combo(props) {
489
496
  };
490
497
  }}
491
498
  {...props}
499
+ disablePresetButtons={!isEditor}
492
500
  disablePagination={disablePagination}
493
501
  fireEvent={onEvent}
494
502
  setSelection={(selection) => {
495
503
  // Decorator fn to add local functionality
496
504
  // Close the menu when row is selected on grid
497
505
  setSelection(selection);
498
- hideMenu();
506
+ if (hideMenuOnSelection) {
507
+ hideMenu();
508
+ }
499
509
  }}
500
510
  selectionMode={selectionMode}
501
511
  setValue={(value) => {
@@ -515,13 +525,30 @@ export function Combo(props) {
515
525
  return comboComponent;
516
526
  }
517
527
 
518
- export default
519
- // withEvents(
520
- withData(
528
+ export const Combo = withData(
521
529
  withValue(
522
530
  withSelection(
523
- Combo
531
+ ComboComponent
524
532
  )
525
533
  )
526
534
  );
527
- // );
535
+
536
+
537
+
538
+ function withAdditionalProps(WrappedComponent) {
539
+ return (props) => {
540
+ return <WrappedComponent
541
+ isEditor={true}
542
+ hideMenuOnSelection={false}
543
+ disableView={true}
544
+ disableCopy={true}
545
+ disableDuplicate={true}
546
+ disablePrint={true}
547
+ {...props}
548
+ />;
549
+ };
550
+ }
551
+
552
+ export const ComboEditor = withAdditionalProps(Combo);
553
+
554
+ export default Combo;
@@ -559,19 +559,18 @@ function Form(props) {
559
559
  {editor}
560
560
 
561
561
  <Footer justifyContent="flex-end" {...footerProps}>
562
- {onDelete && <Row flex={1} justifyContent="flex-start">
563
- <Button
564
- key="deleteBtn"
565
- onPress={() => {
566
- confirm('Are you sure you want to delete this record?', onDelete);
567
- }}
568
- bg="warning"
569
- _hover={{
570
- bg: 'warningHover',
571
- }}
572
- color="#fff"
573
- >Delete</Button>
574
- </Row>}
562
+ {onDelete && editorMode === EDITOR_MODE__EDIT &&
563
+ <Row flex={1} justifyContent="flex-start">
564
+ <Button
565
+ key="deleteBtn"
566
+ onPress={onDelete}
567
+ bg="warning"
568
+ _hover={{
569
+ bg: 'warningHover',
570
+ }}
571
+ color="#fff"
572
+ >Delete</Button>
573
+ </Row>}
575
574
  <Button.Group space={2} {...buttonGroupProps}>
576
575
 
577
576
  {!isViewOnly && <IconButton
@@ -69,6 +69,16 @@ export default function GridRow(props) {
69
69
  'showDragHandles',
70
70
  ]);
71
71
 
72
+ if (!extraProps._web) {
73
+ extraProps._web = {};
74
+ }
75
+ if (!extraProps._web.style) {
76
+ extraProps._web.style = {};
77
+ }
78
+ extraProps._web.style = {
79
+ userSelect: 'none',
80
+ };
81
+
72
82
  return <Row key={key} {...propsToPass} {...extraProps}>{config.renderer(item)}</Row>;
73
83
  }
74
84
  if (config.fieldName) {
@@ -103,7 +113,9 @@ export default function GridRow(props) {
103
113
  overflow="hidden"
104
114
  textOverflow="ellipsis"
105
115
  alignSelf="center"
106
- style={{ userSelect: 'none', }}
116
+ style={{
117
+ userSelect: 'none',
118
+ }}
107
119
  fontSize={styles.GRID_CELL_FONTSIZE}
108
120
  px={styles.GRID_CELL_PX}
109
121
  py={styles.GRID_CELL_PY}
@@ -64,6 +64,12 @@ export default function withContextMenu(WrappedComponent) {
64
64
  };
65
65
  icon = React.cloneElement(icon, {...iconProps});
66
66
  }
67
+
68
+ // <div style={{
69
+ // userSelect: 'none',
70
+ // }}>
71
+ // </div>
72
+
67
73
  return <Pressable
68
74
  key={ix}
69
75
  onPress={() => {
@@ -79,6 +85,10 @@ export default function withContextMenu(WrappedComponent) {
79
85
  bg: '#ffc',
80
86
  }}
81
87
  isDisabled={isDisabled}
88
+ style={{
89
+ userSelect: 'none',
90
+ }}
91
+ userSelect="none"
82
92
  >
83
93
  {icon}
84
94
  <Text
@@ -86,6 +96,10 @@ export default function withContextMenu(WrappedComponent) {
86
96
  color={isDisabled ? 'disabled' : 'trueGray.800'}
87
97
  numberOfLines={1}
88
98
  ellipsizeMode="head"
99
+ style={{
100
+ userSelect: 'none',
101
+ }}
102
+ userSelect="none"
89
103
  >{text}</Text>
90
104
  </Pressable>;
91
105
  });
@@ -96,6 +110,7 @@ export default function withContextMenu(WrappedComponent) {
96
110
  flex={1}
97
111
  py={2}
98
112
  px={4}
113
+ userSelect="none"
99
114
  >id: {selection?.[0]?.id}</Text>);
100
115
  }
101
116
  setContextMenuItemComponents(contextMenuItemComponents);
@@ -115,7 +115,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
115
115
  setEditorMode(EDITOR_MODE__EDIT);
116
116
  setIsEditorShown(true);
117
117
  },
118
- onDelete = async () => {
118
+ onDelete = async (cb) => {
119
119
  if (getListeners().onBeforeDelete) {
120
120
  const listenerResult = await getListeners().onBeforeDelete();
121
121
  if (listenerResult === false) {
@@ -126,7 +126,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
126
126
  isSingle = selection.length === 1,
127
127
  firstSelection = selection[0],
128
128
  isTree = firstSelection?.isTree,
129
- hasChildren = firstSelection?.hasChildren,
129
+ hasChildren = isTree ? firstSelection?.hasChildren : false,
130
130
  isPhantom = firstSelection?.isPhantom;
131
131
 
132
132
  if (isSingle && isTree && hasChildren) {
@@ -135,10 +135,10 @@ export default function withEditor(WrappedComponent, isTree = false) {
135
135
  message: 'The node you have selected for deletion has children. ' +
136
136
  'Should these children be moved up to this node\'s parent, or be deleted?',
137
137
  buttons: [
138
- <Button colorScheme="danger" onPress={onMoveChildren} key="moveBtn">
138
+ <Button colorScheme="danger" onPress={() => onMoveChildren(cb)} key="moveBtn">
139
139
  Move Children
140
140
  </Button>,
141
- <Button colorScheme="danger" onPress={onDeleteChildren} key="deleteBtn">
141
+ <Button colorScheme="danger" onPress={() => onDeleteChildren(cb)} key="deleteBtn">
142
142
  Delete Children
143
143
  </Button>
144
144
  ],
@@ -146,21 +146,21 @@ export default function withEditor(WrappedComponent, isTree = false) {
146
146
  });
147
147
  } else
148
148
  if (isSingle && isPhantom) {
149
- deleteRecord();
149
+ deleteRecord(cb);
150
150
  } else {
151
151
  const identifier = getRecordIdentifier(selection);
152
- confirm('Are you sure you want to delete the ' + identifier, deleteRecord);
152
+ confirm('Are you sure you want to delete the ' + identifier, () => deleteRecord(cb));
153
153
  }
154
154
  },
155
- onMoveChildren = () => {
155
+ onMoveChildren = (cb) => {
156
156
  hideAlert();
157
- deleteRecord(true);
157
+ deleteRecord(true, cb);
158
158
  },
159
- onDeleteChildren = () => {
159
+ onDeleteChildren = (cb) => {
160
160
  hideAlert();
161
- deleteRecord();
161
+ deleteRecord(false, cb);
162
162
  },
163
- deleteRecord = async (moveSubtreeUp) => {
163
+ deleteRecord = async (moveSubtreeUp, cb) => {
164
164
  if (getListeners().onBeforeDeleteSave) {
165
165
  await getListeners().onBeforeDeleteSave(selection);
166
166
  }
@@ -172,6 +172,9 @@ export default function withEditor(WrappedComponent, isTree = false) {
172
172
  if (getListeners().onAfterDelete) {
173
173
  await getListeners().onAfterDelete(selection);
174
174
  }
175
+ if (cb) {
176
+ cb();
177
+ }
175
178
  },
176
179
  viewRecord = async () => {
177
180
  if (!userCanView) {
@@ -259,17 +262,10 @@ export default function withEditor(WrappedComponent, isTree = false) {
259
262
  setIsEditorShown(false);
260
263
  },
261
264
  onEditorDelete = async () => {
262
- if (getListeners().onBeforeDeleteSave) {
263
- await getListeners().onBeforeDeleteSave(selection);
264
- }
265
-
266
- await deleteRecord();
267
- setEditorMode(EDITOR_MODE__VIEW);
268
- setIsEditorShown(false);
269
-
270
- if (getListeners().onAfterDelete) {
271
- await getListeners().onAfterDelete(selection);
272
- }
265
+ onDelete(() => {
266
+ setEditorMode(EDITOR_MODE__VIEW);
267
+ setIsEditorShown(false);
268
+ });
273
269
  },
274
270
  calculateEditorMode = () => {
275
271
  let mode = EDITOR_MODE__VIEW;
@@ -58,9 +58,6 @@ export default function withInlineEditor(WrappedComponent) {
58
58
  moveEditor(currentRow);
59
59
  },
60
60
  moveEditor = (currentRow) => {
61
- if (!inlineEditorRef.current) {
62
- debugger;
63
- }
64
61
  const
65
62
  rowBounds = currentRow.getBoundingClientRect(),
66
63
  editor = inlineEditorRef.current,
@@ -24,6 +24,12 @@ const presetButtons = [
24
24
 
25
25
  export default function withPresetButtons(WrappedComponent, isGrid = false) {
26
26
  return (props) => {
27
+
28
+ if (props.disablePresetButtons) {
29
+ // bypass everything
30
+ return <WrappedComponent {...props} />;
31
+ }
32
+
27
33
  const {
28
34
  // extract and pass
29
35
  contextMenuItems,
@@ -13,7 +13,7 @@ import BooleanCombo from './Form/Field/Combo/BooleanCombo.js';
13
13
  import CheckboxGroup from './Form/Field/CheckboxGroup/CheckboxGroup.js';
14
14
  import Color from './Form/Field/Color.js';
15
15
  import Combo from './Form/Field/Combo/Combo.js';
16
- // import ComboEditor from '../Components/Form/Field/Combo/ComboEditor.js';
16
+ // import { ComboEditor } from '../Components/Form/Field/Combo/Combo.js';
17
17
  import Container from './Container/Container.js';
18
18
  import DataMgt from './Screens/DataMgt.js';
19
19
  import Date from './Form/Field/Date.js';
@@ -1,22 +0,0 @@
1
- import withAlert from '../../../Hoc/withAlert.js';
2
- import withData from '../../../Hoc/withData.js';
3
- import withPresetButtons from '../../../Hoc/withPresetButtons.js';
4
- import withSelection from '../../../Hoc/withSelection.js';
5
- import withValue from '../../../Hoc/withValue.js';
6
- import withWindowedEditor from '../../../Hoc/withWindowedEditor.js';
7
- import { Combo } from './Combo.js';
8
-
9
- export default
10
- // withAlert(
11
- withData(
12
- withValue(
13
- withSelection(
14
- withWindowedEditor(
15
- withPresetButtons(
16
- Combo
17
- )
18
- )
19
- )
20
- )
21
- );
22
- //);