From 009ba601ef9ca2015fbe43eab5dd0b639fb558a3 Mon Sep 17 00:00:00 2001 From: TomyJan Date: Thu, 29 Aug 2024 15:37:11 +0800 Subject: [PATCH] perf(plugin-logger): permission control & log preview (#1491) Co-authored-by: wjh Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1491 Co-authored-by: TomyJan Co-committed-by: TomyJan --- .../src/client/LogsDownloader.tsx | 113 ++++++++++++++---- .../plugin-logger/src/locale/en-US.ts | 2 + .../plugin-logger/src/locale/ko_KR.ts | 4 +- .../plugin-logger/src/locale/zh-CN.ts | 2 + .../src/server/resourcer/logger.ts | 63 ++++++++-- 5 files changed, 147 insertions(+), 37 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-logger/src/client/LogsDownloader.tsx b/packages/plugins/@tachybase/plugin-logger/src/client/LogsDownloader.tsx index d96f56dc0..5a279e927 100644 --- a/packages/plugins/@tachybase/plugin-logger/src/client/LogsDownloader.tsx +++ b/packages/plugins/@tachybase/plugin-logger/src/client/LogsDownloader.tsx @@ -1,5 +1,5 @@ -import React, { useCallback, useMemo } from 'react'; -import { useAPIClient, useRequest } from '@tachybase/client'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import { CodeMirror, css, useAPIClient, useRequest } from '@tachybase/client'; import { FileOutlined, FolderOutlined } from '@ant-design/icons'; import { useMemoizedFn } from 'ahooks'; @@ -46,12 +46,28 @@ export const LogsDownloader = React.memo((props) => { const [searchValue, setSearchValue] = React.useState(''); const [autoExpandParent, setAutoExpandParent] = React.useState(true); const [checkedKeys, setCheckedKeys] = React.useState([]); + const [checkedName, setCheckedName] = useState(); const { data } = useRequest(() => api .resource('logger') .list() .then((res) => res.data?.data), ); + const { data: previewData, run } = useRequest( + { + url: 'logger:preview', + method: 'post', + data: { file: checkedName }, + }, + { + manual: true, + }, + ); + useEffect(() => { + if (checkedName) { + run(); + } + }, [checkedName]); const data2tree = useCallback( (data: Log[], parent: string): DataNode[] => data.map((log: Log, index: number) => { @@ -186,31 +202,62 @@ export const LogsDownloader = React.memo((props) => { } type="info" showIcon />
- {tree.length ? ( - setCheckedKeys(keys)} - treeData={tree} - /> - ) : ( - - )} +
+ {tree.length ? ( + setCheckedKeys(keys)} + treeData={tree} + selectable={true} + onSelect={(selectedKeys, e: { selected: boolean; selectedNodes; node; event }) => { + if (!e.node.children) { + const name = getTreeNodeName(tree, selectedKeys[0], 0, ''); + if (name) { + setCheckedName(name); + } else { + setCheckedName(undefined); + } + } + }} + /> + ) : ( + + )} +
+
+ {checkedName ? : null} +