some base work to try to get display names searchable for process models w/ burnettk

This commit is contained in:
jasquat 2022-12-09 11:23:18 -05:00
parent 3800389e4c
commit 6231ccab6c
4 changed files with 34 additions and 9 deletions

View File

@ -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

View File

@ -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:

View File

@ -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 (
<ComboBox

View File

@ -39,7 +39,7 @@ export default function ProcessGroupList() {
};
// for search box
HttpService.makeCallToBackend({
path: `/process-models?per_page=1000&recursive=true`,
path: `/process-models?per_page=1000&recursive=true&include_parent_groups=true`,
successCallback: processResultForProcessModels,
});
}, [searchParams]);