From 4a61e6ed4afe876c2511d338184a7a354b69b26e Mon Sep 17 00:00:00 2001 From: Gavsto Date: Wed, 8 Dec 2021 23:02:45 +0000 Subject: [PATCH] REACT: Added One Drive List REACT: Added One Drive List --- src/store/modules/oneDrive.js | 46 ++++++++ .../teams-share/onedrive/OneDriveList.js | 109 +++++++++++++++++- 2 files changed, 151 insertions(+), 4 deletions(-) diff --git a/src/store/modules/oneDrive.js b/src/store/modules/oneDrive.js index 6b55e4c2f7fd..80eefb604b63 100644 --- a/src/store/modules/oneDrive.js +++ b/src/store/modules/oneDrive.js @@ -4,12 +4,22 @@ const initialState = { loading: false, loaded: false, }, + oneDrive: { + list: [], + loading: false, + loaded: false, + error: undefined, + }, } const ONEDRIVE_USAGE_LOAD = 'user/ONEDRIVE_USAGE_LOAD' const ONEDRIVE_USAGE_LOAD_SUCCESS = 'user/ONEDRIVE_USAGE_LOAD_SUCCESS' const ONEDRIVE_USAGE_LOAD_FAIL = 'user/ONEDRIVE_USAGE_LOAD_FAIL' +const ONEDRIVE_LOAD = 'oneDrive/ONEDRIVE_LOAD' +const ONEDRIVE_LOAD_SUCCESS = 'oneDrive/ONEDRIVE_LOAD_SUCCESS' +const ONEDRIVE_LOAD_ERROR = 'oneDrive/ONEDRIVE_LOAD_ERROR' + export default function reducer(state = initialState, action = {}) { switch (action.type) { case ONEDRIVE_USAGE_LOAD: @@ -37,10 +47,46 @@ export default function reducer(state = initialState, action = {}) { error: action.error, }, } + case ONEDRIVE_LOAD: + return { + ...state, + oneDrive: { + ...state.oneDrive, + loading: true, + loaded: false, + }, + } + case ONEDRIVE_LOAD_SUCCESS: + return { + ...state, + oneDrive: { + ...state.oneDrive, + list: action.result, + loading: false, + loaded: true, + }, + } + case ONEDRIVE_LOAD_ERROR: + return { + ...state, + oneDrive: { + ...initialState.oneDrive, + error: action.error, + }, + } default: return state } } +export function listOneDrives({ tenant }) { + return { + types: [ONEDRIVE_LOAD, ONEDRIVE_LOAD_SUCCESS, ONEDRIVE_LOAD_ERROR], + promise: (client) => + client + .get('/api/ListSites?type=OneDriveUsageAccount&Tenantfilter=' + tenant.defaultDomainName) + .then((result) => result.data), + } +} // @todo is this only used for onedrive? export function listOneDriveUsage({ tenantDomain, userUPN }) { diff --git a/src/views/teams-share/onedrive/OneDriveList.js b/src/views/teams-share/onedrive/OneDriveList.js index c4718383cc4b..f21239be147c 100644 --- a/src/views/teams-share/onedrive/OneDriveList.js +++ b/src/views/teams-share/onedrive/OneDriveList.js @@ -1,11 +1,112 @@ -import React from 'react' +import React, { useEffect } from 'react' +import TenantSelector from 'src/components/cipp/TenantSelector' +import { useDispatch, useSelector } from 'react-redux' +import { CSpinner } from '@coreui/react' +import ToolkitProvider, { Search, CSVExport } from 'react-bootstrap-table2-toolkit' +import BootstrapTable from 'react-bootstrap-table-next' +import paginationFactory from 'react-bootstrap-table2-paginator' +import { listOneDrives } from '../../../store/modules/oneDrive.js' +import { CButton } from '@coreui/react' + +const { SearchBar } = Search +const pagination = paginationFactory() +const { ExportCSVButton } = CSVExport + +const columns = [ + { + text: 'Name', + dataField: 'displayName', + sort: true, + }, + { + text: 'UPN', + dataField: 'UPN', + sort: true, + }, + { + text: 'Last Active', + dataField: 'LastActive', + sort: true, + }, + { + text: 'File Count (Total)', + dataField: 'FileCount', + sort: true, + }, + { + text: 'Used (GB)', + dataField: 'UsedGB', + sort: true, + }, + { + text: 'Allocated (GB)', + dataField: 'Allocated', + sort: true, + }, +] + +const OneDrives = () => { + const dispatch = useDispatch() + const tenant = useSelector((state) => state.app.currentTenant) + const oneDrives = useSelector((state) => state.oneDrive.oneDrive) + useEffect(() => { + async function load() { + if (Object.keys(tenant).length !== 0) { + dispatch(listOneDrives({ tenant: tenant })) + } + } + + load() + }, []) + + const action = (tenant) => { + dispatch(listOneDrives({ tenant: tenant })) + } -const OneDriveList = (props) => { return (
-

OneDriveList

+ +
+
+

OneDrive List

+ {Object.keys(tenant).length === 0 && Select a tenant to get started.} + {!oneDrives.loaded && oneDrives.loading && } + {oneDrives.loaded && !oneDrives.loading && Object.keys(tenant).length !== 0 && ( + + {(props) => ( +
+ {/* eslint-disable-next-line react/prop-types */} + + {/* eslint-disable-next-line react/prop-types */} + + CSV + +
+ {/*eslint-disable */} + + {/*eslint-enable */} +
+ )} +
+ )} + {!oneDrives.loaded && !oneDrives.loading && oneDrives.error && ( + Failed to load OneDrive List + )} +
) } -export default OneDriveList +export default OneDrives