@onehat/ui 0.2.39 → 0.2.41
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,8 +1,8 @@
|
|
|
1
|
-
import { useState, } from 'react';
|
|
1
|
+
import { useEffect, useState, } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
EDITOR_MODE__VIEW,
|
|
4
|
+
EDITOR_MODE__ADD,
|
|
5
|
+
EDITOR_MODE__EDIT,
|
|
6
6
|
} from '../../Constants/Editor.js';
|
|
7
7
|
import _ from 'lodash';
|
|
8
8
|
|
|
@@ -38,7 +38,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
38
38
|
[currentRecord, setCurrentRecord] = useState(null),
|
|
39
39
|
[isEditorShown, setIsEditorShown] = useState(false),
|
|
40
40
|
[isEditorViewOnly, setIsEditorViewOnly] = useState(false),
|
|
41
|
-
[
|
|
41
|
+
[editorMode, setEditorMode] = useState(EDITOR_MODE__VIEW),
|
|
42
42
|
addRecord = async () => {
|
|
43
43
|
if (!userCanEdit) {
|
|
44
44
|
return;
|
|
@@ -48,7 +48,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
48
48
|
entity = await Repository.add(defaultValues, false, true, true);
|
|
49
49
|
setSelection([entity]);
|
|
50
50
|
setIsEditorViewOnly(false);
|
|
51
|
-
|
|
51
|
+
setEditorMode(EDITOR_MODE__ADD);
|
|
52
52
|
setIsEditorShown(true);
|
|
53
53
|
},
|
|
54
54
|
editRecord = () => {
|
|
@@ -56,7 +56,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
setIsEditorViewOnly(false);
|
|
59
|
-
|
|
59
|
+
setEditorMode(EDITOR_MODE__EDIT);
|
|
60
60
|
setIsEditorShown(true);
|
|
61
61
|
},
|
|
62
62
|
deleteRecord = (e) => {
|
|
@@ -88,7 +88,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
setIsEditorViewOnly(true);
|
|
91
|
-
|
|
91
|
+
setEditorMode(EDITOR_MODE__VIEW);
|
|
92
92
|
setIsEditorShown(true);
|
|
93
93
|
},
|
|
94
94
|
duplicateRecord = async () => {
|
|
@@ -141,13 +141,26 @@ export default function withEditor(WrappedComponent) {
|
|
|
141
141
|
setIsEditorShown(false);
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (selection.length === 1 && selection.isPhantom && userCanEdit) {
|
|
146
|
+
if (editorMode !== EDITOR_MODE__ADD) {
|
|
147
|
+
setEditorMode(EDITOR_MODE__ADD);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
if (editorMode !== EDITOR_MODE__VIEW) {
|
|
151
|
+
setEditorMode(EDITOR_MODE__VIEW);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}, [selection]);
|
|
155
|
+
|
|
144
156
|
return <WrappedComponent
|
|
145
157
|
{...props}
|
|
146
158
|
currentRecord={currentRecord}
|
|
147
159
|
setCurrentRecord={setCurrentRecord}
|
|
148
160
|
isEditorShown={isEditorShown}
|
|
149
161
|
isEditorViewOnly={isEditorViewOnly}
|
|
150
|
-
|
|
162
|
+
editorMode={editorMode}
|
|
163
|
+
setEditorMode={setEditorMode}
|
|
151
164
|
setIsEditorShown={setIsEditorShown}
|
|
152
165
|
onAdd={addRecord}
|
|
153
166
|
onEdit={editRecord}
|
package/src/Constants/Editor.js
CHANGED
|
@@ -3,6 +3,6 @@ export const EDITOR_TYPE__WINDOWED = 'EDITOR_TYPE__WINDOWED';
|
|
|
3
3
|
export const EDITOR_TYPE__SIDE = 'EDITOR_TYPE__SIDE';
|
|
4
4
|
export const EDITOR_TYPE__SMART = 'EDITOR_TYPE__SMART';
|
|
5
5
|
export const EDITOR_TYPE__PLAIN = 'EDITOR_TYPE__PLAIN';
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
6
|
+
export const EDITOR_MODE__VIEW = 'EDITOR_MODE__VIEW';
|
|
7
|
+
export const EDITOR_MODE__ADD = 'EDITOR_MODE__ADD';
|
|
8
|
+
export const EDITOR_MODE__EDIT = 'EDITOR_MODE__EDIT';
|