-
Notifications
You must be signed in to change notification settings - Fork 17
fix(TenantDashboard): hide if charts not enabled #675
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
Changes from all commits
68ee1b2
aa60433
ca3a411
2a9d644
e06808b
123cebc
ead5901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export type {MetricDescription, Metric, ChartOptions} from './types'; | ||
| export * from './types'; | ||
| export {MetricChart} from './MetricChart'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import {TenantDashboard} from '../TenantDashboard/TenantDashboard'; | ||
| import {defaultDashboardConfig} from './defaultDashboardConfig'; | ||
|
|
||
| export const DefaultOverviewContent = () => { | ||
| return <TenantDashboard charts={defaultDashboardConfig} />; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import type {AdditionalNodesProps} from '../../../../../types/additionalProps'; | ||
| import {CpuDashboard} from './CpuDashboard'; | ||
| import {TenantDashboard} from '../TenantDashboard/TenantDashboard'; | ||
| import {cpuDashboardConfig} from './cpuDashboardConfig'; | ||
| import {TopNodesByLoad} from './TopNodesByLoad'; | ||
| import {TopNodesByCpu} from './TopNodesByCpu'; | ||
| import {TopShards} from './TopShards'; | ||
|
|
@@ -13,7 +14,7 @@ interface TenantCpuProps { | |
| export function TenantCpu({path, additionalNodesProps}: TenantCpuProps) { | ||
| return ( | ||
| <> | ||
| <CpuDashboard /> | ||
| <TenantDashboard charts={cpuDashboardConfig} /> | ||
| <TopNodesByLoad path={path} additionalNodesProps={additionalNodesProps} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are all this components in one
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| <TopNodesByCpu path={path} additionalNodesProps={additionalNodesProps} /> | ||
| <TopShards path={path} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| import {useState} from 'react'; | ||
| import {StringParam, useQueryParam} from 'use-query-params'; | ||
|
|
||
| import {cn} from '../../../../../utils/cn'; | ||
| import type {TimeFrame} from '../../../../../utils/timeframes'; | ||
| import {useSetting, useTypedSelector} from '../../../../../utils/hooks'; | ||
| import {DISPLAY_CHARTS_IN_DB_DIAGNOSTICS_KEY} from '../../../../../utils/constants'; | ||
| import {useTypedSelector} from '../../../../../utils/hooks'; | ||
| import {TimeFrameSelector} from '../../../../../components/TimeFrameSelector/TimeFrameSelector'; | ||
| import { | ||
| type ChartOptions, | ||
| MetricChart, | ||
| type MetricDescription, | ||
| type ChartDataStatus, | ||
| } from '../../../../../components/MetricChart'; | ||
|
|
||
| import './TenantDashboard.scss'; | ||
|
|
@@ -29,39 +30,56 @@ interface TenantDashboardProps { | |
| } | ||
|
|
||
| export const TenantDashboard = ({charts}: TenantDashboardProps) => { | ||
| const [isDashboardHidden, setIsDashboardHidden] = useState<boolean>(true); | ||
|
|
||
| const [timeFrame = '1h', setTimeframe] = useQueryParam('timeframe', StringParam); | ||
|
|
||
| const {autorefresh} = useTypedSelector((state) => state.schema); | ||
|
|
||
| const [chartsEnabled] = useSetting(DISPLAY_CHARTS_IN_DB_DIAGNOSTICS_KEY); | ||
| // Refetch data only if dashboard successfully loaded | ||
| const shouldRefresh = autorefresh && !isDashboardHidden; | ||
|
|
||
| if (!chartsEnabled) { | ||
| return null; | ||
| } | ||
| /** | ||
| * Charts should be hidden, if they are not enabled: | ||
| * 1. GraphShard is not enabled | ||
| * 2. ydb version does not have /viewer/json/render endpoint (400, 404, CORS error, etc.) | ||
| * | ||
| * If at least one chart successfully loaded, dashboard should be shown | ||
| * @link https://github.com/ydb-platform/ydb-embedded-ui/issues/659 | ||
| * @todo disable only for specific errors ('GraphShard is not enabled') after ydb-stable-24 is generally used | ||
| */ | ||
| const handleChartDataStatusChange = (chartStatus: ChartDataStatus) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that you are interested only in success finish. So, lets rename this to let's say
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made quite a universal solution, to make it possible to extend it later - hide charts only on specific errors. Currently they are hidden on every error, including timeouts when node is not healthy, some internal problems, etc. The reason - versions without render endpoint don't return specific error. Further charts should be hidden only on specific errors, when GraphShard is not enabled - added todo not to forger. |
||
| if (chartStatus === 'success') { | ||
| setIsDashboardHidden(false); | ||
| } | ||
| }; | ||
|
|
||
| // If there is only one chart, display it with full width | ||
| const chartWidth = charts.length === 1 ? CHART_WIDTH_FULL : CHART_WIDTH; | ||
| const chartHeight = CHART_WIDTH / 1.5; | ||
|
|
||
| const renderContent = () => { | ||
| return charts.map((chartConfig) => { | ||
| const chartId = chartConfig.metrics.map(({target}) => target).join('&'); | ||
| return ( | ||
| <MetricChart | ||
| key={chartConfig.metrics.map(({target}) => target).join('&')} | ||
| key={chartId} | ||
| title={chartConfig.title} | ||
| metrics={chartConfig.metrics} | ||
| timeFrame={timeFrame as TimeFrame} | ||
| chartOptions={chartConfig.options} | ||
| autorefresh={autorefresh} | ||
| autorefresh={shouldRefresh} | ||
| width={chartWidth} | ||
| height={chartHeight} | ||
| onChartDataStatusChange={handleChartDataStatusChange} | ||
| isChartVisible={!isDashboardHidden} | ||
| /> | ||
| ); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={b(null)}> | ||
| <div className={b(null)} style={{display: isDashboardHidden ? 'none' : undefined}}> | ||
| <div className={b('controls')}> | ||
| <TimeFrameSelector value={timeFrame as TimeFrame} onChange={setTimeframe} /> | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should resolve problem with changable callback. It seems that such a combination of
useStateanduseEffectmay cause a lot of unneeded re-renders. Let's try to fix it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced it with
useEffect, dependant on chart state. It should not cause additional rerenders, since component already rerenders on reducer state change