-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08f4f8a
commit 2241734
Showing
13 changed files
with
303 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
web/src/components/export-workflow-button/export-workflow-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import { useExportWorkflow } from "@/hooks/use-export-workflow"; | ||
import { useToast } from "@/providers/toast"; | ||
import { DownloadIcon } from "@radix-ui/react-icons"; | ||
import { Button } from "@radix-ui/themes"; | ||
import { useState } from "react"; | ||
|
||
export default function ExportWorkflowButton({ | ||
workflowId, | ||
}: { | ||
workflowId: string; | ||
}) { | ||
const [isDownloading, setIsDownloading] = useState(false); | ||
const exportWorkflow = useExportWorkflow(); | ||
const { errorToast } = useToast(); | ||
|
||
const handleExport = async () => { | ||
try { | ||
setIsDownloading(true); | ||
await exportWorkflow.mutateAsync({ workflowId }); | ||
} catch (error) { | ||
errorToast("Failed to export workflow. Please try again."); | ||
} finally { | ||
setIsDownloading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
variant="outline" | ||
style={{ cursor: "pointer" }} | ||
onClick={handleExport} | ||
loading={isDownloading} | ||
> | ||
Export <DownloadIcon /> | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"use client"; | ||
|
||
import { useImportWorkflow } from "@/hooks/use-import-workflow"; | ||
import { UploadIcon } from "@radix-ui/react-icons"; | ||
import { Flex, Text } from "@radix-ui/themes"; | ||
import { useCallback, useState } from "react"; | ||
|
||
interface FileUploadProps { | ||
fileType: string; | ||
} | ||
|
||
export default function FileUpload({ fileType }: FileUploadProps) { | ||
const { importWorkflow, errorMessage } = useImportWorkflow(); | ||
const [isDragging, setIsDragging] = useState(false); | ||
|
||
const onDragOver = useCallback((e: React.DragEvent<HTMLDivElement>) => { | ||
e.preventDefault(); | ||
setIsDragging(true); | ||
}, []); | ||
|
||
const onDragLeave = useCallback((e: React.DragEvent<HTMLDivElement>) => { | ||
e.preventDefault(); | ||
setIsDragging(true); | ||
}, []); | ||
|
||
const onDrop = useCallback( | ||
(e: React.DragEvent<HTMLDivElement>) => { | ||
e.preventDefault(); | ||
setIsDragging(false); | ||
|
||
const files = e.dataTransfer.files; | ||
if (files.length > 0) { | ||
const file = files[0]; | ||
importWorkflow(file); | ||
} | ||
}, | ||
[importWorkflow], | ||
); | ||
|
||
const handleFileInput = useCallback( | ||
(e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault(); | ||
const files = e.target.files; | ||
if (files && files.length > 0) { | ||
const file = files[0]; | ||
importWorkflow(file); | ||
} | ||
}, | ||
[importWorkflow], | ||
); | ||
|
||
return ( | ||
<Flex direction="column" gap="4"> | ||
<Flex | ||
onDragOver={onDragOver} | ||
onDragLeave={onDragLeave} | ||
onDrop={onDrop} | ||
className={`relative border-2 border-dashed rounded-lg p-8 text-center | ||
${isDragging ? "border-blue-500 bg-blue-50" : "border-gray-300 hover:border-gray-400"} | ||
transition-colors duration-200 ease-in-out`} | ||
direction="column" | ||
> | ||
<input | ||
type="file" | ||
onChange={handleFileInput} | ||
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer" | ||
/> | ||
|
||
<Flex direction="column" gap="4"> | ||
<Flex justify="center" width="100%"> | ||
<UploadIcon color="gray" height={32} width={32} /> | ||
</Flex> | ||
<Text> | ||
<Text color="blue">Click to upload</Text> or drag and | ||
drop {fileType} | ||
</Text> | ||
</Flex> | ||
</Flex> | ||
{errorMessage && <Text color="red">{errorMessage}</Text>} | ||
</Flex> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
export function useExportWorkflow() { | ||
return useMutation({ | ||
mutationFn: async ({ workflowId }: { workflowId: string }) => { | ||
const response = await fetch( | ||
`/api/v1/workflows/export/${workflowId}`, | ||
); | ||
if (!response.ok) { | ||
throw new Error("Failed to export workflow."); | ||
} | ||
|
||
const blob = await response.blob(); | ||
const url = window.URL.createObjectURL(blob); | ||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = `${workflowId}.yaml`; | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.