mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
Errors read five ways ("Failed to X", "X failed", "Could not X",
"Error loading X", "Couldn't X") and many dropped their period.
407 core strings now say "Couldn't {verb} {object}." with any
{{placeholder}} kept after it, and the generic common.error strings
say what to do next.
Interpolated English verbs could not be translated and produced
"Failed to restart container"-style grammar for every action, so 17
sites (container, compose, service, unit, process, alert and on/off
toasts, sort labels) now pick one string per action. 37 hand-rolled
plurals ("(s)", item{{value}}, fragment + `count === 1 ? '' : 's'`)
use i18next _one/_other keys: extract-i18n reads defaultValue_one /
defaultValue_other into k_one / k_other, and check-i18n accepts a
translator's extra forms (k_few, k_many) beside the English pair.
Validation says what is valid (IP or CIDR range, JSON payloads,
verification codes, sign-in links). The PRIMARY backup badge and the
upper-cased service type are plain text; container status labels go
to sentence case. Orphaned translations pruned; the i18n literal
ceiling drops to 840.
58 lines
1.9 KiB
React
58 lines
1.9 KiB
React
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { t } from '@/i18n/t';
|
|
import { errorReason } from '@/utils/errorMessage';
|
|
|
|
/**
|
|
* Consistent error state for pages and panels. Shows an icon, title, message,
|
|
* and optional retry action.
|
|
*
|
|
* <ErrorState
|
|
* title="Failed to load servers"
|
|
* message="The backend returned an error. Please try again."
|
|
* onRetry={loadData}
|
|
* />
|
|
*/
|
|
export function ErrorState({
|
|
title = t('common.error.failedToLoad', "Couldn't load this."),
|
|
message,
|
|
error,
|
|
onRetry,
|
|
compact = false,
|
|
className = '',
|
|
}) {
|
|
const errorMessage = message || errorReason(error)
|
|
|| t('common.error.loadingData', 'The server returned an error. Try again.');
|
|
|
|
if (compact) {
|
|
return (
|
|
<div className={`error-state-compact ${className}`.trim()} role="alert">
|
|
<AlertTriangle size={16} />
|
|
<span>{errorMessage}</span>
|
|
{onRetry && (
|
|
<Button variant="ghost" size="sm" onClick={onRetry}>
|
|
<RefreshCw size={14} /> {t('common.actions.retry', 'Retry')}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={`sk-error-state ${className}`.trim()} role="alert">
|
|
<div className="sk-error-state__icon">
|
|
<AlertTriangle size={32} />
|
|
</div>
|
|
<h3 className="sk-error-state__title">{title}</h3>
|
|
{errorMessage && <p className="sk-error-state__message">{errorMessage}</p>}
|
|
{onRetry && (
|
|
<Button variant="outline" size="sm" onClick={onRetry}>
|
|
<RefreshCw size={14} /> {t('common.actions.tryAgain', 'Try again')}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default ErrorState;
|