@autobusal/common 1.33.0 → 1.33.1
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/CHANGELOG.md +6 -0
- package/Table/Rows/Rows.tsx +25 -2
- package/Table/Rows/styles.ts +5 -1
- package/Table/Table.tsx +11 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## 1.33.1
|
|
5
|
+
|
|
6
|
+
### Added
|
|
7
|
+
|
|
8
|
+
- **`Table` accepts an optional `onReorder(draggedId, targetId)` prop.** When set, every row becomes an HTML5 drag source/drop target (dims to 40% opacity while being dragged) and a completed drag reports the dragged row's id and the row it was dropped on - the caller decides what "reorder" means for its own data. Omitted by every existing table, so this is purely additive; first consumer is `@autobusal/admin-menu` 1.1.2.
|
|
9
|
+
|
|
4
10
|
## 1.33.0
|
|
5
11
|
|
|
6
12
|
### Fixed
|
package/Table/Rows/Rows.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TFunction } from 'i18next';
|
|
2
|
+
import { useState } from 'react';
|
|
2
3
|
import { NavigateFunction } from 'react-router-dom';
|
|
3
4
|
import Loading from './Loading';
|
|
4
5
|
import NotFound from './NotFound';
|
|
@@ -18,9 +19,11 @@ interface Props {
|
|
|
18
19
|
actions?: string[]
|
|
19
20
|
handlers?: any
|
|
20
21
|
navigate: NavigateFunction
|
|
22
|
+
onReorder?: (draggedId: number, targetId: number) => void
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
const Rows = ({ url, urlWith, data, loading, fetching, colLength, empty, t, actions, handlers, navigate }: Props): JSX.Element => {
|
|
25
|
+
const Rows = ({ url, urlWith, data, loading, fetching, colLength, empty, t, actions, handlers, navigate, onReorder }: Props): JSX.Element => {
|
|
26
|
+
const [ draggedId, setDraggedId ] = useState<number | null>(null);
|
|
24
27
|
if (loading) {
|
|
25
28
|
return <Loading length={ colLength } t={ t } />;
|
|
26
29
|
}
|
|
@@ -43,8 +46,28 @@ const Rows = ({ url, urlWith, data, loading, fetching, colLength, empty, t, acti
|
|
|
43
46
|
// table's list, which is what every existing caller relies on.
|
|
44
47
|
const available = item.props.actions ?? actions;
|
|
45
48
|
|
|
49
|
+
const id = item.props.id;
|
|
50
|
+
|
|
46
51
|
return (
|
|
47
|
-
<Tr
|
|
52
|
+
<Tr
|
|
53
|
+
key={ index }
|
|
54
|
+
$viewable={ isViewable }
|
|
55
|
+
$dragging={ onReorder !== undefined && draggedId === id }
|
|
56
|
+
draggable={ onReorder !== undefined }
|
|
57
|
+
onClick={ () => onClick(id) }
|
|
58
|
+
onDragStart={ onReorder && (() => setDraggedId(id)) }
|
|
59
|
+
onDragOver={ onReorder && (event => event.preventDefault()) }
|
|
60
|
+
onDragEnd={ onReorder && (() => setDraggedId(null)) }
|
|
61
|
+
onDrop={ onReorder && (event => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
|
|
64
|
+
if (draggedId !== null && draggedId !== id) {
|
|
65
|
+
onReorder(draggedId, id);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setDraggedId(null);
|
|
69
|
+
}) }
|
|
70
|
+
>
|
|
48
71
|
{ item }
|
|
49
72
|
|
|
50
73
|
{ rowActions(available).length > 0 && (
|
package/Table/Rows/styles.ts
CHANGED
|
@@ -19,11 +19,15 @@ export const Tbody = styled.tbody<{ $fetching: boolean }>`
|
|
|
19
19
|
` }
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
|
-
export const Tr = styled.tr<{ $viewable?: boolean }>`
|
|
22
|
+
export const Tr = styled.tr<{ $viewable?: boolean, $dragging?: boolean }>`
|
|
23
23
|
${ props => props.$viewable && css`
|
|
24
24
|
cursor: pointer;
|
|
25
25
|
` }
|
|
26
26
|
|
|
27
|
+
${ props => props.$dragging && css`
|
|
28
|
+
opacity: .4;
|
|
29
|
+
` }
|
|
30
|
+
|
|
27
31
|
text-align: center;
|
|
28
32
|
|
|
29
33
|
& > td:first-of-type {
|
package/Table/Table.tsx
CHANGED
|
@@ -33,9 +33,18 @@ interface Props {
|
|
|
33
33
|
*/
|
|
34
34
|
empty?: string
|
|
35
35
|
handlers?: any
|
|
36
|
+
/*
|
|
37
|
+
* Edited: Ferjolt Ozuni - Date: 2026-08-10
|
|
38
|
+
* Turns every row into an HTML5 drag source/drop target and reports a
|
|
39
|
+
* completed drag as (the dragged row's id, the row it was dropped on).
|
|
40
|
+
* The caller decides what "reorder" means for its own data (e.g.
|
|
41
|
+
* recomputing a full id list to persist) - Table only reports the drag.
|
|
42
|
+
* Omitted by every other table, so this is purely additive.
|
|
43
|
+
*/
|
|
44
|
+
onReorder?: (draggedId: number, targetId: number) => void
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
const Table = ({ url, urlWith, columns, rows, pages, sorting, search, loading, fetching, t, actions, extra, empty, handlers }: Props): JSX.Element => {
|
|
47
|
+
const Table = ({ url, urlWith, columns, rows, pages, sorting, search, loading, fetching, t, actions, extra, empty, handlers, onReorder }: Props): JSX.Element => {
|
|
39
48
|
const navigate = useNavigate();
|
|
40
49
|
|
|
41
50
|
const colLength = columns.length + 1;
|
|
@@ -75,6 +84,7 @@ const Table = ({ url, urlWith, columns, rows, pages, sorting, search, loading, f
|
|
|
75
84
|
actions={ actions }
|
|
76
85
|
handlers={ handlers }
|
|
77
86
|
navigate={ navigate }
|
|
87
|
+
onReorder={ onReorder }
|
|
78
88
|
/>
|
|
79
89
|
|
|
80
90
|
<Paginate data={ pages } colLength={ colLength } t={ t } />
|