Browse Source

row selected type

amenpunk 3 years ago
parent
commit
d705de3fc2
3 changed files with 54 additions and 43 deletions
  1. 1 1
      src/Components/Password/Rows.js
  2. 21 24
      src/Components/Password/config.js
  3. 32 18
      src/Pages/Contras.jsx

+ 1 - 1
src/Components/Password/Rows.js

@@ -49,7 +49,7 @@ export const encabezados = [
49 49
     },
50 50
     {
51 51
         id: 'ope',
52
-        numeric: true,
52
+        numeric: false,
53 53
         disablePadding: false,
54 54
         label: 'Operacion',
55 55
     },

+ 21 - 24
src/Components/Password/config.js

@@ -12,22 +12,30 @@ import { encabezados } from './Rows';
12 12
 import {
13 13
     Delete as DeleteIcon,
14 14
     FilterList as FilterListIcon,
15
-    // LastPage as LastPageIcon, FirstPage as FirstPageIcon, KeyboardArrowRight, KeyboardArrowLeft,
16 15
 } from '@mui/icons-material/'
17 16
 
18 17
 export const rows = [
19 18
     createData('Cupcake', 305, 'Analista',109238109238, 'SI', 'SI', 'Nice', 'Good'),
20 19
 ]
21 20
 
22
-for(let x of new Array(50)){
23
-    console.log(x)
24
-    rows.push(rows[0])
25
-}
21
+new Array(50).fill(50).forEach( (_,i) => {
22
+    rows.push({
23
+        ...rows[0],
24
+        nivel:i + 10000,
25
+        pass : Math.random().toString(36).slice(-6),
26
+    })
27
+})
26 28
 
29
+export const action_icon =  {
30
+    color: '#ec5e69',
31
+    fontSize: "20",
32
+    padding:1
33
+}
27 34
 
