2022-06-23 06:32:18 +00:00
|
|
|
import { ReactNode } from 'react';
|
2022-07-06 08:23:53 +00:00
|
|
|
import clsx from 'clsx';
|
2023-03-07 22:22:08 +00:00
|
|
|
import { Loader2 } from 'lucide-react';
|
2022-06-23 06:32:18 +00:00
|
|
|
|
|
|
|
import { Icon, IconProps } from '@/react/components/Icon';
|
2022-07-06 08:23:53 +00:00
|
|
|
import { pluralize } from '@/portainer/helpers/strings';
|
2022-02-24 23:22:56 +00:00
|
|
|
|
2023-03-07 22:22:08 +00:00
|
|
|
import { Link } from '@@/Link';
|
|
|
|
|
2022-06-23 06:32:18 +00:00
|
|
|
interface Props extends IconProps {
|
2022-02-24 23:22:56 +00:00
|
|
|
type: string;
|
2023-03-07 22:22:08 +00:00
|
|
|
pluralType?: string; // in case the pluralise function isn't suitable
|
|
|
|
isLoading?: boolean;
|
|
|
|
isRefetching?: boolean;
|
|
|
|
value?: number;
|
|
|
|
to?: string;
|
2023-06-11 21:46:48 +00:00
|
|
|
params?: object;
|
2022-06-23 06:32:18 +00:00
|
|
|
children?: ReactNode;
|
2023-03-07 22:22:08 +00:00
|
|
|
dataCy?: string;
|
2022-02-24 23:22:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 22:22:08 +00:00
|
|
|
export function DashboardItem({
|
|
|
|
icon,
|
|
|
|
type,
|
|
|
|
pluralType,
|
|
|
|
isLoading,
|
|
|
|
isRefetching,
|
|
|
|
value,
|
|
|
|
to,
|
2023-06-11 21:46:48 +00:00
|
|
|
params,
|
2023-03-07 22:22:08 +00:00
|
|
|
children,
|
|
|
|
dataCy,
|
|
|
|
}: Props) {
|
|
|
|
const Item = (
|
2022-07-06 08:23:53 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
2023-03-07 22:22:08 +00:00
|
|
|
'relative rounded-lg border border-solid p-3',
|
2023-02-12 21:04:24 +00:00
|
|
|
'border-gray-5 bg-gray-2 hover:border-blue-7 hover:bg-blue-2',
|
|
|
|
'th-dark:border-gray-neutral-8 th-dark:bg-gray-iron-10 th-dark:hover:border-blue-8 th-dark:hover:bg-gray-10',
|
|
|
|
'th-highcontrast:border-white th-highcontrast:bg-black th-highcontrast:hover:border-blue-8 th-highcontrast:hover:bg-gray-11'
|
2022-07-06 08:23:53 +00:00
|
|
|
)}
|
2023-03-07 22:22:08 +00:00
|
|
|
data-cy={dataCy}
|
2022-07-06 08:23:53 +00:00
|
|
|
>
|
2023-03-07 22:22:08 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
2023-06-11 21:46:48 +00:00
|
|
|
'text-muted absolute top-2 right-2 flex items-center text-xs transition-opacity',
|
2023-03-07 22:22:08 +00:00
|
|
|
isRefetching ? 'opacity-100' : 'opacity-0'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Refreshing total
|
|
|
|
<Loader2 className="h-4 animate-spin-slow" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2023-06-11 21:46:48 +00:00
|
|
|
'text-muted absolute top-2 right-2 flex items-center text-xs transition-opacity',
|
2023-03-07 22:22:08 +00:00
|
|
|
isLoading ? 'opacity-100' : 'opacity-0'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Loading total
|
|
|
|
<Loader2 className="h-4 animate-spin-slow" />
|
|
|
|
</div>
|
2022-07-06 08:23:53 +00:00
|
|
|
<div className="flex items-center" aria-label={type}>
|
2022-08-01 01:29:49 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
2023-02-12 21:04:24 +00:00
|
|
|
'icon-badge mr-4 !p-2 text-2xl',
|
2022-08-01 01:29:49 +00:00
|
|
|
'bg-blue-3 text-blue-8',
|
|
|
|
'th-dark:bg-blue-3 th-dark:text-blue-8',
|
|
|
|
'th-highcontrast:bg-blue-3 th-highcontrast:text-blue-8'
|
|
|
|
)}
|
|
|
|
>
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={icon} />
|
2022-07-06 08:23:53 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col justify-around">
|
2022-08-01 01:29:49 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
2023-02-12 21:04:24 +00:00
|
|
|
'text-2xl font-medium',
|
2022-08-01 01:29:49 +00:00
|
|
|
'text-gray-9',
|
|
|
|
'th-dark:text-white',
|
|
|
|
'th-highcontrast:text-white'
|
|
|
|
)}
|
|
|
|
aria-label="value"
|
|
|
|
>
|
2023-03-07 22:22:08 +00:00
|
|
|
{typeof value === 'undefined' ? '-' : value}
|
2022-02-24 23:22:56 +00:00
|
|
|
</div>
|
2022-08-01 01:29:49 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'text-xl',
|
|
|
|
'text-gray-7',
|
|
|
|
'th-dark:text-gray-warm-5',
|
|
|
|
'th-highcontrast:text-gray-warm-5'
|
|
|
|
)}
|
|
|
|
aria-label="resourceType"
|
|
|
|
>
|
2023-03-07 22:22:08 +00:00
|
|
|
{pluralize(value || 0, type, pluralType)}
|
2022-02-24 23:22:56 +00:00
|
|
|
</div>
|
2022-07-06 08:23:53 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="ml-auto">{children}</div>
|
|
|
|
</div>
|
2022-02-24 23:22:56 +00:00
|
|
|
</div>
|
|
|
|
);
|
2023-03-07 22:22:08 +00:00
|
|
|
|
|
|
|
if (to) {
|
|
|
|
return (
|
2023-06-11 21:46:48 +00:00
|
|
|
<Link to={to} className="!no-underline" params={params}>
|
2023-03-07 22:22:08 +00:00
|
|
|
{Item}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Item;
|
2022-02-24 23:22:56 +00:00
|
|
|
}
|