@onehat/ui 0.2.36 → 0.2.37
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/Form/Form.js +17 -16
- package/src/Components/Grid/Grid.js +21 -0
- package/src/Components/Hoc/withEditor.js +10 -0
- package/src/Components/Hoc/withInlineEditor.js +4 -4
- package/src/Components/Hoc/withSideEditor.js +25 -0
- package/src/Components/Hoc/withWindowedEditor.js +7 -5
- package/src/Components/Panel/GridPanel.js +5 -4
- package/src/Constants/Editor.js +8 -0
- package/src/Constants/EditorTypes.js +0 -4
package/package.json
CHANGED
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
Text,
|
|
10
10
|
} from 'native-base';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
EDITOR_TYPE__INLINE,
|
|
13
|
+
EDITOR_TYPE__WINDOWED,
|
|
14
|
+
EDITOR_TYPE__SIDE,
|
|
15
|
+
EDITOR_TYPE__SMART,
|
|
16
|
+
EDITOR_TYPE__PLAIN,
|
|
17
|
+
} from '../../Constants/Editor.js';
|
|
17
18
|
import { useForm, Controller } from 'react-hook-form'; // https://react-hook-form.com/api/
|
|
18
19
|
import * as yup from 'yup'; // https://github.com/jquense/yup#string
|
|
19
20
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
@@ -32,27 +33,27 @@ import _ from 'lodash';
|
|
|
32
33
|
// TODO: memoize field Components
|
|
33
34
|
|
|
34
35
|
// Modes:
|
|
35
|
-
//
|
|
36
|
+
// EDITOR_TYPE__INLINE
|
|
36
37
|
// Form is a single scrollable row, based on columnsConfig and Repository
|
|
37
38
|
//
|
|
38
|
-
//
|
|
39
|
+
// EDITOR_TYPE__WINDOWED
|
|
39
40
|
// Form is a popup window, used for editing items in a grid. Integrated with Repository
|
|
40
41
|
//
|
|
41
|
-
//
|
|
42
|
+
// EDITOR_TYPE__SMART
|
|
42
43
|
// Form is a standalone editor
|
|
43
44
|
//
|
|
44
|
-
//
|
|
45
|
+
// EDITOR_TYPE__PLAIN
|
|
45
46
|
// Form is embedded on screen in some other way. Mainly use startingValues, items, validator
|
|
46
47
|
|
|
47
48
|
function Form(props) {
|
|
48
49
|
const
|
|
49
50
|
{
|
|
50
|
-
editorType =
|
|
51
|
+
editorType = EDITOR_TYPE__WINDOWED, // EDITOR_TYPE__INLINE | EDITOR_TYPE__WINDOWED | EDITOR_TYPE__SIDE | EDITOR_TYPE__SMART | EDITOR_TYPE__PLAIN
|
|
51
52
|
startingValues = {},
|
|
52
53
|
items = [], // Columns, FieldSets, Fields, etc to define the form
|
|
53
54
|
columnDefaults = {}, // defaults for each Column defined in items (above)
|
|
54
|
-
columnsConfig, // Which columns are shown in Grid, so the inline editor can match. Used only for
|
|
55
|
-
validator, // custom validator, mainly for
|
|
55
|
+
columnsConfig, // Which columns are shown in Grid, so the inline editor can match. Used only for EDITOR_TYPE__INLINE
|
|
56
|
+
validator, // custom validator, mainly for EDITOR_TYPE__PLAIN
|
|
56
57
|
footerProps = {},
|
|
57
58
|
buttonGroupProps = {}, // buttons in footer
|
|
58
59
|
|
|
@@ -356,7 +357,7 @@ function Form(props) {
|
|
|
356
357
|
{...editorTypeProps}
|
|
357
358
|
/>;
|
|
358
359
|
if (error) {
|
|
359
|
-
if (editorType !==
|
|
360
|
+
if (editorType !== EDITOR_TYPE__INLINE) {
|
|
360
361
|
element = <Column pt={1} flex={1}>
|
|
361
362
|
{element}
|
|
362
363
|
<Text color="#f00">{error.message}</Text>
|
|
@@ -367,7 +368,7 @@ function Form(props) {
|
|
|
367
368
|
|
|
368
369
|
}
|
|
369
370
|
}
|
|
370
|
-
if (label && editorType !==
|
|
371
|
+
if (label && editorType !== EDITOR_TYPE__INLINE) {
|
|
371
372
|
const labelProps = {};
|
|
372
373
|
if (defaults?.labelWidth) {
|
|
373
374
|
labelProps.w = defaults.labelWidth;
|
|
@@ -385,7 +386,7 @@ function Form(props) {
|
|
|
385
386
|
},
|
|
386
387
|
onSubmitError = (errors, e) => {
|
|
387
388
|
debugger;
|
|
388
|
-
if (editorType ===
|
|
389
|
+
if (editorType === EDITOR_TYPE__INLINE) {
|
|
389
390
|
alert(errors.message);
|
|
390
391
|
}
|
|
391
392
|
};
|
|
@@ -429,7 +430,7 @@ function Form(props) {
|
|
|
429
430
|
|
|
430
431
|
let formComponents,
|
|
431
432
|
editor;
|
|
432
|
-
if (editorType ===
|
|
433
|
+
if (editorType === EDITOR_TYPE__INLINE) {
|
|
433
434
|
// for inline editor
|
|
434
435
|
formComponents = buildFromColumnsConfig();
|
|
435
436
|
editor = <ScrollView
|
|
@@ -27,6 +27,7 @@ import withContextMenu from '../Hoc/withContextMenu.js';
|
|
|
27
27
|
import withAlert from '../Hoc/withAlert.js';
|
|
28
28
|
import withData from '../Hoc/withData.js';
|
|
29
29
|
import withEvents from '../Hoc/withEvents.js';
|
|
30
|
+
import withSideEditor from '../Hoc/withSideEditor.js';
|
|
30
31
|
import withFilters from '../Hoc/withFilters.js';
|
|
31
32
|
import withPresetButtons from '../Hoc/withPresetButtons.js';
|
|
32
33
|
import withMultiSelection from '../Hoc/withMultiSelection.js';
|
|
@@ -839,6 +840,26 @@ export function Grid(props) {
|
|
|
839
840
|
|
|
840
841
|
}
|
|
841
842
|
|
|
843
|
+
export const SideGridEditor = withAlert(
|
|
844
|
+
withEvents(
|
|
845
|
+
withData(
|
|
846
|
+
withMultiSelection(
|
|
847
|
+
withSelection(
|
|
848
|
+
withSideEditor(
|
|
849
|
+
withFilters(
|
|
850
|
+
withPresetButtons(
|
|
851
|
+
withContextMenu(
|
|
852
|
+
Grid
|
|
853
|
+
)
|
|
854
|
+
)
|
|
855
|
+
)
|
|
856
|
+
)
|
|
857
|
+
)
|
|
858
|
+
)
|
|
859
|
+
)
|
|
860
|
+
)
|
|
861
|
+
);
|
|
862
|
+
|
|
842
863
|
export const WindowedGridEditor = withAlert(
|
|
843
864
|
withEvents(
|
|
844
865
|
withData(
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { useState, } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
EDITOR_VIEW_MODE__VIEW,
|
|
4
|
+
EDITOR_VIEW_MODE__ADD,
|
|
5
|
+
EDITOR_VIEW_MODE__EDIT,
|
|
6
|
+
} from '../../Constants/Editor.js';
|
|
2
7
|
import _ from 'lodash';
|
|
3
8
|
|
|
4
9
|
export default function withEditor(WrappedComponent) {
|
|
@@ -33,6 +38,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
33
38
|
[currentRecord, setCurrentRecord] = useState(null),
|
|
34
39
|
[isEditorShown, setIsEditorShown] = useState(false),
|
|
35
40
|
[isEditorViewOnly, setIsEditorViewOnly] = useState(false),
|
|
41
|
+
[editorViewMode, setEditorViewMode] = useState(EDITOR_VIEW_MODE__VIEW),
|
|
36
42
|
addRecord = async () => {
|
|
37
43
|
if (!userCanEdit) {
|
|
38
44
|
return;
|
|
@@ -42,6 +48,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
42
48
|
entity = await Repository.add(defaultValues, false, true, true);
|
|
43
49
|
setSelection([entity]);
|
|
44
50
|
setIsEditorViewOnly(false);
|
|
51
|
+
setEditorViewMode(EDITOR_VIEW_MODE__ADD);
|
|
45
52
|
setIsEditorShown(true);
|
|
46
53
|
},
|
|
47
54
|
editRecord = () => {
|
|
@@ -49,6 +56,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
49
56
|
return;
|
|
50
57
|
}
|
|
51
58
|
setIsEditorViewOnly(false);
|
|
59
|
+
setEditorViewMode(EDITOR_VIEW_MODE__EDIT);
|
|
52
60
|
setIsEditorShown(true);
|
|
53
61
|
},
|
|
54
62
|
deleteRecord = (e) => {
|
|
@@ -80,6 +88,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
80
88
|
return;
|
|
81
89
|
}
|
|
82
90
|
setIsEditorViewOnly(true);
|
|
91
|
+
setEditorViewMode(EDITOR_VIEW_MODE__VIEW);
|
|
83
92
|
setIsEditorShown(true);
|
|
84
93
|
},
|
|
85
94
|
duplicateRecord = async () => {
|
|
@@ -138,6 +147,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
138
147
|
setCurrentRecord={setCurrentRecord}
|
|
139
148
|
isEditorShown={isEditorShown}
|
|
140
149
|
isEditorViewOnly={isEditorViewOnly}
|
|
150
|
+
editorViewMode={editorViewMode}
|
|
141
151
|
setIsEditorShown={setIsEditorShown}
|
|
142
152
|
onAdd={addRecord}
|
|
143
153
|
onEdit={editRecord}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
Text,
|
|
7
7
|
} from 'native-base';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
} from '../../Constants/
|
|
9
|
+
EDITOR_TYPE__INLINE,
|
|
10
|
+
} from '../../Constants/Editor.js';
|
|
11
11
|
import {
|
|
12
12
|
UI_MODE_WEB,
|
|
13
13
|
UI_MODE_REACT_NATIVE,
|
|
@@ -77,14 +77,14 @@ export default function withInlineEditor(WrappedComponent) {
|
|
|
77
77
|
onChangeColumnsConfig={onChangeColumnsConfig}
|
|
78
78
|
onEditorRowClick={onRowClick}
|
|
79
79
|
/>
|
|
80
|
-
{useEditor && editorType ===
|
|
80
|
+
{useEditor && editorType === EDITOR_TYPE__INLINE && Repository &&
|
|
81
81
|
<Modal
|
|
82
82
|
isOpen={isEditorShown}
|
|
83
83
|
onClose={() => setIsEditorShown(false)}
|
|
84
84
|
>
|
|
85
85
|
<Column position="absolute" ref={inlineEditorRef}>
|
|
86
86
|
{isEditorShown && <Form
|
|
87
|
-
editorType={
|
|
87
|
+
editorType={EDITOR_TYPE__INLINE}
|
|
88
88
|
record={selection[0]}
|
|
89
89
|
Repository={Repository}
|
|
90
90
|
isMultiple={selection.length > 1}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDITOR_TYPE__SIDE,
|
|
3
|
+
} from '../../Constants/Editor.js';
|
|
4
|
+
import Container from '../Container/Container.js';
|
|
5
|
+
import withEditor from './withEditor.js';
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default function withSideEditor(WrappedComponent) {
|
|
10
|
+
return withEditor((props) => {
|
|
11
|
+
const {
|
|
12
|
+
Editor,
|
|
13
|
+
editorProps = {},
|
|
14
|
+
} = props;
|
|
15
|
+
|
|
16
|
+
return <Container
|
|
17
|
+
center={<WrappedComponent {...props} />}
|
|
18
|
+
east={<Editor
|
|
19
|
+
editorType={EDITOR_TYPE__SIDE}
|
|
20
|
+
{...props}
|
|
21
|
+
{...editorProps}
|
|
22
|
+
/>}
|
|
23
|
+
/>;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
Text,
|
|
5
5
|
} from 'native-base';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
} from '../../Constants/
|
|
7
|
+
EDITOR_TYPE__WINDOWED,
|
|
8
|
+
} from '../../Constants/Editor.js';
|
|
9
9
|
import withEditor from './withEditor.js';
|
|
10
10
|
// import withDraggable from './withDraggable.js';
|
|
11
11
|
import _ from 'lodash';
|
|
@@ -31,7 +31,8 @@ export default function withWindowedEditor(WrappedComponent) {
|
|
|
31
31
|
useEditor = false,
|
|
32
32
|
isEditorShown,
|
|
33
33
|
setIsEditorShown,
|
|
34
|
-
|
|
34
|
+
Editor,
|
|
35
|
+
editorProps = {},
|
|
35
36
|
} = props;
|
|
36
37
|
|
|
37
38
|
return <>
|
|
@@ -41,9 +42,10 @@ export default function withWindowedEditor(WrappedComponent) {
|
|
|
41
42
|
isOpen={true}
|
|
42
43
|
onClose={() => setIsEditorShown(false)}
|
|
43
44
|
>
|
|
44
|
-
<
|
|
45
|
-
editorType={
|
|
45
|
+
<Editor
|
|
46
|
+
editorType={EDITOR_TYPE__WINDOWED}
|
|
46
47
|
{...props}
|
|
48
|
+
{...editorProps}
|
|
47
49
|
/>
|
|
48
50
|
</Modal>}
|
|
49
51
|
</>;
|
|
@@ -2,9 +2,10 @@ import { useEffect, useState, } from 'react';
|
|
|
2
2
|
import Panel from './Panel.js';
|
|
3
3
|
import Grid, { InlineGridEditor, } from '../Grid/Grid.js';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
EDITOR_TYPE__INLINE,
|
|
6
|
+
EDITOR_TYPE__WINDOWED,
|
|
7
|
+
EDITOR_TYPE__SIDE,
|
|
8
|
+
} from '../../Constants/Editor.js';
|
|
8
9
|
import _ from 'lodash';
|
|
9
10
|
|
|
10
11
|
export function GridPanel(props) {
|
|
@@ -14,7 +15,7 @@ export function GridPanel(props) {
|
|
|
14
15
|
selectorSelected,
|
|
15
16
|
} = props,
|
|
16
17
|
originalTitle = props.title,
|
|
17
|
-
WhichGrid = (editorType ===
|
|
18
|
+
WhichGrid = (editorType === EDITOR_TYPE__INLINE) ? InlineGridEditor : Grid,
|
|
18
19
|
[isReady, setIsReady] = useState(disableTitleChange),
|
|
19
20
|
[title, setTitle] = useState(originalTitle);
|
|
20
21
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const EDITOR_TYPE__INLINE = 'EDITOR_TYPE__INLINE';
|
|
2
|
+
export const EDITOR_TYPE__WINDOWED = 'EDITOR_TYPE__WINDOWED';
|
|
3
|
+
export const EDITOR_TYPE__SIDE = 'EDITOR_TYPE__SIDE';
|
|
4
|
+
export const EDITOR_TYPE__SMART = 'EDITOR_TYPE__SMART';
|
|
5
|
+
export const EDITOR_TYPE__PLAIN = 'EDITOR_TYPE__PLAIN';
|
|
6
|
+
export const EDITOR_VIEW_MODE__VIEW = 'EDITOR_VIEW_MODE__VIEW';
|
|
7
|
+
export const EDITOR_VIEW_MODE__ADD = 'EDITOR_VIEW_MODE__ADD';
|
|
8
|
+
export const EDITOR_VIEW_MODE__EDIT = 'EDITOR_VIEW_MODE__EDIT';
|