From bc4e4758092b802789945a211f2e09a0791408ca Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Thu, 7 Sep 2023 11:13:27 -0400 Subject: [PATCH] when we replace variables in enum list in jsonschema ensure it is actually a non-empty list w/ burnettk (#455) Co-authored-by: jasquat --- .../routes/tasks_controller.py | 18 ++++++++++++++++++ .../src/routes/TaskShow.tsx | 19 +++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 3d25391c..144658d3 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -932,6 +932,24 @@ def _update_form_schema_with_task_data_as_needed(in_dict: dict, task_model: Task ) select_options_from_task_data = task_model.data.get(task_data_var) + if select_options_from_task_data == []: + raise ApiError( + error_code="invalid_form_data", + message=( + "This form depends on variables, but at least one variable was empty. The" + f" variable '{task_data_var}' must be a list with at least one element." + ), + status_code=500, + ) + if isinstance(select_options_from_task_data, str): + raise ApiError( + error_code="invalid_form_data", + message=( + "This form depends on enum variables, but at least one variable was a string." + f" The variable '{task_data_var}' must be a list with at least one element." + ), + status_code=500, + ) if isinstance(select_options_from_task_data, list): if all("value" in d and "label" in d for d in select_options_from_task_data): diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 0366a5d9..007a45a5 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -12,7 +12,12 @@ import { modifyProcessIdentifierForPathParam, recursivelyChangeNullAndUndefined, } from '../helpers'; -import { BasicTask, EventDefinition, Task } from '../interfaces'; +import { + BasicTask, + ErrorForDisplay, + EventDefinition, + Task, +} from '../interfaces'; import CustomForm from '../components/CustomForm'; import ProcessBreadcrumb from '../components/ProcessBreadcrumb'; import InstructionsForEndUser from '../components/InstructionsForEndUser'; @@ -36,6 +41,8 @@ export default function TaskShow() { const [taskData, setTaskData] = useState(null); const [autosaveOnFormChanges, setAutosaveOnFormChanges] = useState(true); + const [atLeastOneTaskFetchHasError, setAtLeastOneTaskFetchHasError] = + useState(false); const { addError, removeError } = useAPIError(); @@ -68,16 +75,20 @@ export default function TaskShow() { setTaskData(recursivelyChangeNullAndUndefined(taskDataToUse, undefined)); setFormButtonsDisabled(false); }; + const handleTaskFetchError = (error: ErrorForDisplay) => { + setAtLeastOneTaskFetchHasError(true); + addError(error); + }; HttpService.makeCallToBackend({ path: `/tasks/${params.process_instance_id}/${params.task_id}`, successCallback: processBasicTaskResult, - failureCallback: addError, + failureCallback: handleTaskFetchError, }); HttpService.makeCallToBackend({ path: `/tasks/${params.process_instance_id}/${params.task_id}?with_form_data=true`, successCallback: processTaskWithDataResult, - failureCallback: addError, + failureCallback: handleTaskFetchError, }); // FIXME: not sure what to do about addError. adding it to this array causes the page to endlessly reload // eslint-disable-next-line react-hooks/exhaustive-deps @@ -387,7 +398,7 @@ export default function TaskShow() { } else if (basicTask && taskData) { pageElements.push(); pageElements.push(formElement()); - } else { + } else if (!atLeastOneTaskFetchHasError) { pageElements.push(getLoadingIcon()); }