|
@@ -1,6 +1,5 @@
|
|
|
import {useRef} from 'react';
|
|
|
import styled from '@emotion/styled';
|
|
|
-import moment from 'moment';
|
|
|
|
|
|
import {
|
|
|
deleteMonitorEnvironment,
|
|
@@ -11,11 +10,9 @@ import Text from 'sentry/components/text';
|
|
|
import {t} from 'sentry/locale';
|
|
|
import {space} from 'sentry/styles/space';
|
|
|
import type {Organization} from 'sentry/types';
|
|
|
-import {parsePeriodToHours} from 'sentry/utils/dates';
|
|
|
import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
|
|
|
import useApi from 'sentry/utils/useApi';
|
|
|
import {useDimensions} from 'sentry/utils/useDimensions';
|
|
|
-import usePageFilters from 'sentry/utils/usePageFilters';
|
|
|
import useRouter from 'sentry/utils/useRouter';
|
|
|
import {
|
|
|
GridLineOverlay,
|
|
@@ -23,9 +20,9 @@ import {
|
|
|
} from 'sentry/views/monitors/components/overviewTimeline/gridLines';
|
|
|
import {TimelineTableRow} from 'sentry/views/monitors/components/overviewTimeline/timelineTableRow';
|
|
|
import type {MonitorBucketData} from 'sentry/views/monitors/components/overviewTimeline/types';
|
|
|
-import {getConfigFromTimeRange} from 'sentry/views/monitors/components/overviewTimeline/utils';
|
|
|
import type {Monitor} from 'sentry/views/monitors/types';
|
|
|
import {makeMonitorDetailsQueryKey} from 'sentry/views/monitors/utils';
|
|
|
+import {useMonitorTimes} from 'sentry/views/monitors/utils/useMonitorDates';
|
|
|
|
|
|
interface Props {
|
|
|
monitor: Monitor;
|
|
@@ -36,27 +33,11 @@ export function CronDetailsTimeline({monitor, organization}: Props) {
|
|
|
const {location} = useRouter();
|
|
|
const api = useApi();
|
|
|
const queryClient = useQueryClient();
|
|
|
- const nowRef = useRef<Date>(new Date());
|
|
|
- const {selection} = usePageFilters();
|
|
|
- const {period} = selection.datetime;
|
|
|
- let {end, start} = selection.datetime;
|
|
|
-
|
|
|
- if (!start || !end) {
|
|
|
- end = nowRef.current;
|
|
|
- start = moment(end)
|
|
|
- .subtract(parsePeriodToHours(period ?? '24h'), 'hour')
|
|
|
- .toDate();
|
|
|
- } else {
|
|
|
- start = new Date(start);
|
|
|
- end = new Date(end);
|
|
|
- }
|
|
|
|
|
|
const elementRef = useRef<HTMLDivElement>(null);
|
|
|
const {width: timelineWidth} = useDimensions<HTMLDivElement>({elementRef});
|
|
|
- const config = getConfigFromTimeRange(start, end, timelineWidth);
|
|
|
|
|
|
- const elapsedMinutes = config.elapsedMinutes;
|
|
|
- const rollup = Math.floor((elapsedMinutes * 60) / timelineWidth);
|
|
|
+ const {dates, selectionQuery, timeWindowConfig} = useMonitorTimes({timelineWidth});
|
|
|
|
|
|
const monitorStatsQueryKey = `/organizations/${organization.slug}/monitors-stats/`;
|
|
|
const {data: monitorStats, isLoading} = useApiQuery<Record<string, MonitorBucketData>>(
|
|
@@ -64,10 +45,8 @@ export function CronDetailsTimeline({monitor, organization}: Props) {
|
|
|
monitorStatsQueryKey,
|
|
|
{
|
|
|
query: {
|
|
|
- until: Math.floor(end.getTime() / 1000),
|
|
|
- since: Math.floor(start.getTime() / 1000),
|
|
|
monitor: monitor.slug,
|
|
|
- resolution: `${rollup}s`,
|
|
|
+ ...selectionQuery,
|
|
|
...location.query,
|
|
|
},
|
|
|
},
|
|
@@ -137,25 +116,25 @@ export function CronDetailsTimeline({monitor, organization}: Props) {
|
|
|
<Header>
|
|
|
<TimelineTitle>{t('Check-Ins')}</TimelineTitle>
|
|
|
<GridLineTimeLabels
|
|
|
- timeWindowConfig={config}
|
|
|
- start={start}
|
|
|
- end={end}
|
|
|
+ timeWindowConfig={timeWindowConfig}
|
|
|
+ start={dates.start}
|
|
|
+ end={dates.end}
|
|
|
width={timelineWidth}
|
|
|
/>
|
|
|
</Header>
|
|
|
<StyledGridLineOverlay
|
|
|
showCursor={!isLoading}
|
|
|
- timeWindowConfig={config}
|
|
|
- start={start}
|
|
|
- end={end}
|
|
|
+ timeWindowConfig={timeWindowConfig}
|
|
|
+ start={dates.start}
|
|
|
+ end={dates.end}
|
|
|
width={timelineWidth}
|
|
|
/>
|
|
|
<TimelineTableRow
|
|
|
monitor={monitor}
|
|
|
bucketedData={monitorStats?.[monitor.slug]}
|
|
|
- timeWindowConfig={config}
|
|
|
- end={end}
|
|
|
- start={start}
|
|
|
+ timeWindowConfig={timeWindowConfig}
|
|
|
+ start={dates.start}
|
|
|
+ end={dates.end}
|
|
|
width={timelineWidth}
|
|
|
onDeleteEnvironment={handleDeleteEnvironment}
|
|
|
onToggleMuteEnvironment={handleToggleMuteEnvironment}
|