-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,668 additions
and
1,070 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
'use client'; | ||
|
||
import { AllocationTable, useDashboardFilter } from '@/components'; | ||
import { useApiServerItems } from '@/hooks'; | ||
import { | ||
useOperatingSystemItems, | ||
useOrganizations, | ||
useServerItems, | ||
useTenants, | ||
} from '@/hooks/lists'; | ||
import { useFilteredStore } from '@/store'; | ||
import { useRouter } from 'next/navigation'; | ||
import { toast } from 'react-toastify'; | ||
|
||
export default function ServerDashboard() { | ||
const router = useRouter(); | ||
const { tenants } = useTenants({ init: true }); | ||
const { organizations } = useOrganizations({ | ||
init: true, | ||
includeTenants: true, | ||
}); | ||
const { operatingSystemItems } = useOperatingSystemItems({ | ||
init: true, | ||
}); | ||
const { isReady, serverItems } = useServerItems({ init: true }); | ||
const setFilteredValues = useFilteredStore((state) => state.setValues); | ||
const setFilteredOrganizations = useFilteredStore((state) => state.setOrganizations); | ||
const setFilteredServerItems = useFilteredStore((state) => state.setServerItems); | ||
const { download } = useApiServerItems(); | ||
|
||
const updateDashboard = useDashboardFilter(); | ||
|
||
return ( | ||
<AllocationTable | ||
margin={-75} | ||
serverItems={serverItems} | ||
loading={!isReady} | ||
onClick={async (serverItem) => { | ||
if (serverItem) { | ||
const tenant = tenants.find((tenant) => tenant.id === serverItem?.tenantId); | ||
const organization = organizations.find( | ||
(organization) => organization.id === serverItem?.organizationId, | ||
); | ||
const operatingSystemItem = operatingSystemItems.find( | ||
(operatingSystemItem) => operatingSystemItem.id === serverItem?.operatingSystemItemId, | ||
); | ||
const filteredOrganizations = tenant | ||
? organizations.filter((o) => o.tenants?.some((t) => t.id === tenant?.id)) | ||
: organizations; | ||
const filteredServerItems = serverItems.filter( | ||
(si) => | ||
(!tenant || si.tenantId === tenant.id) && | ||
(!organization || si.organizationId === organization.id) && | ||
(!operatingSystemItem || si.operatingSystemItemId === operatingSystemItem.id), | ||
); | ||
setFilteredOrganizations(filteredOrganizations); | ||
setFilteredServerItems(filteredServerItems); | ||
setFilteredValues((state) => ({ | ||
serverItem, | ||
tenant, | ||
organization, | ||
operatingSystemItem, | ||
})); | ||
await updateDashboard({ | ||
tenant, | ||
tenants, | ||
organization, | ||
organizations: filteredOrganizations, | ||
operatingSystemItem, | ||
operatingSystemItems, | ||
serverItem, | ||
serverItems: filteredServerItems, | ||
fetchFileSystemItems: false, | ||
}); | ||
router.push(`/client/dashboard?serverItem=${serverItem?.serviceNowKey}`); | ||
} | ||
}} | ||
showExport | ||
onExport={async (search) => { | ||
const toastLoading = toast.loading('Generating Excel document...'); | ||
|
||
try { | ||
await download({ | ||
search: search ? search : undefined, | ||
}); | ||
|
||
toast.dismiss(toastLoading); | ||
toast.success('Excel document has been downloaded successfully.'); | ||
} catch (ex) { | ||
toast.dismiss(toastLoading); | ||
|
||
const error = ex as Error; | ||
toast.error('Failed to download data. ' + error.message); | ||
console.error(error); | ||
} | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,21 @@ | ||
'use client'; | ||
|
||
import { AllocationTable, useDashboardFilter } from '@/components'; | ||
import { LoadingAnimation } from '@/components/loadingAnimation'; | ||
import { useApiServerItems, useAuth } from '@/hooks'; | ||
import { | ||
useOperatingSystemItems, | ||
useOrganizations, | ||
useServerItems, | ||
useTenants, | ||
} from '@/hooks/lists'; | ||
import { useFilteredStore } from '@/store'; | ||
import { redirect, useRouter } from 'next/navigation'; | ||
import { toast } from 'react-toastify'; | ||
import { useAuth } from '@/hooks'; | ||
import { redirect } from 'next/navigation'; | ||
import { Suspense } from 'react'; | ||
import ServerDashboard from './ServerDashboard'; | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
const state = useAuth(); | ||
const { tenants } = useTenants({ init: true }); | ||
const { organizations } = useOrganizations({ | ||
init: true, | ||
includeTenants: true, | ||
}); | ||
const { operatingSystemItems } = useOperatingSystemItems({ | ||
init: true, | ||
}); | ||
const { isReady, serverItems } = useServerItems({ init: true }); | ||
const setFilteredValues = useFilteredStore((state) => state.setValues); | ||
const setFilteredOrganizations = useFilteredStore((state) => state.setOrganizations); | ||
const setFilteredServerItems = useFilteredStore((state) => state.setServerItems); | ||
const { download } = useApiServerItems(); | ||
|
||
const updateDashboard = useDashboardFilter(); | ||
|
||
// Only allow Client role to view this page. | ||
if (state.status === 'loading') return <LoadingAnimation />; | ||
if (!state.isClient) redirect('/'); | ||
|
||
return ( | ||
<AllocationTable | ||
margin={-75} | ||
serverItems={serverItems} | ||
loading={!isReady} | ||
onClick={async (serverItem) => { | ||
if (serverItem) { | ||
const tenant = tenants.find((tenant) => tenant.id === serverItem?.tenantId); | ||
const organization = organizations.find( | ||
(organization) => organization.id === serverItem?.organizationId, | ||
); | ||
const operatingSystemItem = operatingSystemItems.find( | ||
(operatingSystemItem) => operatingSystemItem.id === serverItem?.operatingSystemItemId, | ||
); | ||
const filteredOrganizations = tenant | ||
? organizations.filter((o) => o.tenants?.some((t) => t.id === tenant?.id)) | ||
: organizations; | ||
const filteredServerItems = serverItems.filter( | ||
(si) => | ||
(!tenant || si.tenantId === tenant.id) && | ||
(!organization || si.organizationId === organization.id) && | ||
(!operatingSystemItem || si.operatingSystemItemId === operatingSystemItem.id), | ||
); | ||
setFilteredOrganizations(filteredOrganizations); | ||
setFilteredServerItems(filteredServerItems); | ||
setFilteredValues((state) => ({ serverItem, tenant, organization, operatingSystemItem })); | ||
await updateDashboard({ | ||
tenant, | ||
tenants, | ||
organization, | ||
organizations: filteredOrganizations, | ||
operatingSystemItem, | ||
operatingSystemItems, | ||
serverItem, | ||
serverItems: filteredServerItems, | ||
fetchFileSystemItems: false, | ||
}); | ||
router.push(`/client/dashboard?serverItem=${serverItem?.serviceNowKey}`); | ||
} | ||
}} | ||
showExport | ||
onExport={async (search) => { | ||
const toastLoading = toast.loading("Generating Excel document..."); | ||
|
||
try { | ||
await download({ | ||
search: search ? search : undefined, | ||
}); | ||
|
||
toast.dismiss(toastLoading); | ||
toast.success('Excel document has been downloaded successfully.'); | ||
|
||
} catch (ex) { | ||
toast.dismiss(toastLoading); | ||
|
||
const error = ex as Error; | ||
toast.error('Failed to download data. ' + error.message); | ||
console.error(error); | ||
} | ||
}} | ||
/> | ||
<Suspense fallback={<LoadingAnimation />}> | ||
<ServerDashboard /> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use client'; | ||
|
||
import { AllocationTable, useDashboardFilter } from '@/components'; | ||
import { useApiServerItems } from '@/hooks'; | ||
import { | ||
useOperatingSystemItems, | ||
useOrganizations, | ||
useServerItems, | ||
useTenants, | ||
} from '@/hooks/lists'; | ||
import { useFilteredStore } from '@/store'; | ||
import { useRouter } from 'next/navigation'; | ||
import { toast } from 'react-toastify'; | ||
|
||
export default function ServerDashboard() { | ||
const router = useRouter(); | ||
const { tenants } = useTenants({ init: true }); | ||
const { organizations } = useOrganizations({ | ||
init: true, | ||
includeTenants: true, | ||
}); | ||
const { operatingSystemItems } = useOperatingSystemItems({ | ||
init: true, | ||
}); | ||
const { isReady, serverItems } = useServerItems({ init: true }); | ||
const setFilteredValues = useFilteredStore((state) => state.setValues); | ||
const setFilteredOrganizations = useFilteredStore((state) => state.setOrganizations); | ||
const setFilteredServerItems = useFilteredStore((state) => state.setServerItems); | ||
const { download } = useApiServerItems(); | ||
|
||
const updateDashboard = useDashboardFilter(); | ||
|
||
return ( | ||
<AllocationTable | ||
margin={-75} | ||
serverItems={serverItems} | ||
loading={!isReady} | ||
onClick={async (serverItem) => { | ||
if (serverItem) { | ||
const tenant = tenants.find((tenant) => tenant.id === serverItem?.tenantId); | ||
const organization = organizations.find( | ||
(organization) => organization.id === serverItem?.organizationId, | ||
); | ||
const operatingSystemItem = operatingSystemItems.find( | ||
(operatingSystemItem) => operatingSystemItem.id === serverItem?.operatingSystemItemId, | ||
); | ||
const filteredOrganizations = tenant | ||
? organizations.filter((o) => o.tenants?.some((t) => t.id === tenant?.id)) | ||
: organizations; | ||
const filteredServerItems = serverItems.filter( | ||
(si) => | ||
(!tenant || si.tenantId === tenant.id) && | ||
(!organization || si.organizationId === organization.id) && | ||
(!operatingSystemItem || si.operatingSystemItemId === operatingSystemItem.id), | ||
); | ||
setFilteredOrganizations(filteredOrganizations); | ||
setFilteredServerItems(filteredServerItems); | ||
setFilteredValues((state) => ({ serverItem, tenant, organization, operatingSystemItem })); | ||
await updateDashboard({ | ||
tenant, | ||
tenants, | ||
organization, | ||
organizations: filteredOrganizations, | ||
operatingSystemItem, | ||
operatingSystemItems, | ||
serverItem, | ||
serverItems: filteredServerItems, | ||
fetchFileSystemItems: false, | ||
}); | ||
router.push(`/hsb/dashboard?serverItem=${serverItem?.serviceNowKey}`); | ||
} | ||
}} | ||
showExport | ||
onExport={async (search) => { | ||
const toastLoading = toast.loading('Generating Excel document...'); | ||
|
||
try { | ||
await download({ | ||
search: search ? search : undefined, | ||
}); | ||
|
||
toast.dismiss(toastLoading); | ||
toast.success('Excel document has been downloaded successfully.'); | ||
} catch (ex) { | ||
toast.dismiss(toastLoading); | ||
|
||
const error = ex as Error; | ||
toast.error('Failed to download data. ' + error.message); | ||
console.error(error); | ||
} | ||
}} | ||
/> | ||
); | ||
} |
Oops, something went wrong.