MCPcopy
hub / github.com/Tencent/CodeAnalysis / Tools

Function Tools

web/packages/tca-layout/src/modules/tools/index.tsx:25–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23const DEFAULT_SIZE = 50;
24
25const Tools = () => {
26 const history = useHistory();
27 const { orgSid }: any = useParams();
28 const editable = useOrgAdminPerm();
29
30 const [visible, setVisible] = useState(false);
31 const [data, setData] = useState<any[]>([]);
32 const [pager, setPager] = useState({ ...DEFAULT_PAGER, pageSize: DEFAULT_SIZE });
33 const { count, pageStart } = pager;
34 const { searchParams } = useURLParams(filterFields);
35
36
37 const getData = useCallback((pageStart: number, pageSize: number, params: any, isMore = false) => {
38 getTools(orgSid, {
39 offset: pageStart,
40 limit: pageSize,
41 ...params,
42 }).then(({ results, count }: any) => {
43 const list = results || [];
44 setData(pre => (isMore ? [...pre, ...list] : list));
45 setPager({
46 count,
47 pageSize,
48 pageStart,
49 });
50 });
51 }, [orgSid]);
52
53 useEffect(() => {
54 getData(DEFAULT_PAGER.pageStart, DEFAULT_SIZE, searchParams);
55 }, [getData, searchParams]);
56
57 const onScroll = (e: any) => {
58 // 滚动条触底加载更多数据
59 if (e.target.scrollTop + e.target.clientHeight === e.target.scrollHeight) {
60 if (data.length !== count) {
61 getData(pageStart + DEFAULT_SIZE, DEFAULT_SIZE, searchParams, true);
62 }
63 }
64 };
65
66 return (
67 <>
68 <PageHeader title={t('工具管理')} description={`共 ${count} 个工具,包含公开工具 + 团队可用工具,团队成员可使用工具规则,仅团队管理员能添加工具和规则`} action={editable && (
69 <Button type='primary' onClick={() => {
70 setVisible(true);
71 }}>{t('创建工具')}</Button>
72 )} />
73 <Search fields={TOOL_SEARCH_FIELDS}
74 searchParams={searchParams} callback={(params: any) => {
75 getData(DEFAULT_PAGER.pageStart, DEFAULT_SIZE, params);
76 }} />
77 <div className={style.tools}>
78 <div
79 className={style.contentWrapper}
80 onScrollCapture={onScroll}
81 >
82 <div className={style.content}>

Callers

nothing calls this directly

Calls 7

useOrgAdminPermFunction · 0.90
useURLParamsFunction · 0.90
getToolsFunction · 0.90
getToolsRouterFunction · 0.90
formatDateTimeFunction · 0.90
getFunction · 0.85
getDataFunction · 0.50

Tested by

no test coverage detected