filter report column list by process_model_identifier if any

This commit is contained in:
burnettk 2023-03-24 17:54:37 -04:00
parent 199cf05960
commit ba067b320d
No known key found for this signature in database
3 changed files with 29 additions and 7 deletions

View File

@ -1251,9 +1251,16 @@ paths:
$ref: "#/components/schemas/OkTrue"
/process-instances/reports/columns:
parameters:
- name: process_model_identifier
in: query
required: false
description: The process model identifier to filter by
schema:
type: string
get:
operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_report_column_list
summary: Returns all available columns for a process instance report.
summary: Returns all available columns for a process instance report, including custom metadata
tags:
- Process Instances
responses:

View File

@ -390,15 +390,21 @@ def process_instance_list(
return make_response(jsonify(response_json), 200)
def process_instance_report_column_list() -> flask.wrappers.Response:
def process_instance_report_column_list(process_model_identifier: Optional[str] = None) -> flask.wrappers.Response:
"""Process_instance_report_column_list."""
table_columns = ProcessInstanceReportService.builtin_column_options()
columns_for_metadata = (
columns_for_metadata_query = (
db.session.query(ProcessInstanceMetadataModel.key)
.order_by(ProcessInstanceMetadataModel.key)
.distinct() # type: ignore
.all()
)
if process_model_identifier:
columns_for_metadata_query = columns_for_metadata_query.join(ProcessInstanceModel)
columns_for_metadata_query = columns_for_metadata_query.filter(
ProcessInstanceModel.process_model_identifier == process_model_identifier
)
columns_for_metadata = columns_for_metadata_query.all()
columns_for_metadata_strings = [
{"Header": i[0], "accessor": i[0], "filterable": True} for i in columns_for_metadata
]

View File

@ -140,6 +140,7 @@ export default function ProcessInstanceListTable({
const [endFromTimeInvalid, setEndFromTimeInvalid] = useState<boolean>(false);
const [endToTimeInvalid, setEndToTimeInvalid] = useState<boolean>(false);
const [requiresRefilter, setRequiresRefilter] = useState<boolean>(false);
const [lastColumnFilter, setLastColumnFilter] = useState<string>('');
const processInstanceListPathPrefix =
variant === 'all'
@ -1105,10 +1106,18 @@ export default function ProcessInstanceListTable({
return null;
}
// get the columns anytime we display the filter options if they are empty
if (availableReportColumns.length < 1) {
let queryParamString = '';
if (processModelSelection) {
queryParamString += `?process_model_identifier=${processModelSelection.id}`;
}
// get the columns anytime we display the filter options if they are empty.
// and if the columns are not empty, check if the columns are stale
// because we selected a different process model in the filter options.
const columnFilterIsStale = lastColumnFilter !== queryParamString;
if (availableReportColumns.length < 1 || columnFilterIsStale) {
setLastColumnFilter(queryParamString);
HttpService.makeCallToBackend({
path: `/process-instances/reports/columns`,
path: `/process-instances/reports/columns${queryParamString}`,
successCallback: setAvailableReportColumns,
});
}