Repository navigation
Chore: change query log time range #28052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8ad9be
feat: new time range picker outline
iamjoel 0e21c93
chore: remove log
iamjoel 9a64edd
fix: hanle select date ui
iamjoel 5e35322
chore: some i18n
iamjoel a463c79
feat: range picker
iamjoel 6f2981a
feat: refactor the components
iamjoel 5aba9b6
chore: combe start or end change
iamjoel fe1f0fd
chore: ui
iamjoel 6ad7633
feat: support direct choose date
iamjoel b072606
feat: support start end range
iamjoel 68c8ac0
Merge branch 'main' into chore/change-query-log-time-range
iamjoel a26aeff
chore: add missing dep
iamjoel 7271934
Update web/app/components/base/date-and-time-picker/date-picker/index…
iamjoel 3cd8f09
Update web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/…
iamjoel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
...p/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx
This file contains hidden or 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,80 @@ | ||
| 'use client' | ||
| import { RiCalendarLine } from '@remixicon/react' | ||
| import type { Dayjs } from 'dayjs' | ||
| import type { FC } from 'react' | ||
| import React, { useCallback } from 'react' | ||
| import cn from '@/utils/classnames' | ||
| import { formatToLocalTime } from '@/utils/format' | ||
| import { useI18N } from '@/context/i18n' | ||
| import Picker from '@/app/components/base/date-and-time-picker/date-picker' | ||
| import type { TriggerProps } from '@/app/components/base/date-and-time-picker/types' | ||
| import { noop } from 'lodash-es' | ||
| import dayjs from 'dayjs' | ||
|
|
||
| type Props = { | ||
| start: Dayjs | ||
| end: Dayjs | ||
| onStartChange: (date?: Dayjs) => void | ||
| onEndChange: (date?: Dayjs) => void | ||
| } | ||
|
|
||
| const today = dayjs() | ||
| const DatePicker: FC<Props> = ({ | ||
| start, | ||
| end, | ||
| onStartChange, | ||
| onEndChange, | ||
| }) => { | ||
| const { locale } = useI18N() | ||
|
|
||
| const renderDate = useCallback(({ value, handleClickTrigger, isOpen }: TriggerProps) => { | ||
| return ( | ||
| <div className={cn('system-sm-regular flex h-7 cursor-pointer items-center rounded-lg px-1 text-components-input-text-filled hover:bg-state-base-hover', isOpen && 'bg-state-base-hover')} onClick={handleClickTrigger}> | ||
| {value ? formatToLocalTime(value, locale, 'MMM D') : ''} | ||
| </div> | ||
| ) | ||
| }, [locale]) | ||
|
|
||
| const availableStartDate = end.subtract(30, 'day') | ||
| const startDateDisabled = useCallback((date: Dayjs) => { | ||
| if (date.isAfter(today, 'date')) | ||
| return true | ||
| return !((date.isAfter(availableStartDate, 'date') || date.isSame(availableStartDate, 'date')) && (date.isBefore(end, 'date') || date.isSame(end, 'date'))) | ||
|
iamjoel marked this conversation as resolved.
Resolved
|
||
| }, [availableStartDate, end]) | ||
|
|
||
| const availableEndDate = start.add(30, 'day') | ||
| const endDateDisabled = useCallback((date: Dayjs) => { | ||
| if (date.isAfter(today, 'date')) | ||
| return true | ||
| return !((date.isAfter(start, 'date') || date.isSame(start, 'date')) && (date.isBefore(availableEndDate, 'date') || date.isSame(availableEndDate, 'date'))) | ||
|
iamjoel marked this conversation as resolved.
Resolved
|
||
| }, [availableEndDate, start]) | ||
|
|
||
| return ( | ||
| <div className='flex h-8 items-center space-x-0.5 rounded-lg bg-components-input-bg-normal px-2'> | ||
| <div className='p-px'> | ||
| <RiCalendarLine className='size-3.5 text-text-tertiary' /> | ||
| </div> | ||
| <Picker | ||
| value={start} | ||
| onChange={onStartChange} | ||
| renderTrigger={renderDate} | ||
| needTimePicker={false} | ||
| onClear={noop} | ||
| noConfirm | ||
| getIsDateDisabled={startDateDisabled} | ||
| /> | ||
| <span className='system-sm-regular text-text-tertiary'>-</span> | ||
| <Picker | ||
| value={end} | ||
| onChange={onEndChange} | ||
| renderTrigger={renderDate} | ||
| needTimePicker={false} | ||
| onClear={noop} | ||
| noConfirm | ||
| getIsDateDisabled={endDateDisabled} | ||
| /> | ||
| </div> | ||
|
|
||
| ) | ||
| } | ||
| export default React.memo(DatePicker) | ||
86 changes: 86 additions & 0 deletions
86
web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx
This file contains hidden or 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,86 @@ | ||
| 'use client' | ||
| import type { PeriodParams, PeriodParamsWithTimeRange } from '@/app/components/app/overview/app-chart' | ||
| import type { FC } from 'react' | ||
| import React, { useCallback, useState } from 'react' | ||
| import type { Dayjs } from 'dayjs' | ||
| import { HourglassShape } from '@/app/components/base/icons/src/vender/other' | ||
| import RangeSelector from './range-selector' | ||
| import DatePicker from './date-picker' | ||
| import dayjs from 'dayjs' | ||
| import { useI18N } from '@/context/i18n' | ||
| import { formatToLocalTime } from '@/utils/format' | ||
|
|
||
| const today = dayjs() | ||
|
iamjoel marked this conversation as resolved.
Resolved
|
||
|
|
||
| type Props = { | ||
| ranges: { value: number; name: string }[] | ||
| onSelect: (payload: PeriodParams) => void | ||
| queryDateFormat: string | ||
| } | ||
|
|
||
| const TimeRangePicker: FC<Props> = ({ | ||
| ranges, | ||
| onSelect, | ||
| queryDateFormat, | ||
| }) => { | ||
| const { locale } = useI18N() | ||
|
|
||
| const [isCustomRange, setIsCustomRange] = useState(false) | ||
| const [start, setStart] = useState<Dayjs>(today) | ||
| const [end, setEnd] = useState<Dayjs>(today) | ||
|
|
||
| const handleRangeChange = useCallback((payload: PeriodParamsWithTimeRange) => { | ||
| setIsCustomRange(false) | ||
| setStart(payload.query!.start) | ||
| setEnd(payload.query!.end) | ||
| onSelect({ | ||
| name: payload.name, | ||
| query: { | ||
| start: payload.query!.start.format(queryDateFormat), | ||
| end: payload.query!.end.format(queryDateFormat), | ||
| }, | ||
| }) | ||
| }, [onSelect, queryDateFormat]) | ||
|
|
||
| const handleDateChange = useCallback((type: 'start' | 'end') => { | ||
| return (date?: Dayjs) => { | ||
| if (!date) return | ||
| if (type === 'start' && date.isSame(start)) return | ||
| if (type === 'end' && date.isSame(end)) return | ||
| if (type === 'start') | ||
| setStart(date) | ||
| else | ||
| setEnd(date) | ||
|
|
||
| const currStart = type === 'start' ? date : start | ||
| const currEnd = type === 'end' ? date : end | ||
| onSelect({ | ||
| name: `${formatToLocalTime(currStart, locale, 'MMM D')} - ${formatToLocalTime(currEnd, locale, 'MMM D')}`, | ||
| query: { | ||
| start: currStart.format(queryDateFormat), | ||
| end: currEnd.format(queryDateFormat), | ||
| }, | ||
| }) | ||
|
|
||
| setIsCustomRange(true) | ||
| } | ||
| }, [start, end, onSelect, locale, queryDateFormat]) | ||
|
|
||
| return ( | ||
| <div className='flex items-center'> | ||
| <RangeSelector | ||
| isCustomRange={isCustomRange} | ||
| ranges={ranges} | ||
| onSelect={handleRangeChange} | ||
| /> | ||
| <HourglassShape className='h-3.5 w-2 text-components-input-bg-normal' /> | ||
| <DatePicker | ||
| start={start} | ||
| end={end} | ||
| onStartChange={handleDateChange('start')} | ||
| onEndChange={handleDateChange('end')} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
| export default React.memo(TimeRangePicker) | ||
81 changes: 81 additions & 0 deletions
81
...commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/range-selector.tsx
This file contains hidden or 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,81 @@ | ||
| 'use client' | ||
| import type { PeriodParamsWithTimeRange, TimeRange } from '@/app/components/app/overview/app-chart' | ||
| import type { FC } from 'react' | ||
| import React, { useCallback } from 'react' | ||
| import { SimpleSelect } from '@/app/components/base/select' | ||
| import type { Item } from '@/app/components/base/select' | ||
| import dayjs from 'dayjs' | ||
| import { RiArrowDownSLine, RiCheckLine } from '@remixicon/react' | ||
| import cn from '@/utils/classnames' | ||
| import { useTranslation } from 'react-i18next' | ||
|
|
||
| const today = dayjs() | ||
|
iamjoel marked this conversation as resolved.
Resolved
|
||
|
|
||
| type Props = { | ||
| isCustomRange: boolean | ||
| ranges: { value: number; name: string }[] | ||
| onSelect: (payload: PeriodParamsWithTimeRange) => void | ||
| } | ||
|
|
||
| const RangeSelector: FC<Props> = ({ | ||
| isCustomRange, | ||
| ranges, | ||
| onSelect, | ||
| }) => { | ||
| const { t } = useTranslation() | ||
|
|
||
| const handleSelectRange = useCallback((item: Item) => { | ||
| const { name, value } = item | ||
| let period: TimeRange | null = null | ||
| if (value === 0) { | ||
| const startOfToday = today.startOf('day') | ||
| const endOfToday = today.endOf('day') | ||
| period = { start: startOfToday, end: endOfToday } | ||
| } | ||
| else { | ||
| period = { start: today.subtract(item.value as number, 'day').startOf('day'), end: today.endOf('day') } | ||
| } | ||
| onSelect({ query: period!, name }) | ||
| }, [onSelect]) | ||
|
|
||
| const renderTrigger = useCallback((item: Item | null, isOpen: boolean) => { | ||
| return ( | ||
| <div className={cn('flex h-8 cursor-pointer items-center space-x-1.5 rounded-lg bg-components-input-bg-normal pl-3 pr-2', isOpen && 'bg-state-base-hover-alt')}> | ||
| <div className='system-sm-regular text-components-input-text-filled'>{isCustomRange ? t('appLog.filter.period.custom') : item?.name}</div> | ||
| <RiArrowDownSLine className={cn('size-4 text-text-quaternary', isOpen && 'text-text-secondary')} /> | ||
| </div> | ||
| ) | ||
| }, [isCustomRange]) | ||
|
|
||
| const renderOption = useCallback(({ item, selected }: { item: Item; selected: boolean }) => { | ||
| return ( | ||
| <> | ||
| {selected && ( | ||
| <span | ||
| className={cn( | ||
| 'absolute left-2 top-[9px] flex items-center text-text-accent', | ||
| )} | ||
| > | ||
| <RiCheckLine className="h-4 w-4" aria-hidden="true" /> | ||
| </span> | ||
| )} | ||
| <span className={cn('system-md-regular block truncate')}>{item.name}</span> | ||
| </> | ||
| ) | ||
| }, []) | ||
| return ( | ||
| <SimpleSelect | ||
| items={ranges.map(v => ({ ...v, name: t(`appLog.filter.period.${v.name}`) }))} | ||
| className='mt-0 !w-40' | ||
| notClearable={true} | ||
| onSelect={handleSelectRange} | ||
| defaultValue={0} | ||
| wrapperClassName='h-8' | ||
| optionWrapClassName='w-[200px] translate-x-[-24px]' | ||
| renderTrigger={renderTrigger} | ||
| optionClassName='flex items-center py-0 pl-7 pr-2 h-8' | ||
| renderOption={renderOption} | ||
| /> | ||
| ) | ||
| } | ||
| export default React.memo(RangeSelector) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.