-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Secrets list as dropdown from existing secrets and frontend warnings for deleted secrets #37
Changes from 15 commits
40321e7
32e7fc5
e65deca
371a375
5f87f24
8955122
13deda5
95bd9ed
e16ef49
25ed337
3b631ff
da9bb9c
faadc26
8cd605f
f9cd92b
4b59595
32e10d4
013e8ae
ad89e44
df638cd
4f62392
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
"use client"; | ||
|
||
import { useGetWorkflowApi } from "@/hooks/use-get-workflow-api"; | ||
import { useListSecretsApi } from "@/hooks/use-list-credentials-api"; | ||
import { useListEditorActionsApi } from "@/hooks/use-list-editor-actions-api"; | ||
import { useEditorActionStore } from "@/stores/editor-action-store"; | ||
import { useWorkflowStore } from "@/stores/workflow-store"; | ||
import { useSecretsStore } from "@/stores/secrets-store"; | ||
import { Box, Flex, Grid, Tabs, Text } from "@radix-ui/themes"; | ||
import Link from "next/link"; | ||
import { useEffect, useState } from "react"; | ||
|
@@ -36,9 +38,11 @@ export default function WorkflowEditor({ | |
|
||
const [view, setView] = useState<View>("workflowBuilder"); | ||
|
||
const { isNew, setWorkflow, clearWorkflowStore } = useWorkflowStore(); | ||
const { isNew, setWorkflow, clearWorkflowStore, addDeletedSecrets } = | ||
useWorkflowStore(); | ||
const { setEditorActions } = useEditorActionStore(); | ||
const { errorToast } = useToast(); | ||
const { setSecrets, clear } = useSecretsStore(); | ||
|
||
// Loading Actions | ||
const { | ||
|
@@ -56,6 +60,15 @@ export default function WorkflowEditor({ | |
} | ||
}, [editorActions, setEditorActions, editActionsError]); | ||
|
||
const { data: encryptedSecrets } = useListSecretsApi(); | ||
|
||
useEffect(() => { | ||
if (encryptedSecrets) { | ||
setSecrets(encryptedSecrets); | ||
return () => clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should rename |
||
} | ||
}, [encryptedSecrets, setSecrets, clear]); | ||
|
||
// Load Workflow | ||
// Note: we only load from the DB if the workflow is not newly created | ||
const { | ||
|
@@ -98,6 +111,36 @@ export default function WorkflowEditor({ | |
router, | ||
]); | ||
|
||
useEffect(() => { | ||
if (!workflow || !encryptedSecrets) { | ||
return; | ||
} | ||
const secretIds = new Set(encryptedSecrets.map((s) => s.secretId)); | ||
const missingSecrets = workflow?.nodes | ||
.filter((node) => node.type === "action") | ||
.reduce((acc, node) => { | ||
const secretsMapping = node.secretsMapping; | ||
const secretsForNode = Object.keys(secretsMapping); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
secretsForNode.forEach((secretPlaceholder) => { | ||
if (!secretIds.has(secretsMapping[secretPlaceholder])) { | ||
if (!acc.has(node.id)) { | ||
acc.set(node.id, new Set()); | ||
} | ||
acc.get(node.id)?.add(secretPlaceholder); | ||
} | ||
}); | ||
return acc; | ||
}, new Map<string, Set<string>>()); | ||
if (missingSecrets) { | ||
addDeletedSecrets(missingSecrets); | ||
} | ||
if (missingSecrets && missingSecrets.size > 0) { | ||
errorToast( | ||
"Some secrets are missing. Please add them before running the workflow.", | ||
); | ||
} | ||
}, [encryptedSecrets, workflow, addDeletedSecrets]); | ||
|
||
// TODO(frontend): nicer loading screen | ||
if (isLoadingEditorActions || (!isNew && isLoadingWorkflow)) { | ||
return <Box>Loading...</Box>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,12 @@ class WorkflowValidationError extends Error { | |
} | ||
|
||
interface SaveWorkflowContextType { | ||
saveWorkflow: () => Promise<void>; | ||
saveWorkflow: () => Promise<boolean>; | ||
isPending: boolean; | ||
} | ||
|
||
const SaveWorkflowContext = createContext<SaveWorkflowContextType>({ | ||
saveWorkflow: async () => {}, | ||
saveWorkflow: async () => false, | ||
isPending: false, | ||
}); | ||
|
||
|
@@ -42,7 +42,7 @@ export function SaveWorkflowProvider({ | |
|
||
const handleSaveWorkflow = async () => { | ||
if (isPending) { | ||
return; | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix workflow name validation control flow. The workflow name validation check doesn't return early, allowing invalid workflows to proceed with the save operation. This could lead to inconsistent state. Apply this fix: if (!isValidWorkflowName(workflow.workflowName)) {
errorToast(WORKFLOW_NAME_VALIDATION_ERROR_MESSAGE);
+ return false;
} Also applies to: 59-59, 60-60, 61-61, 62-62 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is okay to remove the if-condition. It is probably more dangerous to return |
||
} | ||
setIsPending(true); | ||
|
||
|
@@ -60,7 +60,6 @@ export function SaveWorkflowProvider({ | |
} | ||
if (!isValidWorkflowName(workflow.workflowName)) { | ||
errorToast(WORKFLOW_NAME_VALIDATION_ERROR_MESSAGE); | ||
return; | ||
} | ||
|
||
// Make sure that we only save args which are present in the current | ||
|
@@ -102,6 +101,7 @@ export function SaveWorkflowProvider({ | |
if (webhookId && webhookSecret) { | ||
updateWebhookIdAndSecret(webhookId, webhookSecret); | ||
} | ||
return true; | ||
} catch (error) { | ||
if ( | ||
error instanceof AxiosError && | ||
|
@@ -115,6 +115,7 @@ export function SaveWorkflowProvider({ | |
} else { | ||
errorToast("Failed to save workflow. Please try again."); | ||
} | ||
return false; | ||
} finally { | ||
setIsPending(false); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the component has props for doing what you want (text color, font weight), then please use this instead of using tailwindcss. You can just do
<Text color="red" weight="medium">
for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
<Flex>
has props for margin top:<Flex mt="2">
.