attempting to filter process instances with json instead of report filters w/ burnettk

This commit is contained in:
jasquat 2023-04-25 17:21:38 -04:00
parent 04864692b6
commit 3984aa16aa
5 changed files with 289 additions and 259 deletions

View File

@ -697,7 +697,7 @@ paths:
description: Base64 encoded json of report filter by. description: Base64 encoded json of report filter by.
schema: schema:
type: string type: string
get: post:
operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_list_for_me operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_list_for_me
summary: Returns a list of process instances that are associated with me. summary: Returns a list of process instances that are associated with me.
tags: tags:
@ -828,7 +828,7 @@ paths:
description: Base64 encoded json of report filter by. description: Base64 encoded json of report filter by.
schema: schema:
type: string type: string
get: post:
operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_list operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_list
summary: Returns a list of process instances. summary: Returns a list of process instances.
tags: tags:

View File

@ -22,7 +22,21 @@ from spiffworkflow_backend.services.process_instance_processor import (
) )
ReportMetadata = dict[str, Any] class FilterValue(TypedDict):
field_name: str
field_value: str
operator: str
class ReportMetadataColumn(TypedDict):
Header: str
accessor: str
class ReportMetadata(TypedDict):
columns: list[ReportMetadataColumn]
filter_by: list[FilterValue]
order_by: list[str]
class ProcessInstanceReportAlreadyExistsError(Exception): class ProcessInstanceReportAlreadyExistsError(Exception):

View File

