@onehat/ui 0.2.43 → 0.2.44
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 +1 -1
- package/src/Components/Editor/Editor.js +58 -0
- package/src/Components/Form/Field/Input.js +1 -1
- package/src/Components/Grid/Grid.js +3 -3
- package/src/Components/Grid/GridRow.js +1 -1
- package/src/Components/Hoc/withEditor.js +1 -1
- package/src/Components/Hoc/withPresetButtons.js +30 -0
- package/src/Components/Screens/DataMgt.js +1 -1
- package/src/Hooks/useAdjustedWindowSize.js +18 -0
- package/src/Hooks/useWindowSize.js +25 -0
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDITOR_MODE__VIEW,
|
|
3
|
+
EDITOR_MODE__ADD,
|
|
4
|
+
EDITOR_MODE__EDIT,
|
|
5
|
+
} from '../../Constants/Editor.js';
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default function Editor(props) {
|
|
10
|
+
const {
|
|
11
|
+
Form,
|
|
12
|
+
Viewer,
|
|
13
|
+
isEditorViewOnly: isViewOnly,
|
|
14
|
+
onEditorCancel: onCancel,
|
|
15
|
+
onEditorSave: onSave,
|
|
16
|
+
onEditorClose: onClose,
|
|
17
|
+
editorMode,
|
|
18
|
+
setEditorMode,
|
|
19
|
+
|
|
20
|
+
// withData
|
|
21
|
+
Repository,
|
|
22
|
+
|
|
23
|
+
// withSelection
|
|
24
|
+
selection,
|
|
25
|
+
|
|
26
|
+
} = props,
|
|
27
|
+
onEditMode = () => {
|
|
28
|
+
setEditorMode(EDITOR_MODE__EDIT);
|
|
29
|
+
},
|
|
30
|
+
onBack = () => {
|
|
31
|
+
setEditorMode(EDITOR_MODE__VIEW);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (_.isEmpty(selection)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Repository.isRemotePhantomMode && selection.length === 1 && editorMode === EDITOR_MODE__VIEW) {
|
|
39
|
+
return <Viewer
|
|
40
|
+
record={selection[0]}
|
|
41
|
+
Repository={Repository}
|
|
42
|
+
onEditMode={isViewOnly ? null : onEditMode}
|
|
43
|
+
{...props}
|
|
44
|
+
/>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// NOTE: Ideally, this form should use multiple columns when screen is wide enough,
|
|
48
|
+
// and only show in one column when it's not.
|
|
49
|
+
|
|
50
|
+
return <Form
|
|
51
|
+
record={selection}
|
|
52
|
+
onBack={onBack}
|
|
53
|
+
onCancel={onCancel}
|
|
54
|
+
onSave={onSave}
|
|
55
|
+
onClose={onClose}
|
|
56
|
+
{...props}
|
|
57
|
+
/>;
|
|
58
|
+
}
|
|
@@ -14,7 +14,7 @@ function InputElement(props) {
|
|
|
14
14
|
let {
|
|
15
15
|
value,
|
|
16
16
|
setValue,
|
|
17
|
-
autoSubmit =
|
|
17
|
+
autoSubmit = true, // automatically setValue after user stops typing for autoSubmitDelay
|
|
18
18
|
autoSubmitDelay = AUTO_SUBMIT_DELAY,
|
|
19
19
|
maxLength,
|
|
20
20
|
onKeyPress,
|
|
@@ -751,11 +751,11 @@ export function Grid(props) {
|
|
|
751
751
|
return () => {};
|
|
752
752
|
}
|
|
753
753
|
if (!disableSelectorSelected) {
|
|
754
|
-
let
|
|
754
|
+
let id = selectorSelected?.id;
|
|
755
755
|
if (_.isEmpty(selectorSelected)) {
|
|
756
|
-
|
|
756
|
+
id = noSelectorMeansNoResults ? 'NO_MATCHES' : null;
|
|
757
757
|
}
|
|
758
|
-
Repository.filter(selectorId,
|
|
758
|
+
Repository.filter(selectorId, id, false); // so it doesn't clear existing filters
|
|
759
759
|
}
|
|
760
760
|
|
|
761
761
|
}, [selectorId, selectorSelected]);
|
|
@@ -162,7 +162,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
162
162
|
// For multiple entities selected, change it to edit multiple mode
|
|
163
163
|
mode = EDITOR_MODE__EDIT;
|
|
164
164
|
}
|
|
165
|
-
} else if (selection.length === 1 && selection.isPhantom) {
|
|
165
|
+
} else if (selection.length === 1 && selection[0].isPhantom) {
|
|
166
166
|
if (!disableAdd) {
|
|
167
167
|
// When a phantom entity is selected, change it to add mode.
|
|
168
168
|
mode = EDITOR_MODE__ADD;
|
|
@@ -126,29 +126,59 @@ export default function withPresetButtons(WrappedComponent) {
|
|
|
126
126
|
text = 'Edit';
|
|
127
127
|
handler = onEdit;
|
|
128
128
|
icon = <Edit />;
|
|
129
|
+
if (selectorId && !selectorSelected) {
|
|
130
|
+
isDisabled = true;
|
|
131
|
+
}
|
|
132
|
+
if (_.isEmpty(selection)) {
|
|
133
|
+
isDisabled = true;
|
|
134
|
+
}
|
|
129
135
|
break;
|
|
130
136
|
case 'delete':
|
|
131
137
|
text = 'Delete';
|
|
132
138
|
handler = onDelete;
|
|
133
139
|
icon = <Trash />;
|
|
140
|
+
if (selectorId && !selectorSelected) {
|
|
141
|
+
isDisabled = true;
|
|
142
|
+
}
|
|
143
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
144
|
+
isDisabled = true;
|
|
145
|
+
}
|
|
134
146
|
break;
|
|
135
147
|
case 'view':
|
|
136
148
|
text = 'View';
|
|
137
149
|
handler = onView;
|
|
138
150
|
icon = <Eye />;
|
|
139
151
|
isDisabled = !selection.length || selection.length !== 1;
|
|
152
|
+
if (selectorId && !selectorSelected) {
|
|
153
|
+
isDisabled = true;
|
|
154
|
+
}
|
|
155
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
156
|
+
isDisabled = true;
|
|
157
|
+
}
|
|
140
158
|
break;
|
|
141
159
|
case 'copy':
|
|
142
160
|
text = 'Copy to Clipboard';
|
|
143
161
|
handler = onCopyToClipboard;
|
|
144
162
|
icon = <Clipboard />;
|
|
145
163
|
isDisabled = !selection.length;
|
|
164
|
+
if (selectorId && !selectorSelected) {
|
|
165
|
+
isDisabled = true;
|
|
166
|
+
}
|
|
167
|
+
if (_.isEmpty(selection)) {
|
|
168
|
+
isDisabled = true;
|
|
169
|
+
}
|
|
146
170
|
break;
|
|
147
171
|
case 'duplicate':
|
|
148
172
|
text = 'Duplicate';
|
|
149
173
|
handler = onDuplicate;
|
|
150
174
|
icon = <Duplicate />;
|
|
151
175
|
isDisabled = !selection.length || selection.length !== 1;
|
|
176
|
+
if (selectorId && !selectorSelected) {
|
|
177
|
+
isDisabled = true;
|
|
178
|
+
}
|
|
179
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
180
|
+
isDisabled = true;
|
|
181
|
+
}
|
|
152
182
|
break;
|
|
153
183
|
// case 'print':
|
|
154
184
|
// text = 'Print';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import useWindowSize from './useWindowSize.js';
|
|
2
|
+
|
|
3
|
+
// This hook takes the submitted window size and adjusts it
|
|
4
|
+
// to fit the actual screen size
|
|
5
|
+
|
|
6
|
+
export default function(width, height, percentage = 0.9) {
|
|
7
|
+
|
|
8
|
+
const windowSize = useWindowSize();
|
|
9
|
+
|
|
10
|
+
if (width > windowSize.width) {
|
|
11
|
+
width = windowSize.width * percentage;
|
|
12
|
+
}
|
|
13
|
+
if (height > windowSize.height) {
|
|
14
|
+
height = windowSize.height * percentage;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return [ width, height, ];
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// from https://designcode.io/react-hooks-usewindowsize-hook
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
// For web only!
|
|
6
|
+
export default function useWindowSize() {
|
|
7
|
+
const [windowSize, setWindowSize] = useState({ width: 0, height: 0 });
|
|
8
|
+
|
|
9
|
+
const handleSize = () => {
|
|
10
|
+
setWindowSize({
|
|
11
|
+
width: window.innerWidth,
|
|
12
|
+
height: window.innerHeight
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
handleSize();
|
|
18
|
+
|
|
19
|
+
window.addEventListener('resize', handleSize);
|
|
20
|
+
|
|
21
|
+
return () => window.removeEventListener('resize', handleSize);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return windowSize;
|
|
25
|
+
};
|