Auto Reload the Process Lists on the home pages' in-progress, and complete tabs

This commit is contained in:
Dan 2022-11-25 11:56:37 -05:00
parent 7a926c690e
commit 43d46c5251
3 changed files with 44 additions and 23 deletions

View File

@ -32,7 +32,7 @@ import {
convertSecondsToFormattedTimeHoursMinutes, convertSecondsToFormattedTimeHoursMinutes,
getPageInfoFromSearchParams, getPageInfoFromSearchParams,
getProcessModelFullIdentifierFromSearchParams, getProcessModelFullIdentifierFromSearchParams,
modifyProcessIdentifierForPathParam, modifyProcessIdentifierForPathParam, refreshAtInterval,
} from '../helpers'; } from '../helpers';
import PaginationForTable from './PaginationForTable'; import PaginationForTable from './PaginationForTable';
@ -52,6 +52,9 @@ import {
import ProcessModelSearch from './ProcessModelSearch'; import ProcessModelSearch from './ProcessModelSearch';
import ProcessInstanceReportSearch from './ProcessInstanceReportSearch'; import ProcessInstanceReportSearch from './ProcessInstanceReportSearch';
const REFRESH_INTERVAL = 5;
const REFRESH_TIMEOUT = 600;
type OwnProps = { type OwnProps = {
filtersEnabled?: boolean; filtersEnabled?: boolean;
processModelFullIdentifier?: string; processModelFullIdentifier?: string;
@ -61,6 +64,7 @@ type OwnProps = {
reportIdentifier?: string; reportIdentifier?: string;
textToShowIfEmpty?: string; textToShowIfEmpty?: string;
paginationClassName?: string; paginationClassName?: string;
autoReload?: boolean;
}; };
interface dateParameters { interface dateParameters {
@ -76,6 +80,7 @@ export default function ProcessInstanceListTable({
reportIdentifier, reportIdentifier,
textToShowIfEmpty, textToShowIfEmpty,
paginationClassName, paginationClassName,
autoReload = false,
}: OwnProps) { }: OwnProps) {
const params = useParams(); const params = useParams();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
@ -264,16 +269,25 @@ export default function ProcessInstanceListTable({
getProcessInstances(); getProcessInstances();
} }
const checkFiltersAndRun = () => {
console.log("Checking again!", filtersEnabled)
if (filtersEnabled) {
// populate process model selection
HttpService.makeCallToBackend({
path: `/process-models?per_page=1000&recursive=true`,
successCallback: processResultForProcessModels,
});
} else {
getProcessInstances();
}
};
if (filtersEnabled) { checkFiltersAndRun();
// populate process model selection if (autoReload) {
HttpService.makeCallToBackend({ refreshAtInterval(REFRESH_INTERVAL, REFRESH_TIMEOUT, checkFiltersAndRun);
path: `/process-models?per_page=1000&recursive=true`,
successCallback: processResultForProcessModels,
});
} else { } else {
getProcessInstances();
} }
}, [ }, [
searchParams, searchParams,
params, params,
@ -758,13 +772,13 @@ export default function ProcessInstanceListTable({
<> <>
<Grid fullWidth> <Grid fullWidth>
<Column <Column
className="filterIcon"
sm={{ span: 1, offset: 3 }} sm={{ span: 1, offset: 3 }}
md={{ span: 1, offset: 7 }} md={{ span: 1, offset: 7 }}
lg={{ span: 1, offset: 15 }} lg={{ span: 1, offset: 15 }}
> >
<Button <Button
data-qa="filter-section-expand-toggle" data-qa="filter-section-expand-toggle"
kind="ghost"
renderIcon={Filter} renderIcon={Filter}
iconDescription="Filter Options" iconDescription="Filter Options"
hasIconOnly hasIconOnly

View File

@ -6,7 +6,7 @@ import PaginationForTable from './PaginationForTable';
import { import {
convertSecondsToFormattedDateTime, convertSecondsToFormattedDateTime,
getPageInfoFromSearchParams, getPageInfoFromSearchParams,
modifyProcessIdentifierForPathParam, modifyProcessIdentifierForPathParam, refreshAtInterval,
} from '../helpers'; } from '../helpers';
import HttpService from '../services/HttpService'; import HttpService from '../services/HttpService';
import { PaginationObject } from '../interfaces'; import { PaginationObject } from '../interfaces';
@ -14,6 +14,8 @@ import TableCellWithTimeAgoInWords from './TableCellWithTimeAgoInWords';
const PER_PAGE_FOR_TASKS_ON_HOME_PAGE = 5; const PER_PAGE_FOR_TASKS_ON_HOME_PAGE = 5;
const paginationQueryParamPrefix = 'tasks_for_my_open_processes'; const paginationQueryParamPrefix = 'tasks_for_my_open_processes';
const REFRESH_INTERVAL = 5;
const REFRESH_TIMEOUT = 600;
export default function MyOpenProcesses() { export default function MyOpenProcesses() {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
@ -21,20 +23,24 @@ export default function MyOpenProcesses() {
const [pagination, setPagination] = useState<PaginationObject | null>(null); const [pagination, setPagination] = useState<PaginationObject | null>(null);
useEffect(() => { useEffect(() => {
const { page, perPage } = getPageInfoFromSearchParams( const getTasks = () => {
searchParams, const { page, perPage } = getPageInfoFromSearchParams(
PER_PAGE_FOR_TASKS_ON_HOME_PAGE, searchParams,
undefined, PER_PAGE_FOR_TASKS_ON_HOME_PAGE,
paginationQueryParamPrefix undefined,
); paginationQueryParamPrefix
const setTasksFromResult = (result: any) => { );
setTasks(result.results); const setTasksFromResult = (result: any) => {
setPagination(result.pagination); setTasks(result.results);
setPagination(result.pagination);
};
HttpService.makeCallToBackend({
path: `/tasks/for-my-open-processes?per_page=${perPage}&page=${page}`,
successCallback: setTasksFromResult,
});
}; };
HttpService.makeCallToBackend({ getTasks();
path: `/tasks/for-my-open-processes?per_page=${perPage}&page=${page}`, refreshAtInterval(REFRESH_INTERVAL, REFRESH_TIMEOUT, getTasks);
successCallback: setTasksFromResult,
});
}, [searchParams]); }, [searchParams]);
const buildTable = () => { const buildTable = () => {

View File

@ -15,6 +15,7 @@ export default function CompletedInstances() {
showReports={false} showReports={false}
textToShowIfEmpty="You have no completed instances at this time." textToShowIfEmpty="You have no completed instances at this time."
paginationClassName="with-large-bottom-margin" paginationClassName="with-large-bottom-margin"
autoReload
/> />
<h2>Tasks completed by me</h2> <h2>Tasks completed by me</h2>
<p className="data-table-description"> <p className="data-table-description">