fix: show selected organizations' statistics in dashboard page (#2805)

* fix: show selected organizations' statistics in dashboard page

* Update get-dashboard.go

* Update saml_idp.go

---------

Co-authored-by: Eric Luo <hsluoyz@qq.com>
This commit is contained in:
xiao-kong-long 2024-03-15 19:36:39 +08:00 committed by GitHub
parent e1e5943a3e
commit 2cb6ff69ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,11 @@ const Dashboard = (props) => {
return () => window.removeEventListener("storageTourChanged", handleTourChange); return () => window.removeEventListener("storageTourChanged", handleTourChange);
}, []); }, []);
React.useEffect(() => {
window.addEventListener("storageOrganizationChanged", handleOrganizationChange);
return () => window.removeEventListener("storageOrganizationChanged", handleOrganizationChange);
}, [props.owner]);
React.useEffect(() => { React.useEffect(() => {
if (!Setting.isLocalAdminUser(props.account)) { if (!Setting.isLocalAdminUser(props.account)) {
props.history.push("/apps"); props.history.push("/apps");
@ -54,6 +59,22 @@ const Dashboard = (props) => {
setIsTourVisible(TourConfig.getTourVisible()); setIsTourVisible(TourConfig.getTourVisible());
}; };
const handleOrganizationChange = () => {
if (!Setting.isLocalAdminUser(props.account)) {
return;
}
const newOrganization = localStorage.getItem("organization") === "All" ? "" : localStorage.getItem("organization");
DashboardBackend.getDashboard(newOrganization).then((res) => {
if (res.status === "ok") {
setDashboardData(res.data);
} else {
Setting.showMessage("error", res.msg);
}
});
};
const setIsTourToLocal = () => { const setIsTourToLocal = () => {
TourConfig.setIsTourVisible(false); TourConfig.setIsTourVisible(false);
setIsTourVisible(false); setIsTourVisible(false);