feat: fix GetDashboard() page

This commit is contained in:
Yang Luo 2024-03-15 19:52:19 +08:00
parent 2cb6ff69ae
commit 88a4736520
2 changed files with 18 additions and 6 deletions

View File

@ -28,6 +28,10 @@ type Dashboard struct {
}
func GetDashboard(owner string) (*Dashboard, error) {
if owner == "All" {
owner = ""
}
dashboard := &Dashboard{
OrganizationCounts: make([]int, 31),
UserCounts: make([]int, 31),
@ -36,14 +40,13 @@ func GetDashboard(owner string) (*Dashboard, error) {
SubscriptionCounts: make([]int, 31),
}
var wg sync.WaitGroup
organizations := []Organization{}
users := []User{}
providers := []Provider{}
applications := []Application{}
subscriptions := []Subscription{}
var wg sync.WaitGroup
wg.Add(5)
go func() {
defer wg.Done()

View File

@ -42,11 +42,21 @@ const Dashboard = (props) => {
}
}, [props.account]);
const getOrganizationName = () => {
let organization = localStorage.getItem("organization") === "All" ? "" : localStorage.getItem("organization");
if (!Setting.isAdminUser(props.account) && Setting.isLocalAdminUser(props.account)) {
organization = props.account.owner;
}
return organization;
};
React.useEffect(() => {
if (!Setting.isLocalAdminUser(props.account)) {
return;
}
DashboardBackend.getDashboard(props.account.owner).then((res) => {
const organization = getOrganizationName();
DashboardBackend.getDashboard(organization).then((res) => {
if (res.status === "ok") {
setDashboardData(res.data);
} else {
@ -64,9 +74,8 @@ const Dashboard = (props) => {
return;
}
const newOrganization = localStorage.getItem("organization") === "All" ? "" : localStorage.getItem("organization");
DashboardBackend.getDashboard(newOrganization).then((res) => {
const organization = getOrganizationName();
DashboardBackend.getDashboard(organization).then((res) => {
if (res.status === "ok") {
setDashboardData(res.data);
} else {