From 6c0f41d177046f48e936c10d4251b007657426c6 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Wed, 23 Nov 2022 14:55:08 +0800 Subject: [PATCH] refactor(console): audit log table (#2485) --- .../AuditLogTable/index.module.scss | 15 +++++- .../src/components/AuditLogTable/index.tsx | 53 ++++++++++--------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/packages/console/src/components/AuditLogTable/index.module.scss b/packages/console/src/components/AuditLogTable/index.module.scss index 90cac4e27..27cfacd5d 100644 --- a/packages/console/src/components/AuditLogTable/index.module.scss +++ b/packages/console/src/components/AuditLogTable/index.module.scss @@ -2,8 +2,12 @@ .filter { display: flex; - justify-content: right; + justify-content: flex-end; align-items: center; + padding: _.unit(3); + border-bottom: 1px solid var(--color-divider); + background-color: var(--color-layer-1); + border-radius: 12px 12px 0 0; .title { color: var(--color-text-secondary); @@ -21,6 +25,15 @@ } } +.tableLayout { + display: flex; + flex-direction: column; + + .tableContainer { + border-top-left-radius: 0; + border-top-right-radius: 0; + } +} .pagination { margin-top: _.unit(4); diff --git a/packages/console/src/components/AuditLogTable/index.tsx b/packages/console/src/components/AuditLogTable/index.tsx index 95cf6ec8a..2c3857d74 100644 --- a/packages/console/src/components/AuditLogTable/index.tsx +++ b/packages/console/src/components/AuditLogTable/index.tsx @@ -1,6 +1,6 @@ import type { LogDto } from '@logto/schemas'; import { LogResult } from '@logto/schemas'; -import { conditionalString } from '@silverhand/essentials'; +import { conditional, conditionalString } from '@silverhand/essentials'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; @@ -27,6 +27,8 @@ type Props = { userId?: string; }; +const defaultTableColumn = 4; + const AuditLogTable = ({ userId }: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { pathname } = useLocation(); @@ -50,6 +52,7 @@ const AuditLogTable = ({ userId }: Props) => { const navigate = useNavigate(); const [logs, totalCount] = data ?? []; const showUserColumn = !userId; + const tableColumnCount = showUserColumn ? defaultTableColumn : defaultTableColumn - 1; const updateQuery = (key: string, value: string) => { const queries: Record = {}; @@ -67,28 +70,28 @@ const AuditLogTable = ({ userId }: Props) => { return ( <> -
-
{t('logs.filter_by')}
-
- { - updateQuery('event', value ?? ''); - }} - /> +
+
+
{t('logs.filter_by')}
+
+ { + updateQuery('event', value ?? ''); + }} + /> +
+
+ { + updateQuery('applicationId', value ?? ''); + }} + /> +
-
- { - updateQuery('applicationId', value ?? ''); - }} - /> -
-
-
-
- +
+
{showUserColumn && } @@ -106,13 +109,13 @@ const AuditLogTable = ({ userId }: Props) => { {!data && error && ( mutate(undefined, true)} /> )} - {isLoading && } - {logs?.length === 0 && } + {isLoading && } + {logs?.length === 0 && } {logs?.map(({ type, payload, createdAt, id }) => (