(feat) view team based usage on ui

This commit is contained in:
Ishaan Jaff 2024-03-16 19:05:33 -07:00
parent 37d0087b56
commit a581b45775
2 changed files with 39 additions and 2 deletions

View file

@ -341,6 +341,35 @@ export const keySpendLogsCall = async (accessToken: String, token: String) => {
} }
}; };
export const teamSpendLogsCall = async (accessToken: String) => {
try {
const url = proxyBaseUrl
? `${proxyBaseUrl}/global/spend/teams`
: `/global/spend/teams`;
console.log("in teamSpendLogsCall:", url);
const response = await fetch(`${url}`, {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
});
if (!response.ok) {
const errorData = await response.text();
message.error(errorData);
throw new Error("Network response was not ok");
}
const data = await response.json();
console.log(data);
return data;
} catch (error) {
console.error("Failed to create key:", error);
throw error;
}
};
export const userSpendLogsCall = async ( export const userSpendLogsCall = async (
accessToken: String, accessToken: String,
token: String, token: String,

View file

@ -8,6 +8,7 @@ import {
adminSpendLogsCall, adminSpendLogsCall,
adminTopKeysCall, adminTopKeysCall,
adminTopModelsCall, adminTopModelsCall,
teamSpendLogsCall,
} from "./networking"; } from "./networking";
import { start } from "repl"; import { start } from "repl";
@ -157,6 +158,8 @@ const UsagePage: React.FC<UsagePageProps> = ({
const [topKeys, setTopKeys] = useState<any[]>([]); const [topKeys, setTopKeys] = useState<any[]>([]);
const [topModels, setTopModels] = useState<any[]>([]); const [topModels, setTopModels] = useState<any[]>([]);
const [topUsers, setTopUsers] = useState<any[]>([]); const [topUsers, setTopUsers] = useState<any[]>([]);
const [teamSpendData, setTeamSpendData] = useState<any[]>([]);
const [uniqueTeamIds, setUniqueTeamIds] = useState<any[]>([]);
const firstDay = new Date( const firstDay = new Date(
currentDate.getFullYear(), currentDate.getFullYear(),
@ -217,6 +220,11 @@ const UsagePage: React.FC<UsagePageProps> = ({
spend: k["total_spend"], spend: k["total_spend"],
})); }));
setTopModels(filtered_models); setTopModels(filtered_models);
const teamSpend = await teamSpendLogsCall(accessToken);
console.log("teamSpend", teamSpend);
setTeamSpendData(teamSpend.daily_spend);
setUniqueTeamIds(teamSpend.teams)
} else if (userRole == "App Owner") { } else if (userRole == "App Owner") {
await userSpendLogsCall( await userSpendLogsCall(
accessToken, accessToken,
@ -346,9 +354,9 @@ const UsagePage: React.FC<UsagePageProps> = ({
<Title>Monthly Team Spend</Title> <Title>Monthly Team Spend</Title>
<BarChart <BarChart
className="h-72" className="h-72"
data={chartData} data={teamSpendData}
index="date" index="date"
categories={['proj1', 'proj2', 'proj3']} categories={uniqueTeamIds}
yAxisWidth={30} yAxisWidth={30}
stack={true} stack={true}
/> />