@ -226,103 +226,107 @@ def process_instance_resume(
def process_instance_list_for_me( def process_instance_list_for_me(
body: Dict[str, Any],
process_model_identifier: Optional[str] = None, process_model_identifier: Optional[str] = None,
page: int = 1, page: int = 1,
per_page: int = 100, per_page: int = 100,
start_from: Optional[int] = None, # start_from: Optional[int] = None,
start_to: Optional[int] = None, # start_to: Optional[int] = None,
end_from: Optional[int] = None, # end_from: Optional[int] = None,
end_to: Optional[int] = None, # end_to: Optional[int] = None,
process_status: Optional[str] = None, # process_status: Optional[str] = None,
user_filter: Optional[bool] = False, # user_filter: Optional[bool] = False,
report_identifier: Optional[str] = None, # report_identifier: Optional[str] = None,
report_id: Optional[int] = None, # report_id: Optional[int] = None,
user_group_identifier: Optional[str] = None, # user_group_identifier: Optional[str] = None,
process_initiator_username: Optional[str] = None, # process_initiator_username: Optional[str] = None,
report_columns: Optional[str] = None, # report_columns: Optional[str] = None,
report_filter_by: Optional[str] = None, # report_filter_by: Optional[str] = None,
) -> flask.wrappers.Response: ) -> flask.wrappers.Response:
"""Process_instance_list_for_me.""" """Process_instance_list_for_me."""
return process_instance_list( return process_instance_list(
process_model_identifier=process_model_identifier, process_model_identifier=process_model_identifier,
page=page, page=page,
per_page=per_page, per_page=per_page,
start_from=start_from, # start_from=start_from,
start_to=start_to, # start_to=start_to,
end_from=end_from, # end_from=end_from,
end_to=end_to, # end_to=end_to,
process_status=process_status, # process_status=process_status,
user_filter=user_filter, # user_filter=user_filter,
report_identifier=report_identifier, # report_identifier=report_identifier,
report_id=report_id, # report_id=report_id,
user_group_identifier=user_group_identifier, # user_group_identifier=user_group_identifier,
with_relation_to_me=True, # with_relation_to_me=True,
report_columns=report_columns, # report_columns=report_columns,
report_filter_by=report_filter_by, # report_filter_by=report_filter_by,
process_initiator_username=process_initiator_username, # process_initiator_username=process_initiator_username,
body=body
) )
def process_instance_list( def process_instance_list(
body: Dict[str, Any],
process_model_identifier: Optional[str] = None, process_model_identifier: Optional[str] = None,
page: int = 1, page: int = 1,
per_page: int = 100, per_page: int = 100,
start_from: Optional[int] = None, # start_from: Optional[int] = None,
start_to: Optional[int] = None, # start_to: Optional[int] = None,
end_from: Optional[int] = None, # end_from: Optional[int] = None,
end_to: Optional[int] = None, # end_to: Optional[int] = None,
process_status: Optional[str] = None, # process_status: Optional[str] = None,
with_relation_to_me: Optional[bool] = None, # with_relation_to_me: Optional[bool] = None,
user_filter: Optional[bool] = False, # user_filter: Optional[bool] = False,
report_identifier: Optional[str] = None, # report_identifier: Optional[str] = None,
report_id: Optional[int] = None, # report_id: Optional[int] = None,
user_group_identifier: Optional[str] = None, # user_group_identifier: Optional[str] = None,
process_initiator_username: Optional[str] = None, # process_initiator_username: Optional[str] = None,
report_columns: Optional[str] = None, # report_columns: Optional[str] = None,
report_filter_by: Optional[str] = None, # report_filter_by: Optional[str] = None,
) -> flask.wrappers.Response: ) -> flask.wrappers.Response:
"""Process_instance_list.""" # process_instance_report = ProcessInstanceReportService.report_with_identifier(g.user, body['report_id'], body['report_identifier'])
process_instance_report = ProcessInstanceReportService.report_with_identifier(g.user, report_id, report_identifier) process_instance_report = ProcessInstanceReportService.report_with_identifier(g.user)
report_column_list = None # report_column_list = None
if report_columns: # if report_columns:
report_column_list = json.loads(base64.b64decode(report_columns)) # report_column_list = json.loads(base64.b64decode(report_columns))
report_filter_by_list = None # report_filter_by_list = None
if report_filter_by: # if report_filter_by:
report_filter_by_list = json.loads(base64.b64decode(report_filter_by)) # report_filter_by_list = json.loads(base64.b64decode(report_filter_by))
if user_filter: # if user_filter:
report_filter = ProcessInstanceReportFilter( # report_filter = ProcessInstanceReportFilter(
process_model_identifier=process_model_identifier, # process_model_identifier=process_model_identifier,
user_group_identifier=user_group_identifier, # # user_group_identifier=user_group_identifier,
start_from=start_from, # # start_from=start_from,
start_to=start_to, # # start_to=start_to,
end_from=end_from, # # end_from=end_from,
end_to=end_to, # # end_to=end_to,
with_relation_to_me=with_relation_to_me, # # with_relation_to_me=with_relation_to_me,
process_status=process_status.split(",") if process_status else None, # # process_status=process_status.split(",") if process_status else None,
process_initiator_username=process_initiator_username, # # process_initiator_username=process_initiator_username,
report_column_list=report_column_list, # # report_column_list=report_column_list,
report_filter_by_list=report_filter_by_list, # # report_filter_by_list=report_filter_by_list,
) # )
else: # else:
report_filter = ProcessInstanceReportService.filter_from_metadata_with_overrides( # report_filter = ProcessInstanceReportService.filter_from_metadata_with_overrides(
process_instance_report=process_instance_report, # process_instance_report=process_instance_report,
process_model_identifier=process_model_identifier, # process_model_identifier=process_model_identifier,
user_group_identifier=user_group_identifier, # # user_group_identifier=user_group_identifier,
start_from=start_from, # # start_from=start_from,
start_to=start_to, # # start_to=start_to,
end_from=end_from, # # end_from=end_from,
end_to=end_to, # # end_to=end_to,
process_status=process_status, # # process_status=process_status,
with_relation_to_me=with_relation_to_me, # # with_relation_to_me=with_relation_to_me,
process_initiator_username=process_initiator_username, # # process_initiator_username=process_initiator_username,
report_column_list=report_column_list, # # report_column_list=report_column_list,
report_filter_by_list=report_filter_by_list, # # report_filter_by_list=report_filter_by_list,
) # )
response_json = ProcessInstanceReportService.run_process_instance_report( response_json = ProcessInstanceReportService.run_process_instance_report(
report_filter=report_filter, # report_filter=report_filter,
report_metadata=body['report_metadata'],
process_instance_report=process_instance_report, process_instance_report=process_instance_report,
page=page, page=page,
per_page=per_page, per_page=per_page,

View File

@ -1,7 +1,7 @@
"""Process_instance_report_service.""" """Process_instance_report_service."""
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any from typing import Any, Generator, Iterable
from typing import Optional from typing import Optional
from typing import Type from typing import Type
@ -24,7 +24,9 @@ from spiffworkflow_backend.models.process_instance_metadata import (
ProcessInstanceMetadataModel, ProcessInstanceMetadataModel,
) )
from spiffworkflow_backend.models.process_instance_report import ( from spiffworkflow_backend.models.process_instance_report import (
FilterValue,
ProcessInstanceReportModel, ProcessInstanceReportModel,
ReportMetadata,
) )
from spiffworkflow_backend.models.user import UserModel from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.models.user_group_assignment import UserGroupAssignmentModel from spiffworkflow_backend.models.user_group_assignment import UserGroupAssignmentModel
@ -236,7 +238,6 @@ class ProcessInstanceReportService:
report_id: Optional[int] = None, report_id: Optional[int] = None,
report_identifier: Optional[str] = None, report_identifier: Optional[str] = None,
) -> ProcessInstanceReportModel: ) -> ProcessInstanceReportModel:
"""Report_with_filter."""
if report_id is not None: if report_id is not None:
process_instance_report = ProcessInstanceReportModel.query.filter_by( process_instance_report = ProcessInstanceReportModel.query.filter_by(
id=report_id, created_by_id=user.id id=report_id, created_by_id=user.id
@ -496,25 +497,31 @@ class ProcessInstanceReportService:
{"Header": "Status", "accessor": "status", "filterable": False}, {"Header": "Status", "accessor": "status", "filterable": False},
] ]
@classmethod
def blah(cls, filters: list[FilterValue], filter_key: str) -> Generator:
for filter in filters:
if filter['field_name'] == filter_key and filter['field_value'] is not None:
yield filter['field_value']
@classmethod @classmethod
def run_process_instance_report( def run_process_instance_report(
cls, cls,
report_filter: ProcessInstanceReportFilter, # report_filter: ProcessInstanceReportFilter,
report_metadata: ReportMetadata,
process_instance_report: ProcessInstanceReportModel, process_instance_report: ProcessInstanceReportModel,
user: UserModel, user: UserModel,
page: int = 1, page: int = 1,
per_page: int = 100, per_page: int = 100,
) -> dict: ) -> dict:
"""Run_process_instance_report."""
process_instance_query = ProcessInstanceModel.query process_instance_query = ProcessInstanceModel.query
# Always join that hot user table for good performance at serialization time. # Always join that hot user table for good performance at serialization time.
process_instance_query = process_instance_query.options(selectinload(ProcessInstanceModel.process_initiator)) process_instance_query = process_instance_query.options(selectinload(ProcessInstanceModel.process_initiator))
filters = report_metadata['filter_by']
if report_filter.process_model_identifier is not None: for value in cls.blah(filters, 'process_model_identifier'):
process_model = ProcessModelService.get_process_model( process_model = ProcessModelService.get_process_model(
f"{report_filter.process_model_identifier}", f"{value}",
) )
process_instance_query = process_instance_query.filter_by(process_model_identifier=process_model.id) process_instance_query = process_instance_query.filter_by(process_model_identifier=process_model.id)
# this can never happen. obviously the class has the columns it defines. this is just to appease mypy. # this can never happen. obviously the class has the columns it defines. this is just to appease mypy.
@ -527,187 +534,188 @@ class ProcessInstanceReportService:
) )
) )
if report_filter.start_from is not None: # if report_filter.start_from is not None:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.start_in_seconds >= report_filter.start_from # ProcessInstanceModel.start_in_seconds >= report_filter.start_from
) # )
if report_filter.start_to is not None: # if report_filter.start_to is not None:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.start_in_seconds <= report_filter.start_to # ProcessInstanceModel.start_in_seconds <= report_filter.start_to
) # )
if report_filter.end_from is not None: # if report_filter.end_from is not None:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.end_in_seconds >= report_filter.end_from # ProcessInstanceModel.end_in_seconds >= report_filter.end_from
) # )
if report_filter.end_to is not None: # if report_filter.end_to is not None:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.end_in_seconds <= report_filter.end_to # ProcessInstanceModel.end_in_seconds <= report_filter.end_to
) # )
if report_filter.process_status is not None: # if report_filter.process_status is not None:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.status.in_(report_filter.process_status) # type: ignore # ProcessInstanceModel.status.in_(report_filter.process_status) # type: ignore
) # )
#
if report_filter.initiated_by_me is True: # if report_filter.initiated_by_me is True:
process_instance_query = process_instance_query.filter_by(process_initiator=user) # process_instance_query = process_instance_query.filter_by(process_initiator=user)
#
if report_filter.has_terminal_status is True: # if report_filter.has_terminal_status is True:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.status.in_(ProcessInstanceModel.terminal_statuses()) # type: ignore # ProcessInstanceModel.status.in_(ProcessInstanceModel.terminal_statuses()) # type: ignore
) # )
elif report_filter.has_terminal_status is False: # elif report_filter.has_terminal_status is False:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.status.not_in(ProcessInstanceModel.terminal_statuses()) # type: ignore # ProcessInstanceModel.status.not_in(ProcessInstanceModel.terminal_statuses()) # type: ignore
) # )
if report_filter.has_active_status is True: # if report_filter.has_active_status is True:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.status.in_(ProcessInstanceModel.active_statuses()) # type: ignore # ProcessInstanceModel.status.in_(ProcessInstanceModel.active_statuses()) # type: ignore
) # )
#
if report_filter.process_initiator_username is not None: # if report_filter.process_initiator_username is not None:
initiator = UserModel.query.filter_by(username=report_filter.process_initiator_username).first() # initiator = UserModel.query.filter_by(username=report_filter.process_initiator_username).first()
process_initiator_id = -1 # process_initiator_id = -1
if initiator: # if initiator:
process_initiator_id = initiator.id # process_initiator_id = initiator.id
process_instance_query = process_instance_query.filter_by(process_initiator_id=process_initiator_id) # process_instance_query = process_instance_query.filter_by(process_initiator_id=process_initiator_id)
#
if ( # if (
not report_filter.with_tasks_completed_by_me # not report_filter.with_tasks_completed_by_me
and not report_filter.with_tasks_assigned_to_my_group # and not report_filter.with_tasks_assigned_to_my_group
and not report_filter.with_tasks_i_can_complete # and not report_filter.with_tasks_i_can_complete
and report_filter.with_relation_to_me is True # and report_filter.with_relation_to_me is True
): # ):
process_instance_query = process_instance_query.outerjoin(HumanTaskModel).outerjoin( # process_instance_query = process_instance_query.outerjoin(HumanTaskModel).outerjoin(
HumanTaskUserModel, # HumanTaskUserModel,
and_( # and_(
HumanTaskModel.id == HumanTaskUserModel.human_task_id, # HumanTaskModel.id == HumanTaskUserModel.human_task_id,
HumanTaskUserModel.user_id == user.id, # HumanTaskUserModel.user_id == user.id,
), # ),
) # )
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
or_( # or_(
HumanTaskUserModel.id.is_not(None), # HumanTaskUserModel.id.is_not(None),
ProcessInstanceModel.process_initiator_id == user.id, # ProcessInstanceModel.process_initiator_id == user.id,
) # )
) # )
#
if report_filter.with_tasks_completed_by_me is True: # if report_filter.with_tasks_completed_by_me is True:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.process_initiator_id != user.id # ProcessInstanceModel.process_initiator_id != user.id
) # )
process_instance_query = process_instance_query.join( # process_instance_query = process_instance_query.join(
HumanTaskModel, # HumanTaskModel,
and_( # and_(
HumanTaskModel.process_instance_id == ProcessInstanceModel.id, # HumanTaskModel.process_instance_id == ProcessInstanceModel.id,
HumanTaskModel.completed_by_user_id == user.id, # HumanTaskModel.completed_by_user_id == user.id,
), # ),
) # )
#
if report_filter.with_tasks_i_can_complete is True: # if report_filter.with_tasks_i_can_complete is True:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
ProcessInstanceModel.process_initiator_id != user.id # ProcessInstanceModel.process_initiator_id != user.id
) # )
process_instance_query = process_instance_query.join( # process_instance_query = process_instance_query.join(
HumanTaskModel, # HumanTaskModel,
and_( # and_(
HumanTaskModel.process_instance_id == ProcessInstanceModel.id, # HumanTaskModel.process_instance_id == ProcessInstanceModel.id,
HumanTaskModel.lane_assignment_id.is_(None), # type: ignore # HumanTaskModel.lane_assignment_id.is_(None), # type: ignore
), # ),
).join( # ).join(
HumanTaskUserModel, # HumanTaskUserModel,
and_(HumanTaskUserModel.human_task_id == HumanTaskModel.id, HumanTaskUserModel.user_id == user.id), # and_(HumanTaskUserModel.human_task_id == HumanTaskModel.id, HumanTaskUserModel.user_id == user.id),
) # )
if report_filter.has_active_status: # if report_filter.has_active_status:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
HumanTaskModel.completed.is_(False) # type: ignore # HumanTaskModel.completed.is_(False) # type: ignore
) # )
#
if report_filter.with_tasks_assigned_to_my_group is True: # if report_filter.with_tasks_assigned_to_my_group is True:
group_model_join_conditions = [GroupModel.id == HumanTaskModel.lane_assignment_id] # group_model_join_conditions = [GroupModel.id == HumanTaskModel.lane_assignment_id]
if report_filter.user_group_identifier: # if report_filter.user_group_identifier:
group_model_join_conditions.append(GroupModel.identifier == report_filter.user_group_identifier) # group_model_join_conditions.append(GroupModel.identifier == report_filter.user_group_identifier)
#
process_instance_query = process_instance_query.join(HumanTaskModel) # process_instance_query = process_instance_query.join(HumanTaskModel)
if report_filter.has_active_status: # if report_filter.has_active_status:
process_instance_query = process_instance_query.filter( # process_instance_query = process_instance_query.filter(
HumanTaskModel.completed.is_(False) # type: ignore # HumanTaskModel.completed.is_(False) # type: ignore
) # )
#
process_instance_query = process_instance_query.join(GroupModel, and_(*group_model_join_conditions)) # process_instance_query = process_instance_query.join(GroupModel, and_(*group_model_join_conditions))
process_instance_query = process_instance_query.join( # process_instance_query = process_instance_query.join(
UserGroupAssignmentModel, # UserGroupAssignmentModel,
UserGroupAssignmentModel.group_id == GroupModel.id, # UserGroupAssignmentModel.group_id == GroupModel.id,
) # )
process_instance_query = process_instance_query.filter(UserGroupAssignmentModel.user_id == user.id) # process_instance_query = process_instance_query.filter(UserGroupAssignmentModel.user_id == user.id)
#
instance_metadata_aliases = {} # instance_metadata_aliases = {}
stock_columns = cls.get_column_names_for_model(ProcessInstanceModel) # stock_columns = cls.get_column_names_for_model(ProcessInstanceModel)
if isinstance(report_filter.report_column_list, list): # if isinstance(report_filter.report_column_list, list):
process_instance_report.report_metadata["columns"] = report_filter.report_column_list # process_instance_report.report_metadata["columns"] = report_filter.report_column_list
if isinstance(report_filter.report_filter_by_list, list): # if isinstance(report_filter.report_filter_by_list, list):
process_instance_report.report_metadata["filter_by"] = report_filter.report_filter_by_list # process_instance_report.report_metadata["filter_by"] = report_filter.report_filter_by_list
#
for column in process_instance_report.report_metadata["columns"]: # for column in process_instance_report.report_metadata["columns"]:
if column["accessor"] in stock_columns: # if column["accessor"] in stock_columns:
continue # continue
instance_metadata_alias = aliased(ProcessInstanceMetadataModel) # 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 # 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( # filter_for_column = next(
( # (
f # f
for f in process_instance_report.report_metadata["filter_by"] # for f in process_instance_report.report_metadata["filter_by"]
if f["field_name"] == column["accessor"] # if f["field_name"] == column["accessor"]
), # ),
None, # None,
) # )
isouter = True # isouter = True
conditions = [ # conditions = [
ProcessInstanceModel.id == instance_metadata_alias.process_instance_id, # ProcessInstanceModel.id == instance_metadata_alias.process_instance_id,
instance_metadata_alias.key == column["accessor"], # instance_metadata_alias.key == column["accessor"],
] # ]
if filter_for_column: # if filter_for_column:
isouter = False # isouter = False
conditions.append(instance_metadata_alias.value == filter_for_column["field_value"]) # conditions.append(instance_metadata_alias.value == filter_for_column["field_value"])
process_instance_query = process_instance_query.join( # process_instance_query = process_instance_query.join(
instance_metadata_alias, and_(*conditions), isouter=isouter # instance_metadata_alias, and_(*conditions), isouter=isouter
).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"])) # ).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"]))
#
order_by_query_array = [] # 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: # if len(order_by_array) < 1:
order_by_array = ProcessInstanceReportModel.default_order_by() # order_by_array = ProcessInstanceReportModel.default_order_by()
for order_by_option in order_by_array: # 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 attribute in stock_columns:
if order_by_option.startswith("-"): # if order_by_option.startswith("-"):
order_by_query_array.append(getattr(ProcessInstanceModel, attribute).desc()) # order_by_query_array.append(getattr(ProcessInstanceModel, attribute).desc())
else: # 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: # elif attribute in instance_metadata_aliases:
if order_by_option.startswith("-"): # if order_by_option.startswith("-"):
order_by_query_array.append(func.max(instance_metadata_aliases[attribute].value).desc()) # order_by_query_array.append(func.max(instance_metadata_aliases[attribute].value).desc())
else: # else:
order_by_query_array.append(func.max(instance_metadata_aliases[attribute].value).asc()) # order_by_query_array.append(func.max(instance_metadata_aliases[attribute].value).asc())
process_instances = ( process_instances = (
process_instance_query.group_by(ProcessInstanceModel.id) process_instance_query.group_by(ProcessInstanceModel.id)
.add_columns(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) .paginate(page=page, per_page=per_page, error_out=False)
) )
results = cls.add_metadata_columns_to_process_instance( results = cls.add_metadata_columns_to_process_instance(
process_instances.items, process_instance_report.report_metadata["columns"] process_instances.items, process_instance_report.report_metadata["columns"]
) )
if report_filter.oldest_open_human_task_fields: # if report_filter.oldest_open_human_task_fields:
results = cls.add_human_task_fields(results, report_filter.oldest_open_human_task_fields) # results = cls.add_human_task_fields(results, report_filter.oldest_open_human_task_fields)
response_json = { response_json = {
"report": process_instance_report, "report": process_instance_report,
"results": results, "results": results,
"filters": report_filter.to_dict(), "filters": filters,
"hash": "HEY",
"pagination": { "pagination": {
"count": len(results), "count": len(results),
"total": process_instances.total, "total": process_instances.total,

View File

@ -114,12 +114,12 @@ export default function ProcessInstanceListTable({
canCompleteAllTasks = false, canCompleteAllTasks = false,
showActionsColumn = false, showActionsColumn = false,
}: OwnProps) { }: OwnProps) {
let apiPath = '/process-instances/for-me'; let processInstanceApiSearchPath = '/process-instances/for-me';
if (variant === 'all') { if (variant === 'all') {
apiPath = '/process-instances'; processInstanceApiSearchPath = '/process-instances';
} }
const params = useParams(); const params = useParams();
const [searchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const navigate = useNavigate(); const navigate = useNavigate();
const { addError, removeError } = useAPIError(); const { addError, removeError } = useAPIError();
@ -284,6 +284,8 @@ export default function ProcessInstanceListTable({
if (result.report.id) { if (result.report.id) {
setProcessInstanceReportSelection(result.report); setProcessInstanceReportSelection(result.report);
} }
// searchParams.set('key', result.hash);
// setSearchParams(searchParams);
} }
const stopRefreshing = () => { const stopRefreshing = () => {
if (clearRefreshRef.current) { if (clearRefreshRef.current) {
@ -372,9 +374,11 @@ export default function ProcessInstanceListTable({
} }
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: `${apiPath}?${queryParamString}`, path: `${processInstanceApiSearchPath}?${queryParamString}`,
successCallback: setProcessInstancesFromResult, successCallback: setProcessInstancesFromResult,
httpMethod: 'POST',
onUnauthorized: stopRefreshing, onUnauthorized: stopRefreshing,
postBody: {'report_metadata': {'filter_by': [{'field_name': 'process_model_identifier', 'field_value': 'example/with-milestones' }]}},
}); });
} }
function processResultForProcessModels(result: any) { function processResultForProcessModels(result: any) {
@ -441,7 +445,7 @@ export default function ProcessInstanceListTable({
perPageOptions, perPageOptions,
reportIdentifier, reportIdentifier,
additionalParams, additionalParams,
apiPath, processInstanceApiSearchPath,
]); ]);
// This sets the filter data using the saved reports returned from the initial instance_list query. // This sets the filter data using the saved reports returned from the initial instance_list query.