feat: usage
This commit is contained in:
@@ -108,27 +108,34 @@ const ExportData: React.FC<{
|
||||
const handleSubmit = () => {
|
||||
const fileName = `usage-data_${query.start_date || ''}_${query.end_date || ''}.xlsx`;
|
||||
exportJsonToExcel({
|
||||
jsonData: result.data?.items || [],
|
||||
fileName: fileName,
|
||||
fields: exportTableColumns
|
||||
.map((col) => col.dataIndex)
|
||||
.filter(Boolean) as string[],
|
||||
fieldLabels: {
|
||||
user_id: 'User',
|
||||
model_id: 'Model',
|
||||
date: 'Date',
|
||||
prompt_token_count: 'Prompt Tokens',
|
||||
completion_token_count: 'Completion Tokens',
|
||||
request_count: 'API Requests'
|
||||
},
|
||||
formatMap: {
|
||||
user_id: (value: string) => {
|
||||
return userList.find((item) => item.value === value)?.label || value;
|
||||
},
|
||||
model_id: (value: string, record: any) => {
|
||||
return getModelName(record);
|
||||
sheets: [
|
||||
{
|
||||
jsonData: result.data?.items || [],
|
||||
sheetName: 'usage_data',
|
||||
fields: exportTableColumns
|
||||
.map((col) => col.dataIndex)
|
||||
.filter(Boolean) as string[],
|
||||
fieldLabels: {
|
||||
user_id: 'User',
|
||||
model_id: 'Model',
|
||||
date: 'Date',
|
||||
prompt_token_count: 'Prompt Tokens',
|
||||
completion_token_count: 'Completion Tokens',
|
||||
request_count: 'API Requests'
|
||||
},
|
||||
formatMap: {
|
||||
user_id: (value: string) => {
|
||||
return (
|
||||
userList.find((item) => item.value === value)?.label || value
|
||||
);
|
||||
},
|
||||
model_id: (value: string, record: any) => {
|
||||
return getModelName(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ import dayjs, { type Dayjs } from 'dayjs';
|
||||
|
||||
interface RangePickerPreset {
|
||||
range: number;
|
||||
presetRanges?: {
|
||||
label: React.ReactNode;
|
||||
value: [Dayjs, Dayjs] | (() => [Dayjs, Dayjs]);
|
||||
}[];
|
||||
disabledDate?: boolean;
|
||||
}
|
||||
|
||||
@@ -15,7 +19,7 @@ export default function useRangePickerPreset(options?: RangePickerPreset): {
|
||||
}[];
|
||||
range: number;
|
||||
} {
|
||||
const { range = 60, disabledDate } = options || {};
|
||||
const { range = 60, disabledDate, presetRanges } = options || {};
|
||||
const intl = useIntl();
|
||||
|
||||
const getYearMonth = (date: Dayjs) => date.year() * 12 + date.month();
|
||||
@@ -54,7 +58,7 @@ export default function useRangePickerPreset(options?: RangePickerPreset): {
|
||||
const rangePresets: {
|
||||
label: React.ReactNode;
|
||||
value: [Dayjs, Dayjs] | (() => [Dayjs, Dayjs]);
|
||||
}[] = [
|
||||
}[] = presetRanges || [
|
||||
{
|
||||
label: intl.formatMessage({ id: 'dashboard.usage.datePicker.last7days' }),
|
||||
value: [dayjs().add(-6, 'd'), dayjs()]
|
||||
|
||||
Reference in New Issue
Block a user