fix: turn off the local dashboards(#3740) (#3793)

This commit is contained in:
Yury Molodov 2023-02-08 20:13:15 +01:00 committed by GitHub
parent a1ee679042
commit 75bcf86a31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,7 +26,8 @@ export const useFetchDashboards = (): {
const fetchLocalDashboards = async () => { const fetchLocalDashboards = async () => {
const filenames = window.__VMUI_PREDEFINED_DASHBOARDS__; const filenames = window.__VMUI_PREDEFINED_DASHBOARDS__;
if (!filenames?.length) return []; if (!filenames?.length) return [];
return await Promise.all(filenames.map(async f => importModule(f))); const dashboards = await Promise.all(filenames.map(async f => importModule(f)));
setDashboards((prevDash) => [...dashboards, ...prevDash]);
}; };
const fetchRemoteDashboards = async () => { const fetchRemoteDashboards = async () => {
@ -45,19 +46,20 @@ export const useFetchDashboards = (): {
} }
setIsLoading(false); setIsLoading(false);
} else { } else {
await fetchLocalDashboards();
setError(resp.error); setError(resp.error);
setIsLoading(false); setIsLoading(false);
} }
} catch (e) { } catch (e) {
setIsLoading(false); setIsLoading(false);
if (e instanceof Error) setError(`${e.name}: ${e.message}`); if (e instanceof Error) setError(`${e.name}: ${e.message}`);
await fetchLocalDashboards();
} }
}; };
useEffect(() => { useEffect(() => {
if (appModeEnable) return; if (appModeEnable) return;
setDashboards([]); setDashboards([]);
fetchLocalDashboards().then(d => d.length && setDashboards((prevDash) => [...d, ...prevDash]));
fetchRemoteDashboards(); fetchRemoteDashboards();
}, [serverUrl]); }, [serverUrl]);