Skip to content

Commit

Permalink
O3-1494: Adjusted API calls to backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
druchniewicz committed Jan 16, 2025
1 parent e074b6f commit 5d966d4
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import { first } from 'rxjs/operators';
import styles from './edit-scheduled-report-form.scss';
import SimpleCronEditor from '../simple-cron-editor/simple-cron-editor.component';
import {
useReportDefinition,
useReportDesigns,
useReportRequest,
runReportObservable,
RunReportRequest,
} from '../reports.resource';
import { useReportDefinition, useReportDesigns, useReportRequest, runReportObservable } from '../reports.resource';
import ReportParameterInput from '../report-parameter-input.component';
import { Button, ButtonSet, Form, Select, SelectItem, Stack } from '@carbon/react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -52,16 +46,22 @@ const EditScheduledReportForm: React.FC<EditScheduledReportForm> = ({

setIsSubmitting(true);

const runReportRequest: RunReportRequest = {
existingRequestUuid: reportRequestUuid,
reportDefinitionUuid,
renderModeUuid,
reportParameters,
const scheduleRequest = {
uuid: reportRequestUuid ? reportRequestUuid : null,
reportDefinition: {
parameterizable: {
uuid: reportDefinitionUuid,
},
parameterMappings: reportParameters,
},
renderingMode: {
argument: renderModeUuid,
},
schedule,
};

const abortController = new AbortController();
runReportObservable(runReportRequest, abortController)
runReportObservable(scheduleRequest, abortController)
.pipe(first())
.subscribe(
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { closeOverlay, launchOverlay } from '../hooks/useOverlay';
import RunReportForm from './run-report/run-report-form.component';
import Overlay from './overlay.component';
import ReportStatus from './report-status.component';
import { COMPLETED, SAVED } from './report-statuses-constants';
import { COMPLETED, FAILED, PROCESSING, RAN_REPORT_STATUSES, REQUESTED, SAVED } from './report-statuses-constants';
import ReportOverviewButton from './report-overview-button.component';
import { PRIVILEGE_SYSTEM_DEVELOPER } from '../constants';

Expand Down Expand Up @@ -59,7 +59,11 @@ const OverviewComponent: React.FC = () => {
const [currentPage, setCurrentPage] = useState(DEFAULT_PAGE_NUMBER);
const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE);

const { reports, reportsTotalCount, mutateReports } = useReports('ran', currentPage, pageSize);
const { reports, reportsTotalCount, mutateReports } = useReports(
RAN_REPORT_STATUSES.join(','),
currentPage,
pageSize,
);

const layout = useLayoutType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export const FAILED = 'FAILED';
export const SCHEDULED = 'SCHEDULED';
export const SCHEDULE_COMPLETED = 'SCHEDULE_COMPLETED';
export const REQUESTED = 'REQUESTED';

export const RAN_REPORT_STATUSES = [REQUESTED, COMPLETED, SAVED, FAILED, PROCESSING];
export const PROCESSING_REPORT_STATUSES = [REQUESTED, PROCESSING];
export const SCHEDULED_REPORT_STATUSES = [SCHEDULED, SCHEDULE_COMPLETED];
34 changes: 12 additions & 22 deletions packages/esm-reports-app/src/components/reports.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ interface ScheduledReportModel {
schedule: string;
}

export interface RunReportRequest {
existingRequestUuid?: string | undefined;
reportDefinitionUuid: string;
renderModeUuid: string;
reportParameters: any;
schedule?: string | undefined;
}

export function useLocations() {
const apiUrl = `/ws/rest/v1/location?tag=Login+Location`;

Expand All @@ -44,9 +36,9 @@ export function useLocations() {
};
}

export function useReports(statusesGroup: string, pageNumber: number, pageSize: number, sortBy?: string): any {
export function useReports(statuses: string, pageNumber: number, pageSize: number, sortBy?: string): any {
const reportsUrl =
`/ws/rest/v1/reportingrest/reportRequest?statusesGroup=${statusesGroup}&startIndex=${pageNumber}&limit=${pageSize}&totalCount=true` +
`/ws/rest/v1/reportingrest/reportRequest?status=${statuses}&startIndex=${pageNumber}&limit=${pageSize}&totalCount=true` +
(sortBy ? `&sortBy=${sortBy}` : '');

const { data, error, isValidating, mutate } = useSWR<{ data: { results: Array<any>; totalCount: number } }, Error>(
Expand Down Expand Up @@ -81,7 +73,8 @@ export function useReportRequest(reportRequestUuid: string): any {
}

export function useScheduledReports(sortBy?: string): any {
const scheduledReportsUrl = `/ws/rest/v1/reportingrest/scheduledReport` + (sortBy ? `?sortBy=${sortBy}` : '');
const scheduledReportsUrl =
`/ws/rest/v1/reportingrest/reportDefinitionsWithScheduledRequests` + (sortBy ? `?sortBy=${sortBy}` : '');

const { data, error, isValidating, mutate } = useSWR<{ data: { results: Array<any> } }, Error>(
scheduledReportsUrl,
Expand Down Expand Up @@ -120,7 +113,7 @@ export function useReportDefinition(reportDefinitionUuid: string): ReportDefinit
}

export function useReportDesigns(reportDefinitionUuid: string) {
const apiUrl = `/ws/rest/v1/reportingrest/designs?reportDefinitionUuid=${reportDefinitionUuid}`;
const apiUrl = `/ws/rest/v1/reportingrest/reportDesign?reportDefinitionUuid=${reportDefinitionUuid}`;

const { data, error, isValidating, mutate } = useSWR<{ data: { results: ReportDesign[] } }, Error>(
reportDefinitionUuid ? apiUrl : null,
Expand All @@ -142,11 +135,8 @@ function mapDesignResults(design: any): ReportDesign {
};
}

export function runReportObservable(
payload: RunReportRequest,
abortController: AbortController,
): Observable<FetchResponse<any>> {
return openmrsObservableFetch(`/ws/rest/v1/reportingrest/runReport`, {
export function runReportObservable(payload: any, abortController: AbortController): Observable<FetchResponse<any>> {
return openmrsObservableFetch(`/ws/rest/v1/reportingrest/reportRequest`, {
signal: abortController.signal,
method: 'POST',
headers: {
Expand All @@ -157,15 +147,15 @@ export function runReportObservable(
}

export async function cancelReportRequest(reportRequestUuid: string) {
const apiUrl = `/ws/rest/v1/reportingrest/cancelReport?reportRequestUuid=${reportRequestUuid}`;
const apiUrl = `/ws/rest/v1/reportingrest/reportRequest/${reportRequestUuid}`;

return openmrsFetch(apiUrl, {
method: 'DELETE',
});
}

export async function preserveReport(reportRequestUuid: string) {
const apiUrl = `/ws/rest/v1/reportingrest/preserveReport?reportRequestUuid=${reportRequestUuid}`;
const apiUrl = `/ws/rest/v1/reportingrest/saveReport?reportRequestUuid=${reportRequestUuid}`;

return openmrsFetch(apiUrl, {
method: 'POST',
Expand Down Expand Up @@ -208,9 +198,9 @@ function mapReportResults(data: any): ReportModel {
function mapScheduledReportResults(data: any): ScheduledReportModel {
return {
reportDefinitionUuid: data.reportDefinition.uuid,
reportRequestUuid: data.reportScheduleRequest?.uuid,
name: data.reportDefinition.name,
schedule: data.reportScheduleRequest?.schedule,
reportRequestUuid: data.scheduledRequests?.[0]?.uuid,
name: data.reportDefinition.display,
schedule: data.scheduledRequests?.[0]?.schedule,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { useTranslation } from 'react-i18next';
import { cancelReportRequest } from '../reports.resource';
import { showToast } from '@openmrs/esm-framework';
import { mutate } from 'swr';
import {
PROCESSING_REPORT_STATUSES,
RAN_REPORT_STATUSES,
SCHEDULED_REPORT_STATUSES,
} from '../report-statuses-constants';

interface CancelReportModalProps {
closeModal: () => void;
Expand Down Expand Up @@ -39,14 +44,14 @@ const CancelReportModal: React.FC<CancelReportModalProps> = ({ closeModal, repor
}, [closeModal]);

const callMutates = (modalType) => {
let baseUrl = '/ws/rest/v1/reportingrest/reportRequest?statusesGroup=';
let baseUrl = '/ws/rest/v1/reportingrest/reportRequest?status=';
if (modalType === 'delete') {
mutate(baseUrl + 'ran');
mutate(baseUrl + RAN_REPORT_STATUSES.join(','));
} else if (modalType === 'cancel') {
mutate(baseUrl + 'ran');
mutate(baseUrl + 'processing');
mutate(baseUrl + RAN_REPORT_STATUSES.join(','));
mutate(baseUrl + PROCESSING_REPORT_STATUSES.join(','));
} else if (modalType === 'schedule') {
mutate(baseUrl + 'scheduled&sortBy=name');
mutate(baseUrl + SCHEDULED_REPORT_STATUSES.join(',') + '&sortBy=name');
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import styles from './run-report-form.scss';
import {
useLocations,
useReportDefinitions,
useReportDesigns,
runReportObservable,
RunReportRequest,
} from '../reports.resource';
import { ReportDesign } from '../../types/report-design';
import { useLocations, useReportDefinitions, useReportDesigns, runReportObservable } from '../reports.resource';
import { closeOverlay } from '../../hooks/useOverlay';
import { Button, ButtonSet, DatePicker, DatePickerInput, Form, Select, SelectItem, TextInput } from '@carbon/react';
import { showToast, useLayoutType } from '@openmrs/esm-framework';
Expand Down Expand Up @@ -138,14 +131,22 @@ const RunReportForm: React.FC<RunReportForm> = ({ closePanel }) => {

setIsSubmitting(true);

const runReportRequest: RunReportRequest = {
reportDefinitionUuid: reportUuid,
renderModeUuid: renderModeUuid,
reportParameters: reportParameters,
const reportRequest = {
uuid: null,
reportDefinition: {
parameterizable: {
uuid: reportUuid,
},
parameterMappings: reportParameters,
},
renderingMode: {
argument: renderModeUuid,
},
schedule: null,
};

const abortController = new AbortController();
runReportObservable(runReportRequest, abortController)
runReportObservable(reportRequest, abortController)
.pipe(first())
.subscribe(
() => {
Expand Down
77 changes: 0 additions & 77 deletions packages/esm-reports-app/translations/ar.json

This file was deleted.

Loading

0 comments on commit 5d966d4

Please sign in to comment.