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

NERT-712 Issue with PI report resolved and also with Date ranges sele… #262

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions api/src/repositories/report-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@
* @return {*} {Promise<IGetPIMgmtReport>}
* @memberof ReportRepository
*/
async getPIMgmtReportData(startDate: string, endDate: string): Promise<IGetPIMgmtReport[]> {
defaultLog.debug({ label: 'getPIMgmtReportData', message: 'params', startDate, endDate });
async getPIMgmtReportData(startDateTime: string, endDateTime: string): Promise<IGetPIMgmtReport[]> {
defaultLog.debug({ label: 'getPIMgmtReportData', message: 'params', startDateTime, endDateTime });

Check warning on line 202 in api/src/repositories/report-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/report-repository.ts#L202

Added line #L202 was not covered by tests

try {
const sqlStatement = SQL`
Expand All @@ -216,18 +216,22 @@
LEFT JOIN system_user su ON al.system_user_id = su.system_user_id
LEFT JOIN project prj ON (al.after_value -> 'project_id')::TEXT::int = prj.project_id
WHERE
al.create_date >= DATE(${startDate}) AND
al.create_date <= DATE(${endDate}) AND
al.create_date >= DATE(`;
sqlStatement.append("'" + startDateTime + "'");
sqlStatement.append(SQL`) AND al.create_date <= DATE(`);
sqlStatement.append("'" + endDateTime + "'");
sqlStatement.append(SQL`) AND

Check warning on line 223 in api/src/repositories/report-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/report-repository.ts#L220-L223

Added lines #L220 - L223 were not covered by tests
al.operation IN ('INSERT', 'UPDATE') AND
al.table_name IN ('restoration.project_attachment', 'restoration.project')
al.table_name IN ('restoration.project_attachment', 'restoration.project') AND
prj.name IS NOT NULL
GROUP BY
prj.name,
su.user_identifier,
al.audit_log_id,
al.create_date,
al.operation
ORDER BY al.audit_log_id DESC;
`;
`);

const response = await this.connection.sql(sqlStatement);
return response.rows;
Expand All @@ -243,8 +247,8 @@
* @return {*} {Promise<IGetCustomReport>}
* @memberof ReportRepository
*/
async getCustomReportData(startDate: string, endDate: string): Promise<IGetCustomReport[]> {
defaultLog.debug({ label: 'getCustomReportData', message: 'params', startDate, endDate });
async getCustomReportData(startDateTime: string, endDateTime: string): Promise<IGetCustomReport[]> {
defaultLog.debug({ label: 'getCustomReportData', message: 'params', startDateTime, endDateTime });

Check warning on line 251 in api/src/repositories/report-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/report-repository.ts#L251

Added line #L251 was not covered by tests

try {
const sqlStatement = SQL`
Expand Down Expand Up @@ -319,8 +323,11 @@
FROM project_species ps) t7
ON prj.project_id = t7.project_id
WHERE
prj.create_date >= DATE(${startDate}) AND
prj.create_date <= DATE(${endDate})
prj.create_date >= DATE(`;
sqlStatement.append("'" + startDateTime + "'");
sqlStatement.append(SQL`) AND prj.create_date <= DATE(`);
sqlStatement.append("'" + endDateTime + "'");
sqlStatement.append(SQL`)

Check warning on line 330 in api/src/repositories/report-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/report-repository.ts#L327-L330

Added lines #L327 - L330 were not covered by tests
GROUP BY
prj.project_id,
prj.is_project,
Expand All @@ -347,7 +354,7 @@
sc.size_ha,
sc.create_date
ORDER BY prj.project_id ASC;
`;
`);

const response = await this.connection.sql(sqlStatement);
return response.rows;
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/fields/ReportsStartEndDateFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DatePicker } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateValidationError } from '@mui/x-date-pickers/models';
import { DATE_FORMAT, DATE_LIMIT } from 'constants/dateTimeFormats';
import { DATE_FORMAT } from 'constants/dateTimeFormats';
import { default as dayjs } from 'dayjs';
import React, { useMemo } from 'react';

