forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: api keys API (langflow-ai#2652)
* feat: create useDeleteApiKey hook to handle api keys delete * refactor: use mutation to handle delete api key * [autofix.ci] apply automated fixes * feat: create useGetApiKeys hook * refactor: use useGetApiKeysQuery hook to get api keys data * [autofix.ci] apply automated fixes * refactor: change interface name * refactor: remove unnused loading state and use react state instead of react ref to ensure component render * fix: multiple refreshs when auto_login=false --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cffed2c
commit 6fa3c7b
Showing
7 changed files
with
136 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "./use-delete-api-key"; | ||
export * from "./use-get-api-keys"; | ||
export * from "./use-post-add-api-key"; |
24 changes: 24 additions & 0 deletions
24
src/frontend/src/controllers/API/queries/api-keys/use-delete-api-key.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,24 @@ | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
interface IDeleteApiKey { | ||
keyId: string; | ||
} | ||
|
||
// add types for error handling and success | ||
export const useDeleteApiKey: useMutationFunctionType<IDeleteApiKey> = ( | ||
options, | ||
) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const deleteApiKeyFn = async (payload: IDeleteApiKey): Promise<any> => { | ||
const res = await api.delete(`${getURL("API_KEY")}/${payload.keyId}`); | ||
return res.data; | ||
}; | ||
|
||
const mutation = mutate(["useDeleteApiKey"], deleteApiKeyFn, options); | ||
|
||
return mutation; | ||
}; |
42 changes: 42 additions & 0 deletions
42
src/frontend/src/controllers/API/queries/api-keys/use-get-api-keys.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,42 @@ | ||
import { useDarkStore } from "@/stores/darkStore"; | ||
import { useQueryFunctionType } from "@/types/api"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
export interface IApiKeysDataArray { | ||
name: string; | ||
last_used_at: string | null; | ||
total_uses: number; | ||
is_active: boolean; | ||
id: string; | ||
api_key: string; | ||
user_id: string; | ||
created_at: string; | ||
} | ||
|
||
interface IApiQueryResponse { | ||
total_count: number; | ||
user_id: string; | ||
api_keys: Array<IApiKeysDataArray>; | ||
} | ||
|
||
export const useGetApiKeysQuery: useQueryFunctionType< | ||
undefined, | ||
IApiQueryResponse | ||
> = (_, options) => { | ||
const { query } = UseRequestProcessor(); | ||
|
||
const getApiKeysFn = async () => { | ||
return await api.get<IApiQueryResponse>(`${getURL("API_KEY")}/`); | ||
}; | ||
|
||
const responseFn = async () => { | ||
const { data } = await getApiKeysFn(); | ||
return data; | ||
}; | ||
|
||
const queryResult = query(["useGetApiKeysQuery"], responseFn, { ...options }); | ||
|
||
return queryResult; | ||
}; |
32 changes: 0 additions & 32 deletions
32
src/frontend/src/pages/SettingsPage/pages/ApiKeysPage/hooks/use-api-keys.tsx
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
src/frontend/src/pages/SettingsPage/pages/ApiKeysPage/hooks/use-handle-delete-key.tsx
This file was deleted.
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