28 35
 export const TableEncabezadoOperation = (props) => {
29 36
 
30 37
     const { numSelected } = props;
38
+
31 39
     return (
32 40
         <Toolbar
33 41
             sx={{
@@ -46,7 +54,7 @@ export const TableEncabezadoOperation = (props) => {
46 54
                     variant="subtitle1"
47 55
                     component="div"
48 56
                 >
49
-                    {numSelected} selected
57
+                    {numSelected} Seleccionados
50 58
                 </Typography>
51 59
             ) : (
52 60
                     <Typography
@@ -60,13 +68,13 @@ export const TableEncabezadoOperation = (props) => {
60 68
                 )}
61 69
 
62 70
             {numSelected > 0 ? (
63
-                <Tooltip title="Delete">
71
+                <Tooltip title="Elimnar">
64 72
                     <IconButton>
65 73
                         <DeleteIcon />
66 74
                     </IconButton>
67 75
                 </Tooltip>
68 76
             ) : (
69
-                    <Tooltip title="Filter list">
77
+                    <Tooltip title="Buscar">
70 78
                         <IconButton>
71 79
                             <FilterListIcon />
72 80
                         </IconButton>
@@ -121,10 +129,10 @@ export function Cuerpo(array, comparator) {
121 129
     return stabilizedThis.map((el) => el[0]);
122 130
 }
123 131
 
124
-export function TableHeader(props){
125
-
126
-    const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } =
127
-        props;
132
+export function EnhancedTableHead(props){
133
+    // header de la tabla
134
+    
135
+    const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } = props;
128 136
     const createSortHandler = (property) => (event) => {
129 137
         onRequestSort(event, property);
130 138
     };
@@ -141,7 +149,7 @@ export function TableHeader(props){
141 149
                         inputProps={{
142 150
                             'aria-label': 'select all desserts',
143 151
                         }}
144
-                        />
152
+                    />
145 153
                 </TableCell>
146 154
                 { encabezados.map( (headCell, index) => (
147 155
                     <TableCell
@@ -169,14 +177,3 @@ export function TableHeader(props){
169 177
         </TableHead>
170 178
     );
171 179
 }
172
-
173
-export const action_icon =  {
174
-    color: '#ec5e69',
175
-    fontSize: "20",
176
-    padding:1
177
-    // background: '#ec5e69',
178
-    // color: "#fff",
179
-}
180
-
181
-
182
-

+ 32 - 18
src/Pages/Contras.jsx

@@ -11,7 +11,7 @@ import {
11 11
     action_icon,
12 12
     Comparar,
13 13
     Cuerpo,
14
-    TableHeader as EnhancedTableHead,
14
+    EnhancedTableHead,
15 15
     TableEncabezadoOperation
16 16
 } from '../Components/Password/config.js';
17 17
 
@@ -29,20 +29,19 @@ import { Row, Col, Container } from 'react-bootstrap';
29 29
 export function Contras() {
30 30
 
31 31
     const [order, setOrder] = React.useState('asc');
32
-    const [orderBy, setOrderBy] = React.useState('calories');
32
+    const [orderBy, setOrderBy] = React.useState('pass');
33 33
     const [selected, setSelected] = React.useState([]);
34 34
     const [page, setPage] = React.useState(0);
35 35
     const [dense, setDense] = React.useState(false);
36 36
     const [rowsPerPage, setRowsPerPage] = React.useState(10);
37 37
 
38
-    const handleRequestSort = (_event, property) => {
38
+    const CambiarTipoOrden = (_event, property) => {
39 39
         const isAsc = orderBy === property && order === 'asc';
40 40
         setOrder(isAsc ? 'desc' : 'asc');
41 41
         setOrderBy(property);
42 42
     };
43 43
 
44
-    const handleSelectAllClick = (event) => {
45
-
44
+    const SeleccionarTodos = (event) => {
46 45
         if (event.target.checked) {
47 46
             const newSelecteds = rows.map( (n) => n.name);
48 47
             setSelected(newSelecteds);
@@ -51,10 +50,13 @@ export function Contras() {
51 50
         setSelected([]);
52 51
     };
53 52
 
54
-    const handleClick = (__event, name) => {
53
+    const Seleccionar = (event, name) => {
54
+
55 55
         const selectedIndex = selected.indexOf(name);
56 56
         let newSelected = [];
57 57
 
58
+        console.log(name, selectedIndex)
59
+
58 60
         if (selectedIndex === -1) {
59 61
             newSelected = newSelected.concat(selected, name);
60 62
         } else if (selectedIndex === 0) {
@@ -96,36 +98,43 @@ export function Contras() {
96 98
                         <Col>
97 99
                             <Box sx={{ width: '100%' }}>
98 100
                                 <Paper sx={{ width: '100%', mb: 2 }}>
101
+
99 102
                                     <TableEncabezadoOperation numSelected={selected.length} />
103
+
100 104
                                     <TableContainer>
105
+
101 106
                                         <Table
102 107
                                             sx={{ minWidth: 750 }}
103 108
                                             aria-labelledby="tableTitle"
104
-                                            size={dense ? 'small' : 'medium'}
109
+                                            size={dense ? 'small' : 'medium'} 
105 110
                                         >
111
+
106 112
                                             <EnhancedTableHead
107 113
                                                 numSelected={selected.length}
108 114
                                                 order={order}
109 115
                                                 orderBy={orderBy}
110
-                                                onSelectAllClick={handleSelectAllClick}
111
-                                                onRequestSort={handleRequestSort}
112
-                                                rowCount={rows.length}
113
-                                                />
116
+                                                onSelectAllClick={SeleccionarTodos}
117
+                                                onRequestSort={CambiarTipoOrden}
118
+                                                rowCount={rows.length} />
119
+
120
+
114 121
                                             <TableBody>
115 122
                                                 {Cuerpo(rows, Comparar(order, orderBy))
116 123
                                                 .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
117 124
                                                 .map( (row, index) => {
118
-                                                    const isItemSelected = isSelected(row.name);
125
+
126
+                                                    const isItemSelected = isSelected(row.pass);
119 127
                                                     const labelId = `enhanced-table-checkbox-${index}`;
120 128
 
121 129
                                                     return (
122 130
                                                         <TableRow
123 131
                                                             hover
124
-                                                            onClick={(event) => handleClick(event, row.name)}
132
+                                                            onClick={(event) => Seleccionar(event, row.pass)}
133
+                                                            // onClick={(event) => console.log(event)}
125 134
                                                             role="checkbox"
126 135
                                                             aria-checked={isItemSelected}
127 136
                                                             tabIndex={-1}
128
-                                                            key={row.name}
137
+                                                            key={row.pass}
129 138
                                                             selected={isItemSelected}
130 139
                                                         >
131 140
                                                             <TableCell padding="checkbox">
@@ -135,7 +144,7 @@ export function Contras() {
135 144
                                                                     inputProps={{
136 145
                                                                         'aria-labelledby': labelId,
137 146
                                                                     }}
138
-                                                                />
147
+                                                                    />
139 148
                                                             </TableCell>
140 149
                                                             <TableCell
141 150
                                                                 component="th"
@@ -152,7 +161,7 @@ export function Contras() {
152 161
                                                             <TableCell align="right">{row.picture}</TableCell>
153 162
                                                             <TableCell align="right">{row.cv}</TableCell>
154 163
                                                             <TableCell align="right">{row.replic}</TableCell>
155
-                                                            <TableCell align="right">
164
+                                                            <TableCell align="center">
156 165
                                                                 <EditSharp  style={action_icon} />
157 166
                                                                 <MailSharp style={action_icon}/>
158 167
                                                             </TableCell>
@@ -171,6 +180,7 @@ export function Contras() {
171 180
                                             </TableBody>
172 181
                                         </Table>
173 182
                                     </TableContainer>
183
+
174 184
                                     <TablePagination
175 185
                                         rowsPerPageOptions={[5, 10, 25]}
176 186
                                         component="div"
@@ -179,12 +189,16 @@ export function Contras() {
179 189
                                         page={page}
180 190
                                         onPageChange={handleChangePage}
181 191
                                         onRowsPerPageChange={handleChangeRowsPerPage}
182
-                                        />
192
+                                    />
193
+
194
+
183 195
                                 </Paper>
196
+
184 197
                                 <FormControlLabel
185 198
                                     control={<Switch checked={dense} onChange={handleChangeDense} />}
186 199
                                     label="Comprimir"
187
-                                    />
200
+                                />
201
+
188 202
                             </Box>
189 203
                         </Col>
190 204
                     </Row>