import {
ActionIcon,
Alert,
Badge,
Card,
Center,
Grid,
Group,
Loader,
ScrollArea,
Stack,
Text,
} from '@mantine/core';
import {
IconAlertCircle,
IconBrandMysql,
IconBrandPhp,
IconBrandWordpress,
IconCalendarClock,
IconCloud,
IconDatabase,
IconInfoCircle,
IconRefresh,
IconServer,
IconTrash,
IconUpload,
} from '@tabler/icons-react';
import { __ } from '@wordpress/i18n';
import useSWR from 'swr';
import { post } from '../../utils/post';
import { DiskOverview } from './DiskOverview';
import classes from './Overview.module.scss';
import { OverviewCard } from './OverviewCard';
function formatBytes(bytes: number): string {
if (bytes === 0) {
return '0 B';
}
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
}
interface OverviewProps {
setActiveView?: (view: string) => void;
}
export function Overview({ setActiveView }: OverviewProps) {
const { data, error, isLoading, isValidating, mutate } = useSWR('overview', post);
if (isLoading) {
return (
);
}
// Without this guard a failed request (expired nonce, PHP fatal, network) threw on
// `data.posts_status` and, with no error boundary above, unmounted the whole app: a blank page
// instead of a message. Same guard the dashboard widget already has.
if (error || !data) {
return (
}
color="red"
variant="light"
title={__('Error', 'scotty')}
>
{__('Unable to load overview data.', 'scotty')}
);
}
return (
{
await mutate(undefined, { revalidate: true });
}}
>
setActiveView('trash') : undefined}
/>
setActiveView('trash') : undefined}
/>
setActiveView('trash') : undefined}
/>
{/* Quick info cards */}
setActiveView('cron') : undefined}
classNames={{ root: classes.rootCard }}
>
{data.cron_count}
{__('Scheduled Cron Jobs', 'scotty')}
{setActiveView && (
{__('View details', 'scotty')}
)}
setActiveView('database') : undefined}
padding={0}
classNames={{ root: classes.rootCard }}
>
{formatBytes(data.database_size)}
{__('Database Size', 'scotty')}
{setActiveView && (
{__('View details', 'scotty')}
)}
{/* Trash Summary */}
setActiveView('trash') : undefined}
padding={0}
classNames={{ root: classes.rootCard }}
>
0
? 'var(--mantine-color-red-6)'
: 'var(--mantine-color-gray-5)'
}
/>
0 ? 'red' : undefined}>
{data.trash_summary.total}
{__('Items to Clean', 'scotty')}
{data.trash_summary.total > 0 && (
{data.trash_summary.revisions > 0 && (
{data.trash_summary.revisions} {__('revisions', 'scotty')}
)}
{data.trash_summary.auto_drafts > 0 && (
{data.trash_summary.auto_drafts} {__('drafts', 'scotty')}
)}
{data.trash_summary.trashed_posts > 0 && (
{data.trash_summary.trashed_posts} {__('trashed', 'scotty')}
)}
{data.trash_summary.spam_comments > 0 && (
{data.trash_summary.spam_comments} {__('spam', 'scotty')}
)}
{data.trash_summary.orphan_postmeta > 0 && (
{data.trash_summary.orphan_postmeta} {__('orphans', 'scotty')}
)}
)}
{setActiveView && data.trash_summary.total > 0 && (
{__('Clean now', 'scotty')}
)}
{/* Environment Info */}
PHP
{window.NSScottyPluginMantine.environment.php_version}
WordPress
{window.NSScottyPluginMantine.environment.wp_version}
MySQL
{window.NSScottyPluginMantine.environment.mysql_version}
{__('Memory', 'scotty')}
{window.NSScottyPluginMantine.environment.memory_limit}
{__('Max Upload', 'scotty')}
{window.NSScottyPluginMantine.environment.max_upload}
{window.NSScottyPluginMantine.environment.server && (
{__('Server', 'scotty')}
{window.NSScottyPluginMantine.environment.server}
)}
);
}