Files
ServerKit/frontend/src/components/JournalControls.jsx
T
Juan Denis c0de9fbcac refactor(i18n): consolidate duplicate locale strings into common.* namespace
en.json drops from 8107 to 6624 keys: repeated UI copy (Cancel x95,
Status x67, Refresh x54, ...) now lives under common.actions /
common.labels / common.loading, and extractor-era suffix duplicates
(refresh2, status3) within a component collapse onto one key.
Trailing ... defaults are normalized to the ellipsis character.

Translations are preserved: all 16 locales were re-keyed, carrying
existing per-component translations onto their new common.* keys
(majority vote where sources disagreed), and stale keys were pruned.

Verified: npm run lint (0 errors), node --test (140 pass), vite build.

edit
2026-08-22 01:32:52 -04:00

94 lines
3.6 KiB
React

import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { useTranslation } from 'react-i18next';
const PRIORITY_OPTIONS = [
{ value: '', labelKey: 'common.labels.all', label: 'All' },
{ value: '0', labelKey: 'app.journalControls.emergency', label: 'Emergency' },
{ value: '1', labelKey: 'app.journalControls.alert', label: 'Alert' },
{ value: '2', labelKey: 'app.journalControls.critical', label: 'Critical' },
{ value: '3', labelKey: 'app.journalControls.error', label: 'Error' },
{ value: '4', labelKey: 'common.labels.warning', label: 'Warning' },
{ value: '5', labelKey: 'app.journalControls.notice', label: 'Notice' },
{ value: '6', labelKey: 'common.labels.info', label: 'Info' },
{ value: '7', labelKey: 'app.journalControls.debug', label: 'Debug' },
];
export function JournalControls({
unit = '',
onUnitChange,
unitLabel = 'Service/Unit',
unitPlaceholder = 'All services',
quickUnits = [],
showQuickUnits = true,
lineCount,
onLineCountChange,
lineCountOptions = [50, 100, 200, 500],
priority,
onPriorityChange,
showPriority = true,
loading = false,
onLoad,
loadLabel = 'Load Logs',
}) {
const { t } = useTranslation();
return (
<div className="journal-controls">
<div className="control-group">
<label>{unitLabel}</label>
<div className="input-with-suggestions">
<Input
type="text"
value={unit}
onChange={(e) => onUnitChange?.(e.target.value)}
placeholder={unitPlaceholder}
/>
{showQuickUnits && quickUnits.length > 0 && (
<div className="quick-units">
{quickUnits.map(u => (
<button type="button"
key={u}
className={`unit-chip ${unit === u ? 'active' : ''}`}
onClick={() => onUnitChange?.(unit === u ? '' : u)}
>
{u}
</button>
))}
</div>
)}
</div>
</div>
{onLineCountChange && (
<div className="control-group">
<label>{t('app.journalControls.lines', 'Lines')}</label>
<select value={lineCount} onChange={(e) => onLineCountChange(parseInt(e.target.value, 10))}>
{lineCountOptions.map(n => (
<option key={n} value={n}>{n}</option>
))}
</select>
</div>
)}
{showPriority && onPriorityChange && (
<div className="control-group">
<label>{t('app.journalControls.priority', 'Priority')}</label>
<select value={priority ?? ''} onChange={(e) => onPriorityChange(e.target.value)}>
{PRIORITY_OPTIONS.map(o => (
<option key={o.value} value={o.value}>{o.label}</option>
))}
</select>
</div>
)}
{onLoad && (
<Button onClick={onLoad} disabled={loading}>
{loading ? 'Loading...' : loadLabel}
</Button>
)}
</div>
);
}
export default JournalControls;