Skip to content

Commit 97250d7

Browse files
authored
Merge pull request #416 from gavsto/react
REACT: Added One Drive List
2 parents 9e8494b + 4a61e6e commit 97250d7

File tree

2 files changed

+151
-4
lines changed

2 files changed

+151
-4
lines changed

src/store/modules/oneDrive.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ const initialState = {
44
loading: false,
55
loaded: false,
66
},
7+
oneDrive: {
8+
list: [],
9+
loading: false,
10+
loaded: false,
11+
error: undefined,
12+
},
713
}
814

915
const ONEDRIVE_USAGE_LOAD = 'user/ONEDRIVE_USAGE_LOAD'
1016
const ONEDRIVE_USAGE_LOAD_SUCCESS = 'user/ONEDRIVE_USAGE_LOAD_SUCCESS'
1117
const ONEDRIVE_USAGE_LOAD_FAIL = 'user/ONEDRIVE_USAGE_LOAD_FAIL'
1218

19+
const ONEDRIVE_LOAD = 'oneDrive/ONEDRIVE_LOAD'
20+
const ONEDRIVE_LOAD_SUCCESS = 'oneDrive/ONEDRIVE_LOAD_SUCCESS'
21+
const ONEDRIVE_LOAD_ERROR = 'oneDrive/ONEDRIVE_LOAD_ERROR'
22+
1323
export default function reducer(state = initialState, action = {}) {
1424
switch (action.type) {
1525
case ONEDRIVE_USAGE_LOAD:
@@ -37,10 +47,46 @@ export default function reducer(state = initialState, action = {}) {
3747
error: action.error,
3848
},
3949
}
50+
case ONEDRIVE_LOAD:
51+
return {
52+
...state,
53+
oneDrive: {
54+
...state.oneDrive,
55+
loading: true,
56+
loaded: false,
57+
},
58+
}
59+
case ONEDRIVE_LOAD_SUCCESS:
60+
return {
61+
...state,
62+
oneDrive: {
63+
...state.oneDrive,
64+
list: action.result,
65+
loading: false,
66+
loaded: true,
67+
},
68+
}
69+
case ONEDRIVE_LOAD_ERROR:
70+
return {
71+
...state,
72+
oneDrive: {
73+
...initialState.oneDrive,
74+
error: action.error,
75+
},
76+
}
4077
default:
4178
return state
4279
}
4380
}
81+
export function listOneDrives({ tenant }) {
82+
return {
83+
types: [ONEDRIVE_LOAD, ONEDRIVE_LOAD_SUCCESS, ONEDRIVE_LOAD_ERROR],
84+
promise: (client) =>
85+
client
86+
.get('/api/ListSites?type=OneDriveUsageAccount&Tenantfilter=' + tenant.defaultDomainName)
87+
.then((result) => result.data),
88+
}
89+
}
4490

4591
// @todo is this only used for onedrive?
4692
export function listOneDriveUsage({ tenantDomain, userUPN }) {
Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,112 @@
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+
}
265

3-
const OneDriveList = (props) => {
466
return (
567
<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>
7108
</div>
8109
)
9110
}
10111

11-
export default OneDriveList
112+
export default OneDrives

0 commit comments

Comments
 (0)