mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add an account analytics dashboard to /usage (#45764)
## What changed - Add “Explore analytics” to the `/usage` menu for ChatGPT accounts, opening a full-screen dashboard. - Show usage and messages for consumer accounts, credits and token usage for Business and Enterprise accounts, and plugin and skill activity for both. - Support overview and maximized views, 7- and 30-day ranges, report grouping, daily details, model filtering for token usage, and refresh. - Keep report loading and errors independent, cancel pending loads on close, and retain navigation state across reopening while preserving the composer draft. ## Testing Add regression and snapshot coverage for account-specific reports, range and grouping changes, model filtering, loading and cancellation, small terminals, terminal colors, and draft preservation. GitOrigin-RevId: 46da94a14d6e227551e740b85f9d2d552aaf75b0
This commit is contained in:
1 parent
af3bc6f796
commit
ca53e19c75
68 files changed
+6357
-67
No files matched your search
@@ -0,0 +1,108 @@
|
||||
//! Responsive panels with consistent category colors and signed daily amounts.
|
||||
|
||||
use super::AnalyticsView;
|
||||
use super::render::columns;
|
||||
use super::styles::secondary_style;
|
||||
use crate::analytics::sections::Section;
|
||||
use crate::style::accent_style;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::word_wrap_lines;
|
||||
use ratatui::style::Styled;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use std::ops::Range;
|
||||
|
||||
/// Panel content and measured geometry shared by layout and scrolling.
|
||||
pub(super) struct Panel {
|
||||
pub(super) lines: Vec<Line<'static>>,
|
||||
pub(super) selection: Range<usize>,
|
||||
pub(super) chart_bands: usize,
|
||||
}
|
||||
|
||||
impl AnalyticsView {
|
||||
pub(super) fn panel(&self, section: Section, width: usize, chart_height: usize) -> Panel {
|
||||
let focused = section == self.section;
|
||||
let title = format!(
|
||||
"{} {}",
|
||||
if focused { "▎" } else { " " },
|
||||
self.section_title(section)
|
||||
);
|
||||
let heading = if focused {
|
||||
title.set_style(accent_style()).into()
|
||||
} else {
|
||||
title.bold().into()
|
||||
};
|
||||
let group = self.sections[section].group;
|
||||
let heading = if matches!(
|
||||
section,
|
||||
Section::Usage | Section::Credits | Section::Activity
|
||||
) {
|
||||
columns(
|
||||
heading,
|
||||
format!("By {}", self.group_label(section, group).to_lowercase())
|
||||
.set_style(secondary_style())
|
||||
.into(),
|
||||
width,
|
||||
)
|
||||
} else {
|
||||
heading
|
||||
};
|
||||
let mut lines = vec![heading, "─".repeat(width).dim().into()];
|
||||
if section == Section::Usage && self.business() {
|
||||
lines.push(
|
||||
format!(
|
||||
"{} · m change model",
|
||||
self.token_model.as_deref().unwrap_or("All models")
|
||||
)
|
||||
.set_style(secondary_style())
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
let mut selection;
|
||||
if focused && let Some(choice) = self.group_picker {
|
||||
lines.extend(
|
||||
self.group_options()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, group)| {
|
||||
let label = format!(
|
||||
"{} {}",
|
||||
if index == choice { "›" } else { " " },
|
||||
self.group_label(section, *group)
|
||||
);
|
||||
if index == choice {
|
||||
label.set_style(accent_style()).into()
|
||||
} else {
|
||||
label.into()
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
let history = self.history_lines(section, width, chart_height);
|
||||
let chart_bands = history.bands;
|
||||
lines.extend(history.lines);
|
||||
selection = 0..lines.len();
|
||||
if focused && self.group_picker.is_some() {
|
||||
selection = 0..2 + self.group_options().len();
|
||||
}
|
||||
let mut wrapped = Vec::new();
|
||||
let mut wrapped_selection = 0..0;
|
||||
for (index, line) in lines.into_iter().enumerate() {
|
||||
if index == selection.start {
|
||||
wrapped_selection.start = wrapped.len();
|
||||
}
|
||||
wrapped.extend(word_wrap_lines(
|
||||
[line],
|
||||
RtOptions::new(width.max(/*other*/ 1)),
|
||||
));
|
||||
if index + 1 == selection.end {
|
||||
wrapped_selection.end = wrapped.len();
|
||||
}
|
||||
}
|
||||
Panel {
|
||||
lines: wrapped,
|
||||
selection: wrapped_selection,
|
||||
chart_bands,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user