diff --git a/frontend/src/components/action-node.tsx b/frontend/src/components/action-node.tsx index bb048f84d..e4e44cba3 100644 --- a/frontend/src/components/action-node.tsx +++ b/frontend/src/components/action-node.tsx @@ -64,9 +64,9 @@ export default React.memo(function ActionNode({ data: { type, title, status, isConfigured, numberOfEvents }, }: NodeProps) { - const statusCapitalized = status[0].toUpperCase() + status.slice(1); const avatarImageAlt = `${type}-${title}`; const tileIcon = tileIconMapping[type]; + const isConfiguredMessage = isConfigured ? "ready" : "missing inputs"; return ( @@ -106,21 +106,21 @@ export default React.memo(function ActionNode({
{status === "online" && ( - + )} {status === 'offline' && ( )} - {statusCapitalized} + {status}
{isConfigured && ( - + )} {!isConfigured && ( )} - {statusCapitalized} + {isConfiguredMessage}
diff --git a/frontend/src/components/forms/action.tsx b/frontend/src/components/forms/action.tsx index 4db3eca36..8965cc04b 100644 --- a/frontend/src/components/forms/action.tsx +++ b/frontend/src/components/forms/action.tsx @@ -173,7 +173,6 @@ export function ActionForm({ actionId, actionType }: ActionFormProps): React.JSX setStatus(status); } }, [data, form.reset]); - const statusCapitalized = status[0].toUpperCase() + status.slice(1); // Submit form and update Action async function updateAction(actionId: string, values: actionFormSchemaType) { @@ -201,6 +200,19 @@ export function ActionForm({ actionId, actionType }: ActionFormProps): React.JSX // Configure your mutation behavior here onSuccess: (data, variables, context) => { console.log("Action update successful", data); + setNodes((nds: Node[]) => + nds.map((node: Node) => { + if (node.id === actionId) { + node.data = { + ...node.data, + title: data.title, + status: data.status, + isConfigured: data.inputs ? true : false, + }; + } + return node; + }) + ); }, onError: (error, variables, context) => { console.error("Failed to update action:", error); @@ -213,20 +225,7 @@ export function ActionForm({ actionId, actionType }: ActionFormProps): React.JSX const { mutate } = useUpdateAction(actionId); function onSubmit(values: actionFormSchemaType) { - // Execute the mutate operation - mutate(values); - // Directly update the nodes after calling mutate, assuming mutate triggers the changes you need - setNodes((nds: Node[]) => - nds.map((node: Node) => { - if (node.id === actionId) { - node.data = { - ...node.data, - title: values.title, - }; - } - return node; - }) - ); + mutate(values) } // Loading state to defend in a user friendly way @@ -253,7 +252,7 @@ export function ActionForm({ actionId, actionType }: ActionFormProps): React.JSX
- {statusCapitalized} + {status} diff --git a/frontend/src/components/forms/workflow.tsx b/frontend/src/components/forms/workflow.tsx index 9e8d7208a..6074c3a31 100644 --- a/frontend/src/components/forms/workflow.tsx +++ b/frontend/src/components/forms/workflow.tsx @@ -37,8 +37,6 @@ interface WorkflowFormProps { export function WorkflowForm({ workflowId, workflowTitle, workflowDescription, workflowStatus }: WorkflowFormProps): React.JSX.Element { - const statusCapitalized = workflowStatus[0].toUpperCase() + workflowStatus.slice(1); - const form = useForm>({ resolver: zodResolver(workflowFormSchema), defaultValues: { @@ -82,7 +80,7 @@ export function WorkflowForm({ workflowId, workflowTitle, workflowDescription, w
- {statusCapitalized} + {workflowStatus} diff --git a/tracecat/api.py b/tracecat/api.py index 770f37ec3..fef0d2325 100644 --- a/tracecat/api.py +++ b/tracecat/api.py @@ -267,8 +267,8 @@ class UpdateActionParams(BaseModel): inputs: str | None = None -@app.post("/actions/{action_id}", status_code=204) -def update_action(action_id: str, params: UpdateActionParams) -> None: +@app.post("/actions/{action_id}") +def update_action(action_id: str, params: UpdateActionParams) -> ActionResponse: with Session(create_db_engine()) as session: # Fetch the action by id statement = select(Action).where(Action.id == action_id) @@ -286,6 +286,15 @@ def update_action(action_id: str, params: UpdateActionParams) -> None: session.add(action) session.commit() + session.refresh(action) + + return ActionResponse( + id=action.id, + title=action.title, + description=action.description, + status=action.status, + inputs=json.loads(action.inputs) if action.inputs else None, + ) @app.delete("/actions/{action_id}", status_code=204)