Skip to content

Commit

Permalink
[JN-565] fix trigger editing for inactive triggers (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlbark authored Dec 11, 2024
1 parent a6d4fb7 commit 8c8faf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public Trigger replace(PortalStudyEnvAuthContext authContext, UUID configId, Tri

Trigger existing = triggerService.find(configId).get();
verifyTrigger(authContext, existing);
if (!existing.isActive()) {
throw new IllegalArgumentException("Cannot edit inactive trigger");
}

Trigger newConfig = create(update, authContext.getStudyEnvironment(), portalEnvironment);
// after creating the new config, deactivate the old config
Expand Down Expand Up @@ -186,6 +189,10 @@ private void verifyTrigger(PortalStudyEnvAuthContext authContext, Trigger config

private Trigger create(
Trigger newConfig, StudyEnvironment studyEnvironment, PortalEnvironment portalEnvironment) {
if (!newConfig.isActive()) {
throw new IllegalArgumentException("Cannot create inactive trigger");
}

newConfig.cleanForCopying();
newConfig.setStudyEnvironmentId(studyEnvironment.getId());
newConfig.setPortalEnvironmentId(portalEnvironment.getId());
Expand Down
17 changes: 15 additions & 2 deletions ui-admin/src/study/notifications/TriggerDesigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export const TriggerDesigner = (
}

return <div>
{!workingTrigger.active &&
<div className="alert alert-warning mt-0">
This trigger is no longer active. Inactive triggers cannot be edited.
</div>}

<TriggerDesignerEditor
studyEnvContext={studyEnvContext}
Expand All @@ -93,8 +97,17 @@ export const TriggerDesigner = (
/>

<div className="d-flex justify-content-center mt-2">
<button type="button" className="btn btn-primary" onClick={saveConfig}>Save</button>
<button type="button" className="btn btn-danger ms-4" onClick={() => setShowDeleteModal(true)}>Delete</button>
<button type="button" className="btn btn-primary" disabled={!workingTrigger.active} onClick={saveConfig}>
Save
</button>
<button
type="button"
className="btn btn-danger ms-4"
disabled={!workingTrigger.active}
onClick={() => setShowDeleteModal(true)}
>
Delete
</button>
</div>

{showDeleteModal && (
Expand Down
2 changes: 1 addition & 1 deletion ui-admin/src/study/notifications/TriggerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function TriggerList({ studyEnvContext, portalContext }:
</li> }
</ul>
</div> }
<div className="flex-grow-1 bg-white p-3">
<div className="flex-grow-1 bg-white px-3">
<Routes>
<Route path="triggers/:triggerId"
element={<TriggerDesigner studyEnvContext={studyEnvContext}
Expand Down

0 comments on commit 8c8faf2

Please sign in to comment.