@onehat/ui 0.3.55 → 0.3.56
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
|
@@ -31,7 +31,7 @@ function Editor(props) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Repository?.isRemotePhantomMode && selection.length === 1 &&
|
|
34
|
-
if (editorMode === EDITOR_MODE__VIEW) {
|
|
34
|
+
if (editorMode === EDITOR_MODE__VIEW || isEditorViewOnly) {
|
|
35
35
|
const record = selection[0];
|
|
36
36
|
if (record.isDestroyed) {
|
|
37
37
|
return null;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { useState, } from 'react';
|
|
1
2
|
import {
|
|
2
3
|
Column,
|
|
3
|
-
|
|
4
|
+
Modal,
|
|
4
5
|
Row,
|
|
5
6
|
Text,
|
|
6
7
|
} from 'native-base';
|
|
8
|
+
import {
|
|
9
|
+
EDITOR_TYPE__WINDOWED,
|
|
10
|
+
} from '@onehat/ui/src/Constants/Editor.js';
|
|
11
|
+
import withAlert from '../../../Hoc/withAlert.js';
|
|
7
12
|
import withComponent from '../../../Hoc/withComponent.js';
|
|
8
13
|
import withData from '../../../Hoc/withData.js';
|
|
9
14
|
import withValue from '../../../Hoc/withValue.js';
|
|
10
15
|
import IconButton from '../../../Buttons/IconButton.js';
|
|
16
|
+
import Eye from '../../../Icons/Eye.js';
|
|
11
17
|
import Xmark from '../../../Icons/Xmark.js';
|
|
12
18
|
import Combo, { ComboEditor } from '../Combo/Combo.js';
|
|
13
19
|
import _ from 'lodash';
|
|
@@ -16,6 +22,7 @@ import _ from 'lodash';
|
|
|
16
22
|
function ValueBox(props) {
|
|
17
23
|
const {
|
|
18
24
|
text,
|
|
25
|
+
onView,
|
|
19
26
|
onDelete,
|
|
20
27
|
} = props;
|
|
21
28
|
|
|
@@ -23,31 +30,72 @@ function ValueBox(props) {
|
|
|
23
30
|
borderWidth={1}
|
|
24
31
|
borderColor="trueGray.400"
|
|
25
32
|
borderRadius="md"
|
|
26
|
-
pl={2}
|
|
27
33
|
mr={1}
|
|
28
34
|
bg="trueGray.200"
|
|
29
35
|
alignItems="center"
|
|
30
36
|
>
|
|
31
|
-
<Text color="trueGray.600">{text}</Text>
|
|
32
37
|
<IconButton
|
|
33
38
|
_icon={{
|
|
34
|
-
as:
|
|
39
|
+
as: Eye,
|
|
35
40
|
color: 'trueGray.600',
|
|
36
41
|
size: 'sm',
|
|
37
42
|
}}
|
|
38
|
-
onPress={
|
|
43
|
+
onPress={onView}
|
|
39
44
|
h="100%"
|
|
40
45
|
/>
|
|
46
|
+
<Text color="trueGray.600">{text}</Text>
|
|
47
|
+
{onDelete &&
|
|
48
|
+
<IconButton
|
|
49
|
+
_icon={{
|
|
50
|
+
as: Xmark,
|
|
51
|
+
color: 'trueGray.600',
|
|
52
|
+
size: 'sm',
|
|
53
|
+
}}
|
|
54
|
+
onPress={onDelete}
|
|
55
|
+
h="100%"
|
|
56
|
+
/>}
|
|
41
57
|
</Row>;
|
|
42
58
|
}
|
|
43
59
|
|
|
44
60
|
function TagComponent(props) {
|
|
45
61
|
|
|
46
62
|
const {
|
|
63
|
+
isEditor = false,
|
|
64
|
+
isValueAlwaysArray,
|
|
65
|
+
isValueAsStringifiedJson,
|
|
66
|
+
Editor,
|
|
67
|
+
|
|
68
|
+
// parent Form
|
|
69
|
+
onChangeValue,
|
|
70
|
+
|
|
71
|
+
// withComponent
|
|
72
|
+
self,
|
|
73
|
+
|
|
47
74
|
// withValue
|
|
48
75
|
value = [],
|
|
49
76
|
setValue,
|
|
77
|
+
...propsToPass // break connection between Tag and Combo props
|
|
50
78
|
} = props,
|
|
79
|
+
[isViewerShown, setIsViewerShown] = useState(false),
|
|
80
|
+
[viewerSelection, setViewerSelection] = useState(false),
|
|
81
|
+
onViewerClose = () => setIsViewerShown(false),
|
|
82
|
+
onView = async (item, e) => {
|
|
83
|
+
const
|
|
84
|
+
id = item.id,
|
|
85
|
+
repository = propsToPass.Repository;
|
|
86
|
+
let record = repository.getById(id); // first try to get from entities in memory
|
|
87
|
+
if (!record && repository.getSingleEntityFromServer) {
|
|
88
|
+
record = await repository.getSingleEntityFromServer(id); // TODO: Build this
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!record) {
|
|
92
|
+
alert('Record could not be found!');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setViewerSelection([record]);
|
|
97
|
+
setIsViewerShown(true);
|
|
98
|
+
},
|
|
51
99
|
onAdd = (item, e) => {
|
|
52
100
|
// make sure value doesn't already exist
|
|
53
101
|
let exists = false;
|
|
@@ -57,16 +105,18 @@ function TagComponent(props) {
|
|
|
57
105
|
return false; // break
|
|
58
106
|
}
|
|
59
107
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const newValue = _.clone(value); // so we trigger a re-render
|
|
64
|
-
newValue.push({
|
|
65
|
-
id: item.getId(),
|
|
66
|
-
text: item.getDisplayValue(),
|
|
67
|
-
})
|
|
68
|
-
setValue(newValue);
|
|
108
|
+
if (exists) {
|
|
109
|
+
alert('Value already exists!');
|
|
110
|
+
return;
|
|
69
111
|
}
|
|
112
|
+
|
|
113
|
+
// add new value
|
|
114
|
+
const newValue = _.clone(value); // so we trigger a re-render
|
|
115
|
+
newValue.push({
|
|
116
|
+
id: item.getId(),
|
|
117
|
+
text: item.getDisplayValue(),
|
|
118
|
+
})
|
|
119
|
+
setValue(newValue);
|
|
70
120
|
},
|
|
71
121
|
onDelete = (val) => {
|
|
72
122
|
// Remove from value array
|
|
@@ -76,29 +126,51 @@ function TagComponent(props) {
|
|
|
76
126
|
setValue(newValue);
|
|
77
127
|
},
|
|
78
128
|
valueBoxes = _.map(value, (val, ix) => {
|
|
79
|
-
return <ValueBox
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
129
|
+
return <ValueBox
|
|
130
|
+
key={ix}
|
|
131
|
+
text={val.text}
|
|
132
|
+
onView={() => onView(val)}
|
|
133
|
+
onDelete={isEditor ? () => onDelete(val) : null}
|
|
134
|
+
/>;
|
|
135
|
+
}),
|
|
136
|
+
WhichCombo = isEditor ? ComboEditor : Combo;
|
|
137
|
+
|
|
138
|
+
return <>
|
|
139
|
+
<Column w="100%" flex={1}>
|
|
140
|
+
{!_.isEmpty(valueBoxes) &&
|
|
141
|
+
<Row
|
|
142
|
+
w="100%"
|
|
143
|
+
borderWidth={1}
|
|
144
|
+
borderColor="trueGray.300"
|
|
145
|
+
borderRadius="md"
|
|
146
|
+
bg="trueGray.100"
|
|
147
|
+
p={1}
|
|
148
|
+
mb={1}
|
|
149
|
+
flexWrap="wrap"
|
|
150
|
+
>{valueBoxes}</Row>}
|
|
151
|
+
<WhichCombo
|
|
152
|
+
Repository={props.Repository}
|
|
153
|
+
Editor={props.Editor}
|
|
154
|
+
onRowPress={onAdd}
|
|
155
|
+
/>
|
|
156
|
+
</Column>
|
|
157
|
+
{isViewerShown &&
|
|
158
|
+
<Modal
|
|
159
|
+
isOpen={true}
|
|
160
|
+
onClose={onViewerClose}
|
|
161
|
+
>
|
|
162
|
+
<Editor
|
|
163
|
+
editorType={EDITOR_TYPE__WINDOWED}
|
|
164
|
+
{...propsToPass}
|
|
165
|
+
parent={self}
|
|
166
|
+
reference="viewer"
|
|
167
|
+
|
|
168
|
+
isEditorViewOnly={true}
|
|
169
|
+
selection={viewerSelection}
|
|
170
|
+
onEditorClose={onViewerClose}
|
|
171
|
+
/>
|
|
172
|
+
</Modal>}
|
|
173
|
+
</>;
|
|
102
174
|
|
|
103
175
|
}
|
|
104
176
|
|
|
@@ -114,15 +186,37 @@ function withAdditionalProps(WrappedComponent) {
|
|
|
114
186
|
|
|
115
187
|
export const Tag = withAdditionalProps(
|
|
116
188
|
withComponent(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
189
|
+
withAlert(
|
|
190
|
+
withData(
|
|
191
|
+
withValue(
|
|
192
|
+
TagComponent
|
|
193
|
+
)
|
|
120
194
|
)
|
|
121
195
|
)
|
|
122
196
|
)
|
|
123
197
|
);
|
|
124
198
|
|
|
125
|
-
|
|
126
|
-
|
|
199
|
+
function withAdditionalEditorProps(WrappedComponent) {
|
|
200
|
+
return (props) => {
|
|
201
|
+
return <WrappedComponent
|
|
202
|
+
isEditor={true}
|
|
203
|
+
isValueAlwaysArray={true}
|
|
204
|
+
isValueAsStringifiedJson={true}
|
|
205
|
+
{...props}
|
|
206
|
+
/>;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const TagEditor = withAdditionalEditorProps(
|
|
211
|
+
withComponent(
|
|
212
|
+
withAlert(
|
|
213
|
+
withData(
|
|
214
|
+
withValue(
|
|
215
|
+
TagComponent
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
)
|
|
220
|
+
);
|
|
127
221
|
|
|
128
222
|
export default Tag;
|
|
@@ -13,15 +13,13 @@ import {
|
|
|
13
13
|
ALERT_MODE_YES_NO,
|
|
14
14
|
ALERT_MODE_CUSTOM,
|
|
15
15
|
} from '../../Constants/Alert.js';
|
|
16
|
-
import Panel from '../Panel/Panel.js';
|
|
17
|
-
import Footer from '../Layout/Footer.js';
|
|
18
16
|
import TriangleExclamation from '../Icons/TriangleExclamation.js';
|
|
19
17
|
import _ from 'lodash';
|
|
20
18
|
|
|
21
19
|
export default function withAlert(WrappedComponent) {
|
|
22
20
|
return (props) => {
|
|
23
21
|
|
|
24
|
-
if (props.disableWithAlert) {
|
|
22
|
+
if (props.disableWithAlert || props.alert) {
|
|
25
23
|
return <WrappedComponent {...props} />;
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -256,11 +256,12 @@ function Viewer(props) {
|
|
|
256
256
|
color="#fff"
|
|
257
257
|
>Delete</Button>
|
|
258
258
|
</Row>}
|
|
259
|
-
{showCloseBtn &&
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
{onClose && showCloseBtn &&
|
|
260
|
+
<Button
|
|
261
|
+
key="closeBtn"
|
|
262
|
+
onPress={onClose}
|
|
263
|
+
color="#fff"
|
|
264
|
+
>Close</Button>}
|
|
264
265
|
</Footer>}
|
|
265
266
|
|
|
266
267
|
</>}
|