-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update time limit level * chore: update time limit level * chore: update time range selector no overview page * chore: update tidb dashboard for clinic cloud version
- Loading branch information
1 parent
a0f78b9
commit 194d3e0
Showing
6 changed files
with
144 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
ui/packages/tidb-dashboard-lib/src/apps/Overview/components/LimitTimeRange.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { TimeRange, TimeRangeSelector } from '@lib/components' | ||
import dayjs from 'dayjs' | ||
import React, { useMemo } from 'react' | ||
|
||
interface LimitTimeRangeProps { | ||
value: TimeRange | ||
recent_seconds?: number[] | ||
customAbsoluteRangePicker?: boolean | ||
onChange: (val: TimeRange) => void | ||
onZoomOutClick: (start: number, end: number) => void | ||
} | ||
|
||
// array of 24 numbers, start from 0 | ||
const hoursRange = [...Array(24).keys()] | ||
const minutesRange = [...Array(60).keys()] | ||
|
||
// These presets are aligned with Grafana | ||
const DEFAULT_RECENT_SECONDS = [ | ||
5 * 60, | ||
15 * 60, | ||
30 * 60, | ||
60 * 60, | ||
3 * 60 * 60, | ||
6 * 60 * 60, | ||
12 * 60 * 60, | ||
24 * 60 * 60, | ||
2 * 24 * 60 * 60, | ||
7 * 24 * 60 * 60, | ||
30 * 24 * 60 * 60, | ||
90 * 24 * 60 * 60 | ||
] | ||
|
||
export const LimitTimeRange: React.FC<LimitTimeRangeProps> = ({ | ||
value, | ||
recent_seconds = DEFAULT_RECENT_SECONDS, | ||
customAbsoluteRangePicker, | ||
onChange, | ||
onZoomOutClick | ||
}) => { | ||
// get the selectable time range value from rencent_seconds | ||
const selectableHours = useMemo(() => { | ||
return recent_seconds![recent_seconds!.length - 1] / 3600 | ||
}, [recent_seconds]) | ||
|
||
const disabledDate = (current) => { | ||
const today = dayjs().startOf('hour') | ||
// Can not select days before 2 days ago | ||
const tooEarly = | ||
today.subtract(selectableHours, 'hour') > dayjs(current).startOf('hour') | ||
// Can not select days after today | ||
const tooLate = today < dayjs(current).startOf('hour') | ||
return current && (tooEarly || tooLate) | ||
} | ||
|
||
// control avaliable time on Minute level | ||
const disabledTime = (current) => { | ||
// current hour | ||
const hour = dayjs().hour() | ||
const minute = dayjs().minute() | ||
// is current day | ||
if (current && current.isSame(dayjs(), 'day')) { | ||
return { | ||
disabledHours: () => hoursRange.slice(hour + 1), | ||
disabledMinutes: () => minutesRange.slice(minute + 1) | ||
} | ||
} | ||
|
||
// is 2 day ago | ||
if ( | ||
current && | ||
current.isSame(dayjs().subtract(selectableHours / 24, 'day'), 'day') | ||
) { | ||
return { | ||
disabledHours: () => hoursRange.slice(0, hour), | ||
disabledMinutes: () => minutesRange.slice(0, minute) | ||
} | ||
} | ||
|
||
return { disabledHours: () => [] } | ||
} | ||
|
||
return ( | ||
<> | ||
{customAbsoluteRangePicker ? ( | ||
<TimeRangeSelector | ||
value={value} | ||
onChange={onChange} | ||
recent_seconds={recent_seconds} | ||
disabledDate={disabledDate} | ||
disabledTime={disabledTime} | ||
customAbsoluteRangePicker={true} | ||
/> | ||
) : ( | ||
<TimeRangeSelector.WithZoomOut | ||
value={value} | ||
onChange={onChange} | ||
recent_seconds={recent_seconds} | ||
onZoomOutClick={onZoomOutClick} | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters