Skip to content

Commit

Permalink
feat: support disable or enable apps (#1448)
Browse files Browse the repository at this point in the history
* control overview whether show more metrics buttton

* enable to disable apps

* support enable or disable some apps

* bump tidb-dashboard-for-clinic-cloud to 0.0.28
  • Loading branch information
baurine authored Dec 5, 2022
1 parent d0228dd commit 5741300
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ui/packages/tidb-dashboard-for-clinic-cloud/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pingcap/tidb-dashboard-for-clinic-cloud",
"version": "0.0.27",
"version": "0.0.28",
"main": "dist/dashboardApp.js",
"module": "dist/dashboardApp.js",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@
clusterInfo: {
orgId,
clusterId
}
},

appsConfig: {
overview: {
showViewMoreMetrics: false
}
},
appsDisabled: ['monitoring', 'search_logs']
})
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
IOverviewDataSource,
IOverviewContext,
IOverviewConfig,
ReqConfig
} from '@pingcap/tidb-dashboard-lib'

Expand Down Expand Up @@ -60,14 +61,18 @@ const RECENT_SECONDS = [
24 * 60 * 60
]

export const ctx: IOverviewContext = {
export const ctx: (cfg: Partial<IOverviewConfig>) => IOverviewContext = (
cfg
) => ({
ds,
cfg: {
apiPathBase: client.getBasePath(),
metricsQueries: overviewMetrics,
timeRangeSelector: {
recent_seconds: RECENT_SECONDS,
withAbsoluteRangePicker: false
}
},
showViewMoreMetrics: false,
...cfg
}
}
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import { OverviewApp, OverviewProvider } from '@pingcap/tidb-dashboard-lib'
import { getGlobalConfig } from '~/uilts/globalConfig'
import { ctx } from './context'

export default function () {
return (
<OverviewProvider value={ctx}>
<OverviewProvider value={ctx(getGlobalConfig().appsConfig?.overview || {})}>
<OverviewApp />
</OverviewProvider>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ISlowQueryConfig, ITopSQLConfig } from '@pingcap/tidb-dashboard-lib'
import {
IOverviewConfig,
ISlowQueryConfig,
ITopSQLConfig
} from '@pingcap/tidb-dashboard-lib'

export type AppOptions = {
lang: string
Expand Down Expand Up @@ -33,6 +37,7 @@ export type ClusterInfo = {
}

export type AppsConfig = {
overview?: Partial<IOverviewConfig>
slowQuery?: Partial<ISlowQueryConfig>
topSQL?: Partial<ITopSQLConfig>
}
Expand All @@ -41,7 +46,12 @@ export type GlobalConfig = {
appOptions?: AppOptions
clientOptions: ClientOptions
clusterInfo: ClusterInfo

appsConfig?: AppsConfig

// appsDisabled has a higher priority than appsEnabled
appsDisabled?: string[]
appsEnabled?: string[]
}

// export const GlobalConfigContext = createContext<IGlobalConfig | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as singleSpa from 'single-spa'

import { i18n, routing } from '@pingcap/tidb-dashboard-lib'

import { AppOptions } from './globalConfig'
import { AppOptions, getGlobalConfig } from './globalConfig'

export default class AppRegistry {
public defaultRouter = ''
Expand Down Expand Up @@ -48,6 +48,16 @@ export default class AppRegistry {
* }} app
*/
register(app) {
// return if this app is disabled
const disabledApps = getGlobalConfig().appsDisabled
if (disabledApps && disabledApps.includes(app.id)) {
return this
}
const enabledApps = getGlobalConfig().appsEnabled
if (enabledApps && !enabledApps.includes(app.id)) {
return this
}

if (app.translations) {
i18n.addTranslations(app.translations)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const ctx: IOverviewContext = {
cfg: {
apiPathBase: client.getBasePath(),
metricsQueries: overviewMetrics,
promAddrConfigurable: true
promAddrConfigurable: true,
showViewMoreMetrics: true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ export default function Metrics() {
{isSomeLoading && <LoadingOutlined />}
</Space>
<Space>
<Link to={`/monitoring`}>
<Button type="primary" onClick={telemetry.clickViewMoreMetrics}>
{t('overview.view_more_metrics')}
</Button>
</Link>
{ctx?.cfg.showViewMoreMetrics && (
<Link to={`/monitoring`}>
<Button type="primary" onClick={telemetry.clickViewMoreMetrics}>
{t('overview.view_more_metrics')}
</Button>
</Link>
)}
</Space>
</Toolbar>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ export interface IOverviewDataSource {
}): Promise<MetricsQueryResponse>
}

export type IOverviewConfig = IContextConfig &
IMetricConfig & {
showViewMoreMetrics: boolean
}

export interface IOverviewContext {
ds: IOverviewDataSource
cfg: IContextConfig & IMetricConfig
cfg: IOverviewConfig
}

export const OverviewContext = createContext<IOverviewContext | null>(null)
Expand Down

0 comments on commit 5741300

Please sign in to comment.