From be15c01b2e474dca5f7faabd37dc4850aed84c3c Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 17 Apr 2023 17:26:05 -0400 Subject: [PATCH] added api to get task types and added combo box w/ burnettk --- .../src/spiffworkflow_backend/api.yml | 18 ++++++++-- .../process_instance_events_controller.py | 25 +++++++++++-- .../services/authorization_service.py | 1 + .../src/routes/ProcessInstanceLogList.tsx | 36 +++++++++++++++++++ 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 7b97781e..48ab6ded 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -1961,8 +1961,8 @@ paths: type: boolean get: tags: - - Process Instances - operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_log_list + - Process Instance Events + operationId: spiffworkflow_backend.routes.process_instance_events_controller.log_list summary: returns a list of logs associated with the process instance responses: "200": @@ -1972,6 +1972,20 @@ paths: schema: $ref: "#/components/schemas/ProcessInstanceLog" + /logs/types: + get: + tags: + - Process Instance Events + operationId: spiffworkflow_backend.routes.process_instance_events_controller.types + summary: returns a list of task types and event typs. useful for building log queries. + responses: + "200": + description: list of types + content: + application/json: + schema: + $ref: "#/components/schemas/ProcessInstanceLog" + /secrets: parameters: - name: page diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instance_events_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instance_events_controller.py index daf2780a..18fac69d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instance_events_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instance_events_controller.py @@ -1,14 +1,26 @@ +import flask.wrappers + +from sqlalchemy import and_ +from spiffworkflow_backend.models.db import db +from flask import make_response +from flask import jsonify +from spiffworkflow_backend.models.user import UserModel +from spiffworkflow_backend.models.bpmn_process_definition import BpmnProcessDefinitionModel +from spiffworkflow_backend.models.task_definition import TaskDefinitionModel +from spiffworkflow_backend.models.task import TaskModel # noqa: F401 +from spiffworkflow_backend.models.process_instance_event import ProcessInstanceEventModel, ProcessInstanceEventType +from spiffworkflow_backend.routes.process_api_blueprint import ( + _find_process_instance_by_id_or_raise, +) - -def process_instance_log_list( +def log_list( modified_process_model_identifier: str, process_instance_id: int, page: int = 1, per_page: int = 100, detailed: bool = False, ) -> flask.wrappers.Response: - """Process_instance_log_list.""" # to make sure the process instance exists process_instance = _find_process_instance_by_id_or_raise(process_instance_id) @@ -56,3 +68,10 @@ def process_instance_log_list( } return make_response(jsonify(response_json), 200) + + +def types() -> flask.wrappers.Response: + query = db.session.query(TaskDefinitionModel.typename).distinct() # type: ignore + task_types = [t.typename for t in query] + event_types = ProcessInstanceEventType.list() + return make_response(jsonify({'task_types': task_types, 'event_types': event_types}), 200) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py index 7a4b05f5..4c18313e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py @@ -567,6 +567,7 @@ class AuthorizationService: permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/processes")) permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/service-tasks")) permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/user-groups/for-current-user")) + permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/logs/types")) permissions_to_assign.append(PermissionToAssign(permission="create", target_uri="/users/exists/by-username")) permissions_to_assign.append( PermissionToAssign(permission="read", target_uri="/process-instances/find-by-id/*") diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceLogList.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceLogList.tsx index 969e9ee6..ed3e3d50 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceLogList.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceLogList.tsx @@ -9,6 +9,7 @@ import { ButtonSet, Button, TextInput, + ComboBox, // @ts-ignore } from '@carbon/react'; import { @@ -44,6 +45,10 @@ export default function ProcessInstanceLogList({ variant }: OwnProps) { const [taskName, setTaskName] = useState(''); const [taskIdentifier, setTaskIdentifier] = useState(''); + const [taskTypes, setTaskTypes] = useState([]) + const [selectedTaskType, setSelectedTaskType] = useState(null) + const [eventTypes, setEventTypes] = useState([]) + const { targetUris } = useUriListForPermissions(); const isDetailedView = searchParams.get('detailed') === 'true'; @@ -82,6 +87,13 @@ export default function ProcessInstanceLogList({ variant }: OwnProps) { path: `${targetUris.processInstanceLogListPath}?per_page=${perPage}&page=${page}&detailed=${isDetailedView}`, successCallback: setProcessInstanceLogListFromResult, }); + HttpService.makeCallToBackend({ + path: `/v1.0/logs/types`, + successCallback: (result: any) => { + setTaskTypes(result.task_types) + setEventTypes(result.event_types) + }, + }); }, [ searchParams, params, @@ -209,6 +221,15 @@ export default function ProcessInstanceLogList({ variant }: OwnProps) { setSearchParams(searchParams); }; + const shouldFilterTaskType = (options: any) => { + const taskTypeOption = options.item + let { inputValue } = options; + if (!inputValue) { + inputValue = ''; + } + return taskTypeOption.toLowerCase().includes(inputValue.toLowerCase()) + } + const filterOptions = () => { if (!showFilterOptions) { return null; @@ -241,6 +262,21 @@ export default function ProcessInstanceLogList({ variant }: OwnProps) { }} /> + + setSelectedTaskType(value.selectedItem)} + id="task-type-select" + data-qa="task-type-select" + items={taskTypes} + itemToString={(value: string) => { + return value + }} + shouldFilterItem={shouldFilterTaskType} + placeholder="Choose a process model" + titleText="Task Type" + selectedItem={selectedTaskType} + /> +