Save dates

This commit is contained in:
Jon Herron 2022-11-28 17:07:28 -05:00
parent c21022bf05
commit 49e4db6ae2
2 changed files with 86 additions and 13 deletions

View File

@ -16,6 +16,10 @@ type OwnProps = {
orderBy: string; orderBy: string;
processModelSelection: ProcessModel | null; processModelSelection: ProcessModel | null;
processStatusSelection: string[]; processStatusSelection: string[];
startFromSeconds: string | null;
startToSeconds: string | null;
endFromSeconds: string | null;
endToSeconds: string | null;
buttonText?: string; buttonText?: string;
}; };
@ -25,6 +29,10 @@ export default function ProcessInstanceListSaveAsReport({
orderBy, orderBy,
processModelSelection, processModelSelection,
processStatusSelection, processStatusSelection,
startFromSeconds,
startToSeconds,
endFromSeconds,
endToSeconds,
buttonText = 'Save as Perspective', buttonText = 'Save as Perspective',
}: OwnProps) { }: OwnProps) {
const [identifier, setIdentifier] = useState(''); const [identifier, setIdentifier] = useState('');
@ -54,6 +62,34 @@ export default function ProcessInstanceListSaveAsReport({
}); });
} }
if (startFromSeconds) {
filterByArray.push({
field_name: 'start_from',
field_value: startFromSeconds,
});
}
if (startToSeconds) {
filterByArray.push({
field_name: 'start_to',
field_value: startToSeconds,
});
}
if (endFromSeconds) {
filterByArray.push({
field_name: 'end_from',
field_value: endFromSeconds,
});
}
if (endToSeconds) {
filterByArray.push({
field_name: 'end_to',
field_value: endToSeconds,
});
}
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: `/process-instances/reports`, path: `/process-instances/reports`,
successCallback: onSuccess, successCallback: onSuccess,

View File

@ -367,16 +367,7 @@ export default function ProcessInstanceListTable({
} }
}; };
const applyFilter = (event: any) => { const calculateStartAndEndSeconds = () => {
event.preventDefault();
const { page, perPage } = getPageInfoFromSearchParams(
searchParams,
undefined,
undefined,
paginationQueryParamPrefix
);
let queryParamString = `per_page=${perPage}&page=${page}&user_filter=true`;
const startFromSeconds = convertDateAndTimeStringsToSeconds( const startFromSeconds = convertDateAndTimeStringsToSeconds(
startFromDate, startFromDate,
startFromTime || '00:00:00' startFromTime || '00:00:00'
@ -393,28 +384,59 @@ export default function ProcessInstanceListTable({
endToDate, endToDate,
endToTime || '00:00:00' endToTime || '00:00:00'
); );
let valid = true;
if (isTrueComparison(startFromSeconds, '>', startToSeconds)) { if (isTrueComparison(startFromSeconds, '>', startToSeconds)) {
setErrorMessage({ setErrorMessage({
message: '"Start date from" cannot be after "start date to"', message: '"Start date from" cannot be after "start date to"',
}); });
return; valid = false;
} }
if (isTrueComparison(endFromSeconds, '>', endToSeconds)) { if (isTrueComparison(endFromSeconds, '>', endToSeconds)) {
setErrorMessage({ setErrorMessage({
message: '"End date from" cannot be after "end date to"', message: '"End date from" cannot be after "end date to"',
}); });
return; valid = false;
} }
if (isTrueComparison(startFromSeconds, '>', endFromSeconds)) { if (isTrueComparison(startFromSeconds, '>', endFromSeconds)) {
setErrorMessage({ setErrorMessage({
message: '"Start date from" cannot be after "end date from"', message: '"Start date from" cannot be after "end date from"',
}); });
return; valid = false;
} }
if (isTrueComparison(startToSeconds, '>', endToSeconds)) { if (isTrueComparison(startToSeconds, '>', endToSeconds)) {
setErrorMessage({ setErrorMessage({
message: '"Start date to" cannot be after "end date to"', message: '"Start date to" cannot be after "end date to"',
}); });
valid = false;
}
return {
valid,
startFromSeconds,
startToSeconds,
endFromSeconds,
endToSeconds,
};
};
const applyFilter = (event: any) => {
event.preventDefault();
const { page, perPage } = getPageInfoFromSearchParams(
searchParams,
undefined,
undefined,
paginationQueryParamPrefix
);
let queryParamString = `per_page=${perPage}&page=${page}&user_filter=true`;
const {
valid,
startFromSeconds,
startToSeconds,
endFromSeconds,
endToSeconds,
} = calculateStartAndEndSeconds();
if (!valid) {
return; return;
} }
@ -772,6 +794,17 @@ export default function ProcessInstanceListTable({
const saveAsReportComponent = () => { const saveAsReportComponent = () => {
// TODO onSuccess reload/select the new report in the report search // TODO onSuccess reload/select the new report in the report search
const callback = (_: any) => {}; const callback = (_: any) => {};
const {
valid,
startFromSeconds,
startToSeconds,
endFromSeconds,
endToSeconds,
} = calculateStartAndEndSeconds();
if (!valid) {
return null;
}
return ( return (
<ProcessInstanceListSaveAsReport <ProcessInstanceListSaveAsReport
onSuccess={callback} onSuccess={callback}
@ -779,6 +812,10 @@ export default function ProcessInstanceListTable({
orderBy="" orderBy=""
processModelSelection={processModelSelection} processModelSelection={processModelSelection}
processStatusSelection={processStatusSelection} processStatusSelection={processStatusSelection}
startFromSeconds={startFromSeconds}
startToSeconds={startToSeconds}
endFromSeconds={endFromSeconds}
endToSeconds={endToSeconds}
/> />
); );
}; };