@onehat/ui 0.3.215 → 0.3.216
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,9 @@ function GridComponent(props) {
|
|
|
115
115
|
canRowsReorder = false,
|
|
116
116
|
areRowsDragSource = false,
|
|
117
117
|
rowDragSourceType,
|
|
118
|
+
areRowsDropTarget = false,
|
|
119
|
+
dropTargetAccept,
|
|
120
|
+
onRowDrop,
|
|
118
121
|
allowToggleSelection = false, // i.e. single click with no shift key toggles the selection of the item clicked on
|
|
119
122
|
disableBottomToolbar = false,
|
|
120
123
|
disablePagination = false,
|
|
@@ -137,8 +140,6 @@ function GridComponent(props) {
|
|
|
137
140
|
onEdit,
|
|
138
141
|
onDelete,
|
|
139
142
|
onView,
|
|
140
|
-
onDuplicate,
|
|
141
|
-
onReset,
|
|
142
143
|
onContextMenu,
|
|
143
144
|
isAdding,
|
|
144
145
|
|
|
@@ -201,6 +202,7 @@ function GridComponent(props) {
|
|
|
201
202
|
gridRef = useRef(),
|
|
202
203
|
gridContainerRef = useRef(),
|
|
203
204
|
isAddingRef = useRef(),
|
|
205
|
+
expandedRowsRef = useRef({}),
|
|
204
206
|
[isInited, setIsInited] = useState(false),
|
|
205
207
|
[isReady, setIsReady] = useState(false),
|
|
206
208
|
[isLoading, setIsLoading] = useState(false),
|
|
@@ -208,6 +210,13 @@ function GridComponent(props) {
|
|
|
208
210
|
[isDragMode, setIsDragMode] = useState(false),
|
|
209
211
|
[dragRowSlot, setDragRowSlot] = useState(null),
|
|
210
212
|
[dragRowIx, setDragRowIx] = useState(),
|
|
213
|
+
getIsExpanded = (index) => {
|
|
214
|
+
return !!expandedRowsRef.current[index];
|
|
215
|
+
},
|
|
216
|
+
setIsExpanded = (index, isExpanded) => {
|
|
217
|
+
expandedRowsRef.current[index] = isExpanded;
|
|
218
|
+
forceUpdate();
|
|
219
|
+
},
|
|
211
220
|
setLocalColumnsConfig = (config) => {
|
|
212
221
|
if (localColumnsConfigKey && !hasFunctionColumn) {
|
|
213
222
|
setSaved(localColumnsConfigKey, config);
|
|
@@ -322,7 +331,7 @@ function GridComponent(props) {
|
|
|
322
331
|
rowProps = getRowProps && !isHeaderRow ? getRowProps(item) : {},
|
|
323
332
|
isSelected = !isHeaderRow && !disableWithSelection && isInSelection(item);
|
|
324
333
|
|
|
325
|
-
|
|
334
|
+
let rowComponent = <Pressable
|
|
326
335
|
// {...testProps(Repository ? Repository.schema.name + '-' + item.id : item.id)}
|
|
327
336
|
onPress={(e) => {
|
|
328
337
|
if (e.preventDefault && e.cancelable) {
|
|
@@ -435,23 +444,28 @@ function GridComponent(props) {
|
|
|
435
444
|
rowReorderProps = {},
|
|
436
445
|
rowDragProps = {};
|
|
437
446
|
if (canRowsReorder && isDragMode) {
|
|
438
|
-
rowReorderProps =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
getProxy: getReorderProxy,
|
|
448
|
-
};
|
|
447
|
+
rowReorderProps.isDraggable = true;
|
|
448
|
+
rowReorderProps.mode = VERTICAL;
|
|
449
|
+
rowReorderProps.onDragStart = onRowReorderDragStart;
|
|
450
|
+
rowReorderProps.onDrag = onRowReorderDrag;
|
|
451
|
+
rowReorderProps.onDragStop = onRowReorderDragStop;
|
|
452
|
+
rowReorderProps.proxyParent = gridRef.current?.getScrollableNode().children[0];
|
|
453
|
+
rowReorderProps.proxyPositionRelativeToParent = true;
|
|
454
|
+
rowReorderProps.getParentNode = (node) => node.parentElement.parentElement.parentElement;
|
|
455
|
+
rowReorderProps.getProxy = getReorderProxy;
|
|
449
456
|
}
|
|
450
457
|
if (areRowsDragSource) {
|
|
451
458
|
rowDragProps.isDragSource = true;
|
|
452
459
|
rowDragProps.dragSourceType = rowDragSourceType;
|
|
453
460
|
rowDragProps.dragSourceItem = { id: item.id };
|
|
454
461
|
}
|
|
462
|
+
if (areRowsDropTarget) {
|
|
463
|
+
rowDragProps.isDropTarget = true;
|
|
464
|
+
rowDragProps.dropTargetAccept = dropTargetAccept;
|
|
465
|
+
rowDragProps.onDrop = (droppedItem) => {
|
|
466
|
+
onRowDrop(item, droppedItem);
|
|
467
|
+
};
|
|
468
|
+
}
|
|
455
469
|
return <GridRow
|
|
456
470
|
columnsConfig={localColumnsConfig}
|
|
457
471
|
columnProps={columnProps}
|
|
@@ -466,6 +480,25 @@ function GridComponent(props) {
|
|
|
466
480
|
/>;
|
|
467
481
|
}}
|
|
468
482
|
</Pressable>;
|
|
483
|
+
|
|
484
|
+
if (showRowExpander && !isHeaderRow) {
|
|
485
|
+
const isExpanded = getIsExpanded(index);
|
|
486
|
+
rowComponent = <Column>
|
|
487
|
+
<Row>
|
|
488
|
+
<ExpandButton
|
|
489
|
+
isExpanded={isExpanded}
|
|
490
|
+
onToggle={() => setIsExpanded(index, !isExpanded)}
|
|
491
|
+
_icon={{
|
|
492
|
+
size: 'sm',
|
|
493
|
+
}}
|
|
494
|
+
py={0}
|
|
495
|
+
/>
|
|
496
|
+
{rowComponent}
|
|
497
|
+
</Row>
|
|
498
|
+
{isExpanded ? getExpandedRowContent(row) : null}
|
|
499
|
+
</Column>
|
|
500
|
+
}
|
|
501
|
+
return rowComponent;
|
|
469
502
|
},
|
|
470
503
|
getReorderProxy = (node) => {
|
|
471
504
|
const
|
|
@@ -766,6 +799,9 @@ function GridComponent(props) {
|
|
|
766
799
|
}
|
|
767
800
|
Repository.pauseEvents();
|
|
768
801
|
}
|
|
802
|
+
if (onRender) {
|
|
803
|
+
onRender(self)
|
|
804
|
+
}
|
|
769
805
|
return () => {};
|
|
770
806
|
}
|
|
771
807
|
|
|
@@ -873,6 +909,11 @@ function GridComponent(props) {
|
|
|
873
909
|
if (!Repository.isAutoLoad) {
|
|
874
910
|
Repository.reload();
|
|
875
911
|
}
|
|
912
|
+
},
|
|
913
|
+
onChangePage = () => {
|
|
914
|
+
if (showRowExpander) {
|
|
915
|
+
expandedRowsRef.current = {}; // clear expanded rows
|
|
916
|
+
}
|
|
876
917
|
};
|
|
877
918
|
|
|
878
919
|
Repository.on('beforeLoad', setTrue);
|
|
@@ -883,7 +924,7 @@ function GridComponent(props) {
|
|
|
883
924
|
Repository.ons(['changeData', 'change'], forceUpdate);
|
|
884
925
|
Repository.on('changeFilters', onChangeFilters);
|
|
885
926
|
Repository.on('changeSorters', onChangeSorters);
|
|
886
|
-
|
|
927
|
+
Repository.on('changePage', onChangePage);
|
|
887
928
|
|
|
888
929
|
applySelectorSelected();
|
|
889
930
|
Repository.resumeEvents();
|
|
@@ -901,6 +942,7 @@ function GridComponent(props) {
|
|
|
901
942
|
Repository.offs(['changeData', 'change'], forceUpdate);
|
|
902
943
|
Repository.off('changeFilters', onChangeFilters);
|
|
903
944
|
Repository.off('changeSorters', onChangeSorters);
|
|
945
|
+
Repository.off('changePage', onChangePage);
|
|
904
946
|
};
|
|
905
947
|
}, [isInited]);
|
|
906
948
|
|
|
@@ -1055,7 +1097,6 @@ function GridComponent(props) {
|
|
|
1055
1097
|
{...sizeProps}
|
|
1056
1098
|
>{grid}</Box>
|
|
1057
1099
|
}
|
|
1058
|
-
|
|
1059
1100
|
return grid;
|
|
1060
1101
|
|
|
1061
1102
|
}
|
|
@@ -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,
|