|
1 |
| -import React from 'react' |
| 1 | +import React, { useEffect } from 'react' |
| 2 | +import TenantSelector from 'src/components/cipp/TenantSelector' |
| 3 | +import { useDispatch, useSelector } from 'react-redux' |
| 4 | +import { CSpinner } from '@coreui/react' |
| 5 | +import ToolkitProvider, { Search, CSVExport } from 'react-bootstrap-table2-toolkit' |
| 6 | +import BootstrapTable from 'react-bootstrap-table-next' |
| 7 | +import paginationFactory from 'react-bootstrap-table2-paginator' |
| 8 | +import { listOneDrives } from '../../../store/modules/oneDrive.js' |
| 9 | +import { CButton } from '@coreui/react' |
| 10 | + |
| 11 | +const { SearchBar } = Search |
| 12 | +const pagination = paginationFactory() |
| 13 | +const { ExportCSVButton } = CSVExport |
| 14 | + |
| 15 | +const columns = [ |
| 16 | + { |
| 17 | + text: 'Name', |
| 18 | + dataField: 'displayName', |
| 19 | + sort: true, |
| 20 | + }, |
| 21 | + { |
| 22 | + text: 'UPN', |
| 23 | + dataField: 'UPN', |
| 24 | + sort: true, |
| 25 | + }, |
| 26 | + { |
| 27 | + text: 'Last Active', |
| 28 | + dataField: 'LastActive', |
| 29 | + sort: true, |
| 30 | + }, |
| 31 | + { |
| 32 | + text: 'File Count (Total)', |
| 33 | + dataField: 'FileCount', |
| 34 | + sort: true, |
| 35 | + }, |
| 36 | + { |
| 37 | + text: 'Used (GB)', |
| 38 | + dataField: 'UsedGB', |
| 39 | + sort: true, |
| 40 | + }, |
| 41 | + { |
| 42 | + text: 'Allocated (GB)', |
| 43 | + dataField: 'Allocated', |
| 44 | + sort: true, |
| 45 | + }, |
| 46 | +] |
| 47 | + |
| 48 | +const OneDrives = () => { |
| 49 | + const dispatch = useDispatch() |
| 50 | + const tenant = useSelector((state) => state.app.currentTenant) |
| 51 | + const oneDrives = useSelector((state) => state.oneDrive.oneDrive) |
| 52 | + useEffect(() => { |
| 53 | + async function load() { |
| 54 | + if (Object.keys(tenant).length !== 0) { |
| 55 | + dispatch(listOneDrives({ tenant: tenant })) |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + load() |
| 60 | + }, []) |
| 61 | + |
| 62 | + const action = (tenant) => { |
| 63 | + dispatch(listOneDrives({ tenant: tenant })) |
| 64 | + } |
2 | 65 |
|
3 |
| -const OneDriveList = (props) => { |
4 | 66 | return (
|
5 | 67 | <div>
|
6 |
| - <h3>OneDriveList</h3> |
| 68 | + <TenantSelector action={action} /> |
| 69 | + <hr /> |
| 70 | + <div className="bg-white rounded p-5"> |
| 71 | + <h3>OneDrive List</h3> |
| 72 | + {Object.keys(tenant).length === 0 && <span>Select a tenant to get started.</span>} |
| 73 | + {!oneDrives.loaded && oneDrives.loading && <CSpinner />} |
| 74 | + {oneDrives.loaded && !oneDrives.loading && Object.keys(tenant).length !== 0 && ( |
| 75 | + <ToolkitProvider |
| 76 | + keyField="displayName" |
| 77 | + columns={columns} |
| 78 | + data={oneDrives.list} |
| 79 | + search |
| 80 | + exportCSV={{ |
| 81 | + filename: `${tenant.displayName} OneDrive Report List`, |
| 82 | + }} |
| 83 | + > |
| 84 | + {(props) => ( |
| 85 | + <div> |
| 86 | + {/* eslint-disable-next-line react/prop-types */} |
| 87 | + <SearchBar {...props.searchProps} /> |
| 88 | + {/* eslint-disable-next-line react/prop-types */} |
| 89 | + <ExportCSVButton {...props.csvProps}> |
| 90 | + <CButton>CSV</CButton> |
| 91 | + </ExportCSVButton> |
| 92 | + <hr /> |
| 93 | + {/*eslint-disable */} |
| 94 | + <BootstrapTable |
| 95 | + {...props.baseProps} |
| 96 | + pagination={pagination} |
| 97 | + wrapperClasses="table-responsive" |
| 98 | + /> |
| 99 | + {/*eslint-enable */} |
| 100 | + </div> |
| 101 | + )} |
| 102 | + </ToolkitProvider> |
| 103 | + )} |
| 104 | + {!oneDrives.loaded && !oneDrives.loading && oneDrives.error && ( |
| 105 | + <span>Failed to load OneDrive List</span> |
| 106 | + )} |
| 107 | + </div> |
7 | 108 | </div>
|
8 | 109 | )
|
9 | 110 | }
|
10 | 111 |
|
11 |
| -export default OneDriveList |
| 112 | +export default OneDrives |
0 commit comments