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

ui: refine code and error handle #662

Merged
merged 10 commits into from
Jul 13, 2020
4 changes: 2 additions & 2 deletions ui/lib/apps/ClusterInfo/components/HostTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WarningOutlined } from '@ant-design/icons'
import { getValueFormat } from '@baurine/grafana-value-formats'

import client from '@lib/client'
import { Bar, CardTableV2, Pre } from '@lib/components'
import { Bar, CardTable, Pre } from '@lib/components'
import { useClientRequest } from '@lib/utils/useClientRequest'

const { Text } = Typography
Expand Down Expand Up @@ -201,7 +201,7 @@ System: ${getValueFormat('percentunit')(system)}`
]

return (
<CardTableV2
<CardTable
cardNoMargin
loading={isLoading}
columns={columns}
Expand Down
60 changes: 30 additions & 30 deletions ui/lib/apps/ClusterInfo/components/InstanceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Divider, Popconfirm, Tooltip, Alert } from 'antd'
import React, { useMemo, useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { DeleteOutlined } from '@ant-design/icons'
import { CardTableV2, InstanceStatusBadge } from '@lib/components'
import DateTime from '@lib/components/DateTime'
import { useClientRequest } from '@lib/utils/useClientRequest'
import { usePersistFn } from '@umijs/hooks'
import { Divider, Popconfirm, Tooltip } from 'antd'
import React, { useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'

import client from '@lib/client'
import { CardTable, InstanceStatusBadge } from '@lib/components'
import DateTime from '@lib/components/DateTime'
import {
buildInstanceTable,
IInstanceTableItem,
InstanceStatus,
} from '@lib/utils/instanceTable'
import client from '@lib/client'
import { useClientRequest } from '@lib/utils/useClientRequest'

function StatusColumn({
node,
Expand Down Expand Up @@ -78,6 +79,19 @@ export default function ListPage() {
} = useClientRequest((cancelToken) =>
client.getInstance().getPDTopology({ cancelToken })
)
const errMessages = useMemo(() => {
let errMsgs: string[] = []
if (errTiDB) {
errMsgs.push('Load TiDB instances failed')
Copy link
Member

@breezewish breezewish Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better provide detailed error information. Keep the same error message as current one is not verbose enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

}
if (errStores) {
errMsgs.push('Load TiKV / TiFlash instances failed')
}
if (errPD) {
errMsgs.push('Load PD instances failed')
}
return errMsgs
}, [errTiDB, errStores, errPD])

const [tableData, groupData] = useMemo(
() =>
Expand Down Expand Up @@ -178,28 +192,14 @@ export default function ListPage() {
)

return (
<>
{errTiDB && (
<Alert message="Load TiDB instances failed" type="error" showIcon />
)}
{errStores && (
<Alert
message="Load TiKV / TiFlash instances failed"
type="error"
showIcon
/>
)}
{errPD && (
<Alert message="Load PD instances failed" type="error" showIcon />
)}
<CardTableV2
disableSelectionZone
cardNoMargin
loading={loadingTiDB || loadingStores || loadingPD}
columns={columns}
items={tableData}
groups={groupData}
/>
</>
<CardTable
disableSelectionZone
cardNoMargin
loading={loadingTiDB || loadingStores || loadingPD}
columns={columns}
items={tableData}
groups={groupData}
errMessages={errMessages}
/>
)
}
4 changes: 2 additions & 2 deletions ui/lib/apps/Diagnose/components/DiagnoseHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { usePersistFn } from '@umijs/hooks'
import type { TFunction } from 'i18next'

import client, { DiagnoseReport } from '@lib/client'
import { CardTableV2, DateTime } from '@lib/components'
import { CardTable, DateTime } from '@lib/components'
import openLink from '@lib/utils/openLink'
import { useClientRequest } from '@lib/utils/useClientRequest'

Expand Down Expand Up @@ -108,7 +108,7 @@ export default function DiagnoseHistory() {
)

return (
<CardTableV2
<CardTable
cardNoMarginTop
loading={isLoading}
items={data || []}
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/apps/InstanceProfiling/pages/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ArrowLeftOutlined } from '@ant-design/icons'
import { usePersistFn } from '@umijs/hooks'

import client from '@lib/client'
import { CardTableV2, Head } from '@lib/components'
import { CardTable, Head } from '@lib/components'
import { useClientRequestWithPolling } from '@lib/utils/useClientRequest'
import { InstanceKindName } from '@lib/utils/instanceTable'

Expand Down Expand Up @@ -145,7 +145,7 @@ export default function Page() {
</Button>
}
/>
<CardTableV2
<CardTable
loading={isLoading && !data}
columns={columns}
items={data?.tasks_status || []}
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/apps/InstanceProfiling/pages/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import client, {
} from '@lib/client'
import {
Card,
CardTableV2,
CardTable,
InstanceSelect,
IInstanceSelectRefProps,
} from '@lib/components'
Expand Down Expand Up @@ -199,7 +199,7 @@ export default function Page() {

<div style={{ height: '100%', position: 'relative' }}>
<ScrollablePane>
<CardTableV2
<CardTable
cardNoMarginTop
loading={listLoading}
items={historyTable || []}
Expand Down
50 changes: 50 additions & 0 deletions ui/lib/apps/Overview/components/RecentSlowQueries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { RightOutlined } from '@ant-design/icons'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'

import { DateTime } from '@lib/components'
import { SlowQueriesTable, useSlowQuery } from '@lib/apps/SlowQuery'
import { defSlowQueryColumnKeys } from '@lib/apps/SlowQuery/pages/List'
import { DEF_SLOW_QUERY_OPTIONS } from '@lib/apps/SlowQuery/utils/useSlowQuery'

export default function RecentSlowQueries() {
const { t } = useTranslation()
const {
orderOptions,
changeOrder,

loadingSlowQueries,
slowQueries,
queryTimeRange,

errorMsg,
} = useSlowQuery({ ...DEF_SLOW_QUERY_OPTIONS, limit: 10 }, false)

return (
<SlowQueriesTable
key={`slow_query_${slowQueries.length}`}
visibleColumnKeys={defSlowQueryColumnKeys}
loading={loadingSlowQueries}
slowQueries={slowQueries}
orderBy={orderOptions.orderBy}
desc={orderOptions.desc}
onChangeOrder={changeOrder}
errMessages={[errorMsg]}
title={
<Link to="/slow_query">
{t('overview.recent_slow_query.title')} <RightOutlined />
</Link>
}
subTitle={
<span>
<DateTime.Calendar
unixTimestampMs={queryTimeRange.beginTime * 1000}
/>{' '}
~{' '}
<DateTime.Calendar unixTimestampMs={queryTimeRange.endTime * 1000} />
</span>
}
/>
)
}
60 changes: 60 additions & 0 deletions ui/lib/apps/Overview/components/RecentStatements.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { RightOutlined } from '@ant-design/icons'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'

import { StatementsTable, useStatement } from '@lib/apps/Statement'
import { DateTime } from '@lib/components'

export default function RecentStatements() {
const { t } = useTranslation()
const {
orderOptions,
changeOrder,

allTimeRanges,
validTimeRange,
loadingStatements,
statements,

errorMsg,
} = useStatement(undefined, false)

return (
<StatementsTable
key={`statement_${statements.length}`}
visibleColumnKeys={{
digest_text: true,
sum_latency: true,
avg_latency: true,
related_schemas: true,
}}
visibleItemsCount={10}
loading={loadingStatements}
statements={statements}
timeRange={validTimeRange}
orderBy={orderOptions.orderBy}
desc={orderOptions.desc}
onChangeOrder={changeOrder}
errMessages={[errorMsg]}
title={
<Link to="/statement">
{t('overview.top_statements.title')} <RightOutlined />
</Link>
}
subTitle={
allTimeRanges.length > 0 && (
<span>
<DateTime.Calendar
unixTimestampMs={(validTimeRange.begin_time ?? 0) * 1000}
/>{' '}
~{' '}
<DateTime.Calendar
unixTimestampMs={(validTimeRange.end_time ?? 0) * 1000}
/>
</span>
)
}
/>
)
}
Loading