import { ReactElement, useEffect, useState } from 'react'; import { Link, useSearchParams } from 'react-router-dom'; import { Tile, // @ts-ignore } from '@carbon/react'; import HttpService from '../services/HttpService'; import { ProcessModel, ProcessInstance, ProcessGroup } from '../interfaces'; import { modifyProcessIdentifierForPathParam, truncateString, } from '../helpers'; import ProcessInstanceRun from './ProcessInstanceRun'; type OwnProps = { headerElement?: ReactElement; processGroup?: ProcessGroup; checkPermissions?: boolean; }; export default function ProcessModelListTiles({ headerElement, processGroup, checkPermissions = true, }: OwnProps) { const [searchParams] = useSearchParams(); const [processModels, setProcessModels] = useState( null ); const [processInstance, setProcessInstance] = useState(null); useEffect(() => { const setProcessModelsFromResult = (result: any) => { setProcessModels(result.results); }; // only allow 10 for now until we get the backend only returning certain models for user execution let queryParams = '?per_page=20'; if (processGroup) { queryParams = `${queryParams}&process_group_identifier=${processGroup.id}`; } else { queryParams = `${queryParams}&recursive=true&filter_runnable_by_user=true`; } HttpService.makeCallToBackend({ path: `/process-models${queryParams}`, successCallback: setProcessModelsFromResult, }); }, [searchParams, processGroup]); const processInstanceRunResultTag = () => { if (processInstance) { return (

Process Instance {processInstance.id} kicked off ( view ).

); } return null; }; const processModelsDisplayArea = () => { let displayText = null; if (processModels && processModels.length > 0) { displayText = (processModels || []).map((row: ProcessModel) => { return (
{row.display_name}

{truncateString(row.description || '', 100)}

); }); } else { displayText =

No Models To Display

; } return displayText; }; const processModelArea = () => { if (processModels && processModels.length > 0) { return ( <> {headerElement} {processInstanceRunResultTag()} {processModelsDisplayArea()} ); } return null; }; if (processModels) { return <>{processModelArea()}; } return null; }