mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(nomad): sync frontend with EE [EE-3353] (#7758)
This commit is contained in:
parent
78dcba614d
commit
881e99df53
68 changed files with 1799 additions and 17 deletions
83
app/react/nomad/DashboardView/DashboardView.tsx
Normal file
83
app/react/nomad/DashboardView/DashboardView.tsx
Normal file
|
@ -0,0 +1,83 @@
|
|||
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
|
||||
|
||||
import { DashboardItem } from '@@/DashboardItem';
|
||||
import { Widget, WidgetTitle, WidgetBody } from '@@/Widget';
|
||||
import { PageHeader } from '@@/PageHeader';
|
||||
import { DashboardGrid } from '@@/DashboardItem/DashboardGrid';
|
||||
|
||||
import { useDashboard } from './useDashboard';
|
||||
import { RunningStatus } from './RunningStatus';
|
||||
|
||||
export function DashboardView() {
|
||||
const environmentId = useEnvironmentId();
|
||||
const dashboardQuery = useDashboard(environmentId);
|
||||
|
||||
const running = dashboardQuery.data?.RunningTaskCount || 0;
|
||||
const stopped = (dashboardQuery.data?.TaskCount || 0) - running;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Dashboard"
|
||||
breadcrumbs={[{ label: 'Environment summary' }]}
|
||||
/>
|
||||
|
||||
{dashboardQuery.isLoading ? (
|
||||
<div className="text-center" style={{ marginTop: '30%' }}>
|
||||
Connecting to the Edge environment...
|
||||
<i className="fa fa-cog fa-spin space-left" />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="row">
|
||||
<div className="col-sm-12">
|
||||
{/* cluster info */}
|
||||
<Widget>
|
||||
<WidgetTitle
|
||||
icon="fa-tachometer-alt"
|
||||
title="Cluster information"
|
||||
/>
|
||||
<WidgetBody className="no-padding">
|
||||
<table className="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Nodes in the cluster</td>
|
||||
<td>{dashboardQuery.data?.NodeCount ?? '-'}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</WidgetBody>
|
||||
</Widget>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mx-4">
|
||||
<DashboardGrid>
|
||||
{/* jobs */}
|
||||
<DashboardItem
|
||||
value={dashboardQuery.data?.JobCount}
|
||||
icon="fa fa-th-list"
|
||||
type="Nomad Job"
|
||||
/>
|
||||
{/* groups */}
|
||||
<DashboardItem
|
||||
value={dashboardQuery.data?.GroupCount}
|
||||
icon="fa fa-list-alt"
|
||||
type="Group"
|
||||
/>
|
||||
{/* tasks */}
|
||||
<DashboardItem
|
||||
value={dashboardQuery.data?.TaskCount}
|
||||
icon="fa fa-cubes"
|
||||
type="Task"
|
||||
>
|
||||
{/* running status of tasks */}
|
||||
<RunningStatus running={running} stopped={stopped} />
|
||||
</DashboardItem>
|
||||
</DashboardGrid>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
25
app/react/nomad/DashboardView/RunningStatus.tsx
Normal file
25
app/react/nomad/DashboardView/RunningStatus.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
interface Props {
|
||||
running: number;
|
||||
stopped: number;
|
||||
}
|
||||
|
||||
export function RunningStatus({ running, stopped }: Props) {
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<i
|
||||
className="fa fa-power-off green-icon space-right"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{`${running || '-'} running`}
|
||||
</div>
|
||||
<div>
|
||||
<i
|
||||
className="fa fa-power-off red-icon space-right"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{`${stopped || '-'} stopped`}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
1
app/react/nomad/DashboardView/index.ts
Normal file
1
app/react/nomad/DashboardView/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { DashboardView } from './DashboardView';
|
41
app/react/nomad/DashboardView/useDashboard.ts
Normal file
41
app/react/nomad/DashboardView/useDashboard.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
export type DashboardResponse = {
|
||||
JobCount: number;
|
||||
GroupCount: number;
|
||||
TaskCount: number;
|
||||
RunningTaskCount: number;
|
||||
NodeCount: number;
|
||||
};
|
||||
|
||||
export function useDashboard(environmentId: EnvironmentId) {
|
||||
return useQuery(
|
||||
['environments', environmentId, 'nomad', 'dashboard'],
|
||||
() => getDashboard(environmentId),
|
||||
{
|
||||
meta: {
|
||||
error: {
|
||||
title: 'Failure',
|
||||
message: 'Unable to get dashboard information',
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getDashboard(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: dashboard } = await axios.get<DashboardResponse>(
|
||||
`/nomad/endpoints/${environmentId}/dashboard`,
|
||||
{
|
||||
params: {},
|
||||
}
|
||||
);
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue