-
Notifications
You must be signed in to change notification settings - Fork 5
feat: implement use toast mutation for workspaces #184
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2cf621
feat: useKbdShortcuts hook & example implementation
alex-mcgovern 9973939
chore: tidy up remnant
alex-mcgovern 567767f
Merge branch 'main' of github.com:stacklok/codegate-ui into feat/use-…
alex-mcgovern 13249e9
feat: useToastMutation hook
alex-mcgovern 343c342
chore: remove junk comment
alex-mcgovern 3796ddd
feat: implement `useToastMutation` for workspaces
alex-mcgovern 0229a15
Merge branch 'main' of github.com:stacklok/codegate-ui into feat/impl…
alex-mcgovern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
14 changes: 11 additions & 3 deletions
14
src/features/workspace/hooks/use-archive-workspace-button.tsx
This file contains hidden or 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 was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/features/workspace/hooks/use-invalidate-workspace-queries.ts
This file contains hidden or 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,23 @@ | ||
import { | ||
v1ListArchivedWorkspacesQueryKey, | ||
v1ListWorkspacesOptions, | ||
} from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useCallback } from "react"; | ||
|
||
export function useInvalidateWorkspaceQueries() { | ||
const queryClient = useQueryClient(); | ||
|
||
const invalidate = useCallback(() => { | ||
queryClient.invalidateQueries({ | ||
queryKey: v1ListWorkspacesOptions(), | ||
refetchType: "all", | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: v1ListArchivedWorkspacesQueryKey(), | ||
refetchType: "all", | ||
}); | ||
}, [queryClient]); | ||
|
||
return invalidate; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/features/workspace/hooks/use-mutation-activate-workspace.ts
This file contains hidden or 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,13 @@ | ||
import { v1ActivateWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useToastMutation as useToastMutation } from "@/hooks/use-toast-mutation"; | ||
import { useInvalidateWorkspaceQueries } from "./use-invalidate-workspace-queries"; | ||
|
||
export function useMutationActivateWorkspace() { | ||
const invalidate = useInvalidateWorkspaceQueries(); | ||
|
||
return useToastMutation({ | ||
...v1ActivateWorkspaceMutation(), | ||
onSuccess: () => invalidate(), | ||
successMsg: (variables) => `Activated "${variables.body.name}" workspace`, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/features/workspace/hooks/use-mutation-archive-workspace.ts
This file contains hidden or 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,14 @@ | ||
import { v1DeleteWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useToastMutation } from "@/hooks/use-toast-mutation"; | ||
import { useInvalidateWorkspaceQueries } from "./use-invalidate-workspace-queries"; | ||
|
||
export function useMutationArchiveWorkspace() { | ||
const invalidate = useInvalidateWorkspaceQueries(); | ||
|
||
return useToastMutation({ | ||
...v1DeleteWorkspaceMutation(), | ||
onSuccess: () => invalidate(), | ||
successMsg: (variables) => | ||
`Archived "${variables.path.workspace_name}" workspace`, | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/features/workspace/hooks/use-mutation-create-workspace.ts
This file contains hidden or 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,13 @@ | ||
import { v1CreateWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useInvalidateWorkspaceQueries } from "./use-invalidate-workspace-queries"; | ||
import { useToastMutation } from "@/hooks/use-toast-mutation"; | ||
|
||
export function useMutationCreateWorkspace() { | ||
const invalidate = useInvalidateWorkspaceQueries(); | ||
|
||
return useToastMutation({ | ||
...v1CreateWorkspaceMutation(), | ||
onSuccess: () => invalidate(), | ||
successMsg: (variables) => `Created "${variables.body.name}" workspace`, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/features/workspace/hooks/use-mutation-hard-delete-workspace.ts
This file contains hidden or 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,14 @@ | ||
import { v1HardDeleteWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useToastMutation } from "@/hooks/use-toast-mutation"; | ||
import { useInvalidateWorkspaceQueries } from "./use-invalidate-workspace-queries"; | ||
|
||
export function useMutationHardDeleteWorkspace() { | ||
const invalidate = useInvalidateWorkspaceQueries(); | ||
|
||
return useToastMutation({ | ||
...v1HardDeleteWorkspaceMutation(), | ||
onSuccess: () => invalidate(), | ||
successMsg: (variables) => | ||
`Permanently deleted "${variables.path.name}" workspace`, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/features/workspace/hooks/use-mutation-restore-workspace.ts
This file contains hidden or 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,14 @@ | ||
import { v1RecoverWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; | ||
import { useToastMutation } from "@/hooks/use-toast-mutation"; | ||
import { useInvalidateWorkspaceQueries } from "./use-invalidate-workspace-queries"; | ||
|
||
export function useMutationRestoreWorkspace() { | ||
const invalidate = useInvalidateWorkspaceQueries(); | ||
|
||
return useToastMutation({ | ||
...v1RecoverWorkspaceMutation(), | ||
onSuccess: () => invalidate(), | ||
successMsg: (variables) => | ||
`Restored "${variables.path.workspace_name}" workspace`, | ||
}); | ||
} |
6 changes: 3 additions & 3 deletions
6
src/features/workspace/hooks/use-restore-workspace-button.tsx
This file contains hidden or 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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Button } from "@stacklok/ui-kit"; | ||
import { ComponentProps } from "react"; | ||
import { useRestoreWorkspace } from "./use-restore-workspace"; | ||
import { useMutationRestoreWorkspace } from "./use-mutation-restore-workspace"; | ||
|
||
export function useRestoreWorkspaceButton({ | ||
workspaceName, | ||
}: { | ||
workspaceName: string; | ||
}): ComponentProps<typeof Button> { | ||
const { mutate, isPending } = useRestoreWorkspace(); | ||
const { mutateAsync, isPending } = useMutationRestoreWorkspace(); | ||
|
||
return { | ||
isPending, | ||
isDisabled: isPending, | ||
onPress: () => mutate({ path: { workspace_name: workspaceName } }), | ||
onPress: () => mutateAsync({ path: { workspace_name: workspaceName } }), | ||
children: "Restore", | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
❤️