-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): saving workflow doesn't refresh cache (#3336)
- Loading branch information
Showing
8 changed files
with
88 additions
and
21 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
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,34 @@ | ||
import useSWR, { mutate } from "swr"; | ||
import { useApi } from "@/shared/lib/hooks/useApi"; | ||
import { Workflow } from "@/shared/api/workflows"; | ||
|
||
export function useWorkflowDetail(workflowId: string, initialData?: Workflow) { | ||
const api = useApi(); | ||
|
||
const workflowKey = `/workflows/${workflowId}`; | ||
|
||
const { | ||
data: workflow, | ||
error, | ||
isLoading, | ||
} = useSWR<Workflow>( | ||
api.isReady() ? workflowKey : null, | ||
(url: string) => api.get(url), | ||
{ | ||
fallbackData: initialData, | ||
} | ||
); | ||
|
||
const mutateWorkflowDetail = async () => { | ||
await mutate(workflowKey); | ||
// Also mutate the workflows list if it exists in the cache | ||
await mutate("/workflows?is_v2=true"); | ||
}; | ||
|
||
return { | ||
workflow, | ||
isLoading, | ||
error, | ||
mutateWorkflowDetail, | ||
}; | ||
} |
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,25 @@ | ||
import useSWR, { mutate } from "swr"; | ||
import { useApi } from "@/shared/lib/hooks/useApi"; | ||
import { Workflow } from "@/shared/api/workflows"; | ||
|
||
const WORKFLOWS_KEY = "/workflows?is_v2=true"; | ||
|
||
export function useWorkflowsV2() { | ||
const api = useApi(); | ||
|
||
const { data, error, isLoading } = useSWR<Workflow[]>( | ||
api.isReady() ? WORKFLOWS_KEY : null, | ||
(url: string) => api.get(url) | ||
); | ||
|
||
const mutateWorkflows = () => { | ||
return mutate(WORKFLOWS_KEY); | ||
}; | ||
|
||
return { | ||
workflows: data, | ||
isLoading, | ||
error, | ||
mutateWorkflows, | ||
}; | ||
} |
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