diff --git a/neetbox/frontend/src/components/echarts.tsx b/neetbox/frontend/src/components/echarts.tsx index 9a6707ae..99a44234 100644 --- a/neetbox/frontend/src/components/echarts.tsx +++ b/neetbox/frontend/src/components/echarts.tsx @@ -1,5 +1,6 @@ -import { useRef, useEffect, HTMLAttributes } from "react"; -import * as echarts from "echarts"; +import { useRef, useEffect, HTMLAttributes, useState } from "react"; +import type * as echarts from "echarts"; +import Loading from "./loading"; export interface EChartsProps { initialOption: () => echarts.EChartsOption; @@ -10,27 +11,43 @@ export interface EChartsProps { export const ECharts = (props: EChartsProps) => { const chartContainerRef = useRef(null); const chartRef = useRef(null!); + const [echartsModule, setEchartsModule] = useState( + null + ); useEffect(() => { - const chart = echarts.init(chartContainerRef.current); + import("echarts").then((mod) => setEchartsModule(mod)); + }); - chart.setOption(props.initialOption()); - chartRef.current = chart; + useEffect(() => { + if (echartsModule) { + const chart = echartsModule.init(chartContainerRef.current); - const handleResize = () => { - chart.resize(); - }; - window.addEventListener("resize", handleResize); + chart.setOption(props.initialOption()); + chartRef.current = chart; - return () => { - window.removeEventListener("resize", handleResize); - chart.dispose(); - }; - }, []); + const handleResize = () => { + chart?.resize(); + }; + window.addEventListener("resize", handleResize); - useEffect(() => { - chartRef.current.setOption(props.updatingOption); - }, [props.updatingOption]); + return () => { + window.removeEventListener("resize", handleResize); + chart?.dispose(); + }; + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [echartsModule]); - return
; + useEffect(() => { + if (chartRef.current) { + chartRef.current.setOption(props.updatingOption); + } + }, [echartsModule, props.updatingOption]); + + return echartsModule ? ( +
+ ) : ( + + ); }; diff --git a/neetbox/frontend/src/components/loading.tsx b/neetbox/frontend/src/components/loading.tsx new file mode 100644 index 00000000..897feb73 --- /dev/null +++ b/neetbox/frontend/src/components/loading.tsx @@ -0,0 +1,23 @@ +import { Spin } from "@douyinfe/semi-ui"; + +export default function Loading({ + width = "", + height = "100px", +}: { + width?: string; + height?: string; +}) { + return ( +
+ +
+ ); +} diff --git a/neetbox/frontend/src/pages/console/proejctDashboard.tsx b/neetbox/frontend/src/pages/console/proejctDashboard.tsx index 8e6d8b19..98b74bff 100644 --- a/neetbox/frontend/src/pages/console/proejctDashboard.tsx +++ b/neetbox/frontend/src/pages/console/proejctDashboard.tsx @@ -7,8 +7,11 @@ import { ECharts } from "../../components/echarts"; import { ProjectStatus, useProjectStatus } from "../../services/projects"; import { Logs } from "../../components/dashboard/project/logs"; import { Actions } from "../../components/dashboard/project/actions"; +import Loading from "../../components/loading"; -export const ProjectContext = createContext<{ projectName: string } | null>(null); +export const ProjectContext = createContext<{ projectName: string } | null>( + null +); export default function ProjectDashboardButRecreateOnRouteChange() { const { projectName } = useParams(); @@ -47,7 +50,7 @@ function ProjectDashboard() { ) : ( - "Loading..." + )}