-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Implement AWS profile loading and switching
Updated the profile navigation to fetch and display AWS profiles. Users can now select different AWS profiles from a dropdown menu. Furthermore, added a profile context to manage the current profile state at a global level. Additional dependencies were also included to facilitate these changes. Refs: #1
- Loading branch information
Showing
8 changed files
with
221 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
'use client'; | ||
|
||
import React, { | ||
createContext, | ||
PropsWithChildren, | ||
useContext, | ||
useMemo, | ||
} from 'react'; | ||
import useSWR, { Fetcher } from 'swr'; | ||
// see https://stackoverflow.com/a/77264549 | ||
import { invoke } from '@tauri-apps/api/tauri'; | ||
|
||
type ProfileContextType = { | ||
data: Record<string, unknown> | undefined; | ||
error: Error | undefined; | ||
isLoading: boolean; | ||
}; | ||
|
||
export const ProfileContext = createContext<ProfileContextType>({ | ||
data: undefined, | ||
error: undefined, | ||
isLoading: true, | ||
}); | ||
|
||
export const ProfileProvider = ({ children }: PropsWithChildren) => { | ||
const fetcher: Fetcher<Record<string, never>, string> = (cmd: string) => | ||
invoke<Record<string, never>>(cmd); | ||
const { data, error, isLoading } = useSWR<Record<string, never>, Error>( | ||
'get_profiles', | ||
fetcher | ||
); | ||
|
||
const value = useMemo( | ||
() => ({ data, error, isLoading }), | ||
[data, error, isLoading] | ||
); | ||
return ( | ||
<ProfileContext.Provider value={value}>{children}</ProfileContext.Provider> | ||
); | ||
}; | ||
|
||
export const useProfileContext = () => { | ||
const context = useContext(ProfileContext); | ||
|
||
if (!context) { | ||
throw new Error('useThemeContext must be used inside the ThemeProvider'); | ||
} | ||
|
||
return context; | ||
}; |
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,18 @@ | ||
'use client'; | ||
|
||
import useSWR, { Fetcher } from 'swr'; | ||
import { invoke } from '@tauri-apps/api/tauri'; // see https://stackoverflow.com/a/77264549 | ||
|
||
import { ProfileSet } from '@/modules/profiles/profile'; | ||
export const useProfile = () => { | ||
const fetcher: Fetcher<ProfileSet, string> = (cmd: string) => | ||
invoke<ProfileSet>(cmd); | ||
|
||
const { | ||
data: profileSet, | ||
error, | ||
isLoading, | ||
} = useSWR<ProfileSet>('get_profiles', fetcher); | ||
|
||
return { profileSet, error, isLoading }; | ||
}; |
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,3 @@ | ||
declare module 'secure-string' { | ||
export declare class SecureString {} | ||
} |