From 55afc22148983b6becd4df18283955ea434dd0cf Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 5 Dec 2022 14:10:07 -0500 Subject: [PATCH] pyl w/ burnettk --- .../models/process_instance_report.py | 1 + .../routes/process_api_blueprint.py | 34 +++++++++++-------- .../integration/test_process_api.py | 9 ++--- .../components/ProcessInstanceListTable.tsx | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py index ad29dd065..1f22a3830 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py @@ -77,6 +77,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel): @classmethod def default_order_by(cls) -> list[str]: + """Default_order_by.""" return ["-start_in_seconds", "-id"] @classmethod 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 d9a7f68a3..6843fb157 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1,9 +1,9 @@ """APIs for dealing with process groups, process models, and process instances.""" import json import random +import re import string import uuid -import re from typing import Any from typing import Dict from typing import Optional @@ -953,10 +953,10 @@ def process_instance_list( if column["accessor"] in stock_columns: continue instance_metadata_alias = aliased(ProcessInstanceMetadataModel) - instance_metadata_aliases[column['accessor']] = instance_metadata_alias + instance_metadata_aliases[column["accessor"]] = instance_metadata_alias filter_for_column = None - if 'filter_by' in process_instance_report.report_metadata: + if "filter_by" in process_instance_report.report_metadata: filter_for_column = next( ( f @@ -980,28 +980,34 @@ def process_instance_list( ).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"])) order_by_query_array = [] - order_by_array = process_instance_report.report_metadata['order_by'] + order_by_array = process_instance_report.report_metadata["order_by"] if len(order_by_array) < 1: order_by_array = ProcessInstanceReportModel.default_order_by() for order_by_option in order_by_array: - attribute = re.sub('^-', '', order_by_option) + attribute = re.sub("^-", "", order_by_option) if attribute in stock_columns: - if order_by_option.startswith('-'): - order_by_query_array.append(getattr(ProcessInstanceModel, attribute).desc()) + if order_by_option.startswith("-"): + order_by_query_array.append( + getattr(ProcessInstanceModel, attribute).desc() + ) else: - order_by_query_array.append(getattr(ProcessInstanceModel, attribute).asc()) + order_by_query_array.append( + getattr(ProcessInstanceModel, attribute).asc() + ) elif attribute in instance_metadata_aliases: - if order_by_option.startswith('-'): - order_by_query_array.append(instance_metadata_aliases[attribute].value.desc()) + if order_by_option.startswith("-"): + order_by_query_array.append( + instance_metadata_aliases[attribute].value.desc() + ) else: - order_by_query_array.append(instance_metadata_aliases[attribute].value.asc()) + order_by_query_array.append( + instance_metadata_aliases[attribute].value.asc() + ) process_instances = ( process_instance_query.group_by(ProcessInstanceModel.id) .add_columns(ProcessInstanceModel.id) - .order_by( - *order_by_query_array - ) + .order_by(*order_by_query_array) .paginate(page=page, per_page=per_page, error_out=False) ) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index 05e0977a6..cd2d37c6a 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -2665,6 +2665,7 @@ class TestProcessApi(BaseTest): with_db_and_bpmn_file_cleanup: None, with_super_admin_user: UserModel, ) -> None: + """Test_process_instance_list_can_order_by_metadata.""" self.create_process_group( client, with_super_admin_user, "test_group", "test_group" ) @@ -2714,8 +2715,8 @@ class TestProcessApi(BaseTest): assert response.status_code == 200 assert response.json is not None assert len(response.json["results"]) == 2 - assert response.json['results'][0]['id'] == process_instance_one.id - assert response.json['results'][1]['id'] == process_instance_two.id + assert response.json["results"][0]["id"] == process_instance_one.id + assert response.json["results"][1]["id"] == process_instance_two.id report_metadata = { "columns": [ @@ -2738,5 +2739,5 @@ class TestProcessApi(BaseTest): assert response.status_code == 200 assert response.json is not None assert len(response.json["results"]) == 2 - assert response.json['results'][1]['id'] == process_instance_one.id - assert response.json['results'][0]['id'] == process_instance_two.id + assert response.json["results"][1]["id"] == process_instance_one.id + assert response.json["results"][0]["id"] == process_instance_two.id diff --git a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx index ffbaf5ae8..cc5ad75a9 100644 --- a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx @@ -1027,7 +1027,7 @@ export default function ProcessInstanceListTable({ - {saveAsReportComponent()} + {saveAsReportComponent()}