@onehat/ui 0.3.30 → 0.3.32
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/Buttons/Button.js +20 -0
- package/src/Components/Buttons/IconButton.js +68 -51
- package/src/Components/Buttons/SquareButton.js +60 -0
- package/src/Components/Container/Container.js +4 -1
- package/src/Components/Container/ScreenContainer.js +4 -1
- package/src/Components/Editor/Editor.js +15 -1
- package/src/Components/Form/Field/CKEditor/CKEditor.js +2 -1
- package/src/Components/Form/Field/Checkbox/Checkbox.js +2 -1
- package/src/Components/Form/Field/Color.js +2 -1
- package/src/Components/Form/Field/Combo/Combo.js +7 -4
- package/src/Components/Form/Field/Date.js +2 -1
- package/src/Components/Form/Field/DisplayField.js +2 -1
- package/src/Components/Form/Field/File.js +2 -1
- package/src/Components/Form/Field/Input.js +2 -1
- package/src/Components/Form/Field/Number.js +2 -1
- package/src/Components/Form/Field/RadioGroup/RadioGroup.js +2 -1
- package/src/Components/Form/Field/Text.js +2 -1
- package/src/Components/Form/Field/TextArea.js +3 -2
- package/src/Components/Form/Field/Toggle.js +2 -1
- package/src/Components/Form/Form.js +91 -44
- package/src/Components/Grid/Grid.js +67 -53
- package/src/Components/Grid/GridHeaderRow.js +5 -2
- package/src/Components/Grid/GridRow.js +8 -2
- package/src/Components/Hoc/withAlert.js +1 -3
- package/src/Components/Hoc/withComponent.js +59 -0
- package/src/Components/Hoc/withEditor.js +16 -4
- package/src/Components/Hoc/withInlineEditor.js +4 -0
- package/src/Components/Hoc/withPdfButton.js +34 -28
- package/src/Components/Hoc/withPresetButtons.js +26 -1
- package/src/Components/Hoc/withSideEditor.js +7 -1
- package/src/Components/Hoc/withWindowedEditor.js +7 -1
- package/src/Components/Icons/HighPriority.js +20 -0
- package/src/Components/Icons/LowPriority.js +20 -0
- package/src/Components/Icons/MedPriority.js +20 -0
- package/src/Components/Icons/Pdf.js +14 -0
- package/src/Components/Screens/Manager.js +5 -2
- package/src/Components/Tab/TabBar.js +5 -2
- package/src/Components/Toolbar/Pagination.js +2 -1
- package/src/Components/Tree/Tree.js +47 -40
- package/src/Components/Viewer/TagViewer.js +3 -1
- package/src/Components/Viewer/Viewer.js +58 -14
- package/src/Components/index.js +4 -0
- package/src/Functions/getIconButtonFromConfig.js +3 -1
- package/src/Components/Form/Field/Field.js +0 -14
- package/src/Components/Grid/ReactGrid.js +0 -468
- package/src/Components/Grid/SenchaGrid.js +0 -421
- package/src/Components/Grid/reactgrid.css +0 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState, isValidElement, } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Box,
|
|
4
|
-
Button,
|
|
5
4
|
Column,
|
|
6
5
|
Icon,
|
|
7
6
|
Row,
|
|
@@ -24,10 +23,12 @@ import { yupResolver } from '@hookform/resolvers/yup';
|
|
|
24
23
|
import useForceUpdate from '../../Hooks/useForceUpdate.js';
|
|
25
24
|
import UiGlobals from '../../UiGlobals.js';
|
|
26
25
|
import withAlert from '../Hoc/withAlert.js';
|
|
26
|
+
import withComponent from '../Hoc/withComponent.js';
|
|
27
27
|
import withEditor from '../Hoc/withEditor.js';
|
|
28
28
|
import withPdfButton from '../Hoc/withPdfButton.js';
|
|
29
29
|
import inArray from '../../Functions/inArray.js';
|
|
30
30
|
import getComponentFromType from '../../Functions/getComponentFromType.js';
|
|
31
|
+
import Button from '../Buttons/Button.js';
|
|
31
32
|
import IconButton from '../Buttons/IconButton.js';
|
|
32
33
|
import AngleLeft from '../Icons/AngleLeft.js';
|
|
33
34
|
import Eye from '../Icons/Eye.js';
|
|
@@ -71,7 +72,7 @@ function Form(props) {
|
|
|
71
72
|
onViewMode,
|
|
72
73
|
submitBtnLabel,
|
|
73
74
|
onSubmit,
|
|
74
|
-
additionalEditButtons
|
|
75
|
+
additionalEditButtons,
|
|
75
76
|
|
|
76
77
|
// sizing of outer container
|
|
77
78
|
h,
|
|
@@ -81,6 +82,9 @@ function Form(props) {
|
|
|
81
82
|
flex,
|
|
82
83
|
onLayout, // onLayout handler for main view
|
|
83
84
|
|
|
85
|
+
// withComponent
|
|
86
|
+
self,
|
|
87
|
+
|
|
84
88
|
// withData
|
|
85
89
|
Repository,
|
|
86
90
|
|
|
@@ -236,6 +240,8 @@ function Form(props) {
|
|
|
236
240
|
onBlur={onBlur}
|
|
237
241
|
flex={1}
|
|
238
242
|
{...editorProps}
|
|
243
|
+
parent={self}
|
|
244
|
+
reference={fieldName}
|
|
239
245
|
// {...defaults}
|
|
240
246
|
// {...propsToPass}
|
|
241
247
|
/>;
|
|
@@ -294,7 +300,7 @@ function Form(props) {
|
|
|
294
300
|
type: t,
|
|
295
301
|
...p
|
|
296
302
|
} = propertyDef.viewerType;
|
|
297
|
-
type = t
|
|
303
|
+
type = t;
|
|
298
304
|
} else {
|
|
299
305
|
type = 'Text';
|
|
300
306
|
}
|
|
@@ -324,6 +330,8 @@ function Form(props) {
|
|
|
324
330
|
const value = (record && record[name]) || (startingValues && startingValues[name]) || null;
|
|
325
331
|
let element = <Element
|
|
326
332
|
value={value}
|
|
333
|
+
parent={self}
|
|
334
|
+
reference={name}
|
|
327
335
|
{...propsToPass}
|
|
328
336
|
/>;
|
|
329
337
|
if (label) {
|
|
@@ -400,6 +408,8 @@ function Form(props) {
|
|
|
400
408
|
}}
|
|
401
409
|
onBlur={onBlur}
|
|
402
410
|
flex={1}
|
|
411
|
+
parent={self}
|
|
412
|
+
reference={name}
|
|
403
413
|
{...defaults}
|
|
404
414
|
{...propsToPass}
|
|
405
415
|
{...editorTypeProps}
|
|
@@ -455,6 +465,7 @@ function Form(props) {
|
|
|
455
465
|
selectorSelected={selectorSelected || record}
|
|
456
466
|
flex={1}
|
|
457
467
|
uniqueRepository={true}
|
|
468
|
+
parent={self}
|
|
458
469
|
{...propsToPass}
|
|
459
470
|
/>;
|
|
460
471
|
if (title) {
|
|
@@ -468,6 +479,43 @@ function Form(props) {
|
|
|
468
479
|
}
|
|
469
480
|
return components;
|
|
470
481
|
},
|
|
482
|
+
buildAdditionalButtons = (configs) => {
|
|
483
|
+
const additionalButtons = [];
|
|
484
|
+
_.each(additionalEditButtons, (config) => {
|
|
485
|
+
const {
|
|
486
|
+
key,
|
|
487
|
+
text,
|
|
488
|
+
handler,
|
|
489
|
+
icon,
|
|
490
|
+
isDisabled,
|
|
491
|
+
color = '#fff',
|
|
492
|
+
} = config,
|
|
493
|
+
buttonProps = {};
|
|
494
|
+
if (key) {
|
|
495
|
+
buttonProps.key = key;
|
|
496
|
+
buttonProps.reference = key;
|
|
497
|
+
}
|
|
498
|
+
if (handler) {
|
|
499
|
+
buttonProps.onPress = handler;
|
|
500
|
+
}
|
|
501
|
+
if (icon) {
|
|
502
|
+
buttonProps.leftIcon = <Icon as={icon} color="#fff" size="sm" />;
|
|
503
|
+
}
|
|
504
|
+
if (isDisabled) {
|
|
505
|
+
buttonProps.isDisabled = isDisabled;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const button = <Button
|
|
509
|
+
color={color}
|
|
510
|
+
ml={2}
|
|
511
|
+
parent={self}
|
|
512
|
+
reference={key}
|
|
513
|
+
{...buttonProps}
|
|
514
|
+
>{text}</Button>;
|
|
515
|
+
additionalButtons.push(button);
|
|
516
|
+
});
|
|
517
|
+
return additionalButtons;
|
|
518
|
+
},
|
|
471
519
|
onSubmitError = (errors, e) => {
|
|
472
520
|
debugger;
|
|
473
521
|
if (editorType === EDITOR_TYPE__INLINE) {
|
|
@@ -603,11 +651,12 @@ function Form(props) {
|
|
|
603
651
|
buttonGroupProps.left = 10; // TODO: I would prefer to have this be centered, but it's a lot more complex than just making it stick to the left
|
|
604
652
|
footerProps.alignItems = 'flex-start';
|
|
605
653
|
}
|
|
654
|
+
|
|
655
|
+
const additionalButtons = buildAdditionalButtons(additionalEditButtons);
|
|
606
656
|
|
|
607
657
|
return <Column {...sizeProps} onLayout={onLayout}>
|
|
608
658
|
|
|
609
659
|
<Row px={4} pt={4} alignItems="center" justifyContent="flex-end">
|
|
610
|
-
{/* <Text mr={2} fontSize={18}>{editorModeF} Mode</Text> */}
|
|
611
660
|
{isSingle && editorMode === EDITOR_MODE__EDIT && onBack &&
|
|
612
661
|
<Button
|
|
613
662
|
key="backBtn"
|
|
@@ -623,9 +672,9 @@ function Form(props) {
|
|
|
623
672
|
color="#fff"
|
|
624
673
|
>To View</Button>}
|
|
625
674
|
</Row>
|
|
626
|
-
{editorMode === EDITOR_MODE__EDIT && !_.isEmpty(
|
|
675
|
+
{editorMode === EDITOR_MODE__EDIT && !_.isEmpty(additionalButtons) &&
|
|
627
676
|
<Row p={4} alignItems="center" justifyContent="flex-end">
|
|
628
|
-
{
|
|
677
|
+
{additionalButtons}
|
|
629
678
|
</Row>}
|
|
630
679
|
|
|
631
680
|
{editor}
|
|
@@ -643,43 +692,41 @@ function Form(props) {
|
|
|
643
692
|
color="#fff"
|
|
644
693
|
>Delete</Button>
|
|
645
694
|
</Row>}
|
|
646
|
-
<Button.Group space={2} {...buttonGroupProps}>
|
|
647
695
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
</Button.Group>
|
|
696
|
+
{!isEditorViewOnly && <IconButton
|
|
697
|
+
key="resetBtn"
|
|
698
|
+
onPress={() => {
|
|
699
|
+
if (onReset) {
|
|
700
|
+
onReset();
|
|
701
|
+
}
|
|
702
|
+
reset();
|
|
703
|
+
}}
|
|
704
|
+
icon={<Rotate color="#fff" />}
|
|
705
|
+
/>}
|
|
706
|
+
{!isEditorViewOnly && isSingle && onCancel && <Button
|
|
707
|
+
key="cancelBtn"
|
|
708
|
+
variant="ghost"
|
|
709
|
+
onPress={onCancel}
|
|
710
|
+
color="#fff"
|
|
711
|
+
>Cancel</Button>}
|
|
712
|
+
{!isEditorViewOnly && onSave && <Button
|
|
713
|
+
key="saveBtn"
|
|
714
|
+
onPress={(e) => handleSubmit(onSaveDecorated, onSubmitError)(e)}
|
|
715
|
+
isDisabled={isSaveDisabled}
|
|
716
|
+
color="#fff"
|
|
717
|
+
>{editorMode === EDITOR_MODE__ADD ? 'Add' : 'Save'}</Button>}
|
|
718
|
+
{onSubmit && <Button
|
|
719
|
+
key="submitBtn"
|
|
720
|
+
onPress={(e) => handleSubmit(onSubmitDecorated, onSubmitError)(e)}
|
|
721
|
+
isDisabled={isSubmitDisabled}
|
|
722
|
+
color="#fff"
|
|
723
|
+
>{submitBtnLabel || 'Submit'}</Button>}
|
|
724
|
+
|
|
725
|
+
{isEditorViewOnly && onClose && editorType !== EDITOR_TYPE__SIDE && <Button
|
|
726
|
+
key="closeBtn"
|
|
727
|
+
onPress={onClose}
|
|
728
|
+
color="#fff"
|
|
729
|
+
>Close</Button>}
|
|
683
730
|
</Footer>
|
|
684
731
|
</Column>;
|
|
685
732
|
}
|
|
@@ -728,6 +775,6 @@ function getNullFieldValues(initialValues, Repository) {
|
|
|
728
775
|
return ret;
|
|
729
776
|
}
|
|
730
777
|
|
|
731
|
-
export const FormEditor = withAlert(withEditor(withPdfButton(Form)));
|
|
778
|
+
export const FormEditor = withComponent(withAlert(withEditor(withPdfButton(Form))));
|
|
732
779
|
|
|
733
|
-
export default withAlert(withPdfButton(Form));
|
|
780
|
+
export default withComponent(withAlert(withPdfButton(Form)));
|
|
@@ -31,6 +31,7 @@ import UiGlobals from '../../UiGlobals.js';
|
|
|
31
31
|
import useForceUpdate from '../../Hooks/useForceUpdate.js';
|
|
32
32
|
import withContextMenu from '../Hoc/withContextMenu.js';
|
|
33
33
|
import withAlert from '../Hoc/withAlert.js';
|
|
34
|
+
import withComponent from '../Hoc/withComponent.js';
|
|
34
35
|
import withData from '../Hoc/withData.js';
|
|
35
36
|
import withEvents from '../Hoc/withEvents.js';
|
|
36
37
|
import withSideEditor from '../Hoc/withSideEditor.js';
|
|
@@ -96,6 +97,9 @@ function GridComponent(props) {
|
|
|
96
97
|
flex,
|
|
97
98
|
bg,
|
|
98
99
|
|
|
100
|
+
// withComponent
|
|
101
|
+
self,
|
|
102
|
+
|
|
99
103
|
// withEditor
|
|
100
104
|
onAdd,
|
|
101
105
|
onEdit,
|
|
@@ -224,11 +228,13 @@ function GridComponent(props) {
|
|
|
224
228
|
}
|
|
225
229
|
},
|
|
226
230
|
getFooterToolbarItems = () => {
|
|
227
|
-
const items = _.map(additionalToolbarButtons, getIconButtonFromConfig);
|
|
231
|
+
const items = _.map(additionalToolbarButtons, (config, ix) => getIconButtonFromConfig(config, ix, self));
|
|
228
232
|
|
|
229
233
|
if (canRowsReorder) {
|
|
230
234
|
items.unshift(<IconButton
|
|
231
235
|
key="reorderBtn"
|
|
236
|
+
parent={self}
|
|
237
|
+
reference="reorderBtn"
|
|
232
238
|
onPress={() => setIsDragMode(!isDragMode)}
|
|
233
239
|
icon={<Icon as={isDragMode ? NoReorderRows : ReorderRows} color={styles.GRID_TOOLBAR_ITEMS_COLOR} />}
|
|
234
240
|
/>);
|
|
@@ -866,37 +872,41 @@ function GridComponent(props) {
|
|
|
866
872
|
|
|
867
873
|
}
|
|
868
874
|
|
|
869
|
-
export const Grid =
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
875
|
+
export const Grid = withComponent(
|
|
876
|
+
withAlert(
|
|
877
|
+
withEvents(
|
|
878
|
+
withData(
|
|
879
|
+
withMultiSelection(
|
|
880
|
+
withSelection(
|
|
881
|
+
withFilters(
|
|
882
|
+
withPresetButtons(
|
|
883
|
+
withContextMenu(
|
|
884
|
+
GridComponent
|
|
885
|
+
),
|
|
886
|
+
true // isGrid
|
|
887
|
+
)
|
|
888
|
+
)
|
|
889
|
+
)
|
|
880
890
|
)
|
|
881
891
|
)
|
|
882
892
|
)
|
|
883
893
|
)
|
|
884
|
-
)
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
894
|
+
);
|
|
895
|
+
|
|
896
|
+
export const SideGridEditor = withComponent(
|
|
897
|
+
withAlert(
|
|
898
|
+
withEvents(
|
|
899
|
+
withData(
|
|
900
|
+
withMultiSelection(
|
|
901
|
+
withSelection(
|
|
902
|
+
withSideEditor(
|
|
903
|
+
withFilters(
|
|
904
|
+
withPresetButtons(
|
|
905
|
+
withContextMenu(
|
|
906
|
+
GridComponent
|
|
907
|
+
),
|
|
908
|
+
true // isGrid
|
|
909
|
+
)
|
|
900
910
|
)
|
|
901
911
|
)
|
|
902
912
|
)
|
|
@@ -906,18 +916,20 @@ export const SideGridEditor = withAlert(
|
|
|
906
916
|
)
|
|
907
917
|
);
|
|
908
918
|
|
|
909
|
-
export const WindowedGridEditor =
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
919
|
+
export const WindowedGridEditor = withComponent(
|
|
920
|
+
withAlert(
|
|
921
|
+
withEvents(
|
|
922
|
+
withData(
|
|
923
|
+
withMultiSelection(
|
|
924
|
+
withSelection(
|
|
925
|
+
withWindowedEditor(
|
|
926
|
+
withFilters(
|
|
927
|
+
withPresetButtons(
|
|
928
|
+
withContextMenu(
|
|
929
|
+
GridComponent
|
|
930
|
+
),
|
|
931
|
+
true // isGrid
|
|
932
|
+
)
|
|
921
933
|
)
|
|
922
934
|
)
|
|
923
935
|
)
|
|
@@ -927,19 +939,21 @@ export const WindowedGridEditor = withAlert(
|
|
|
927
939
|
)
|
|
928
940
|
);
|
|
929
941
|
|
|
930
|
-
export const InlineGridEditor =
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
942
|
+
export const InlineGridEditor = withComponent(
|
|
943
|
+
withAlert(
|
|
944
|
+
withEvents(
|
|
945
|
+
withData(
|
|
946
|
+
withMultiSelection(
|
|
947
|
+
withSelection(
|
|
948
|
+
withInlineEditor(
|
|
949
|
+
withFilters(
|
|
950
|
+
withPresetButtons(
|
|
951
|
+
withContextMenu(
|
|
952
|
+
GridComponent
|
|
953
|
+
)
|
|
954
|
+
),
|
|
955
|
+
true // isGrid
|
|
956
|
+
)
|
|
943
957
|
)
|
|
944
958
|
)
|
|
945
959
|
)
|
|
@@ -327,6 +327,10 @@ export default function GridHeaderRow(props) {
|
|
|
327
327
|
propsToPass.minWidth = styles.INLINE_EDITOR_MIN_WIDTH;
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
const textProps = {};
|
|
331
|
+
if (UiGlobals.mode === UI_MODE_WEB) {
|
|
332
|
+
textProps.textOverflow = 'ellipsis';
|
|
333
|
+
}
|
|
330
334
|
return <Pressable
|
|
331
335
|
key={ix}
|
|
332
336
|
onPress={(e) => {
|
|
@@ -375,12 +379,10 @@ export default function GridHeaderRow(props) {
|
|
|
375
379
|
return proxy;
|
|
376
380
|
}}
|
|
377
381
|
/>}
|
|
378
|
-
|
|
379
382
|
<Text
|
|
380
383
|
key="Text"
|
|
381
384
|
fontSize={styles.GRID_HEADER_FONTSIZE}
|
|
382
385
|
overflow="hidden"
|
|
383
|
-
textOverflow="ellipsis"
|
|
384
386
|
flex={1}
|
|
385
387
|
h="100%"
|
|
386
388
|
px={styles.GRID_HEADER_CELL_PX}
|
|
@@ -389,6 +391,7 @@ export default function GridHeaderRow(props) {
|
|
|
389
391
|
justifyContent="center"
|
|
390
392
|
numberOfLines={1}
|
|
391
393
|
ellipsizeMode="head"
|
|
394
|
+
{...textProps}
|
|
392
395
|
>{header}</Text>
|
|
393
396
|
|
|
394
397
|
{isSorter && <Icon key="Icon" as={isSortDirectionAsc ? SortDown : SortUp} textAlign="center" size="sm" mt={3} mr={2} color="trueGray.500" />}
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
VERTICAL,
|
|
9
9
|
} from '../../Constants/Directions.js';
|
|
10
|
+
import {
|
|
11
|
+
UI_MODE_WEB,
|
|
12
|
+
} from '../../Constants/UiModes.js';
|
|
10
13
|
import getComponentFromType from '../../Functions/getComponentFromType.js';
|
|
11
14
|
import UiGlobals from '../../UiGlobals.js';
|
|
12
15
|
import withDraggable from '../Hoc/withDraggable.js';
|
|
@@ -100,11 +103,14 @@ export default function GridRow(props) {
|
|
|
100
103
|
|
|
101
104
|
if (property?.viewerType?.type) {
|
|
102
105
|
const Element = getComponentFromType(property?.viewerType?.type);
|
|
106
|
+
const elementProps = {};
|
|
107
|
+
if (UiGlobals.mode === UI_MODE_WEB) {
|
|
108
|
+
elementProps.textOverflow = 'ellipsis';
|
|
109
|
+
}
|
|
103
110
|
return <Element
|
|
104
111
|
value={value}
|
|
105
112
|
key={key}
|
|
106
113
|
overflow="hidden"
|
|
107
|
-
textOverflow="ellipsis"
|
|
108
114
|
alignSelf="center"
|
|
109
115
|
style={{
|
|
110
116
|
userSelect: 'none',
|
|
@@ -115,7 +121,7 @@ export default function GridRow(props) {
|
|
|
115
121
|
numberOfLines={1}
|
|
116
122
|
ellipsizeMode="head"
|
|
117
123
|
{...propsToPass}
|
|
118
|
-
{...
|
|
124
|
+
{...elementProps}
|
|
119
125
|
/>;
|
|
120
126
|
}
|
|
121
127
|
} else if (item[config.fieldName]) {
|
|
@@ -168,9 +168,7 @@ export default function withAlert(WrappedComponent) {
|
|
|
168
168
|
</Row>
|
|
169
169
|
</AlertDialog.Body>
|
|
170
170
|
<AlertDialog.Footer>
|
|
171
|
-
|
|
172
|
-
{buttons}
|
|
173
|
-
</Button.Group>
|
|
171
|
+
{buttons}
|
|
174
172
|
</AlertDialog.Footer>
|
|
175
173
|
</AlertDialog.Content>
|
|
176
174
|
</AlertDialog>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, } from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
|
|
4
|
+
// This HOC establishes a parent-child relationship between components.
|
|
5
|
+
// Basically anything wrapped in withComponent registers itself with a parent
|
|
6
|
+
// and allows children to register.
|
|
7
|
+
|
|
8
|
+
export default function withComponent(WrappedComponent) {
|
|
9
|
+
return (props) => {
|
|
10
|
+
const {
|
|
11
|
+
// self: parent,
|
|
12
|
+
parent,
|
|
13
|
+
...propsToPass
|
|
14
|
+
} = props,
|
|
15
|
+
{ reference } = props,
|
|
16
|
+
childrenRef = useRef({}),
|
|
17
|
+
selfRef = useRef({
|
|
18
|
+
parent,
|
|
19
|
+
reference,
|
|
20
|
+
registerChild: (childRef) => {
|
|
21
|
+
const {
|
|
22
|
+
reference,
|
|
23
|
+
} = childRef;
|
|
24
|
+
if (typeof childrenRef.current[reference] !== 'undefined') {
|
|
25
|
+
throw Error('reference already exists!');
|
|
26
|
+
}
|
|
27
|
+
childrenRef.current[reference] = childRef; // so we can do component addresses like self.children.workOrdersGridEditor
|
|
28
|
+
},
|
|
29
|
+
unregisterChild: (childRef) => {
|
|
30
|
+
const {
|
|
31
|
+
reference,
|
|
32
|
+
} = childRef;
|
|
33
|
+
if (typeof childrenRef.current[reference] !== 'undefined') {
|
|
34
|
+
delete childrenRef.current[reference];
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
children: childrenRef.current,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (parent && reference) {
|
|
42
|
+
parent.registerChild(selfRef.current);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
if (parent && reference) {
|
|
46
|
+
parent.unregisterChild(selfRef.current);
|
|
47
|
+
}
|
|
48
|
+
childrenRef.current = {};
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
return <WrappedComponent
|
|
53
|
+
// parent={parent}
|
|
54
|
+
self={selfRef.current}
|
|
55
|
+
{...propsToPass}
|
|
56
|
+
/>;
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -30,6 +30,9 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
30
30
|
},
|
|
31
31
|
record,
|
|
32
32
|
|
|
33
|
+
// withComponent
|
|
34
|
+
self,
|
|
35
|
+
|
|
33
36
|
// parent container
|
|
34
37
|
selectorId,
|
|
35
38
|
selectorSelected,
|
|
@@ -199,7 +202,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
199
202
|
cb();
|
|
200
203
|
}
|
|
201
204
|
},
|
|
202
|
-
|
|
205
|
+
onView = async () => {
|
|
203
206
|
if (!userCanView) {
|
|
204
207
|
return;
|
|
205
208
|
}
|
|
@@ -214,7 +217,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
214
217
|
await getListeners().onAfterView(entity);
|
|
215
218
|
}
|
|
216
219
|
},
|
|
217
|
-
|
|
220
|
+
onDuplicate = async () => {
|
|
218
221
|
if (!userCanEdit || disableDuplicate) {
|
|
219
222
|
return;
|
|
220
223
|
}
|
|
@@ -339,6 +342,15 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
339
342
|
setLastSelection(selection);
|
|
340
343
|
}, [selection]);
|
|
341
344
|
|
|
345
|
+
if (self) {
|
|
346
|
+
self.onAdd = onAdd;
|
|
347
|
+
self.onEdit = onEdit;
|
|
348
|
+
self.onDelete = onDelete;
|
|
349
|
+
self.onMoveChildren = onMoveChildren;
|
|
350
|
+
self.onDeleteChildren = onDeleteChildren;
|
|
351
|
+
self.onDuplicate = onDuplicate;
|
|
352
|
+
}
|
|
353
|
+
|
|
342
354
|
if (lastSelection !== selection) {
|
|
343
355
|
// NOTE: If I don't calculate this on the fly for selection changes,
|
|
344
356
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
@@ -361,8 +373,8 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
361
373
|
onAdd={(!userCanEdit || disableAdd) ? null : onAdd}
|
|
362
374
|
onEdit={(!userCanEdit || disableEdit) ? null : onEdit}
|
|
363
375
|
onDelete={(!userCanEdit || disableDelete) ? null : onDelete}
|
|
364
|
-
onView={
|
|
365
|
-
onDuplicate={
|
|
376
|
+
onView={onView}
|
|
377
|
+
onDuplicate={onDuplicate}
|
|
366
378
|
onEditorSave={onEditorSave}
|
|
367
379
|
onEditorCancel={onEditorCancel}
|
|
368
380
|
onEditorDelete={(!userCanEdit || disableDelete) ? null : onEditorDelete}
|
|
@@ -30,6 +30,9 @@ export default function withInlineEditor(WrappedComponent) {
|
|
|
30
30
|
onEditorClose,
|
|
31
31
|
editorStateRef,
|
|
32
32
|
|
|
33
|
+
// withComponent
|
|
34
|
+
self,
|
|
35
|
+
|
|
33
36
|
// withSelection
|
|
34
37
|
selection,
|
|
35
38
|
|
|
@@ -102,6 +105,7 @@ export default function withInlineEditor(WrappedComponent) {
|
|
|
102
105
|
zIndex={10}
|
|
103
106
|
>
|
|
104
107
|
{isEditorShown && <Form
|
|
108
|
+
parent={self}
|
|
105
109
|
editorType={EDITOR_TYPE__INLINE}
|
|
106
110
|
editorStateRef={editorStateRef}
|
|
107
111
|
record={selection[0]}
|