Expand Down Expand Up @@ -84,7 +84,7 @@ const ReportsStartEndDateFields: React.FC<IReportsStartEndDateFieldsProps> = (pr
label="Start Date"
format={DATE_FORMAT.ShortDateFormat}
minDate={dayjs('2024-09-01')}
maxDate={dayjs(DATE_LIMIT.max)}
maxDate={dayjs()}
value={formattedStartDateValue}
onChange={(value) => {
if (!value || String(value) === 'Invalid Date') {
Expand Down Expand Up @@ -123,7 +123,7 @@ const ReportsStartEndDateFields: React.FC<IReportsStartEndDateFieldsProps> = (pr
label="End Date"
format={DATE_FORMAT.ShortDateFormat}
minDate={dayjs(startDate)}
maxDate={dayjs(DATE_LIMIT.max)}
maxDate={dayjs()}
value={formattedEndDateValue}
onChange={(value: dayjs.Dayjs | null) => {
if (!value || String(value) === 'Invalid Date') {
Expand Down
6 changes: 5 additions & 1 deletion app/src/features/admin/reports/AppCustomReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { CustomReportI18N } from 'constants/i18n';
import { IGetCustomReportData } from 'interfaces/useAdminApi.interface';
import { csvDownload } from 'utils/cvsUtils';
import dayjs from 'dayjs';

const pageStyles = {
breadCrumbLink: {
Expand Down Expand Up @@ -40,8 +41,11 @@
const location = useLocation();
const { startDate, endDate } = location.state;

const startDateTime = dayjs(startDate).startOf('day').toISOString();
const endDateTime = dayjs(endDate).endOf('day').toISOString();

Check warning on line 45 in app/src/features/admin/reports/AppCustomReportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/AppCustomReportPage.tsx#L44-L45

Added lines #L44 - L45 were not covered by tests

const getCustomReportData = async () => {
const data = await restorationTrackerApi.admin.getCustomReport(startDate, endDate);
const data = await restorationTrackerApi.admin.getCustomReport(startDateTime, endDateTime);

Check warning on line 48 in app/src/features/admin/reports/AppCustomReportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/AppCustomReportPage.tsx#L48

Added line #L48 was not covered by tests
setIsLoading(false);
setCustomReportData(data);
};
Expand Down
5 changes: 4 additions & 1 deletion app/src/features/admin/reports/AppPiMgmtReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@
return rowsPiMgmtReport;
}

const startDateTime = dayjs(startDate).startOf('day').toISOString();
const endDateTime = dayjs(endDate).endOf('day').toISOString();

Check warning on line 94 in app/src/features/admin/reports/AppPiMgmtReportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/AppPiMgmtReportPage.tsx#L93-L94

Added lines #L93 - L94 were not covered by tests

const getPiMgmtReportData = async () => {
const data = await restorationTrackerApi.admin.getPiMgmtReport(startDate, endDate);
const data = await restorationTrackerApi.admin.getPiMgmtReport(startDateTime, endDateTime);

Check warning on line 97 in app/src/features/admin/reports/AppPiMgmtReportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/AppPiMgmtReportPage.tsx#L97

Added line #L97 was not covered by tests
setIsLoading(false);
setPiMgmtReportData(mapToTableData(data));
};
Expand Down
31 changes: 23 additions & 8 deletions app/src/features/admin/reports/ReportsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Box, Container, Paper, Typography, Button, Divider, Stack } from '@mui/material';
import { mdiNewspaperVariant } from '@mdi/js';
import { Icon } from '@mdi/react';
import { useNertApi } from 'hooks/useNertApi';
import React, { useContext, useState } from 'react';
import DateRangeSelection from './DateRangeSelection';
Expand Down Expand Up @@ -179,20 +181,33 @@
variant="contained"
color="primary"
size="large"
startIcon={<Icon path={mdiNewspaperVariant} size={1} />}
onClick={() => {
if ('appUserReport' === selectedReport) {
history('/admin/reports/user');
return;
}
if ('customRange' === selectedRange && (!startDate || !endDate)) {
dialogContext.setErrorDialog({
dialogTitle: 'Dates Validation Failed',
dialogText: 'Please enter the required start and end dates.',
...defaultErrorDialogProps,
open: true
});
return;
if ('customRange' === selectedRange) {
if (!startDate || !endDate) {
dialogContext.setErrorDialog({

Check warning on line 192 in app/src/features/admin/reports/ReportsPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/ReportsPage.tsx#L192

Added line #L192 was not covered by tests
dialogTitle: 'Dates Validation Failed',
dialogText: 'Please enter the required start and end dates.',
...defaultErrorDialogProps,
open: true
});
return;

Check warning on line 198 in app/src/features/admin/reports/ReportsPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/ReportsPage.tsx#L198

Added line #L198 was not covered by tests
}
if (dayjs(startDate) > dayjs(endDate)) {
dialogContext.setErrorDialog({

Check warning on line 201 in app/src/features/admin/reports/ReportsPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/ReportsPage.tsx#L201

Added line #L201 was not covered by tests
dialogTitle: 'Dates Validation Failed',
dialogText: 'Start date cannot be after end date.',
...defaultErrorDialogProps,
open: true
});
return;

Check warning on line 207 in app/src/features/admin/reports/ReportsPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/admin/reports/ReportsPage.tsx#L207

Added line #L207 was not covered by tests
}
}

if ('customReport' === selectedReport) {
history('/admin/reports/custom', {
state: {
Expand Down
Loading