From 6231ccab6cf43e45686f8f3c02812f0df54790c7 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 9 Dec 2022 11:23:18 -0500 Subject: [PATCH] some base work to try to get display names searchable for process models w/ burnettk --- .../src/spiffworkflow_backend/api.yml | 6 ++++++ .../routes/process_api_blueprint.py | 16 ++++++++++++---- .../src/components/ProcessModelSearch.tsx | 19 +++++++++++++++---- .../src/routes/ProcessGroupList.tsx | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index f5836d632..52890114c 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -285,6 +285,12 @@ paths: description: Get only the process models that the user can run schema: type: boolean + - name: include_parent_groups + in: query + required: false + description: Get the display names for the parent groups as well + schema: + type: boolean - name: page in: query required: false diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index d8effe0d7..7e583de9e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -388,6 +388,7 @@ def process_model_list( process_group_identifier: Optional[str] = None, recursive: Optional[bool] = False, filter_runnable_by_user: Optional[bool] = False, + include_parent_groups: Optional[bool] = False, page: int = 1, per_page: int = 100, ) -> flask.wrappers.Response: @@ -397,22 +398,29 @@ def process_model_list( recursive=recursive, filter_runnable_by_user=filter_runnable_by_user, ) - batch = ProcessModelService().get_batch( + process_models_to_return = ProcessModelService().get_batch( process_models, page=page, per_page=per_page ) + + if include_parent_groups: + for process_model in process_models_to_return: + process_model.parent_groups = ProcessModelService.get_parent_group_array( + process_model.id + ) + pages = len(process_models) // per_page remainder = len(process_models) % per_page if remainder > 0: pages += 1 response_json = { - "results": ProcessModelInfoSchema(many=True).dump(batch), + "results": process_models_to_return, "pagination": { - "count": len(batch), + "count": len(process_models_to_return), "total": len(process_models), "pages": pages, }, } - return Response(json.dumps(response_json), status=200, mimetype="application/json") + return make_response(jsonify(response_json), 200) def process_list() -> Any: diff --git a/spiffworkflow-frontend/src/components/ProcessModelSearch.tsx b/spiffworkflow-frontend/src/components/ProcessModelSearch.tsx index 8a3c0b9f7..06fa4d847 100644 --- a/spiffworkflow-frontend/src/components/ProcessModelSearch.tsx +++ b/spiffworkflow-frontend/src/components/ProcessModelSearch.tsx @@ -3,7 +3,7 @@ import { // @ts-ignore } from '@carbon/react'; import { truncateString } from '../helpers'; -import { ProcessModel } from '../interfaces'; +import { ProcessGroupLite, ProcessModel } from '../interfaces'; type OwnProps = { onChange: (..._args: any[]) => any; @@ -18,12 +18,23 @@ export default function ProcessModelSearch({ onChange, titleText = 'Process model', }: OwnProps) { + const getParentGroupsDisplayName = (processModel: ProcessModel) => { + if (processModel.parent_groups) { + return processModel.parent_groups + .map((parentGroup: ProcessGroupLite) => { + return parentGroup.display_name; + }) + .join(' '); + } + return ''; + }; + const shouldFilterProcessModel = (options: any) => { const processModel: ProcessModel = options.item; const { inputValue } = options; - return `${processModel.id} (${processModel.display_name})`.includes( - inputValue - ); + return `${processModel.id} (${getParentGroupsDisplayName(processModel)} ${ + processModel.display_name + })`.includes(inputValue); }; return (