Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize UI without clusters #8

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion web/config/router.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ export default [
path: "/data",
name: "data",
icon: "database",
authority: ["data"],
authority: [
"data.index:all",
"data.index:read",
"data.alias:all",
"data.alias:read",
"data.view:all",
"data.view:read",
],
routes: [
{
path: "/data/index",
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/GlobalHeader/RightContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export default class GlobalHeaderRight extends PureComponent {
topLeft: false,
}}> */}
{this.props.clusterList.length > 0 &&
this.props.selectedCluster.id != "" && (
this.props.selectedCluster?.id && (
<ConsoleUI
selectedCluster={this.props.selectedCluster}
clusterList={this.props.clusterList}
Expand Down
151 changes: 79 additions & 72 deletions web/src/components/Overview/Monitor/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useMemo, useEffect, useCallback } from "react";
import { Card, Tabs, Breadcrumb, Button, BackTop } from "antd";
import { Card, Tabs, Breadcrumb, Button, BackTop, Empty } from "antd";
import { calculateBounds } from "@/components/vendor/data/common/query/timefilter";
import { formatter } from "@/utils/format";
import moment from "moment";
Expand Down Expand Up @@ -117,81 +117,88 @@ const Monitor = (props) => {
<BreadcrumbList data={breadcrumbList} />

<Card bodyStyle={{ padding: 15 }}>
<div style={{ marginBottom: 5 }}>
<div style={{ display: 'flex', gap: 8 }}>
<div style={{ flexGrow: 0 }}>
<DatePicker
locale={getLocale()}
start={state.timeRange.min}
end={state.timeRange.max}
onRangeChange={({ start, end }) => {
handleTimeChange({ start, end })
}}
{...refresh}
onRefreshChange={setRefresh}
onRefresh={handleTimeChange}
showTimeSetting={true}
showTimeInterval={true}
timeInterval={state.timeInterval}
showTimeout={true}
timeout={state.timeout}
onTimeSettingChange={(timeSetting) => {
localStorage.setItem(TIMEOUT_CACHE_KEY, timeSetting.timeout)
setState({
...state,
timeInterval: timeSetting.timeInterval,
timeout: timeSetting.timeout
});
{
selectedCluster ? (
<>
<div style={{ marginBottom: 5 }}>
<div style={{ display: 'flex', gap: 8 }}>
<div style={{ flexGrow: 0 }}>
<DatePicker
locale={getLocale()}
start={state.timeRange.min}
end={state.timeRange.max}
onRangeChange={({ start, end }) => {
handleTimeChange({ start, end })
}}
{...refresh}
onRefreshChange={setRefresh}
onRefresh={handleTimeChange}
showTimeSetting={true}
showTimeInterval={true}
timeInterval={state.timeInterval}
showTimeout={true}
timeout={state.timeout}
onTimeSettingChange={(timeSetting) => {
localStorage.setItem(TIMEOUT_CACHE_KEY, timeSetting.timeout)
setState({
...state,
timeInterval: timeSetting.timeInterval,
timeout: timeSetting.timeout
});
}}
timeZone={timeZone}
onTimeZoneChange={setTimeZone}
recentlyUsedRangesKey={'monitor'}
/>
</div>
</div>
</div>

<Tabs
activeKey={param?.tab || panes[0]?.key}
onChange={(key) => {
setParam({ ...param, tab: key });
}}
timeZone={timeZone}
onTimeZoneChange={setTimeZone}
recentlyUsedRangesKey={'monitor'}
/>
</div>
</div>
</div>

<Tabs
activeKey={param?.tab || panes[0]?.key}
onChange={(key) => {
setParam({ ...param, tab: key });
}}
tabBarGutter={10}
destroyInactiveTabPane
animated={false}
>
{panes.map((pane) => (
<TabPane tab={pane.title} key={pane.key}>
<StatisticBar
setSpinning={setSpinning}
onInfoChange={onInfoChange}
{...state}
{...extraParams}
/>
<div style={{ marginTop: 15 }}>
{checkPaneParams({
...state,
...extraParams,
}) ? (
typeof pane.component == "string" ? (
pane.component
) : (
<pane.component
selectedCluster={selectedCluster}
isAgent={isAgent}
{...state}
handleTimeChange={handleTimeChange}
tabBarGutter={10}
destroyInactiveTabPane
animated={false}
>
{panes.map((pane) => (
<TabPane tab={pane.title} key={pane.key}>
<StatisticBar
setSpinning={setSpinning}
onInfoChange={onInfoChange}
{...state}
{...extraParams}
bucketSize={state.timeInterval}
timeout={state.timeout}
/>
)
) : null}
</div>
</TabPane>
))}
</Tabs>
<div style={{ marginTop: 15 }}>
{checkPaneParams({
...state,
...extraParams,
}) ? (
typeof pane.component == "string" ? (
pane.component
) : (
<pane.component
selectedCluster={selectedCluster}
isAgent={isAgent}
{...state}
handleTimeChange={handleTimeChange}
setSpinning={setSpinning}
{...extraParams}
bucketSize={state.timeInterval}
timeout={state.timeout}
/>
)
) : null}
</div>
</TabPane>
))}
</Tabs>
</>
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
}

</Card>

<BackTop />
Expand Down
8 changes: 5 additions & 3 deletions web/src/lib/hooks/use_async.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";

export default function useAsync(callback, dependencies = []) {
export default function useAsync(callback, dependencies = [], runInInit = true) {
const loadingRef = React.useRef(false);
const [loading, setLoading] = React.useState(true);
const [error, setError] = React.useState();
Expand All @@ -24,8 +24,10 @@ export default function useAsync(callback, dependencies = []) {
}, dependencies);

React.useEffect(() => {
callbackMemoized();
}, [callbackMemoized]);
if (runInInit) {
callbackMemoized();
}
}, [callbackMemoized, runInInit]);

return { run: callbackMemoized, loading, error, value };
}
7 changes: 4 additions & 3 deletions web/src/lib/hooks/use_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const DEFAULT_OPTIONS = {
headers: { "Content-Type": "application/json" },
};

export default function useFetch(url, options = {}, dependencies = []) {
export default function useFetch(url, options = {}, dependencies = [], runInInit = true) {
const { returnRawResponse, noticeable, ...rest } = options
return useAsync(() => {
return request(url, { ...DEFAULT_OPTIONS, ...options });
}, dependencies);
return request(url, { ...DEFAULT_OPTIONS, ...rest }, returnRawResponse, noticeable);
}, dependencies, runInInit);
}
23 changes: 10 additions & 13 deletions web/src/pages/Cluster/Metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,10 @@ class ClusterMonitor extends PureComponent {
};

componentDidUpdate(prevProps, prevState, snapshot) {
// console.log(this.props.selectedCluster)
// console.log(this.state.clusterID)

if (this.props.selectedCluster.id !== this.state.clusterID) {
if (this.props.selectedCluster?.id !== this.state.clusterID) {
console.log("cluster changed");

this.setState({ clusterID: this.props.selectedCluster.id }, () => {
this.setState({ clusterID: this.props.selectedCluster?.id }, () => {
//TODO 处理 cancel 事件,先把当前还在执行中的请求结束,避免更新完成之后,被晚到的之前的请求给覆盖了。
this.fetchData();
});
Expand Down Expand Up @@ -225,10 +222,10 @@ class ClusterMonitor extends PureComponent {
},
});
} else if (
this.props.selectedCluster.id !== undefined &&
this.props.selectedCluster.id !== null
this.props.selectedCluster?.id !== undefined &&
this.props.selectedCluster?.id !== null
) {
this.setState({ clusterID: this.props.selectedCluster.id }, () => {});
this.setState({ clusterID: this.props.selectedCluster?.id }, () => {});
} else {
//alert("cluster ID is not set");
return;
Expand Down Expand Up @@ -537,7 +534,7 @@ class ClusterMonitor extends PureComponent {
})}
>
<ClusterMetric
clusterID={this.props.selectedCluster.id}
clusterID={this.props.selectedCluster?.id}
timezone={timezone}
timeRange={this.state.timeRange}
handleTimeChange={this.handleTimeChange}
Expand All @@ -550,7 +547,7 @@ class ClusterMonitor extends PureComponent {
})}
>
<NodeMetric
clusterID={this.props.selectedCluster.id}
clusterID={this.props.selectedCluster?.id}
timezone={timezone}
timeRange={this.state.timeRange}
handleTimeChange={this.handleTimeChange}
Expand All @@ -565,7 +562,7 @@ class ClusterMonitor extends PureComponent {
})}
>
<IndexMetric
clusterID={this.props.selectedCluster.id}
clusterID={this.props.selectedCluster?.id}
timezone={timezone}
timeRange={this.state.timeRange}
handleTimeChange={this.handleTimeChange}
Expand All @@ -580,7 +577,7 @@ class ClusterMonitor extends PureComponent {
})}
>
<QueueMetric
clusterID={this.props.selectedCluster.id}
clusterID={this.props.selectedCluster?.id}
timezone={timezone}
timeRange={this.state.timeRange}
handleTimeChange={this.handleTimeChange}
Expand All @@ -595,7 +592,7 @@ class ClusterMonitor extends PureComponent {
})}
>
<StorageMetric
clusterID={this.props.selectedCluster.id}
clusterID={this.props.selectedCluster?.id}
timezone={timezone}
timeRange={this.state.timeRange}
/>
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/Cluster/components/overview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ const Index = (props) => {
}, [state.timeRange]);

const [selectedClusterID] = React.useMemo(() => {
let selectedClusterID = props.selectedCluster.id;
let selectedClusterID = props.selectedCluster?.id;
if (selectedClusterID && selectedClusterID != state.clusterID) {
setState({ ...state, clusterID: selectedClusterID });
}

return [selectedClusterID];
}, [props.selectedCluster.id]);
}, [props.selectedCluster?.id]);

const handleTimeChange = ({ start, end }) => {
const bounds = calculateBounds({
Expand Down
Loading
Loading