import {useState} from 'react';
import styled from '@emotion/styled';
import {DateTime} from 'sentry/components/dateTime';
import Duration from 'sentry/components/duration';
import GridEditable, {
COL_WIDTH_UNDEFINED,
type GridColumnOrder,
} from 'sentry/components/gridEditable';
import LoadingError from 'sentry/components/loadingError';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import {t} from 'sentry/locale';
import {useParams} from 'sentry/utils/useParams';
import {useGroup} from 'sentry/views/issueDetails/useGroup';
interface OpenPeriodDisplayData {
duration: React.ReactNode;
end: React.ReactNode;
start: React.ReactNode;
title: React.ReactNode;
}
// TODO(snigdha): make this work for the old UI
// TODO(snigdha): support pagination
function IssueOpenPeriodsList() {
const [now] = useState(() => new Date());
const params = useParams<{groupId: string}>();
const {
data: group,
isPending: isGroupPending,
isError: isGroupError,
refetch: refetchGroup,
} = useGroup({groupId: params.groupId});
if (isGroupError) {
return ;
}
if (isGroupPending) {
return ;
}
// update the open periods to have date objects
const openPeriods = group.openPeriods?.map(period => ({
...period,
start: new Date(period.start),
end: period.end ? new Date(period.end) : null,
}));
const getDuration = (start: Date, end?: Date) => {
const duration = end
? (end.getTime() - start.getTime()) / 1000
: (now.getTime() - start.getTime()) / 1000;
return ;
};
if (!openPeriods) {
return ;
}
const data: OpenPeriodDisplayData[] = openPeriods.map(period => ({
title: ,
start: ,
end: period.end ? : '—',
duration: getDuration(period.start, period.end ?? undefined),
}));
const renderHeadCell = (col: GridColumnOrder) => {
return {col.name};
};
const renderBodyCell = (
col: GridColumnOrder,
dataRow: OpenPeriodDisplayData
) => {
const column = col.key as keyof OpenPeriodDisplayData;
return {dataRow[column]};
};
return (
);
}
const AlignLeft = styled('span')`
text-align: left;
width: 100%;
`;
export default IssueOpenPeriodsList;