-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWoComponents.html
130 lines (113 loc) · 5.01 KB
/
WoComponents.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script type="text/babel">
const PaginationComponent = ({ page, setPage, totalItems }) => {
const [lastPage, setLastPage] = React.useState()
React.useEffect(() => {
setLastPage(Math.ceil(totalItems / 15))
}, [totalItems])
return (
<div className='button-container' >
<button disabled={page === 1} onClick={() => setPage(1)} >
<svg xmlns="http://www.w3.org/2000/svg" style={{ height: '0.7em' }} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M11 19l-7-7 7-7m8 14l-7-7 7-7" />
</svg>
</button>
<button disabled={page === 1} onClick={() => setPage(page - 1)} >
<svg xmlns="http://www.w3.org/2000/svg" style={{ height: '0.7em' }} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2">
<path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
</svg>
</button>
<button className={`${page === 1 ? 'selected-page' : ''}`} onClick={() => page > 4 ? setPage(page - 2) : setPage(1)}>
{page > 4 ? page - 2 : 1}
</button>
<button className={`${page === 2 ? 'selected-page' : ''}`} onClick={() => page > 4 ? setPage(page - 1) : setPage(2)}>
{page > 4 ? page - 1 : 2}
</button>
<button className={`${page === 3 || page >= 5 && page <= lastPage - 2 ? 'selected-page' : ''}`} onClick={() => page > 4 ? '' : setPage(3)}>
{page > 4 ? page : 3}
</button>
<button className={`${page === 4 || page === lastPage - 1 ? 'selected-page' : ''}`} onClick={() => page > 4 ? setPage(page + 1) : setPage(4)}>
{page > 4 ? page + 1 : 4}
</button>
<button className={`${page === lastPage ? 'selected-page' : ''}`} onClick={() => page > 4 ? setPage(page + 2) : setPage(5)}>
{page > 4 ? page + 2 : 5}
</button>
<button disabled={page === lastPage} onClick={() => setPage(page + 1)}>
<svg xmlns="http://www.w3.org/2000/svg" style={{ height: '0.7em' }} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
</svg>
</button>
<button disabled={page === lastPage} onClick={() => setPage(lastPage)} >
<svg xmlns="http://www.w3.org/2000/svg" style={{ height: '0.7em' }} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M13 5l7 7-7 7M5 5l7 7-7 7" />
</svg>
</button>
</div>
)
}
const WoTable = ({ searchQuery }) => {
const [allWos, setAllWos] = React.useState([])
const [WOs, setWOs] = React.useState([]);
const [pageNumber, setPageNumber] = React.useState(1);
const [loading, setLoading] = React.useState(true);
const [firstPageItem, setFirstPageItem] = React.useState(0)
const pageItems = 15;
const getRegistersFromBack = () => {
google.script.run.withSuccessHandler((results) => {
setAllWos(results.slice(1).reverse())
setWOs(results.slice(1).reverse())
setLoading(false)
}
).getAllRegisters(pageNumber, pageItems)
}
React.useEffect(() => {
console.log('Effect chamado')
setPageNumber(1)
if (allWos) {
console.log('WOs setadas', searchQuery)
setWOs(allWos.filter(item => `${item[8]} ${item[1]}`.toLowerCase().includes(searchQuery.toLowerCase())))
}
}, [searchQuery])
React.useEffect(() => {
setLoading(true)
getRegistersFromBack();
}, [])
return (
loading ?
<Loading />
:
<div className='table-container'>
<table className='table'>
<thead>
<tr>
<th scope='col'>Data</th>
<th scope='col'>Equipamento</th>
<th scope='col'>Patrimônio</th>
<th scope='col'>Serviço</th>
<th scope='col'>Arquivo</th>
</tr>
</thead>
<tbody>
{
WOs
.slice((pageNumber - 1) * pageItems, pageItems * pageNumber)
.map((item) => {
return (
<tr style={{ maxHeigth: '3rem' }}>
<td>{item[3]}</td>
<td>{item[7]}</td>
<td style={{ textAlign: 'center' }} >{item[2]}</td>
<td>{item[5]}</td>
<td style={{ textAlign: 'center' }} ><a href={item[4]} target='_blank' >
<img src='https://www.iconpacks.net/icons/2/free-file-icon-1453-thumb.png' style={{ width: '2rem' }}></img>
</a></td>
</tr>
)
})
}
</tbody>
</table>
<PaginationComponent page={pageNumber} setPage={setPageNumber} totalItems={WOs.length} />
</div>
)
}
</script>