1
1
import AddIcon from "@mui/icons-material/Add" ;
2
+ import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward" ;
3
+ import ArrowUpwardIcon from "@mui/icons-material/ArrowUpward" ;
2
4
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline" ;
3
5
import GroupIcon from "@mui/icons-material/Group" ;
4
6
import {
@@ -14,7 +16,6 @@ import {
14
16
TableRow ,
15
17
Typography ,
16
18
} from "@mui/material" ;
17
- import { styled } from "@mui/material/styles" ;
18
19
import { makeStyles } from "@mui/styles" ;
19
20
import React , { FC , useMemo } from "react" ;
20
21
import { Link } from "react-router-dom" ;
@@ -28,14 +29,31 @@ const useStyles = makeStyles<Theme>((theme) => ({
28
29
button : {
29
30
margin : theme . spacing ( 1 ) ,
30
31
} ,
31
- } ) ) ;
32
+ tableRow : {
33
+ "&:nth-of-type(odd)" : {
34
+ backgroundColor : "white" ,
35
+ } ,
36
+ "&:nth-of-type(even)" : {
37
+ backgroundColor : "#607D8B0A" ,
38
+ } ,
39
+ } ,
40
+ highlightedTableRow : {
41
+ backgroundColor : "yellow" ,
32
42
33
- const StyledTableRow = styled ( TableRow ) ( ( { theme } ) => ( {
34
- "&:nth-of-type(odd)" : {
35
- backgroundColor : "white" ,
43
+ // TODO reset the animation with considering rerendering
44
+ // animation: `$highlighted ease 1s 1`,
45
+ // "&:nth-of-type(odd)": {
46
+ // backgroundColor: "white",
47
+ // },
48
+ // "&:nth-of-type(even)": {
49
+ // backgroundColor: "#607D8B0A",
50
+ // },
36
51
} ,
37
- "&:nth-of-type(even)" : {
38
- backgroundColor : "#607D8B0A" ,
52
+
53
+ "@keyframes highlighted" : {
54
+ "0%" : {
55
+ backgroundColor : "yellow" ,
56
+ } ,
39
57
} ,
40
58
} ) ) ;
41
59
@@ -46,6 +64,8 @@ interface Props {
46
64
referralEntities : Entity [ ] ;
47
65
entityInfo : EntityUpdate ;
48
66
setEntityInfo : ( entityInfo : EntityUpdate ) => void ;
67
+ latestChangedIndex ?: number ;
68
+ setLatestChangedIndex : ( latestChangedIndex : number ) => void ;
49
69
}
50
70
51
71
export const AttributeRow : FC < Props > = ( {
@@ -55,6 +75,8 @@ export const AttributeRow: FC<Props> = ({
55
75
referralEntities,
56
76
entityInfo,
57
77
setEntityInfo,
78
+ latestChangedIndex,
79
+ setLatestChangedIndex,
58
80
} ) => {
59
81
const classes = useStyles ( ) ;
60
82
@@ -69,6 +91,18 @@ export const AttributeRow: FC<Props> = ({
69
91
setEntityInfo ( { ...entityInfo , attrs : [ ...allAttrs ] } ) ;
70
92
} ;
71
93
94
+ const handleChangeOrderAttribute = ( index : number , order : number ) => {
95
+ const newIndex = index - order ;
96
+ const oldIndex = index ;
97
+ const x = allAttrs [ newIndex ] ;
98
+ allAttrs [ newIndex ] = allAttrs [ oldIndex ] ;
99
+ allAttrs [ oldIndex ] = x ;
100
+ allAttrs [ newIndex ] . index = index + 1 - order ;
101
+ allAttrs [ oldIndex ] . index = index + 1 ;
102
+ setLatestChangedIndex ( newIndex ) ;
103
+ setEntityInfo ( { ...entityInfo , attrs : [ ...allAttrs ] } ) ;
104
+ } ;
105
+
72
106
const handleDeleteAttribute = ( index : number ) => {
73
107
allAttrs [ index ] = {
74
108
...allAttrs [ index ] ,
@@ -95,7 +129,13 @@ export const AttributeRow: FC<Props> = ({
95
129
} ;
96
130
97
131
return (
98
- < StyledTableRow >
132
+ < TableRow
133
+ className = {
134
+ index === latestChangedIndex
135
+ ? classes . highlightedTableRow
136
+ : classes . tableRow
137
+ }
138
+ >
99
139
< TableCell >
100
140
{ index !== undefined && (
101
141
< Input
@@ -180,6 +220,28 @@ export const AttributeRow: FC<Props> = ({
180
220
) }
181
221
</ TableCell >
182
222
223
+ < TableCell >
224
+ { index !== undefined && (
225
+ < Box display = "flex" flexDirection = "column" >
226
+ < IconButton
227
+ disabled = { index === 0 }
228
+ className = { classes . button }
229
+ onClick = { ( e ) => handleChangeOrderAttribute ( index , 1 ) }
230
+ >
231
+ < ArrowUpwardIcon />
232
+ </ IconButton >
233
+
234
+ < IconButton
235
+ disabled = { index === allAttrs . length - 1 }
236
+ className = { classes . button }
237
+ onClick = { ( e ) => handleChangeOrderAttribute ( index , - 1 ) }
238
+ >
239
+ < ArrowDownwardIcon />
240
+ </ IconButton >
241
+ </ Box >
242
+ ) }
243
+ </ TableCell >
244
+
183
245
< TableCell >
184
246
{ index !== undefined && (
185
247
< IconButton
@@ -216,6 +278,6 @@ export const AttributeRow: FC<Props> = ({
216
278
</ Button >
217
279
) }
218
280
</ TableCell >
219
- </ StyledTableRow >
281
+ </ TableRow >
220
282
) ;
221
283
} ;
0 commit comments