Files
hanarang-dashboard/frontend/components/admin/LogTerminal.tsx
narang-ai 033c142c0e feat(sprint-004): admin features + API auth guard
Sprint 003 non-blocking 처리:
- API Key Guard (passport-http-bearer) + AuthModule
- Helmet 적용 (main.ts)
- SisterNamePipe - name 파라미터 Controller 검증
- lib/sisters.ts - formatLastSeen/sisterEmojis/sisterDisplayNames 공통 추출

Sprint 004 본문:
- TASK-012: POST /api/admin/sisters/:name/{restart,reset} (ApiKeyGuard 적용)
- TASK-013: GET/PUT /api/admin/harness/:name/:file (허용 파일 allowlist)
- TASK-015: GET /api/admin/logs/:name
- 관리자 전 API @UseGuards(ApiKeyGuard)
- TASK-014: /admin 자매 관리 (재시작/리셋 + ConfirmModal)
- TASK-014: /admin/harness 하네스 편집 (CodeEditor + 파일트리)
- TASK-015: /admin/logs 로그 뷰어 (LogTerminal + 검색/에러필터)
- /admin/repos 저장소 목록
- AdminLayout (API Key 로컬스토리지 저장)
- 테스트 22/22 pass, FE 11 routes build 성공
2026-04-04 12:11:06 +09:00

121 lines
3.0 KiB
TypeScript

'use client';
import React, { useRef, useEffect, useState } from 'react';
import styled from 'styled-components';
const Wrapper = styled.div`
background: #0a0e14;
border: 1px solid #1e2430;
border-radius: 8px;
overflow: hidden;
`;
const Toolbar = styled.div`
background: #0d1117;
border-bottom: 1px solid #1e2430;
padding: 8px 12px;
display: flex;
align-items: center;
gap: 12px;
`;
const SearchInput = styled.input`
background: rgba(255,255,255,0.05);
border: 1px solid #1e2430;
border-radius: 5px;
color: #8B949E;
font-size: 12px;
padding: 4px 10px;
outline: none;
width: 200px;
&:focus { border-color: #58A6FF; color: #E6EDF3; }
`;
const FilterBtn = styled.button<{ $active: boolean }>`
padding: 3px 10px;
border-radius: 4px;
font-size: 11px;
cursor: pointer;
border: 1px solid ${({ $active }) => $active ? 'rgba(255,23,68,0.5)' : '#1e2430'};
background: ${({ $active }) => $active ? 'rgba(255,23,68,0.1)' : 'transparent'};
color: ${({ $active }) => $active ? '#FF1744' : '#8B949E'};
transition: all 0.15s;
`;
const Terminal = styled.div`
height: 420px;
overflow-y: auto;
padding: 12px;
font-family: 'Fira Code', 'Cascadia Code', monospace;
font-size: 12px;
line-height: 1.7;
&::-webkit-scrollbar { width: 4px; }
&::-webkit-scrollbar-thumb { background: #1e2430; border-radius: 2px; }
`;
const LogLine = styled.div<{ $isError: boolean }>`
color: ${({ $isError }) => $isError ? '#FF1744' : '#a8c4e0'};
white-space: pre-wrap;
word-break: break-all;
&:hover { background: rgba(255,255,255,0.03); }
`;
const LineNum = styled.span`
color: #3d4f5a;
margin-right: 12px;
user-select: none;
min-width: 32px;
display: inline-block;
text-align: right;
`;
interface LogTerminalProps {
lines: string[];
}
export default function LogTerminal({ lines }: LogTerminalProps) {
const [search, setSearch] = useState('');
const [errorsOnly, setErrorsOnly] = useState(false);
const bottomRef = useRef<HTMLDivElement>(null);
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [lines]);
const filtered = lines.filter((line) => {
if (errorsOnly && !/error|fail|exception|warn/i.test(line)) return false;
if (search && !line.toLowerCase().includes(search.toLowerCase())) return false;
return true;
});
return (
<Wrapper>
<Toolbar>
<SearchInput
placeholder="검색..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
<FilterBtn $active={errorsOnly} onClick={() => setErrorsOnly(!errorsOnly)}>
🔴
</FilterBtn>
<span style={{ fontSize: '11px', color: '#3d4f5a', marginLeft: 'auto' }}>
{filtered.length}/{lines.length} lines
</span>
</Toolbar>
<Terminal>
{filtered.map((line, i) => (
<LogLine key={i} $isError={/error|fail|exception/i.test(line)}>
<LineNum>{i + 1}</LineNum>
{line}
</LogLine>
))}
<div ref={bottomRef} />
</Terminal>
</Wrapper>
);
}