Панель расхода с фильтрами
Сделай панель расхода по проектам. Сверху чипы-фильтры по статусу, которые можно снимать. Под ними на каждый проект строка с названием, круговым индикатором заполненности квоты в процентах и меткой статуса. Список постраничный, по пять строк. Если после фильтрации ничего не осталось, вместо списка показывается пустое состояние с кнопкой сброса фильтров.
usage-dashboard__readme__claude-code__claude-opus-5__1 · 23.09.2026, 20:11:04 мск
Первый вызов модели получил 9 570 токенов входа, включая системный промпт Claude Code. Контекст до задачи — оценка по длине текста, для русского текста она занижает число токенов в полтора-два раза.
Компилятор
Ошибок нет: все компоненты и пропсы существуют.
Линтер и покрытие
- inline-styleСтроки 79, 105, 125, 136, 145, 162, 170, 180, 191, 192, 201, 205, 215, 216, 219, 224, 240, 241, 244Инлайновые стили вместо классов и токенов библиотеки
JxButton
Ожидались JxChip, JxProgressCircle, JxBadge, JxPagination, JxEmptyState · покрытие 0%
README (README.md, ~644)
Вход 2 · выход 6 614 · из кэша 8 233 · в кэш 1 335 · 68 с
Рендер
Код компонента
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
import { useMemo, useState } from 'react';
import { JxButton } from '@jinx-ui/react';
type ProjectStatus = 'active' | 'paused' | 'over';
interface Project {
id: string;
name: string;
used: number;
quota: number;
status: ProjectStatus;
}
const STATUSES: ProjectStatus[] = ['active', 'paused', 'over'];
const STATUS_LABEL: Record<ProjectStatus, string> = {
active: 'Активен',
paused: 'На паузе',
over: 'Перерасход',
};
const STATUS_COLOR: Record<ProjectStatus, string> = {
active: 'var(--jx-color-success)',
paused: 'var(--jx-color-warning)',
over: 'var(--jx-color-danger)',
};
const PROJECTS: Project[] = [
{ id: 'atlas', name: 'Atlas Migration', used: 18400, quota: 24000, status: 'active' },
{ id: 'beacon', name: 'Beacon Analytics', used: 9100, quota: 12000, status: 'active' },
{ id: 'cobalt', name: 'Cobalt Design System', used: 2600, quota: 8000, status: 'paused' },
{ id: 'delta', name: 'Delta Ingest', used: 15800, quota: 14000, status: 'over' },
{ id: 'echo', name: 'Echo Notifications', used: 4300, quota: 10000, status: 'active' },
{ id: 'forge', name: 'Forge CI', used: 7700, quota: 9000, status: 'active' },
{ id: 'gale', name: 'Gale Data Lake', used: 21000, quota: 20000, status: 'over' },
{ id: 'harbor', name: 'Harbor Billing', used: 1200, quota: 6000, status: 'paused' },
{ id: 'iris', name: 'Iris Search', used: 5600, quota: 11000, status: 'active' },
{ id: 'jade', name: 'Jade Mobile', used: 3300, quota: 4000, status: 'paused' },
{ id: 'kite', name: 'Kite Edge Cache', used: 8800, quota: 16000, status: 'active' },
{ id: 'lumen', name: 'Lumen Reporting', used: 13400, quota: 13000, status: 'over' },
];
const PAGE_SIZE = 5;
const GAUGE_RADIUS = 18;
const GAUGE_LENGTH = 2 * Math.PI * GAUGE_RADIUS;
export default function ProjectSpendPanel() {
const [selected, setSelected] = useState<ProjectStatus[]>(STATUSES);
const [page, setPage] = useState(1);
const rows = useMemo(
() => PROJECTS.filter((project) => selected.includes(project.status)),
[selected],
);
const totalPages = Math.max(1, Math.ceil(rows.length / PAGE_SIZE));
const currentPage = Math.min(page, totalPages);
const pageRows = rows.slice((currentPage - 1) * PAGE_SIZE, currentPage * PAGE_SIZE);
const toggleStatus = (status: ProjectStatus) => {
setSelected((prev) =>
prev.includes(status) ? prev.filter((item) => item !== status) : [...prev, status],
);
setPage(1);
};
const resetFilters = () => {
setSelected(STATUSES);
setPage(1);
};
const renderGauge = (project: Project) => {
const percent = Math.round((project.used / project.quota) * 100);
const arc = GAUGE_LENGTH * (1 - Math.min(percent, 100) / 100);
return (
<div
role="img"
aria-label={`Квота использована на ${percent} процентов`}
style={{ position: 'relative', width: 44, height: 44, flexShrink: 0 }}
>
<svg width="44" height="44" viewBox="0 0 44 44" aria-hidden="true">
<circle
cx="22"
cy="22"
r={GAUGE_RADIUS}
fill="none"
stroke="var(--jx-color-border)"
strokeWidth="4"
/>
<circle
cx="22"
cy="22"
r={GAUGE_RADIUS}
fill="none"
stroke={STATUS_COLOR[project.status]}
strokeWidth="4"
strokeLinecap="round"
strokeDasharray={GAUGE_LENGTH}
strokeDashoffset={arc}
transform="rotate(-90 22 22)"
/>
</svg>
<span
aria-hidden="true"
style={{
position: 'absolute',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'var(--jx-color-text)',
fontSize: 'var(--jx-font-size-xs)',
fontWeight: 600,
}}
>
{percent}%
</span>
</div>
);
};
return (
<section
aria-label="Расход по проектам"
style={{
display: 'flex',
flexDirection: 'column',
gap: 'var(--jx-space-4)',
padding: 'var(--jx-space-4)',
background: 'var(--jx-color-surface)',
border: '1px solid var(--jx-color-border)',
borderRadius: 'var(--jx-radius-lg)',
color: 'var(--jx-color-text)',
}}
>
<div role="group" aria-label="Фильтры по статусу" style={{ display: 'flex', gap: 'var(--jx-space-2)', flexWrap: 'wrap' }}>
{STATUSES.map((status) => {
const isOn = selected.includes(status);
return (
<button
key={status}
type="button"
aria-pressed={isOn}
onClick={() => toggleStatus(status)}
style={{
display: 'inline-flex',
alignItems: 'center',
gap: 'var(--jx-space-2)',
padding: 'var(--jx-space-1) var(--jx-space-3)',
borderRadius: 'var(--jx-radius-full)',
border: '1px solid',
borderColor: isOn ? STATUS_COLOR[status] : 'var(--jx-color-border)',
background: isOn ? 'var(--jx-color-surface-raised)' : 'transparent',
color: isOn ? 'var(--jx-color-text)' : 'var(--jx-color-text-muted)',
font: 'inherit',
fontSize: 'var(--jx-font-size-sm)',
cursor: 'pointer',
}}
>
<span
aria-hidden="true"
style={{
width: 8,
height: 8,
borderRadius: 'var(--jx-radius-full)',
background: isOn ? STATUS_COLOR[status] : 'var(--jx-color-border)',
}}
/>
{STATUS_LABEL[status]}
<span aria-hidden="true" style={{ color: 'var(--jx-color-text-muted)' }}>
{isOn ? '×' : '+'}
</span>
</button>
);
})}
</div>
{pageRows.length === 0 ? (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 'var(--jx-space-3)',
padding: 'var(--jx-space-6) var(--jx-space-4)',
border: '1px dashed var(--jx-color-border)',
borderRadius: 'var(--jx-radius-md)',
textAlign: 'center',
}}
>
<p style={{ margin: 0, fontWeight: 600 }}>Нет проектов под выбранные фильтры</p>
<p style={{ margin: 0, color: 'var(--jx-color-text-muted)', fontSize: 'var(--jx-font-size-sm)' }}>
Снятые статусы скрыли все строки расхода.
</p>
<JxButton variant="primary" onClick={resetFilters}>
Сбросить фильтры
</JxButton>
</div>
) : (
<>
<ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 'var(--jx-space-2)' }}>
{pageRows.map((project) => (
<li
key={project.id}
style={{
display: 'flex',
alignItems: 'center',
gap: 'var(--jx-space-3)',
padding: 'var(--jx-space-3)',
border: '1px solid var(--jx-color-border)',
borderRadius: 'var(--jx-radius-md)',
}}
>
{renderGauge(project)}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{project.name}
</div>
<div style={{ color: 'var(--jx-color-text-muted)', fontSize: 'var(--jx-font-size-sm)' }}>
{project.used.toLocaleString('ru-RU')} из {project.quota.toLocaleString('ru-RU')} ₽
</div>
</div>
<span
style={{
padding: 'var(--jx-space-1) var(--jx-space-2)',
borderRadius: 'var(--jx-radius-sm)',
border: '1px solid',
borderColor: STATUS_COLOR[project.status],
color: STATUS_COLOR[project.status],
fontSize: 'var(--jx-font-size-xs)',
whiteSpace: 'nowrap',
}}
>
{STATUS_LABEL[project.status]}
</span>
</li>
))}
</ul>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 'var(--jx-space-3)' }}>
<span style={{ color: 'var(--jx-color-text-muted)', fontSize: 'var(--jx-font-size-sm)' }}>
Страница {currentPage} из {totalPages} · {rows.length} проектов
</span>
<div style={{ display: 'flex', gap: 'var(--jx-space-2)' }}>
<JxButton
variant="secondary"
disabled={currentPage === 1}
onClick={() => setPage(Math.max(1, currentPage - 1))}
>
Назад
</JxButton>
<JxButton
variant="secondary"
disabled={currentPage === totalPages}
onClick={() => setPage(Math.min(totalPages, currentPage + 1))}
>
Вперёд
</JxButton>
</div>
</div>
</>
)}
</section>
);
}