refactor(app): redesign dashboard-item component [EE-3634] (#7175)

pull/7204/head
Chaim Lev-Ari 2022-07-06 11:23:53 +03:00 committed by GitHub
parent a66fd78dc1
commit 8bf1c91bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 236 additions and 248 deletions

View File

@ -89,6 +89,14 @@ pr-icon {
stroke: var(--white-color); stroke: var(--white-color);
} }
.icon-badge {
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
padding: 1.5%;
}
.icon-nested-gray { .icon-nested-gray {
height: 30px; height: 30px;
width: 30px; width: 30px;

View File

@ -32,12 +32,14 @@
} }
a { a {
color: var(--text-link-color); color: inherit;
cursor: pointer;
} }
a:hover, a:hover,
a:focus { a:focus {
color: var(--text-link-hover-color); color: inherit;
text-decoration: none;
} }
.input-group-addon { .input-group-addon {

View File

@ -19,7 +19,7 @@ jest.mock('@uirouter/react', () => ({
test('dashboard items should render correctly', async () => { test('dashboard items should render correctly', async () => {
const { getByLabelText } = await renderComponent(); const { getByLabelText } = await renderComponent();
const subscriptionsItem = getByLabelText('Subscriptions'); const subscriptionsItem = getByLabelText('Subscription');
expect(subscriptionsItem).toBeVisible(); expect(subscriptionsItem).toBeVisible();
const subscriptionElements = within(subscriptionsItem); const subscriptionElements = within(subscriptionsItem);
@ -31,7 +31,7 @@ test('dashboard items should render correctly', async () => {
'Subscriptions' 'Subscriptions'
); );
const resourceGroupsItem = getByLabelText('Resource groups'); const resourceGroupsItem = getByLabelText('Resource group');
expect(resourceGroupsItem).toBeVisible(); expect(resourceGroupsItem).toBeVisible();
const resourceGroupElements = within(resourceGroupsItem); const resourceGroupElements = within(resourceGroupsItem);
@ -47,20 +47,20 @@ test('dashboard items should render correctly', async () => {
test('when there are no subscriptions, should show 0 subscriptions and 0 resource groups', async () => { test('when there are no subscriptions, should show 0 subscriptions and 0 resource groups', async () => {
const { getByLabelText } = await renderComponent(); const { getByLabelText } = await renderComponent();
const subscriptionElements = within(getByLabelText('Subscriptions')); const subscriptionElements = within(getByLabelText('Subscription'));
expect(subscriptionElements.getByLabelText('value')).toHaveTextContent('0'); expect(subscriptionElements.getByLabelText('value')).toHaveTextContent('0');
const resourceGroupElements = within(getByLabelText('Resource groups')); const resourceGroupElements = within(getByLabelText('Resource group'));
expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('0'); expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('0');
}); });
test('when there is subscription & resource group data, should display these', async () => { test('when there is subscription & resource group data, should display these', async () => {
const { getByLabelText } = await renderComponent(1, { 'subscription-1': 2 }); const { getByLabelText } = await renderComponent(1, { 'subscription-1': 2 });
const subscriptionElements = within(getByLabelText('Subscriptions')); const subscriptionElements = within(getByLabelText('Subscription'));
expect(subscriptionElements.getByLabelText('value')).toHaveTextContent('1'); expect(subscriptionElements.getByLabelText('value')).toHaveTextContent('1');
const resourceGroupElements = within(getByLabelText('Resource groups')); const resourceGroupElements = within(getByLabelText('Resource group'));
expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('2'); expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('2');
}); });
@ -70,7 +70,7 @@ test('should correctly show total number of resource groups across multiple subs
'subscription-2': 3, 'subscription-2': 3,
}); });
const resourceGroupElements = within(getByLabelText('Resource groups')); const resourceGroupElements = within(getByLabelText('Resource group'));
expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('5'); expect(resourceGroupElements.getByLabelText('value')).toHaveTextContent('5');
}); });
@ -81,8 +81,8 @@ test('when only subscriptions fail to load, dont show the dashboard', async () =
500, 500,
200 200
); );
expect(queryByLabelText('Subscriptions')).not.toBeInTheDocument(); expect(queryByLabelText('Subscription')).not.toBeInTheDocument();
expect(queryByLabelText('Resource groups')).not.toBeInTheDocument(); expect(queryByLabelText('Resource group')).not.toBeInTheDocument();
}); });
test('when only resource groups fail to load, still show the subscriptions', async () => { test('when only resource groups fail to load, still show the subscriptions', async () => {
@ -92,8 +92,8 @@ test('when only resource groups fail to load, still show the subscriptions', asy
200, 200,
500 500
); );
expect(queryByLabelText('Subscriptions')).toBeInTheDocument(); expect(queryByLabelText('Subscription')).toBeInTheDocument();
expect(queryByLabelText('Resource groups')).not.toBeInTheDocument(); expect(queryByLabelText('Resource group')).not.toBeInTheDocument();
}); });
async function renderComponent( async function renderComponent(

View File

@ -7,6 +7,7 @@ import { r2a } from '@/react-tools/react2angular';
import { DashboardItem } from '@@/DashboardItem'; import { DashboardItem } from '@@/DashboardItem';
import { PageHeader } from '@@/PageHeader'; import { PageHeader } from '@@/PageHeader';
import { DashboardGrid } from '@@/DashboardItem/DashboardGrid';
import { useResourceGroups, useSubscriptions } from '../queries'; import { useResourceGroups, useSubscriptions } from '../queries';
@ -53,22 +54,24 @@ export function DashboardView() {
<> <>
<PageHeader title="Home" breadcrumbs={[{ label: 'Dashboard' }]} /> <PageHeader title="Home" breadcrumbs={[{ label: 'Dashboard' }]} />
{!subscriptionsQuery.isError && ( <div className="mx-4">
<div className="row"> {subscriptionsQuery.data && (
<DashboardItem <DashboardGrid>
value={subscriptionsCount as number}
icon="fa fa-th-list"
type="Subscriptions"
/>
{!resourceGroupsQuery.isError && (
<DashboardItem <DashboardItem
value={resourceGroupsCount as number} value={subscriptionsCount as number}
icon="fa fa-th-list" icon="fa fa-th-list"
type="Resource groups" type="Subscription"
/> />
)} {!resourceGroupsQuery.isError && !resourceGroupsQuery.isLoading && (
</div> <DashboardItem
)} value={resourceGroupsCount}
icon="fa fa-th-list"
type="Resource group"
/>
)}
</DashboardGrid>
)}
</div>
</> </>
); );
} }

