@onehat/ui 0.3.10 → 0.3.11

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.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -11,7 +11,7 @@ export default function Editor(props) {
11
11
  const {
12
12
  Form,
13
13
  Viewer,
14
- isEditorViewOnly: isViewOnly,
14
+ isEditorViewOnly,
15
15
  onEditorCancel: onCancel,
16
16
  onEditorSave: onSave,
17
17
  onEditorClose: onClose,
@@ -36,7 +36,7 @@ export default function Editor(props) {
36
36
  return <Viewer
37
37
  {...props}
38
38
  record={selection[0]}
39
- onEditMode={isViewOnly ? null : onEditMode}
39
+ onEditMode={isEditorViewOnly ? null : onEditMode}
40
40
  onClose={onClose}
41
41
  onDelete={onDelete}
42
42
  />;
@@ -49,7 +49,7 @@ export default function Viewer(props) {
49
49
  Element = getComponentFromType(type),
50
50
  element = <Element
51
51
  selectorId={selectorId}
52
- selectorSelected={selectorId ? record : selectorSelected}
52
+ selectorSelected={selectorSelected || record}
53
53
  flex={1}
54
54
  {...propsToPass}
55
55
  />;
@@ -81,7 +81,7 @@ function Form(props) {
81
81
  Repository,
82
82
 
83
83
  // withEditor
84
- isViewOnly = false,
84
+ isEditorViewOnly = false,
85
85
  editorMode,
86
86
  onCancel,
87
87
  onSave,
@@ -299,7 +299,7 @@ function Form(props) {
299
299
  label = propertyDef.title;
300
300
  }
301
301
 
302
- if (isViewOnly || !isEditable) {
302
+ if (isEditorViewOnly || !isEditable) {
303
303
  const
304
304
  Text = getComponentFromType('Text'),
305
305
  value = (record && record[name]) || (startingValues && startingValues[name]) || null;
@@ -585,7 +585,7 @@ function Form(props) {
585
585
  </Row>}
586
586
  <Button.Group space={2} {...buttonGroupProps}>
587
587
 
588
- {!isViewOnly && <IconButton
588
+ {!isEditorViewOnly && <IconButton
589
589
  key="resetBtn"
590
590
  onPress={() => {
591
591
  if (onReset) {
@@ -595,19 +595,19 @@ function Form(props) {
595
595
  }}
596
596
  icon={<Rotate color="#fff" />}
597
597
  />}
598
- {!isViewOnly && onCancel && <Button
598
+ {!isEditorViewOnly && onCancel && <Button
599
599
  key="cancelBtn"
600
600
  variant="ghost"
601
601
  onPress={onCancel}
602
602
  color="#fff"
603
603
  >Cancel</Button>}
604
- {!isViewOnly && onSave && <Button
604
+ {!isEditorViewOnly && onSave && <Button
605
605
  key="saveBtn"
606
606
  onPress={(e) => handleSubmit(onSave, onSubmitError)(e)}
607
607
  isDisabled={isSaveDisabled}
608
608
  color="#fff"
609
609
  >{editorMode === EDITOR_MODE__ADD ? 'Add' : 'Save'}</Button>}
610
- {isViewOnly && onClose && <Button
610
+ {isEditorViewOnly && onClose && <Button
611
611
  key="closeBtn"
612
612
  onPress={onClose}
613
613
  color="#fff"
@@ -14,9 +14,9 @@ export default function withEditor(WrappedComponent, isTree = false) {
14
14
 
15
15
  let [editorMode, setEditorMode] = useState(EDITOR_MODE__VIEW); // Can change below, so use 'let'
16
16
  const {
17
- useEditor = true,
18
17
  userCanEdit = true,
19
18
  userCanView = true,
19
+ canEditorViewOnly = false,
20
20
  disableAdd = false,
21
21
  disableEdit = false,
22
22
  disableDelete = false,
@@ -50,7 +50,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
50
50
  editorStateRef = useRef(),
51
51
  [currentRecord, setCurrentRecord] = useState(null),
52
52
  [isEditorShown, setIsEditorShown] = useState(false),
53
- [isEditorViewOnly, setIsEditorViewOnly] = useState(false),
53
+ [isEditorViewOnly, setIsEditorViewOnly] = useState(canEditorViewOnly),
54
54
  [lastSelection, setLastSelection] = useState(),
55
55
  setSelectionDecorated = (newSelection) => {
56
56
  function doIt() {
@@ -198,8 +198,8 @@ export default function withEditor(WrappedComponent, isTree = false) {
198
198
  setEditorMode(EDITOR_MODE__VIEW);
199
199
  setIsEditorShown(true);
200
200
 
201
- if (getListeners().onAfterDelete) {
202
- await getListeners().onAfterDelete(entity);
201
+ if (getListeners().onAfterView) {
202
+ await getListeners().onAfterView(entity);
203
203
  }
204
204
  },
205
205
  duplicateRecord = async () => {
@@ -279,8 +279,8 @@ export default function withEditor(WrappedComponent, isTree = false) {
279
279
  });
280
280
  },
281
281
  calculateEditorMode = () => {
282
- let mode = EDITOR_MODE__VIEW;
283
- if (userCanEdit) {
282
+ let mode = editorMode;
283
+ if (!canEditorViewOnly && userCanEdit) {
284
284
  if (selection.length > 1) {
285
285
  if (!disableEdit) {
286
286
  // For multiple entities selected, change it to edit multiple mode
@@ -314,6 +314,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
314
314
  // When selection changes, set the mode appropriately
315
315
  const mode = calculateEditorMode();
316
316
  setEditorMode(mode);
317
+
317
318
  setLastSelection(selection);
318
319
  }, [selection]);
319
320
 
@@ -345,7 +346,6 @@ export default function withEditor(WrappedComponent, isTree = false) {
345
346
  onEditorClose={onEditorClose}
346
347
  setWithEditListeners={setListeners}
347
348
  isEditor={true}
348
- useEditor={useEditor}
349
349
  userCanEdit={userCanEdit}
350
350
  userCanView={userCanView}
351
351
  disableAdd={disableAdd}
@@ -21,9 +21,8 @@ import _ from 'lodash';
21
21
  export default function withInlineEditor(WrappedComponent) {
22
22
  return withEditor((props) => {
23
23
  const {
24
- useEditor = false,
25
24
  editorType,
26
- isEditorShown,
25
+ isEditorShown = false,
27
26
  setIsEditorShown,
28
27
  isEditorViewOnly,
29
28
  onEditorCancel,
@@ -79,7 +78,7 @@ export default function withInlineEditor(WrappedComponent) {
79
78
  }
80
79
 
81
80
  let inlineEditor = null;
82
- if (useEditor && Repository) {
81
+ if (Repository) {
83
82
  inlineEditor = <>
84
83
  {isEditorShown && <Box
85
84
  ref={maskRef}
@@ -108,7 +107,7 @@ export default function withInlineEditor(WrappedComponent) {
108
107
  record={selection[0]}
109
108
  Repository={Repository}
110
109
  isMultiple={selection.length > 1}
111
- isViewOnly={isEditorViewOnly}
110
+ isEditorViewOnly={isEditorViewOnly}
112
111
  columnsConfig={localColumnsConfig}
113
112
  onCancel={onEditorCancel}
114
113
  onSave={onEditorSave}
@@ -16,8 +16,8 @@ const presetButtons = [
16
16
  'add',
17
17
  'edit',
18
18
  'delete',
19
- 'copy',
20
19
  'view',
20
+ 'copy',
21
21
  'duplicate',
22
22
  // 'print',
23
23
  ];
@@ -41,13 +41,14 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
41
41
  // for local use
42
42
  isEditor = false,
43
43
  isTree = false,
44
- useEditor = true,
44
+ isSideEditor = false,
45
+ canEditorViewOnly = false,
45
46
  disableAdd = !isEditor,
46
47
  disableEdit = !isEditor,
47
48
  disableDelete = !isEditor,
48
49
  disableView = !isGrid,
49
50
  disableCopy = !isGrid,
50
- disableDuplicate = !isGrid,
51
+ disableDuplicate = !isEditor,
51
52
  disablePrint = !isGrid,
52
53
 
53
54
  // withEditor
@@ -81,22 +82,22 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
81
82
  let isDisabled = false;
82
83
  switch(type) {
83
84
  case 'add':
84
- if (disableAdd || !useEditor) {
85
+ if (disableAdd || canEditorViewOnly) {
85
86
  isDisabled = true;
86
87
  }
87
88
  break;
88
89
  case 'edit':
89
- if (disableEdit || !useEditor) {
90
+ if (disableEdit || canEditorViewOnly) {
90
91
  isDisabled = true;
91
92
  }
92
93
  break;
93
94
  case 'delete':
94
- if (disableDelete || !useEditor) {
95
+ if (disableDelete || canEditorViewOnly) {
95
96
  isDisabled = true;
96
97
  }
97
98
  break;
98
99
  case 'view':
99
- if (disableView) {
100
+ if (disableView || isSideEditor) {
100
101
  isDisabled = true;
101
102
  }
102
103
  break;
@@ -106,7 +107,7 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
106
107
  }
107
108
  break;
108
109
  case 'duplicate':
109
- if (disableDuplicate || !useEditor) {
110
+ if (disableDuplicate || canEditorViewOnly) {
110
111
  isDisabled = true;
111
112
  }
112
113
  break;
@@ -21,6 +21,7 @@ export default function withSideEditor(WrappedComponent, isTree = false) {
21
21
  return <Container
22
22
  center={<WrappedComponent
23
23
  isTree={isTree}
24
+ isSideEditor={true}
24
25
  {...props}
25
26
  />}
26
27
  east={<Editor
@@ -28,8 +28,7 @@ import _ from 'lodash';
28
28
  export default function withWindowedEditor(WrappedComponent, isTree = false) {
29
29
  return withEditor((props) => {
30
30
  const {
31
- useEditor = false,
32
- isEditorShown,
31
+ isEditorShown = false,
33
32
  setIsEditorShown,
34
33
  Editor,
35
34
  editorProps = {},
@@ -41,7 +40,7 @@ export default function withWindowedEditor(WrappedComponent, isTree = false) {
41
40
 
42
41
  return <>
43
42
  <WrappedComponent {...props} />
44
- {useEditor && isEditorShown &&
43
+ {isEditorShown &&
45
44
  <Modal
46
45
  isOpen={true}
47
46
  onClose={() => setIsEditorShown(false)}