Skip to content

Commit

Permalink
tweak(topsql): time range offset (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
shhdgit authored Oct 25, 2022
1 parent 743f611 commit edefd8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 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.20",
"version": "0.0.22",
"main": "dist/dashboardApp.js",
"module": "dist/dashboardApp.js",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { TopsqlInstanceItem, TopsqlSummaryItem } from '@lib/client'
import {
Card,
TimeRangeSelector,
toTimeRangeValue,
toTimeRangeValue as _toTimeRangeValue,
DEFAULT_TIME_RANGE,
Toolbar,
AutoRefreshButton,
Expand All @@ -44,6 +44,11 @@ import { TopSQLContext } from '../../context'

const TOP_N = 5
const CHART_BAR_WIDTH = 8
const RECENT_RANGE_OFFSET = -60

const toTimeRangeValue: typeof _toTimeRangeValue = (v) => {
return _toTimeRangeValue(v, v?.type === 'recent' ? RECENT_RANGE_OFFSET : 0)
}

export function TopSQLList() {
const ctx = useContext(TopSQLContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ export type TimeRangeValue = [minSecond: number, maxSecond: number]

export type TimeRange = RelativeTimeRange | AbsoluteTimeRange

export function toTimeRangeValue(timeRange?: TimeRange): TimeRangeValue {
export function toTimeRangeValue(
timeRange?: TimeRange,
offset = 0
): TimeRangeValue {
let t2 = timeRange ?? DEFAULT_TIME_RANGE
if (t2.type === 'absolute') {
return [...t2.value]
return t2.value.map((t) => t + offset) as TimeRangeValue
} else {
const now = dayjs().unix()
return [now - t2.value, now + 1]
return [now - t2.value + offset, now + 1 + offset]
}
}

Expand Down

0 comments on commit edefd8b

Please sign in to comment.