Skip to content

Commit 38b1290

Browse files
committed
OU-1264: address CodeRabbit comments
1 parent 6742822 commit 38b1290

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

web/src/components/ols-tool-ui/helpers/AddToDashboardButton.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ export const AddToDashboardButton: React.FC<AddToDashboardButtonProps> = ({
7373

7474
return (
7575
<InfoTooltip description={t('Add To Dashboard')}>
76-
<HeaderIconButton aria-label="panel description" size="small">
76+
<HeaderIconButton
77+
aria-label={t('Add to dashboard')}
78+
size="small"
79+
onClick={addToPersesDashboard}
80+
>
7781
<ViewGridPlusIcon
78-
aria-describedby="info-tooltip"
79-
aria-hidden={false}
82+
aria-hidden={true}
8083
fontSize="inherit"
8184
sx={{ color: (theme) => theme.palette.text.secondary }}
82-
onClick={addToPersesDashboard}
8385
/>
8486
</HeaderIconButton>
8587
</InfoTooltip>

web/src/components/ols-tool-ui/helpers/OlsToolUIPersesWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ interface OlsToolUIPersesWrapperProps {
2323
children: React.ReactNode;
2424
height?: string;
2525
initialTimeRange?: TimeRangeValue;
26+
initialTimeZone?: string;
2627
}
2728

2829
export const OlsToolUIPersesWrapper: React.FC<OlsToolUIPersesWrapperProps> = ({
2930
children,
3031
initialTimeRange = { pastDuration: '1h' as DurationString },
3132
height = '300px',
33+
initialTimeZone = 'UTC',
3234
}) => {
3335
return (
3436
<QueryClientProvider client={queryClient}>
3537
<PersesWrapper project={null}>
36-
<TimeZoneProvider timeZone="UTC">
38+
<TimeZoneProvider timeZone={initialTimeZone}>
3739
<TimeRangeProviderBasic initialTimeRange={initialTimeRange}>
3840
<VariableProvider>
3941
<PersesPrometheusDatasourceWrapper queries={[]}>

web/src/components/ols-tool-ui/helpers/useTimeRange.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { isDurationString, parseDurationString } from '@perses-dev/core';
88
const parseTimeExpr = (expr: string, now: Date): Date | undefined => {
99
const match = expr.match(/^NOW(?:-(.+))?$/);
1010
if (!match) {
11-
return new Date(expr);
11+
const parsed = new Date(expr);
12+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
1213
}
1314
if (!match[1]) {
1415
return now;
@@ -22,17 +23,18 @@ const parseTimeExpr = (expr: string, now: Date): Date | undefined => {
2223
export const useTimeRange = (start?: string, end?: string, duration?: string): TimeRangeValue => {
2324
return useMemo(() => {
2425
const now = new Date();
26+
const safeDuration = duration && isDurationString(duration) ? duration : '1h';
2527
const startDate = start ? parseTimeExpr(start, now) : undefined;
2628
const endDate = end ? parseTimeExpr(end, now) : undefined;
2729

2830
// If end is exactly "NOW" with no offset and no explicit start, use relative time range
2931
if (end === 'NOW' && !start) {
30-
return { pastDuration: duration || '1h' } as RelativeTimeRange;
32+
return { pastDuration: safeDuration } as RelativeTimeRange;
3133
}
3234

3335
if (startDate && endDate) {
3436
return { start: startDate, end: endDate } as AbsoluteTimeRange;
3537
}
36-
return { pastDuration: duration || '1h' } as RelativeTimeRange;
38+
return { pastDuration: safeDuration } as RelativeTimeRange;
3739
}, [duration, end, start]);
3840
};

0 commit comments

Comments
 (0)