View File

@ -235,49 +235,6 @@ angular
return runningTasks; return runningTasks;
}; };
}) })
.filter('runningcontainers', function () {
'use strict';
return function runningContainersFilter(containers) {
return containers.filter(function (container) {
return container.State === 'running';
}).length;
};
})
.filter('stoppedcontainers', function () {
'use strict';
return function stoppedContainersFilter(containers) {
return containers.filter(function (container) {
return container.State === 'exited';
}).length;
};
})
.filter('healthycontainers', function () {
'use strict';
return function healthyContainersFilter(containers) {
return containers.filter(function (container) {
return container.Status === 'healthy';
}).length;
};
})
.filter('unhealthycontainers', function () {
'use strict';
return function unhealthyContainersFilter(containers) {
return containers.filter(function (container) {
return container.Status === 'unhealthy';
}).length;
};
})
.filter('imagestotalsize', function () {
'use strict';
return function (images) {
var totalImageSize = 0;
for (var i = 0; i < images.length; i++) {
var item = images[i];
totalImageSize += item.VirtualSize;
}
return totalImageSize;
};
})
.filter('tasknodename', function () { .filter('tasknodename', function () {
'use strict'; 'use strict';
return function (nodeId, nodes) { return function (nodeId, nodes) {

View File

@ -28,136 +28,74 @@
</span> </span>
</information-panel> </information-panel>
<div class="row" ng-if="(!applicationState.endpoint.mode.agentProxy || applicationState.endpoint.mode.provider !== 'DOCKER_SWARM_MODE') && info && endpoint"> <div ng-if="info">
<div class="col-sm-12"> <div class="row" ng-if="(!applicationState.endpoint.mode.agentProxy || applicationState.endpoint.mode.provider !== 'DOCKER_SWARM_MODE') && info && endpoint">
<rd-widget> <div class="col-sm-12">
<rd-widget-header icon="fa-tachometer-alt" title-text="Environment info"></rd-widget-header> <rd-widget>
<rd-widget-body classes="no-padding"> <rd-widget-header icon="fa-tachometer-alt" title-text="Environment info"></rd-widget-header>
<table class="table"> <rd-widget-body classes="no-padding">
<tbody> <table class="table">
<tr> <tbody>
<td>Environment</td> <tr>
<td> <td>Environment</td>
{{ endpoint.Name }} <td>
<span class="small text-muted space-left"> {{ endpoint.Name }}
<i class="fa fa-microchip"></i> {{ endpoint.Snapshots[0].TotalCPU }} <i class="fa fa-memory space-left"></i> {{ endpoint.Snapshots[0].TotalMemory | humansize }} <span class="small text-muted space-left">
</span> <i class="fa fa-microchip"></i> {{ endpoint.Snapshots[0].TotalCPU }} <i class="fa fa-memory space-left"></i> {{ endpoint.Snapshots[0].TotalMemory | humansize }}
<span class="small text-muted"> </span>
- {{ info.Swarm && info.Swarm.NodeID !== '' ? 'Swarm' : 'Standalone' }} {{ info.ServerVersion }} <span class="small text-muted">
<span ng-if="endpoint.Type === 2">+ <i class="fa fa-bolt" aria-hidden="true"></i> Agent</span></span - {{ info.Swarm && info.Swarm.NodeID !== '' ? 'Swarm' : 'Standalone' }} {{ info.ServerVersion }}
> <span ng-if="endpoint.Type === 2">+ <i class="fa fa-bolt" aria-hidden="true"></i> Agent</span></span
</td> >
</tr> </td>
<tr ng-if="showEnvUrl"> </tr>
<td>URL</td> <tr ng-if="showEnvUrl">
<td>{{ endpoint.URL | stripprotocol }}</td> <td>URL</td>
</tr> <td>{{ endpoint.URL | stripprotocol }}</td>
<tr> </tr>
<td>Tags</td> <tr>
<td>{{ endpointTags }}</td> <td>Tags</td>
</tr> <td>{{ endpointTags }}</td>
<tr ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && applicationState.endpoint.mode.role === 'MANAGER'"> </tr>
<td colspan="2"> <tr ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && applicationState.endpoint.mode.role === 'MANAGER'">
<div class="btn-group" role="group" aria-label="..."> <td colspan="2">
<a ui-sref="docker.swarm.visualizer"><i class="fa fa-object-group space-right" aria-hidden="true"></i>Go to cluster visualizer</a> <div class="btn-group" role="group" aria-label="...">
</div> <a ui-sref="docker.swarm.visualizer"><i class="fa fa-object-group space-right" aria-hidden="true"></i>Go to cluster visualizer</a>
</td> </div>
</tr> </td>
</tbody> </tr>
</table> </tbody>
</rd-widget-body> </table>
</rd-widget> </rd-widget-body>
</rd-widget>
</div>
</div> </div>
</div>
<div class="row"> <div class="dashboard-grid mx-4">
<div class="col-xs-12 col-md-6" ng-if="showStacks"> <a ui-sref="docker.stacks" ng-if="showStacks">
<a ui-sref="docker.stacks"> <dashboard-item icon="'layers'" feather-icon="true" type="'Stack'" value="stackCount"></dashboard-item>
<rd-widget>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="title">{{ stackCount }}</div>
<div class="comment">{{ stackCount === 1 ? 'Stack' : 'Stacks' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div>
<div class="col-xs-12 col-md-6" ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && applicationState.endpoint.mode.role === 'MANAGER'"> <div ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && applicationState.endpoint.mode.role === 'MANAGER'">
<a ui-sref="docker.services"> <a ui-sref="docker.services">
<rd-widget> <dashboard-item icon="'fa-list-alt'" type="'Service'" value="serviceCount"></dashboard-item>
<rd-widget-body> </a>
<div class="widget-icon blue pull-left"> </div>
<i class="fa fa-list-alt"></i>
</div> <a ng-if="containers" ui-sref="docker.containers">
<div class="title">{{ serviceCount }}</div> <dashboard-item icon="'fa-cubes'" type="'Container'" value="containers.length" children="containerStatusComponent"></dashboard-item>
<div class="comment">{{ serviceCount === 1 ? 'Service' : 'Services' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div>
<div class="col-xs-12 col-md-6" ng-if="containers"> <a ng-if="images" ui-sref="docker.images">
<a ui-sref="docker.containers"> <dashboard-item icon="'fa-clone'" type="'Image'" value="images.length" children="imagesTotalSizeComponent"></dashboard-item>
<rd-widget>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-cubes"></i>
</div>
<div class="pull-right" style="padding-left: 5px">
<div><i class="fa fa-power-off space-right green-icon"></i>{{ containers | runningcontainers }} running</div>
<div><i class="fa fa-power-off space-right red-icon"></i>{{ containers | stoppedcontainers }} stopped</div>
</div>
<div class="pull-right" style="padding-right: 5px">
<div><i class="fa fa-heartbeat space-right green-icon"></i>{{ containers | healthycontainers }} healthy</div>
<div><i class="fa fa-heartbeat space-right orange-icon"></i>{{ containers | unhealthycontainers }} unhealthy</div>
</div>
<div class="title">{{ containers.length }}</div>
<div class="comment">{{ containers.length === 1 ? 'Container' : 'Containers' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div>
<div class="col-xs-12 col-md-6" ng-if="images">
<a ui-sref="docker.images">
<rd-widget>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-clone"></i>
</div>
<div class="pull-right">
<div><i class="fa fa-chart-pie space-right"></i>{{ images | imagestotalsize | humansize }}</div>
</div>
<div class="title">{{ images.length }}</div>
<div class="comment">{{ images.length === 1 ? 'Image' : 'Images' }}</div>
</rd-widget-body>
</rd-widget>
</a>
</div>
<div class="col-xs-12 col-md-6">
<a ui-sref="docker.volumes"> <a ui-sref="docker.volumes">
<rd-widget> <dashboard-item icon="'fa-hdd'" type="'Volume'" value="volumeCount"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-hdd"></i>
</div>
<div class="title">{{ volumeCount }}</div>
<div class="comment">{{ volumeCount === 1 ? 'Volume' : 'Volumes' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div>
<div class="col-xs-12 col-md-6">
<a ui-sref="docker.networks"> <a ui-sref="docker.networks">
<rd-widget> <dashboard-item icon="'fa-sitemap'" type="'Network'" value="networkCount"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-sitemap"></i>
</div>
<div class="title">{{ networkCount }}</div>
<div class="comment">{{ networkCount === 1 ? 'Network' : 'Networks' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div> </div>
</div> </div>

View File

@ -3,6 +3,8 @@ import _ from 'lodash';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models'; import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
import { useContainerStatusComponent } from '@/react/docker/DashboardView/ContainerStatus';
import { useImagesTotalSizeComponent } from '@/react/docker/DashboardView/ImagesTotalSize';
angular.module('portainer.docker').controller('DashboardController', [ angular.module('portainer.docker').controller('DashboardController', [
'$scope', '$scope',
@ -60,7 +62,11 @@ angular.module('portainer.docker').controller('DashboardController', [
}) })
.then(function success(data) { .then(function success(data) {
$scope.containers = data.containers; $scope.containers = data.containers;
$scope.containerStatusComponent = useContainerStatusComponent(data.containers);
$scope.images = data.images; $scope.images = data.images;
$scope.imagesTotalSizeComponent = useImagesTotalSizeComponent(imagesTotalSize(data.images));
$scope.volumeCount = data.volumes.length; $scope.volumeCount = data.volumes.length;
$scope.networkCount = data.networks.length; $scope.networkCount = data.networks.length;
$scope.serviceCount = data.services.length; $scope.serviceCount = data.services.length;
@ -94,3 +100,7 @@ angular.module('portainer.docker').controller('DashboardController', [
initView(); initView();
}, },
]); ]);
function imagesTotalSize(images) {
return images.reduce((acc, image) => acc + image.VirtualSize, 0);
}

View File

@ -31,57 +31,26 @@
</div> </div>
</div> </div>
<div class="row"> <div class="dashboard-grid mx-4">
<div class="col-xs-12 col-md-6" ng-if="ctrl.pools" data-cy="k8sDashboard-namespaces"> <div ng-if="ctrl.pools" data-cy="k8sDashboard-namespaces">
<a ui-sref="kubernetes.resourcePools"> <a ui-sref="kubernetes.resourcePools">
<rd-widget> <dashboard-item icon="'fa-layer-group'" type="'Namespace'" value="ctrl.pools.length"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-layer-group"></i>
</div>
<div class="title">{{ ctrl.pools.length }}</div>
<div class="comment">{{ ctrl.pools.length === 1 ? 'Namespace' : 'Namespaces' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div> </div>
<div class="col-xs-12 col-md-6" ng-if="ctrl.applications" data-cy="k8sDashboard-applications">
<div ng-if="ctrl.applications" data-cy="k8sDashboard-applications">
<a ui-sref="kubernetes.applications"> <a ui-sref="kubernetes.applications">
<rd-widget> <dashboard-item icon="'fa-laptop-code'" type="'Application'" value="ctrl.applications.length"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-laptop-code"></i>
</div>
<div class="title">{{ ctrl.applications.length }}</div>
<div class="comment">{{ ctrl.applications.length === 1 ? 'Application' : 'Applications' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div> </div>
<div class="col-xs-12 col-md-6" ng-if="ctrl.configurations" data-cy="k8sDashboard-configurations"> <div ng-if="ctrl.configurations" data-cy="k8sDashboard-configurations">
<a ui-sref="kubernetes.configurations"> <a ui-sref="kubernetes.configurations">
<rd-widget> <dashboard-item icon="'fa-file-code'" type="'Configuration'" value="ctrl.configurations.length"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-file-code"></i>
</div>
<div class="title">{{ ctrl.configurations.length }}</div>
<div class="comment">{{ ctrl.configurations.length === 1 ? 'Configuration' : 'Configurations' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div> </div>
<div class="col-xs-12 col-md-6" ng-if="ctrl.volumes" data-cy="k8sDashboard-volumes"> <div ng-if="ctrl.volumes" data-cy="k8sDashboard-volumes">
<a ui-sref="kubernetes.volumes"> <a ui-sref="kubernetes.volumes">
<rd-widget> <dashboard-item icon="'fa-database'" type="'Volume'" value="ctrl.volumes.length"></dashboard-item>
<rd-widget-body>
<div class="widget-icon blue pull-left">
<i class="fa fa-database"></i>
</div>
<div class="title">{{ ctrl.volumes.length }}</div>
<div class="comment">{{ ctrl.volumes.length === 1 ? 'Volume' : 'Volumes' }}</div>
</rd-widget-body>
</rd-widget>
</a> </a>
</div> </div>
</div> </div>

View File

@ -10,6 +10,7 @@ import { Loading } from '@@/Widget/Loading';
import { PasswordCheckHint } from '@@/PasswordCheckHint'; import { PasswordCheckHint } from '@@/PasswordCheckHint';
import { ViewLoading } from '@@/ViewLoading'; import { ViewLoading } from '@@/ViewLoading';
import { Tooltip } from '@@/Tip/Tooltip'; import { Tooltip } from '@@/Tip/Tooltip';
import { DashboardItem } from '@@/DashboardItem';
import { fileUploadField } from './file-upload-field'; import { fileUploadField } from './file-upload-field';
import { switchField } from './switch-field'; import { switchField } from './switch-field';
@ -38,4 +39,8 @@ export const componentsModule = angular
'prIcon', 'prIcon',
r2a(Icon, ['className', 'feather', 'icon', 'mode', 'size']) r2a(Icon, ['className', 'feather', 'icon', 'mode', 'size'])
) )
.component('reactQueryDevTools', r2a(ReactQueryDevtoolsWrapper, [])).name; .component('reactQueryDevTools', r2a(ReactQueryDevtoolsWrapper, []))
.component(
'dashboardItem',
r2a(DashboardItem, ['featherIcon', 'icon', 'type', 'value', 'children'])
).name;

View File

@ -0,0 +1,3 @@
.dashboard-grid {
@apply grid grid-cols-2 gap-3;
}

View File

@ -0,0 +1,7 @@
import { PropsWithChildren } from 'react';
import './DashboardGrid.css';
export function DashboardGrid({ children }: PropsWithChildren<unknown>) {
return <div className="dashboard-grid">{children}</div>;
}

View File

@ -34,3 +34,11 @@ export function WithLink() {
</Link> </Link>
); );
} }
export function WithChildren() {
return (
<DashboardItem value={1} icon="fa fa-th-list" type="Example resource">
<div>Children</div>
</DashboardItem>
);
}

View File

@ -1,8 +1,8 @@
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import clsx from 'clsx';
import { Icon, IconProps } from '@/react/components/Icon'; import { Icon, IconProps } from '@/react/components/Icon';
import { pluralize } from '@/portainer/helpers/strings';
import { Widget, WidgetBody } from '@@/Widget';
interface Props extends IconProps { interface Props extends IconProps {
value?: number; value?: number;
@ -18,21 +18,29 @@ export function DashboardItem({
featherIcon, featherIcon,
}: Props) { }: Props) {
return ( return (
<div className="col-sm-12 col-md-6" aria-label={type}> <div
<Widget> className={clsx(
<WidgetBody> 'border-solid rounded-lg border-2 hover:border-2 border-gray-5 hover:border-blue-7',
<div className="widget-icon blue pull-left"> 'bg-gray-2 hover:bg-blue-2',
<Icon icon={icon} feather={featherIcon} /> 'p-3'
)}
>
<div className="flex items-center" aria-label={type}>
<div className="icon-badge text-2xl bg-blue-3 text-blue-8 mr-4">
<Icon icon={icon} feather={featherIcon} className="feather" />
</div>
<div className="flex flex-col justify-around">
<div className="text-gray-9 font-medium text-2xl" aria-label="value">
{typeof value !== 'undefined' ? value : '-'}
</div> </div>
<div className="pull-right">{children}</div> <div className="text-gray-7 text-xl" aria-label="resourceType">
<div className="title" aria-label="value"> {pluralize(value || 0, type)}
{value}
</div> </div>
<div className="comment" aria-label="resourceType"> </div>
{type}
</div> <div className="ml-auto">{children}</div>
</WidgetBody> </div>
</Widget>
</div> </div>
); );
} }

View File

@ -0,0 +1,52 @@
import { DockerContainer } from '../containers/types';
interface Props {
containers: DockerContainer[];
}
export function useContainerStatusComponent(containers: DockerContainer[]) {
return <ContainerStatus containers={containers} />;
}
export function ContainerStatus({ containers }: Props) {
return (
<>
<div className="pull-right pl-1">
<div>
<i className="fa fa-power-off space-right green-icon" />
{runningContainersFilter(containers)} running
</div>
<div>
<i className="fa fa-power-off space-right red-icon" />
{stoppedContainersFilter(containers)} stopped
</div>
</div>
<div className="pull-right pr-5">
<div>
<i className="fa fa-heartbeat space-right green-icon" />
{healthyContainersFilter(containers)} healthy
</div>
<div>
<i className="fa fa-heartbeat space-right orange-icon" />
{unhealthyContainersFilter(containers)} unhealthy
</div>
</div>
</>
);
}
function runningContainersFilter(containers: DockerContainer[]) {
return containers.filter((container) => container.Status === 'running')
.length;
}
function stoppedContainersFilter(containers: DockerContainer[]) {
return containers.filter((container) => container.Status === 'exited').length;
}
function healthyContainersFilter(containers: DockerContainer[]) {
return containers.filter((container) => container.Status === 'healthy')
.length;
}
function unhealthyContainersFilter(containers: DockerContainer[]) {
return containers.filter((container) => container.Status === 'unhealthy')
.length;
}

View File

@ -0,0 +1,18 @@
import { humanize } from '@/portainer/filters/filters';
interface Props {
imagesTotalSize: number;
}
export function useImagesTotalSizeComponent(imagesTotalSize: number) {
return <ImagesTotalSize imagesTotalSize={imagesTotalSize} />;
}
export function ImagesTotalSize({ imagesTotalSize }: Props) {
return (
<div>
<i className="fa fa-chart-pie space-right" />
{humanize(imagesTotalSize)}
</div>
);
}