Files
ServerKit/frontend/src/components/LogViewer.jsx
T
Juan Denis cc230a111a feat(ui): name icon buttons and keep keyboard focus visible
- InfoTip: name is "More info about <subject>" (subject prop, else title,
  else the label text right before it); plain "More info" stays the fallback.
- Button: an icon-only button with a title now uses it as its aria-label.
- Files: toolbar toggles and view buttons get aria-pressed; row actions and
  the row checkbox name the file ("Rename config.yml", "Select: config.yml");
  select-all, Up, sidebar Refresh/New folder named.
- Log viewer: line-number/word-wrap toggles use aria-pressed; search and
  filter inputs (Terminal page) get accessible names.
- Overflow/icon-only menus say "More actions" or their action (SSL,
  Webhooks, Vaults, API settings, fleet thresholds, status pages).
- Focus: Terminal unit input and Servers group-name input keep the global
  ring; page tab strip rings pulled inside its overflow clip; $focus-ring is
  now solid accent instead of a 35% tint.
- i18n: common.moreInfoAbout, common.actionTarget, common.moreActions,
  app.fileManager.up in all locales; drop unused app.fileRow.deselect.
2026-11-10 22:25:23 -05:00

156 lines
7.1 KiB
React

import { Search, RefreshCw, FileText } from 'lucide-react';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Switch } from '@/components/ui/switch';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { useTranslation } from 'react-i18next';
export function LogViewer({
files = [],
selectedPath,
onSelectFile,
onRefreshFiles,
content,
contentLoading = false,
contentEmpty,
searchPattern = '',
onSearchChange,
onSearchSubmit,
lineCount,
onLineCountChange,
lineCountOptions = [50, 100, 200, 500, 1000],
autoRefresh = false,
onAutoRefreshChange,
onRefreshContent,
onDownload,
onClear,
formatFileSize = defaultFormatFileSize,
getLogIconType = () => 'default',
}) {
const { t } = useTranslation();
return (
<div className="logs-layout">
<div className="logs-sidebar">
<div className="sidebar-header">
<h3>{t('app.logViewer.logFiles', 'Log files')}</h3>
{onRefreshFiles && (
<Button variant="outline" size="sm" onClick={onRefreshFiles} aria-label={t('common.actions.refresh', 'Refresh')}>
<RefreshCw size={14} />
</Button>
)}
</div>
<div className="log-files-list">
{files.length === 0 ? (
<div className="empty-hint">{t('app.logViewer.noLogFilesFound', 'No log files found')}</div>
) : (
files.map((log) => (
<div
key={log.path}
className={`log-file-item ${selectedPath === log.path ? 'active' : ''}`}
onClick={() => onSelectFile?.(log)}
>
<div className={`log-icon ${getLogIconType(log)}`}>
<FileText size={16} />
</div>
<div className="log-file-info">
<span className="log-file-name">{log.name}</span>
<span className="log-file-path">{log.path}</span>
</div>
<span className="log-file-size">{formatFileSize(log.size)}</span>
</div>
))
)}
</div>
</div>
<div className="logs-viewer">
<div className="viewer-toolbar">
<div className="toolbar-left">
<div className="search-input">
<Search size={16} />
<Input
type="text"
value={searchPattern}
onChange={(e) => onSearchChange?.(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && onSearchSubmit?.()}
placeholder={t('app.logViewer.searchPattern', 'Search pattern…')}
/>
</div>
{onLineCountChange && (
<Select
value={String(lineCount)}
onValueChange={(v) => onLineCountChange(parseInt(v, 10))}
>
<SelectTrigger
className="lines-select"
aria-label={t('app.logViewer.linesToShow', 'Lines to show')}
>
<SelectValue />
</SelectTrigger>
<SelectContent>
{lineCountOptions.map(n => (
<SelectItem key={n} value={String(n)}>{n} lines</SelectItem>
))}
</SelectContent>
</Select>
)}
</div>
<div className="toolbar-right">
{onAutoRefreshChange && (
<label className="auto-refresh-toggle">
<Switch
checked={autoRefresh}
onCheckedChange={onAutoRefreshChange}
/>
<span>{t('app.logViewer.autoRefresh', 'Auto-refresh')}</span>
</label>
)}
{onRefreshContent && (
<Button
variant="outline"
size="sm"
onClick={onRefreshContent}
disabled={!selectedPath || contentLoading}
disabledReason={!selectedPath ? t('app.logViewer.selectALogFileFirst', 'Select a log file first') : undefined}
>
{t('common.actions.refresh', 'Refresh')}
</Button>
)}
{onDownload && (
<Button variant="outline" size="sm" onClick={onDownload} disabled={!content} disabledReason={t('app.logViewer.nothingToDownloadYet', 'Nothing to download yet')}>
{t('common.actions.download', 'Download')}
</Button>
)}
{onClear && (
<Button variant="destructive" size="sm" onClick={onClear} disabled={!selectedPath} disabledReason={t('app.logViewer.selectALogFileFirst', 'Select a log file first')}>
{t('common.actions.clear', 'Clear')}
</Button>
)}
</div>
</div>
<div className="log-content">
{contentLoading ? (
<div className="logs-viewer__loading">{t('common.loading', 'Loading…')}</div>
) : !content ? (
<div className="logs-viewer__empty">
{contentEmpty ?? t('app.logViewer.selectALogFile', 'Select a log file to view its contents.')}
</div>
) : (
<pre>{content}</pre>
)}
</div>
</div>
</div>
);
}
function defaultFormatFileSize(bytes) {
if (bytes == null) return '';
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
}
export default LogViewer;