@onehat/ui 0.3.215 → 0.3.217
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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import IconButton from './IconButton.js';
|
|
2
|
+
import Plus from '../Icons/Plus.js';
|
|
3
|
+
import Minus from '../Icons/Minus.js';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
|
|
6
|
+
export default function ExpandButton(props) {
|
|
7
|
+
const {
|
|
8
|
+
isExpanded = false,
|
|
9
|
+
onToggle,
|
|
10
|
+
} = props;
|
|
11
|
+
|
|
12
|
+
return <IconButton
|
|
13
|
+
icon={isExpanded ? Minus : Plus}
|
|
14
|
+
onPress={onToggle}
|
|
15
|
+
{...props}
|
|
16
|
+
/>;
|
|
17
|
+
};
|
|
@@ -53,6 +53,7 @@ import Loading from '../Messages/Loading.js';
|
|
|
53
53
|
import GridHeaderRow from './GridHeaderRow.js';
|
|
54
54
|
import GridRow from './GridRow.js';
|
|
55
55
|
import IconButton from '../Buttons/IconButton.js';
|
|
56
|
+
import ExpandButton from '../Buttons/ExpandButton.js';
|
|
56
57
|
import PaginationToolbar from '../Toolbar/PaginationToolbar.js';
|
|
57
58
|
import NoRecordsFound from './NoRecordsFound.js';
|
|
58
59
|
import Toolbar from '../Toolbar/Toolbar.js';
|
|
@@ -97,16 +98,15 @@ function GridComponent(props) {
|
|
|
97
98
|
},
|
|
98
99
|
flatListProps = {},
|
|
99
100
|
onRowPress,
|
|
100
|
-
|
|
101
|
+
onRender,
|
|
101
102
|
forceLoadOnRender = false,
|
|
102
103
|
pullToRefresh = true,
|
|
103
104
|
hideNavColumn = true,
|
|
104
105
|
noneFoundText,
|
|
105
106
|
autoAdjustPageSizeToHeight = true,
|
|
106
|
-
disableLoadingIndicator = false,
|
|
107
107
|
disableSelectorSelected = false,
|
|
108
108
|
showRowExpander = false,
|
|
109
|
-
|
|
109
|
+
getExpandedRowContent,
|
|
110
110
|
showHeaders = true,
|
|
111
111
|
showHovers = true,
|
|
112
112
|
canColumnsSort = true,
|
|
@@ -115,6 +115,10 @@ function GridComponent(props) {
|
|
|
115
115
|
canRowsReorder = false,
|
|
116
116
|
areRowsDragSource = false,
|
|
117
117
|
rowDragSourceType,
|
|
118
|
+
rowDragSourceItem,
|
|
119
|
+
areRowsDropTarget = false,
|
|
120
|
+
dropTargetAccept,
|
|
121
|
+
onRowDrop,
|
|
118
122
|
allowToggleSelection = false, // i.e. single click with no shift key toggles the selection of the item clicked on
|
|
119
123
|
disableBottomToolbar = false,
|
|
120
124
|
disablePagination = false,
|
|
@@ -137,8 +141,6 @@ function GridComponent(props) {
|
|
|
137
141
|
onEdit,
|
|
138
142
|
onDelete,
|
|
139
143
|
onView,
|
|
140
|
-
onDuplicate,
|
|
141
|
-
onReset,
|
|
142
144
|
onContextMenu,
|
|
143
145
|
isAdding,
|
|
144
146
|
|
|
@@ -201,6 +203,7 @@ function GridComponent(props) {
|
|
|
201
203
|
gridRef = useRef(),
|
|
202
204
|
gridContainerRef = useRef(),
|
|
203
205
|
isAddingRef = useRef(),
|
|
206
|
+
expandedRowsRef = useRef({}),
|
|
204
207
|
[isInited, setIsInited] = useState(false),
|
|
205
208
|
[isReady, setIsReady] = useState(false),
|
|
206
209
|
[isLoading, setIsLoading] = useState(false),
|
|
@@ -208,6 +211,13 @@ function GridComponent(props) {
|
|
|
208
211
|
[isDragMode, setIsDragMode] = useState(false),
|
|
209
212
|
[dragRowSlot, setDragRowSlot] = useState(null),
|
|
210
213
|
[dragRowIx, setDragRowIx] = useState(),
|
|
214
|
+
getIsExpanded = (index) => {
|
|
215
|
+
return !!expandedRowsRef.current[index];
|
|
216
|
+
},
|
|
217
|
+
setIsExpanded = (index, isExpanded) => {
|
|
218
|
+
expandedRowsRef.current[index] = isExpanded;
|
|
219
|
+
forceUpdate();
|
|
220
|
+
},
|
|
211
221
|
setLocalColumnsConfig = (config) => {
|
|
212
222
|
if (localColumnsConfigKey && !hasFunctionColumn) {
|
|
213
223
|
setSaved(localColumnsConfigKey, config);
|
|
@@ -322,7 +332,7 @@ function GridComponent(props) {
|
|
|
322
332
|
rowProps = getRowProps && !isHeaderRow ? getRowProps(item) : {},
|
|
323
333
|
isSelected = !isHeaderRow && !disableWithSelection && isInSelection(item);
|
|
324
334
|
|
|
325
|
-
|
|
335
|
+
let rowComponent = <Pressable
|
|
326
336
|
// {...testProps(Repository ? Repository.schema.name + '-' + item.id : item.id)}
|
|
327
337
|
onPress={(e) => {
|
|
328
338
|
if (e.preventDefault && e.cancelable) {
|
|
@@ -435,22 +445,27 @@ function GridComponent(props) {
|
|
|
435
445
|
rowReorderProps = {},
|
|
436
446
|
rowDragProps = {};
|
|
437
447
|
if (canRowsReorder && isDragMode) {
|
|
438
|
-
rowReorderProps =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
getProxy: getReorderProxy,
|
|
448
|
-
};
|
|
448
|
+
rowReorderProps.isDraggable = true;
|
|
449
|
+
rowReorderProps.mode = VERTICAL;
|
|
450
|
+
rowReorderProps.onDragStart = onRowReorderDragStart;
|
|
451
|
+
rowReorderProps.onDrag = onRowReorderDrag;
|
|
452
|
+
rowReorderProps.onDragStop = onRowReorderDragStop;
|
|
453
|
+
rowReorderProps.proxyParent = gridRef.current?.getScrollableNode().children[0];
|
|
454
|
+
rowReorderProps.proxyPositionRelativeToParent = true;
|
|
455
|
+
rowReorderProps.getParentNode = (node) => node.parentElement.parentElement.parentElement;
|
|
456
|
+
rowReorderProps.getProxy = getReorderProxy;
|
|
449
457
|
}
|
|
450
458
|
if (areRowsDragSource) {
|
|
451
459
|
rowDragProps.isDragSource = true;
|
|
452
460
|
rowDragProps.dragSourceType = rowDragSourceType;
|
|
453
|
-
rowDragProps.dragSourceItem = { id: item.id };
|
|
461
|
+
rowDragProps.dragSourceItem = rowDragSourceItem || { id: item.id };
|
|
462
|
+
}
|
|
463
|
+
if (areRowsDropTarget) {
|
|
464
|
+
rowDragProps.isDropTarget = true;
|
|
465
|
+
rowDragProps.dropTargetAccept = dropTargetAccept;
|
|
466
|
+
rowDragProps.onDrop = (droppedItem) => {
|
|
467
|
+
onRowDrop(item, droppedItem);
|
|
468
|
+
};
|
|
454
469
|
}
|
|
455
470
|
return <GridRow
|
|
456
471
|
columnsConfig={localColumnsConfig}
|
|
@@ -466,6 +481,25 @@ function GridComponent(props) {
|
|
|
466
481
|
/>;
|
|
467
482
|
}}
|
|
468
483
|
</Pressable>;
|
|
484
|
+
|
|
485
|
+
if (showRowExpander && !isHeaderRow) {
|
|
486
|
+
const isExpanded = getIsExpanded(index);
|
|
487
|
+
rowComponent = <Column>
|
|
488
|
+
<Row>
|
|
489
|
+
<ExpandButton
|
|
490
|
+
isExpanded={isExpanded}
|
|
491
|
+
onToggle={() => setIsExpanded(index, !isExpanded)}
|
|
492
|
+
_icon={{
|
|
493
|
+
size: 'sm',
|
|
494
|
+
}}
|
|
495
|
+
py={0}
|
|
496
|
+
/>
|
|
497
|
+
{rowComponent}
|
|
498
|
+
</Row>
|
|
499
|
+
{isExpanded ? getExpandedRowContent(row) : null}
|
|
500
|
+
</Column>
|
|
501
|
+
}
|
|
502
|
+
return rowComponent;
|
|
469
503
|
},
|
|
470
504
|
getReorderProxy = (node) => {
|
|
471
505
|
const
|
|
@@ -766,6 +800,9 @@ function GridComponent(props) {
|
|
|
766
800
|
}
|
|
767
801
|
Repository.pauseEvents();
|
|
768
802
|
}
|
|
803
|
+
if (onRender) {
|
|
804
|
+
onRender(self)
|
|
805
|
+
}
|
|
769
806
|
return () => {};
|
|
770
807
|
}
|
|
771
808
|
|
|
@@ -873,6 +910,11 @@ function GridComponent(props) {
|
|
|
873
910
|
if (!Repository.isAutoLoad) {
|
|
874
911
|
Repository.reload();
|
|
875
912
|
}
|
|
913
|
+
},
|
|
914
|
+
onChangePage = () => {
|
|
915
|
+
if (showRowExpander) {
|
|
916
|
+
expandedRowsRef.current = {}; // clear expanded rows
|
|
917
|
+
}
|
|
876
918
|
};
|
|
877
919
|
|
|
878
920
|
Repository.on('beforeLoad', setTrue);
|
|
@@ -883,7 +925,7 @@ function GridComponent(props) {
|
|
|
883
925
|
Repository.ons(['changeData', 'change'], forceUpdate);
|
|
884
926
|
Repository.on('changeFilters', onChangeFilters);
|
|
885
927
|
Repository.on('changeSorters', onChangeSorters);
|
|
886
|
-
|
|
928
|
+
Repository.on('changePage', onChangePage);
|
|
887
929
|
|
|
888
930
|
applySelectorSelected();
|
|
889
931
|
Repository.resumeEvents();
|
|
@@ -901,6 +943,7 @@ function GridComponent(props) {
|
|
|
901
943
|
Repository.offs(['changeData', 'change'], forceUpdate);
|
|
902
944
|
Repository.off('changeFilters', onChangeFilters);
|
|
903
945
|
Repository.off('changeSorters', onChangeSorters);
|
|
946
|
+
Repository.off('changePage', onChangePage);
|
|
904
947
|
};
|
|
905
948
|
}, [isInited]);
|
|
906
949
|
|
|
@@ -1055,7 +1098,6 @@ function GridComponent(props) {
|
|
|
1055
1098
|
{...sizeProps}
|
|
1056
1099
|
>{grid}</Box>
|
|
1057
1100
|
}
|
|
1058
|
-
|
|
1059
1101
|
return grid;
|
|
1060
1102
|
|
|
1061
1103
|
}
|
|
@@ -9,9 +9,10 @@ import {
|
|
|
9
9
|
} from '../../Constants/UiModes.js';
|
|
10
10
|
import getComponentFromType from '../../Functions/getComponentFromType.js';
|
|
11
11
|
import UiGlobals from '../../UiGlobals.js';
|
|
12
|
-
import { withDragSource } from '../Hoc/withDnd.js';
|
|
12
|
+
import { withDragSource, withDropTarget } from '../Hoc/withDnd.js';
|
|
13
13
|
import withDraggable from '../Hoc/withDraggable.js';
|
|
14
14
|
import AngleRight from '../Icons/AngleRight.js';
|
|
15
|
+
import RowDragHandle from './RowDragHandle.js';
|
|
15
16
|
import _ from 'lodash';
|
|
16
17
|
|
|
17
18
|
// This was broken out from Grid simply so we can memoize it
|
|
@@ -26,6 +27,8 @@ function GridRow(props) {
|
|
|
26
27
|
bg,
|
|
27
28
|
item,
|
|
28
29
|
isInlineEditorShown,
|
|
30
|
+
isDragSource = false,
|
|
31
|
+
isOver = false,
|
|
29
32
|
} = props,
|
|
30
33
|
styles = UiGlobals.styles;
|
|
31
34
|
|
|
@@ -40,7 +43,9 @@ function GridRow(props) {
|
|
|
40
43
|
if (props.dragSourceRef) {
|
|
41
44
|
rowProps.ref = props.dragSourceRef;
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
if (props.dropTargetRef) {
|
|
47
|
+
rowProps.ref = props.dropTargetRef;
|
|
48
|
+
}
|
|
44
49
|
return useMemo(() => {
|
|
45
50
|
const renderColumns = (item) => {
|
|
46
51
|
if (_.isArray(columnsConfig)) {
|
|
@@ -176,6 +181,13 @@ function GridRow(props) {
|
|
|
176
181
|
throw new Error('Non-array columnsConfig not yet supported');
|
|
177
182
|
}
|
|
178
183
|
};
|
|
184
|
+
if (isOver) {
|
|
185
|
+
rowProps.borderWidth = 4;
|
|
186
|
+
rowProps.borderColor = '#0ff';
|
|
187
|
+
} else {
|
|
188
|
+
rowProps.borderWidth = 0;
|
|
189
|
+
rowProps.borderColor = null;
|
|
190
|
+
}
|
|
179
191
|
return <Row
|
|
180
192
|
alignItems="center"
|
|
181
193
|
flexGrow={1}
|
|
@@ -183,6 +195,7 @@ function GridRow(props) {
|
|
|
183
195
|
bg={bg}
|
|
184
196
|
key={hash}
|
|
185
197
|
>
|
|
198
|
+
{isDragSource && <RowDragHandle />}
|
|
186
199
|
{isPhantom && <Box position="absolute" bg="#f00" h={2} w={2} t={0} l={0} />}
|
|
187
200
|
|
|
188
201
|
{renderColumns(item)}
|
|
@@ -206,7 +219,8 @@ function GridRow(props) {
|
|
|
206
219
|
isPhantom,
|
|
207
220
|
hash, // this is an easy way to determine if the data has changed and the item needs to be rerendered
|
|
208
221
|
isInlineEditorShown,
|
|
222
|
+
isOver,
|
|
209
223
|
]);
|
|
210
224
|
}
|
|
211
225
|
|
|
212
|
-
export default withDraggable(withDragSource(GridRow));
|
|
226
|
+
export default withDraggable(withDragSource(withDropTarget(GridRow)));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
Icon,
|
|
4
|
+
Row,
|
|
5
|
+
Text,
|
|
6
|
+
} from 'native-base';
|
|
7
|
+
import styles from '../../Styles/StyleSheets.js';
|
|
8
|
+
import GripVertical from '../Icons/GripVertical.js';
|
|
9
|
+
|
|
10
|
+
function RowDragHandle(props) {
|
|
11
|
+
return <Column
|
|
12
|
+
testID="HeaderReorderHandle"
|
|
13
|
+
bg="trueGray.100"
|
|
14
|
+
h="100%"
|
|
15
|
+
w={3}
|
|
16
|
+
alignItems="center"
|
|
17
|
+
justifyContent="center"
|
|
18
|
+
style={styles.ewResize}
|
|
19
|
+
>
|
|
20
|
+
<Icon as={GripVertical} testID="handle" size="xs" w="100%" h="100%" color="#ccc" />
|
|
21
|
+
</Column>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default RowDragHandle;
|
package/src/Components/index.js
CHANGED
|
@@ -203,6 +203,7 @@ import DataMgt from './Screens/DataMgt.js';
|
|
|
203
203
|
import Date from './Form/Field/Date.js';
|
|
204
204
|
import DateRange from './Filter/DateRange.js';
|
|
205
205
|
import DisplayField from './Form/Field/DisplayField.js';
|
|
206
|
+
import ExpandButton from './Buttons/ExpandButton.js';
|
|
206
207
|
import FieldSet from './Form/FieldSet.js';
|
|
207
208
|
import FiltersForm from './Form/FiltersForm.js';
|
|
208
209
|
// import FiltersToolbar from '../Components/Toolbar/FiltersToolbar.js';
|
|
@@ -436,6 +437,7 @@ const components = {
|
|
|
436
437
|
Date,
|
|
437
438
|
DateRange,
|
|
438
439
|
DisplayField,
|
|
440
|
+
ExpandButton,
|
|
439
441
|
FieldSet,
|
|
440
442
|
FiltersForm,
|
|
441
443
|
// FiltersToolbar,
|