2022-02-24 23:22:56 +00:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
|
|
|
import { useEnvironmentId } from '@/portainer/hooks/useEnvironmentId';
|
|
|
|
import { error as notifyError } from '@/portainer/services/notifications';
|
|
|
|
import PortainerError from '@/portainer/error';
|
|
|
|
import { r2a } from '@/react-tools/react2angular';
|
|
|
|
|
2022-06-17 16:18:42 +00:00
|
|
|
import { DashboardItem } from '@@/DashboardItem';
|
|
|
|
import { PageHeader } from '@@/PageHeader';
|
2022-07-06 08:23:53 +00:00
|
|
|
import { DashboardGrid } from '@@/DashboardItem/DashboardGrid';
|
2022-06-17 16:18:42 +00:00
|
|
|
|
2022-02-24 23:22:56 +00:00
|
|
|
import { useResourceGroups, useSubscriptions } from '../queries';
|
|
|
|
|
|
|
|
export function DashboardView() {
|
|
|
|
const environmentId = useEnvironmentId();
|
|
|
|
|
|
|
|
const subscriptionsQuery = useSubscriptions(environmentId);
|
|
|
|
useEffect(() => {
|
|
|
|
if (subscriptionsQuery.isError) {
|
|
|
|
notifyError(
|
|
|
|
'Failure',
|
|
|
|
subscriptionsQuery.error as PortainerError,
|
|
|
|
'Unable to retrieve subscriptions'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, [subscriptionsQuery.error, subscriptionsQuery.isError]);
|
|
|
|
|
|
|
|
const resourceGroupsQuery = useResourceGroups(
|
|
|
|
environmentId,
|
|
|
|
subscriptionsQuery.data
|
|
|
|
);
|
|
|
|
useEffect(() => {
|
|
|
|
if (resourceGroupsQuery.isError && resourceGroupsQuery.error) {
|
|
|
|
notifyError(
|
|
|
|
'Failure',
|
|
|
|
resourceGroupsQuery.error as PortainerError,
|
|
|
|
`Unable to retrieve resource groups`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, [resourceGroupsQuery.error, resourceGroupsQuery.isError]);
|
|
|
|
|
|
|
|
const isLoading =
|
|
|
|
subscriptionsQuery.isLoading || resourceGroupsQuery.isLoading;
|
|
|
|
if (isLoading) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const subscriptionsCount = subscriptionsQuery?.data?.length;
|
|
|
|
const resourceGroupsCount = Object.values(
|
|
|
|
resourceGroupsQuery?.resourceGroups
|
|
|
|
).flatMap((x) => Object.values(x)).length;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PageHeader title="Home" breadcrumbs={[{ label: 'Dashboard' }]} />
|
|
|
|
|
2022-07-06 08:23:53 +00:00
|
|
|
<div className="mx-4">
|
|
|
|
{subscriptionsQuery.data && (
|
|
|
|
<DashboardGrid>
|
2022-02-24 23:22:56 +00:00
|
|
|
<DashboardItem
|
2022-07-06 08:23:53 +00:00
|
|
|
value={subscriptionsCount as number}
|
2022-02-24 23:22:56 +00:00
|
|
|
icon="fa fa-th-list"
|
2022-07-06 08:23:53 +00:00
|
|
|
type="Subscription"
|
2022-02-24 23:22:56 +00:00
|
|
|
/>
|
2022-07-06 08:23:53 +00:00
|
|
|
{!resourceGroupsQuery.isError && !resourceGroupsQuery.isLoading && (
|
|
|
|
<DashboardItem
|
|
|
|
value={resourceGroupsCount}
|
|
|
|
icon="fa fa-th-list"
|
|
|
|
type="Resource group"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</DashboardGrid>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-02-24 23:22:56 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DashboardViewAngular = r2a(DashboardView, []);
|