-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from Tauffer-Consulting/feature/workflows_gal…
…lery Feature/external workflows gallery
- Loading branch information
Showing
3 changed files
with
119 additions
and
43 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
frontend/src/features/workflowEditor/api/workflowsExample/getWorkflowExamples.ts
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,59 @@ | ||
import axios from "axios"; | ||
import { type IWorkflowPieceData } from "features/workflowEditor/context/types"; | ||
import { type Edge, type Node } from "reactflow"; | ||
import useSWR from "swr"; | ||
|
||
const REPO_URL = | ||
"https://raw.githubusercontent.com/Tauffer-Consulting/domino_pieces_gallery/main/workflows_gallery"; | ||
|
||
const getWorkflowsExampleUrl = `${REPO_URL}/index.json`; | ||
|
||
type GithubReposContent = Array<{ | ||
title: string; | ||
description: string; | ||
jsonFile: string; | ||
levelTag: "Advanced" | "Beginner" | "Intermediate"; | ||
}>; | ||
|
||
interface JSONFile { | ||
workflowPieces: Record<string, Piece>; | ||
workflowPiecesData: IWorkflowPieceData; | ||
workflowNodes: Node[]; | ||
workflowEdges: Edge[]; | ||
} | ||
|
||
export type WorkflowsGalleryExamples = Array<{ | ||
title: string; | ||
description: string; | ||
jsonFile: JSONFile; | ||
levelTag: "Advanced" | "Beginner" | "Intermediate"; | ||
}>; | ||
|
||
const getWorkflowsExample: () => Promise<WorkflowsGalleryExamples> = | ||
async () => { | ||
const { data } = await axios.get<GithubReposContent>( | ||
getWorkflowsExampleUrl, | ||
); | ||
const jsons: WorkflowsGalleryExamples = []; | ||
for (const value of data) { | ||
const { data: json } = await axios.get<JSONFile>( | ||
`${REPO_URL}/${value.jsonFile}`, | ||
); | ||
jsons.push({ ...value, jsonFile: json }); | ||
} | ||
|
||
return jsons; | ||
}; | ||
|
||
export const useAuthenticatedGetWorkflowsExamples = (fetch: boolean) => { | ||
const fetcher = async () => await getWorkflowsExample().then((data) => data); | ||
|
||
return useSWR( | ||
fetch ? getWorkflowsExampleUrl : null, | ||
async () => await fetcher(), | ||
{ | ||
revalidateOnFocus: false, | ||
revalidateOnReconnect: false, | ||
}, | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
frontend/src/features/workflowEditor/api/workflowsExample/index.ts
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 @@ | ||
export * from "./getWorkflowExamples"; |
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