From d4a0c161c58f1ccf991b5ec0a7a4e01980b61ce1 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 4 Jun 2024 17:53:24 -0300 Subject: [PATCH] Added table renderer on API Keys page --- .../components/tableAutoCellRender/index.tsx | 1 + src/frontend/src/pages/ApiKeysPage/index.tsx | 287 ++++++++++-------- src/frontend/src/utils/utils.ts | 6 +- 3 files changed, 164 insertions(+), 130 deletions(-) diff --git a/src/frontend/src/components/tableAutoCellRender/index.tsx b/src/frontend/src/components/tableAutoCellRender/index.tsx index 21b598dd2..d38e55a9d 100644 --- a/src/frontend/src/components/tableAutoCellRender/index.tsx +++ b/src/frontend/src/components/tableAutoCellRender/index.tsx @@ -24,6 +24,7 @@ export default function TableAutoCellRender({ } break; case "string": + console.log(isTimeStampString(value), value); if (isTimeStampString(value)) { return ; } diff --git a/src/frontend/src/pages/ApiKeysPage/index.tsx b/src/frontend/src/pages/ApiKeysPage/index.tsx index 49f38715e..c971042d0 100644 --- a/src/frontend/src/pages/ApiKeysPage/index.tsx +++ b/src/frontend/src/pages/ApiKeysPage/index.tsx @@ -30,6 +30,8 @@ import { } from "../../constants/constants"; import useAlertStore from "../../stores/alertStore"; import { ApiKey } from "../../types/components"; +import TableComponent from "../../components/tableComponent"; +import TableAutoCellRender from "../../components/tableAutoCellRender"; export default function ApiKeysPage() { const [loadingKeys, setLoadingKeys] = useState(true); @@ -48,7 +50,10 @@ export default function ApiKeysPage() { if (userData) { getApiKey() .then((keys: [ApiKey]) => { - keysList.current = keys["api_keys"]; + keysList.current = keys["api_keys"].map((apikey: ApiKey) => ({ + ...apikey, + last_used_at: apikey.last_used_at ?? "Never", + })); setUserId(keys["user_id"]); setLoadingKeys(false); }) @@ -89,6 +94,26 @@ export default function ApiKeysPage() { ); } + const columnDefs = [ + { headerName: "Name", field: "name", cellRenderer: TableAutoCellRender }, + { headerName: "Key", field: "api_key", cellRenderer: TableAutoCellRender }, + { + headerName: "Created", + field: "created_at", + cellRenderer: TableAutoCellRender, + }, + { + headerName: "Last Used", + field: "last_used_at", + cellRenderer: TableAutoCellRender, + }, + { + headerName: "Total Uses", + field: "total_uses", + cellRenderer: TableAutoCellRender, + }, + ]; + return ( <>
@@ -128,141 +153,147 @@ export default function ApiKeysPage() { )}
{keysList.current && keysList.current.length > 0 && !loadingKeys && ( - - - - Name - Key - Created - - Last Used - -
- -
-
-
- Total Uses - -
-
- {!loadingKeys && ( - - {keysList.current.map( - (api_keys: ApiKey, index: number) => ( - - - - - {api_keys.name ? api_keys.name : "-"} - - - - - - {api_keys.api_key} - - - - -
- {moment(api_keys.created_at).format( - "YYYY-MM-DD HH:mm" - )} -
-
-
- - -
- {moment(api_keys.last_used_at).format( - "YYYY-MM-DD HH:mm" - ) === "Invalid date" - ? "Never" - : moment( - api_keys.last_used_at - ).format("YYYY-MM-DD HH:mm")} -
-
-
- - {api_keys.total_uses} - - -
- { - handleDeleteKey(keys); - }} - > - - - Are you sure you want to delete - this key? This action cannot be - undone. - - - - - - -
-
-
- ) - )} -
- )} -
+ <> + + )}
- + {/* + + + Name + Key + Created + + Last Used + +
+ +
+
+
+ Total Uses + +
+
+ {!loadingKeys && ( + + {keysList.current.map( + (api_keys: ApiKey, index: number) => ( + + + + + {api_keys.name ? api_keys.name : "-"} + + + + + + {api_keys.api_key} + + + + +
+ {moment(api_keys.created_at).format( + "YYYY-MM-DD HH:mm" + )} +
+
+
+ + +
+ {moment(api_keys.last_used_at).format( + "YYYY-MM-DD HH:mm" + ) === "Invalid date" + ? "Never" + : moment( + api_keys.last_used_at + ).format("YYYY-MM-DD HH:mm")} +
+
+
+ + {api_keys.total_uses} + + +
+ { + handleDeleteKey(keys); + }} + > + + + Are you sure you want to delete + this key? This action cannot be + undone. + + + + + + +
+
+
+ ) + )} +
+ )} +
*/}