feat: workflow overhaul#1297
Conversation
…elated methods and types
…g and introducing WorkflowStatus model
…lowStatusId instead of id
…ntroducing CreateWorkflowConnection mutation
…rget status lookups
…vents table and updating related references
…usActionsOnConnection
…lowStructure method
…onsistency in workflow management
…efactoring IsProposalSubmittedGuard
…andling and refactoring related methods
…error for missing proposal workflow
… GuardFn and refactoring related guards
…ent metadata handling
…tatusConnectionId and refactor related properties
…authorization checks for proposal assignments
…orkflow migration scripts
… for proposal status filtering
Hi @ACLay . I have now normalized te database and removed the column |
ACLay
left a comment
There was a problem hiding this comment.
Given that we only seem to have the one state machine, and it seems designed to cover all our types of workflow, the "simple" in it's directory name seems unnecessary. Can we rename "simpleStateMachine" to just "stateMachine"?
ACLay
left a comment
There was a problem hiding this comment.
Read through to the end of /e2e
…uard for improved readability
…Mutations, experiment, and proposal files
…itorModel and usePersistWorkflowEditorModel
|
I haven't reviewed the code but this looks fantastic 👍 I was just getting this running locally and there are some workflow changes that STFC would need to make, where we have proposals in statuses that the workflows don't contain: -- Add SUBMITTED_LOCKED status to 'Import workflow'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(5, 15, 1, 1, 0);
-- Add SUBMITTED_LOCKED status to 'Import workflow for Xpress'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(92, 15, 1, 1, 0);
-- Add UNSUCCESSFUL status to 'Import workflow for Xpress'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(92, 20, 1, 1, 0);
-- Add FINISHED status to 'Import workflow for Xpress'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(92, 21, 1, 1, 0);
-- Add EXPIRED status to 'Import workflow'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(5, 9, 1, 1, 0);
-- Add EXPIRED status to 'ISIS Rapid workflow'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(4, 9, 1, 1, 0);
-- Add EXPIRED status to 'ISIS Xpress workflow'
INSERT INTO workflow_connections(workflow_id, status_id, pos_x, pos_y, sort_order)
VALUES(91, 9, 1, 1, 0);These statuses are all added to the workflows as unconnected and I don't see a problem with doing this. Automatic status changes (e.g. on proposal submission) are working for Xpress/Technique proposals and regular proposals, and status actions are being executed. But manual status changes are only partly working for Xpress/Technique proposals and regular proposals. The status is changing successfully but I'm seeing the below error and status actions are not being executed:
|
ACLay
left a comment
There was a problem hiding this comment.
Okay, initial readthrough complete.
ACLay
left a comment
There was a problem hiding this comment.
Starting to look over the changes made since I did my initial comments
|
|
||
| return reject(`Could not begin transaction: ${transactionError}`); | ||
| } | ||
| throw new Error(`Could not begin transaction: ${transactionError}`); |
There was a problem hiding this comment.
The first couple of reject calls were replaced with throw new GraphQLError(...), but from here it looks like they're replaced with throw new Error(...). Is that difference significant?
There was a problem hiding this comment.
This change is also not part of this Pull Request
ACLay
left a comment
There was a problem hiding this comment.
Okay, finished reading through all the changes since I started reviewing.
| @@ -0,0 +1,171 @@ | |||
| export function stripHtml(input: string): string { | |||
There was a problem hiding this comment.
This feels like we're writing our own xml/html parser, why do we need this?
There was a problem hiding this comment.
Hi, @ACLay, I'm sorry but this is not a change of this Pull Request. I am not sure why is it showing up here. Github bug?
About this changhe. Three weeks ago we were having some problems with this library due to depdendencies, and we decided to remove it completely as we were using only one function.
#1476
- Changed import paths in various guard files to reference the new stateMachine module. - Created new stateMachine module with necessary types and functions.
Yes, I think it makes sense. Thanks |
Hi, @TCMeldrum Regarding the status actions on manual changes there is another PR addressing it |
…chniqueProposalTable
Description
This PR
Motivation and Context
The current workflow management system has limitations and inefficiencies that are addressed by the introduction of new database structures. This change is required to enhance the system's performance and user experience.
State machine
This workflow overhaul aims to align the state changes of proposal to classical state machine behaviour. The implementation of abstract state machine can be found in

stateMachnine.ts. It matches the popularxStatelibrary interface just is much more simple.There are 5 main concepts in the state machine.
ER diagram of the new Workflow Data Structure
Entity Tables:
Transitionunder "State machine" section)Eventunder "State machine" section)Actionunder "State machine" section)Guardunder "State machine" section)Changes
This PR removes a lot of unneeded code in a way simplifying the implementation
Here are the main changes to pay attention when reviewing
Cleanup of the namings DefaultStatus and InitialStatus.
Initial statusis the status of the entity when it enters the workflow.DRAFTfor proposal andAWAITING_ESFfor safetyReview.Defaultstatusis status which system is aware of and is not created by user with through "Create status" button. These two namings were mixed and used interchangebly, but now they are separated.The table
proposal_eventsandexperiment_safety_eventshas been dropped and their alternative implementation has been implemented inguardswhich now checks if the condition is true during the transition. (see apps/backend/src/workflowEngine/guards/*.ts)2.1 There might be an important change for STFC. Since I have removed the
proposal_eventstable and along with it thisproposalEvents.proposal_all_fap_reviews_submitted. Since this is not available any more I have changed to check if all fap reviews are submited by inspecting the fap review table columns https://github.com/UserOfficeProject/user-office-core/pull/1297/changes#diff-f3b982a00651344db8c6516a09c950e0e30df0ac84e1cd543826a0d45875588eR209Statusprimary key now uses the semantic string statusId (formerly short_code), dropping the surrogate int. This removes number => string mapping in the code, and keeps IDs readable in logs/DB dumps and tables that reference status. This prevents mismatch bugs where int keys and short codes drifted. Migration 0205_RenameShortCodeToStatusId.sql rewires FK references across proposals/experiment_safety/workflow tables and reconstitutes dependent views.Operationally this makes debugging and API payloads self-describing and aligns status identity with the business identifier.
Status actions are now attached on transition. Before they were attached the status. This means, that if you change the status manually, the status action will not be run.
How Has This Been Tested?
Added and updated e2e tests
Fixes Jira Issue
https://jira.esss.lu.se/browse/SWAP-4949