Skip to content
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

ADM-973 [frontend] retry all when retry #1524

Merged
merged 9 commits into from
Jul 12, 2024
24 changes: 5 additions & 19 deletions frontend/src/containers/ReportStep/ReportContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ import { uniqueId } from 'lodash';
export interface ReportContentProps {
metrics: string[];
dateRanges: DateRangeList;
startToRequestDoraData: () => void;
startToRequestBoardData: () => void;
startToRequestData: () => void;
reportInfos: IReportInfo[];
handleSave?: () => void;
reportId?: number;
Expand All @@ -75,16 +74,7 @@ export interface DateRangeRequestResult {
}

const ReportContent = (props: ReportContentProps) => {
const {
metrics,
dateRanges,
startToRequestDoraData,
startToRequestBoardData,
reportInfos,
handleSave,
reportId,
hideButtons = false,
} = props;
const { metrics, dateRanges, reportInfos, handleSave, reportId, startToRequestData, hideButtons = false } = props;
const dispatch = useAppDispatch();

const descendingDateRanges = sortDateRanges(dateRanges);
Expand Down Expand Up @@ -258,7 +248,7 @@ const ReportContent = (props: ReportContentProps) => {
<Box>
{shouldShowBoardMetrics && (
<BoardMetrics
startToRequestBoardData={startToRequestBoardData}
startToRequestBoardData={startToRequestData}
onShowDetail={() => setPageType(REPORT_PAGE_TYPE.BOARD)}
boardReport={currentDataInfo.reportData}
errorMessage={getErrorMessage4Board()}
Expand All @@ -267,7 +257,7 @@ const ReportContent = (props: ReportContentProps) => {
)}
{shouldShowDoraMetrics && (
<DoraMetrics
startToRequestDoraData={startToRequestDoraData}
startToRequestDoraData={startToRequestData}
onShowDetail={() => setPageType(REPORT_PAGE_TYPE.DORA)}
doraReport={currentDataInfo.reportData}
metrics={metrics}
Expand Down Expand Up @@ -383,10 +373,6 @@ const ReportContent = (props: ReportContentProps) => {
setPageType(newValue === CHART_INDEX.BOARD ? REPORT_PAGE_TYPE.BOARD_CHART : REPORT_PAGE_TYPE.DORA_CHART);
};

const handleChartRetry = () => {
pageType === REPORT_PAGE_TYPE.DORA_CHART ? startToRequestDoraData() : startToRequestBoardData();
};

const tabProps = (index: number) => {
return {
id: `simple-tab-${index}`,
Expand Down Expand Up @@ -430,7 +416,7 @@ const ReportContent = (props: ReportContentProps) => {
{startDate && endDate && (
<StyledCalendarWrapper data-testid={'calendarWrapper'} justCalendar={!shouldShowTabs}>
{shouldShowChartRetryButton() && (
<StyledRetry aria-label='chart retry' onClick={handleChartRetry}>
<StyledRetry aria-label='chart retry' onClick={startToRequestData}>
<ReplayIcon />
</StyledRetry>
)}
Expand Down
20 changes: 2 additions & 18 deletions frontend/src/containers/ReportStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
selectConfig,
selectDateRange,
} from '@src/context/config/configSlice';
import { BOARD_METRICS, DORA_METRICS, MESSAGE, RequiredData } from '@src/constants/resources';
import { IPipelineConfig, selectMetricsContent } from '@src/context/Metrics/metricsSlice';
import { selectReportId, selectTimeStamp } from '@src/context/stepper/StepperSlice';
import { ReportResponseDTO } from '@src/clients/report/dto/response';
import { MESSAGE, RequiredData } from '@src/constants/resources';
import { useAppDispatch } from '@src/hooks/useAppDispatch';
import { MetricTypes } from '@src/constants/commons';
import ReportContent from './ReportContent';
Expand Down Expand Up @@ -170,21 +170,6 @@ const ReportStep = ({ handleSave }: ReportStepProps) => {
...(shouldShowDoraMetrics ? getDoraSetting() : {}),
};

const boardReportRequestBody = {
...basicReportRequestBody,
metrics: metrics.filter((metric) => BOARD_METRICS.includes(metric)),
metricTypes: [MetricTypes.Board],
buildKiteSetting: undefined,
codebaseSetting: undefined,
};

const doraReportRequestBody = {
...basicReportRequestBody,
metrics: metrics.filter((metric) => DORA_METRICS.includes(metric)),
metricTypes: [MetricTypes.DORA],
jiraBoardSetting: undefined,
};

useEffect(() => {
exportValidityTimeMin &&
isCsvFileGeneratedAtEnd &&
Expand Down Expand Up @@ -242,8 +227,7 @@ const ReportStep = ({ handleSave }: ReportStepProps) => {
<ReportContent
metrics={metrics}
dateRanges={dateRanges}
startToRequestDoraData={() => startToRequestData(doraReportRequestBody)}
startToRequestBoardData={() => startToRequestData(boardReportRequestBody)}
startToRequestData={() => startToRequestData(basicReportRequestBody)}
reportInfos={reportInfos}
handleSave={handleSave}
reportId={reportId}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/containers/ShareReport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const ShareReport = () => {
metrics={metrics}
dateRanges={dateRanges}
reportInfos={reportInfos}
startToRequestBoardData={getData}
startToRequestDoraData={getData}
startToRequestData={getData}
hideButtons
/>
</StyledPageContentWrapper>
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/hooks/useGenerateReportEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const useGenerateReportEffect = (): IUseGenerateReportEffect => {
dateRangeList.map((dateRange) => ({ ...initReportInfo(), id: dateRange.startDate as string })),
);
const [hasPollingStarted, setHasPollingStarted] = useState<boolean>(false);
const [reportId, setReportId] = useState<string>('');
let nextHasPollingStarted = false;

const startToRequestData = async (params: ReportRequestDTO) => {
Expand All @@ -115,8 +116,17 @@ export const useGenerateReportEffect = (): IUseGenerateReportEffect => {

resetReportPageLoadingStatus(dateRangeList);

const reportIdRes = await reportClient.generateReportId();
if (!reportId) {
const reportIdRes = await reportClient.generateReportId();
setReportId(reportIdRes.reportId);
dispatch(updateReportId(reportIdRes.reportId));
await retrieveUrlAndPolling(params, reportIdRes.reportId);
} else {
await retrieveUrlAndPolling(params, reportId);
}
};

const retrieveUrlAndPolling = async (params: ReportRequestDTO, reportId: string) => {
const res: PromiseSettledResult<ReportCallbackResponse>[] = await Promise.allSettled(
dateRangeList.map(({ startDate, endDate }) =>
reportClient.retrieveByUrl(
Expand All @@ -125,16 +135,15 @@ export const useGenerateReportEffect = (): IUseGenerateReportEffect => {
startTime: formatDateToTimestampString(startDate!),
endTime: formatDateToTimestampString(endDate!),
},
`${reportPath}/${reportIdRes.reportId}`,
`${reportPath}/${reportId}`,
),
),
);

updateErrorAfterFetchReport(res, metricTypes);
updateErrorAfterFetchReport(res, params.metricTypes);

const { pollingInfos, pollingInterval } = assemblePollingParams(res);

dispatch(updateReportId(reportIdRes.reportId));
resetPollingLoadingStatusBeforePolling(pollingInfos.map((item) => item.id));
await pollingReport({ pollingInfos, interval: pollingInterval });
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/layouts/ShareReportTrigger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const ShareReportTrigger = () => {
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
if (canShare) {
setAnchorEl(anchorEl ? null : event.currentTarget);
setShowAlert(false);
}
};

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/layouts/ShareReportTrigger/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const LinkLine = styled.div({
display: 'flex',
alignItems: 'center',
margin: '1.5rem 0',
height: '2.125rem',
a: {
cursor: 'pointer',
marginRight: '0.625rem',
Expand All @@ -59,7 +60,7 @@ export const LinkLine = styled.div({

export const ShareIconWrapper = styled.span(({ disabled }: { disabled: boolean }) => ({
padding: '0.5rem',
cursor: disabled ? 'unset !important' : 'pointer',
cursor: disabled ? 'not-allowed !important' : 'pointer',
marginLeft: '0.2rem',
'> svg': {
color: disabled ? theme.main.errorMessage.color : 'white',
Expand Down
Loading