2022-10-12 10:21:49 -04:00
|
|
|
import { useEffect, useState } from 'react';
|
2022-11-22 14:12:08 -05:00
|
|
|
import {
|
2022-11-22 16:21:16 -05:00
|
|
|
// Link,
|
2022-11-22 14:12:08 -05:00
|
|
|
useSearchParams,
|
|
|
|
useParams,
|
|
|
|
useNavigate,
|
|
|
|
} from 'react-router-dom';
|
|
|
|
import {
|
|
|
|
TrashCan,
|
|
|
|
Edit,
|
|
|
|
// @ts-ignore
|
|
|
|
} from '@carbon/icons-react';
|
2022-10-31 15:09:21 -04:00
|
|
|
// @ts-ignore
|
2022-11-22 16:21:16 -05:00
|
|
|
import { Button, Stack } from '@carbon/react';
|
2022-11-15 16:18:25 -05:00
|
|
|
import { Can } from '@casl/react';
|
2022-10-12 10:21:49 -04:00
|
|
|
import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
|
|
|
|
import HttpService from '../services/HttpService';
|
2022-11-09 17:48:50 -05:00
|
|
|
import {
|
|
|
|
getPageInfoFromSearchParams,
|
2022-11-22 10:56:40 -05:00
|
|
|
modifyProcessIdentifierForPathParam,
|
|
|
|
unModifyProcessIdentifierForPathParam,
|
2022-11-09 17:48:50 -05:00
|
|
|
} from '../helpers';
|
2022-11-15 16:18:25 -05:00
|
|
|
import {
|
|
|
|
PaginationObject,
|
|
|
|
PermissionsToCheck,
|
|
|
|
ProcessGroup,
|
2022-11-22 16:21:16 -05:00
|
|
|
// ProcessModel,
|
2022-11-15 16:18:25 -05:00
|
|
|
} from '../interfaces';
|
|
|
|
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
|
|
|
import { usePermissionFetcher } from '../hooks/PermissionService';
|
2022-11-18 13:57:40 -05:00
|
|
|
import ProcessGroupListTiles from '../components/ProcessGroupListTiles';
|
2022-11-22 14:12:08 -05:00
|
|
|
import ButtonWithConfirmation from '../components/ButtonWithConfirmation';
|
2022-11-22 15:09:42 -05:00
|
|
|
import ProcessModelListTiles from '../components/ProcessModelListTiles';
|
2022-10-12 10:21:49 -04:00
|
|
|
|
|
|
|
export default function ProcessGroupShow() {
|
|
|
|
const params = useParams();
|
|
|
|
const [searchParams] = useSearchParams();
|
2022-11-22 14:12:08 -05:00
|
|
|
const navigate = useNavigate();
|
2022-10-12 10:21:49 -04:00
|
|
|
|
|
|
|
const [processGroup, setProcessGroup] = useState<ProcessGroup | null>(null);
|
2022-11-22 16:21:16 -05:00
|
|
|
// const [processModels, setProcessModels] = useState([]);
|
2022-11-11 22:12:35 -05:00
|
|
|
const [modelPagination, setModelPagination] =
|
|
|
|
useState<PaginationObject | null>(null);
|
2022-10-12 10:21:49 -04:00
|
|
|
|
2022-11-15 16:18:25 -05:00
|
|
|
const { targetUris } = useUriListForPermissions();
|
|
|
|
const permissionRequestData: PermissionsToCheck = {
|
|
|
|
[targetUris.processGroupListPath]: ['POST'],
|
2022-11-22 14:12:08 -05:00
|
|
|
[targetUris.processGroupShowPath]: ['PUT', 'DELETE'],
|
2022-11-15 17:35:16 -05:00
|
|
|
[targetUris.processModelCreatePath]: ['POST'],
|
2022-11-15 16:18:25 -05:00
|
|
|
};
|
|
|
|
const { ability } = usePermissionFetcher(permissionRequestData);
|
|
|
|
|
2022-10-12 10:21:49 -04:00
|
|
|
useEffect(() => {
|
|
|
|
const { page, perPage } = getPageInfoFromSearchParams(searchParams);
|
|
|
|
|
|
|
|
const setProcessModelFromResult = (result: any) => {
|
2022-11-22 16:21:16 -05:00
|
|
|
// setProcessModels(result.results);
|
2022-11-11 08:06:05 -05:00
|
|
|
setModelPagination(result.pagination);
|
|
|
|
};
|
2022-10-12 10:21:49 -04:00
|
|
|
const processResult = (result: any) => {
|
|
|
|
setProcessGroup(result);
|
2022-11-22 10:56:40 -05:00
|
|
|
const unmodifiedProcessGroupId = unModifyProcessIdentifierForPathParam(
|
2022-11-09 15:45:45 -05:00
|
|
|
(params as any).process_group_id
|
|
|
|
);
|
2022-10-12 10:21:49 -04:00
|
|
|
HttpService.makeCallToBackend({
|
2022-11-09 15:45:45 -05:00
|
|
|
path: `/process-models?process_group_identifier=${unmodifiedProcessGroupId}&per_page=${perPage}&page=${page}`,
|
2022-10-12 10:21:49 -04:00
|
|
|
successCallback: setProcessModelFromResult,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
HttpService.makeCallToBackend({
|
|
|
|
path: `/process-groups/${params.process_group_id}`,
|
|
|
|
successCallback: processResult,
|
|
|
|
});
|
|
|
|
}, [params, searchParams]);
|
|
|
|
|
2022-11-22 16:21:16 -05:00
|
|
|
// const buildModelTable = () => {
|
|
|
|
// if (processGroup === null) {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
// const rows = processModels.map((row: ProcessModel) => {
|
|
|
|
// const modifiedProcessModelId: String =
|
|
|
|
// modifyProcessIdentifierForPathParam((row as any).id);
|
|
|
|
// return (
|
|
|
|
// <tr key={row.id}>
|
|
|
|
// <td>
|
|
|
|
// <Link
|
|
|
|
// to={`/admin/process-models/${modifiedProcessModelId}`}
|
|
|
|
// data-qa="process-model-show-link"
|
|
|
|
// >
|
|
|
|
// {row.id}
|
|
|
|
// </Link>
|
|
|
|
// </td>
|
|
|
|
// <td>{row.display_name}</td>
|
|
|
|
// </tr>
|
|
|
|
// );
|
|
|
|
// });
|
|
|
|
// return (
|
|
|
|
// <div>
|
|
|
|
// <h2>Process Models</h2>
|
|
|
|
// <Table striped bordered>
|
|
|
|
// <thead>
|
|
|
|
// <tr>
|
|
|
|
// <th>Process Model Id</th>
|
|
|
|
// <th>Display Name</th>
|
|
|
|
// </tr>
|
|
|
|
// </thead>
|
|
|
|
// <tbody>{rows}</tbody>
|
|
|
|
// </Table>
|
|
|
|
// </div>
|
|
|
|
// );
|
|
|
|
// };
|
2022-10-12 10:21:49 -04:00
|
|
|
|
2022-11-22 14:12:08 -05:00
|
|
|
const navigateToProcessGroups = (_result: any) => {
|
|
|
|
navigate(`/admin/process-groups`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const deleteProcessGroup = () => {
|
|
|
|
if (processGroup) {
|
|
|
|
HttpService.makeCallToBackend({
|
|
|
|
path: `/process-groups/${modifyProcessIdentifierForPathParam(
|
|
|
|
processGroup.id
|
|
|
|
)}`,
|
|
|
|
successCallback: navigateToProcessGroups,
|
|
|
|
httpMethod: 'DELETE',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-18 15:25:04 -05:00
|
|
|
if (processGroup && modelPagination) {
|
2022-11-22 16:21:16 -05:00
|
|
|
// const { page, perPage } = getPageInfoFromSearchParams(searchParams);
|
2022-11-22 10:56:40 -05:00
|
|
|
const modifiedProcessGroupId = modifyProcessIdentifierForPathParam(
|
|
|
|
processGroup.id
|
|
|
|
);
|
2022-10-12 10:21:49 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ProcessBreadcrumb
|
|
|
|
hotCrumbs={[
|
|
|
|
['Process Groups', '/admin'],
|
2022-11-23 15:39:10 -05:00
|
|
|
{
|
|
|
|
entityToExplode: processGroup,
|
|
|
|
entityType: 'process-group',
|
|
|
|
},
|
2022-10-12 10:21:49 -04:00
|
|
|
]}
|
|
|
|
/>
|
2022-11-22 14:12:08 -05:00
|
|
|
<Stack orientation="horizontal" gap={1}>
|
|
|
|
<h1 className="with-icons">
|
|
|
|
Process Group: {processGroup.display_name}
|
|
|
|
</h1>
|
|
|
|
<Can I="PUT" a={targetUris.processGroupShowPath} ability={ability}>
|
|
|
|
<Button
|
|
|
|
kind="ghost"
|
|
|
|
data-qa="edit-process-group-button"
|
|
|
|
renderIcon={Edit}
|
|
|
|
iconDescription="Edit Process Group"
|
|
|
|
hasIconOnly
|
|
|
|
href={`/admin/process-groups/${modifiedProcessGroupId}/edit`}
|
|
|
|
>
|
|
|
|
Edit process group
|
|
|
|
</Button>
|
|
|
|
</Can>
|
|
|
|
<Can I="DELETE" a={targetUris.processGroupShowPath} ability={ability}>
|
|
|
|
<ButtonWithConfirmation
|
|
|
|
kind="ghost"
|
|
|
|
data-qa="delete-process-group-button"
|
|
|
|
renderIcon={TrashCan}
|
|
|
|
iconDescription="Delete Process Group"
|
|
|
|
hasIconOnly
|
|
|
|
description={`Delete process group: ${processGroup.display_name}`}
|
|
|
|
onConfirmation={deleteProcessGroup}
|
|
|
|
confirmButtonLabel="Delete"
|
|
|
|
/>
|
|
|
|
</Can>
|
|
|
|
</Stack>
|
2022-11-21 14:12:04 -05:00
|
|
|
<p className="process-description">{processGroup.description}</p>
|
2022-10-12 10:21:49 -04:00
|
|
|
<ul>
|
2022-11-04 18:27:10 -04:00
|
|
|
<Stack orientation="horizontal" gap={3}>
|
2022-11-15 16:18:25 -05:00
|
|
|
<Can I="POST" a={targetUris.processGroupListPath} ability={ability}>
|
|
|
|
<Button
|
|
|
|
href={`/admin/process-groups/new?parentGroupId=${processGroup.id}`}
|
|
|
|
>
|
|
|
|
Add a process group
|
|
|
|
</Button>
|
|
|
|
</Can>
|
2022-11-15 17:35:16 -05:00
|
|
|
<Can
|
|
|
|
I="POST"
|
|
|
|
a={targetUris.processModelCreatePath}
|
|
|
|
ability={ability}
|
2022-10-12 10:21:49 -04:00
|
|
|
>
|
2022-11-15 17:35:16 -05:00
|
|
|
<Button
|
|
|
|
href={`/admin/process-models/${modifiedProcessGroupId}/new`}
|
|
|
|
>
|
|
|
|
Add a process model
|
|
|
|
</Button>
|
|
|
|
</Can>
|
2022-10-12 10:21:49 -04:00
|
|
|
</Stack>
|
|
|
|
<br />
|
|
|
|
<br />
|
2022-11-22 15:09:42 -05:00
|
|
|
<ProcessModelListTiles
|
2022-11-22 09:05:33 -05:00
|
|
|
headerElement={<h2>Process Models</h2>}
|
|
|
|
processGroup={processGroup}
|
2022-11-22 15:09:42 -05:00
|
|
|
/>
|
2022-11-13 18:41:03 -05:00
|
|
|
{/* eslint-disable-next-line sonarjs/no-gratuitous-expressions */}
|
2022-11-22 15:09:42 -05:00
|
|
|
{/* {modelPagination && modelPagination.total > 0 && (
|
2022-11-11 22:12:35 -05:00
|
|
|
<PaginationForTable
|
|
|
|
page={page}
|
|
|
|
perPage={perPage}
|
|
|
|
pagination={modelPagination}
|
|
|
|
tableToDisplay={buildModelTable()}
|
|
|
|
/>
|
2022-11-22 15:09:42 -05:00
|
|
|
)} */}
|
2022-11-09 15:45:45 -05:00
|
|
|
<br />
|
|
|
|
<br />
|
2022-11-18 13:57:40 -05:00
|
|
|
<ProcessGroupListTiles
|
|
|
|
processGroup={processGroup}
|
2022-11-22 15:09:42 -05:00
|
|
|
headerElement={<h2 className="clear-left">Process Groups</h2>}
|
2022-11-18 13:57:40 -05:00
|
|
|
/>
|
2022-10-12 10:21:49 -04:00
|
|
|
</ul>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|