Unverified Commit 2551fd76 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

support filter empty dir (#2491)

* Spotless Apply * Spotless Apply * support filter empty dir * Spotless Apply * support filter empty dir * Spotless Apply * fix --------- Co-authored-by: 's avatarzhu-mingye <zhu-mingye@users.noreply.github.com>
parent f38a06c9
/* /*
*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
import Icon from '@ant-design/icons'; import Icon from '@ant-design/icons';
...@@ -140,17 +142,131 @@ export const FolderSvgExpand = () => { ...@@ -140,17 +142,131 @@ export const FolderSvgExpand = () => {
component={() => ( component={() => (
<svg <svg
className='icon' className='icon'
viewBox='0 0 1152 1024' viewBox='0 0 1024 1024'
version='1.1' version='1.1'
xmlns='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg'
> >
<path <path
d='M543.93566 0c75.071953 0 135.935915 59.327963 135.935915 132.607917h386.239759c47.35997 0 85.887946 35.455978 85.887946 79.103951V767.99952H0V0zM1023.99936 255.99984H127.99992v383.99976h895.99944V255.99984z' d='M809.2 924.48H235.9c-89.6 0-162.9-76.6-162.9-170.3v-511.4c0-93.7 73.3-170.3 162.9-170.3l115 2c20.1 0 39.5 7.6 54.7 21.5l86 80.9c15.1 13.9 34.5 21.5 54.7 21.5h263c89.6 0 162.9 76.6 162.9 170.3v385.5c-0.1 93.7-73.4 170.3-163 170.3z'
fill='#98C3FF' fill='#6477FF'
></path>
<path
d='M761.2 888.48H284c-116 0-210.9-94.9-210.9-210.9v-297c0-25.5 20.7-46.1 46.1-46.1h806.7c25.5 0 46.1 20.7 46.1 46.1v297c0.1 116-94.8 210.9-210.8 210.9z'
fill='#465CDB'
opacity='.69'
></path>
<path
d='M829 738.48H216.1c-31.4 0-57-25.7-57-57v-318c0-31.4 25.7-57 57-57H829c31.4 0 57 25.7 57 57v317.9c0.1 31.4-25.6 57.1-57 57.1z'
fill='#FFFFFF'
></path>
<path
d='M831 719.48H218.1c-31.4 0-57-25.7-57-57v-318c0-31.4 25.7-57 57-57H831c31.4 0 57 25.7 57 57v317.9c0.1 31.4-25.6 57.1-57 57.1z'
fill='#FFFFFF'
opacity='.16'
></path> ></path>
<path <path
d='M1151.99928 937.343414V390.399756c0-38.847976-32.31998-70.399956-71.999955-70.399956H71.999955C32.31998 319.9998 0 351.55178 0 390.399756v546.751658C0 985.023384 39.679975 1023.99936 88.831944 1023.99936h974.527391c48.959969 0.192 88.639945-38.783976 88.639945-86.655946z' d='M807.3 924.48H237.8c-90.6 0-164.8-74.1-164.8-164.8v-356.2h899v356.2c0.1 90.7-74.1 164.8-164.7 164.8z'
fill='#0E73FF' fill='#6477FF'
></path>
<path
d='M805.3 924.48H235.8c-90.6 0-164.8-74.1-164.8-164.8v-17.2h899v17.2c0.1 90.7-74.1 164.8-164.7 164.8z'
fill='#465CDB'
opacity='.14'
></path>
<path
d='M595.6 598.48H413.1c-39.9 0-72.5-32.6-72.5-72.5s32.6-72.5 72.5-72.5h182.5c39.9 0 72.5 32.6 72.5 72.5s-32.6 72.5-72.5 72.5z'
fill='#5D75CE'
opacity='.52'
></path>
<path
d='M585.5 583.48H423.6c-31.6 0-57.5-25.9-57.5-57.5s25.9-57.5 57.5-57.5h161.9c31.6 0 57.5 25.9 57.5 57.5s-25.9 57.5-57.5 57.5z'
fill='#FFD629'
></path>
</svg>
)}
/>
</>
);
};
export const ZipSvg = () => {
return (
<Icon
style={{ ...IconStyle }}
component={() => (
<svg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg'>
<path d='M0 0h1024v341.76H0V0z' fill='#55C7F7'></path>
<path d='M0 682.24h1024V1024H0V682.24z' fill='#7ECF3B'></path>
<path d='M352 430.08h320v172.8h-320z' fill='#F95F5D'></path>
<path
d='M0 341.76v341.76h1024V341.76H0z m720.64 304.64H304.64V386.56h416v259.84z'
fill='#F95F5D'
></path>
<path
d='M352 0h320v386.56h-320zM352 646.4h320V1024h-320zM352 430.08h320v172.8h-320z'
fill='#FDAF42'
></path>
</svg>
)}
/>
);
};
export const ConfigSvg = () => {
return (
<Icon
style={{ ...IconStyle }}
component={() => (
<svg
className='icon'
viewBox='0 0 1024 1024'
version='1.1'
xmlns='http://www.w3.org/2000/svg'
width='200'
height='200'
>
<path
d='M400.384 965.12h-220.16c-59.904 1.536-109.568-45.568-111.616-105.472V131.072C70.656 71.168 120.32 24.064 180.224 25.6h539.136c59.392-1.024 108.032 46.08 110.08 105.472v322.048c-4.608 20.48-25.088 33.28-45.568 28.672-14.336-3.072-25.6-14.336-28.672-28.672V131.072c-1.536-19.968-17.92-34.816-37.888-34.816H180.224c-19.968 0-36.352 15.36-37.888 34.816v728.576c1.536 19.968 17.92 35.328 37.888 35.328h220.16c19.456 0 34.816 15.872 34.816 34.816 0.512 19.456-15.36 35.328-34.816 35.328z'
fill='#A6C5F6'
></path>
<path
d='M626.688 297.472H274.944c-19.456 0-34.816-15.872-34.816-34.816 0-19.456 15.872-34.816 34.816-34.816h351.744c19.456 0 34.816 15.872 34.816 34.816 0 19.456-15.872 34.816-34.816 34.816z m0 178.176H274.944c-19.456 0-34.816-15.872-34.816-34.816 0-19.456 15.872-34.816 34.816-34.816h351.744c19.456 0 34.816 15.872 34.816 34.816 0 19.456-15.872 34.816-34.816 34.816z m327.68 260.096c0-19.968-13.312-30.208-35.328-32.256-25.088 0-45.568-19.968-46.08-45.056 0-3.584 0.512-7.168 1.024-10.752 8.192-37.888 6.656-43.52-29.184-62.976l-23.04-12.8c-20.48-16.896-50.688-14.336-68.096 5.632-26.112 20.48-37.888 19.968-62.976 0-16.896-20.48-47.616-23.04-68.096-6.656l-37.888 20.992c-17.408 7.68-25.088 27.648-18.432 45.056 11.776 37.888-5.12 62.464-46.592 66.56-16.896 2.048-28.672 11.264-29.184 26.112-2.048 30.208-2.048 59.904 0 90.112 0 19.456 12.8 29.184 34.304 31.232 25.6 0 47.104 20.48 47.104 46.592 0 2.56 0 5.632-0.512 8.192-7.68 39.936-7.68 44.032 30.208 64.512 8.192 4.608 15.872 9.728 24.576 13.824 19.456 13.312 45.568 9.728 61.44-8.192 29.184-25.088 37.888-24.576 68.608 0 12.288 8.192 25.088 15.36 37.888 22.016 27.648-17.408 55.296-32.768 79.872-51.2 5.632-8.704 7.168-19.968 3.584-30.208-13.824-34.304 8.192-64.512 48.128-68.096 16.384 0 27.136-10.24 28.16-24.576 1.536-28.672 1.536-58.368 0.512-88.064z m-233.472 132.096c-50.688 0-91.648-40.96-91.648-91.648 0-50.688 40.96-91.648 91.648-91.648s91.648 40.96 91.648 91.648c0 50.176-40.448 91.648-91.136 91.648h-0.512zM237.568 584.192h247.808v70.144H237.568v-70.144z'
fill='#4E8CEE'
></path>
</svg>
)}
/>
);
};
export const JarSvg = () => {
return (
<>
<Icon
style={{ ...IconStyle }}
component={() => (
<svg
className='icon'
viewBox='0 0 1024 1024'
version='1.1'
xmlns='http://www.w3.org/2000/svg'
width='200'
height='200'
>
<path
d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z'
fill='#FF4D4F'
></path>
<path
d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z'
fill='#FF4D4F'
></path>
<path
d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z'
fill='#FF4D4F'
></path>
<path
d='M330.097778 757.504c42.752 0 62.464-30.72 62.464-68.096V563.2H346.737778v122.624c0 24.832-7.936 32.256-22.784 32.256-9.216 0-18.944-5.888-25.6-18.944L267.377778 722.432c13.568 23.552 33.024 35.072 62.72 35.072zM525.169778 563.2l59.136 190.72h-48.128l-11.008-43.776h-56.32l-11.008 43.776h-46.592L470.385778 563.2h54.784z m-27.904 34.304h-1.024c-4.608 19.968-9.728 42.24-14.592 61.184l-4.096 16.128h38.912l-4.096-16.128c-5.12-18.944-9.984-41.728-15.104-61.184zM674.161778 563.2c40.704 0 74.496 14.08 74.496 60.16 0 27.904-13.056 45.824-32.768 55.04l42.496 75.52h-51.2l-35.072-67.072h-22.016v67.072h-45.824V563.2z m-3.584 36.352h-20.48v51.2h20.48c21.76 0 33.536-9.472 33.536-27.392 0-17.92-11.776-23.808-33.536-23.808z'
fill='#FFFFFF'
></path> ></path>
</svg> </svg>
)} )}
......
/* /*
*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -16,7 +17,7 @@ ...@@ -16,7 +17,7 @@
* *
*/ */
import { UserBaseInfo } from '@/types/User/data'; import { UserBaseInfo } from '@/types/AuthCenter/data.d';
import { ProColumns, ProTable } from '@ant-design/pro-components'; import { ProColumns, ProTable } from '@ant-design/pro-components';
import { Transfer } from 'antd'; import { Transfer } from 'antd';
import { TableRowSelection } from 'antd/es/table/interface'; import { TableRowSelection } from 'antd/es/table/interface';
......
...@@ -17,29 +17,31 @@ ...@@ -17,29 +17,31 @@
* *
*/ */
import React, {Key} from 'react'; import { Transfer, Tree } from 'antd';
import {theme, Transfer, Tree} from 'antd'; import type { TransferDirection, TransferItem } from 'antd/es/transfer';
import type {TransferDirection, TransferItem} from 'antd/es/transfer'; import type { DataNode } from 'antd/es/tree';
import type {DataNode} from 'antd/es/tree'; import React, { Key } from 'react';
const { DirectoryTree } = Tree;
interface TreeTransferProps { interface TreeTransferProps {
dataSource: DataNode[]; dataSource: DataNode[];
targetKeys: Key[]; targetKeys: Key[];
onChange?: (targetKeys: Key[], direction: TransferDirection, moveKeys: string[]) => void; onChange?: (targetKeys: Key[], direction: TransferDirection, moveKeys: string[]) => void;
height?: number;
} }
const isChecked = (selectedKeys: React.Key[], eventKey: React.Key) => const isChecked = (selectedKeys: React.Key[], eventKey: React.Key) =>
selectedKeys.includes(eventKey); selectedKeys.includes(eventKey);
const generateTree = (treeNodes: DataNode[] = [], checkedKeys: Key[] = []): DataNode[] => const generateTree = (treeNodes: DataNode[] = [], checkedKeys: Key[] = []): DataNode[] =>
treeNodes.map(({children, ...props}) => ({ treeNodes.map(({ children, ...props }) => ({
...props, ...props,
disabled: checkedKeys.includes(props.key as string), disabled: checkedKeys.includes(props.key as string),
children: generateTree(children, checkedKeys), children: generateTree(children, checkedKeys)
})); }));
export const TreeTransfer: React.FC<TreeTransferProps> = ({dataSource, targetKeys,height, ...restProps}) => { export const TreeTransfer: React.FC<TreeTransferProps> = ({
const {token} = theme.useToken(); dataSource,
targetKeys,
...restProps
}) => {
const transferDataSource: TransferItem[] = []; const transferDataSource: TransferItem[] = [];
function flatten(list: DataNode[] = []) { function flatten(list: DataNode[] = []) {
...@@ -54,34 +56,32 @@ export const TreeTransfer: React.FC<TreeTransferProps> = ({dataSource, targetKey ...@@ -54,34 +56,32 @@ export const TreeTransfer: React.FC<TreeTransferProps> = ({dataSource, targetKey
return ( return (
<Transfer <Transfer
{...restProps} {...restProps}
// @ts-ignore Don't worry about it here rowKey={(record) => record.id as string}
targetKeys={targetKeys} targetKeys={targetKeys as string[]}
dataSource={transferDataSource} dataSource={transferDataSource}
className="tree-transfer" className={'treeList'}
render={(item) => item.path} render={(item) => item.path}
showSelectAll={false} showSelectAll={true}
> >
{({direction, onItemSelect, selectedKeys}) => { {({ direction, onItemSelect, selectedKeys }) => {
if (direction === 'left') { if (direction === 'left') {
const checkedKeys = [...selectedKeys, ...targetKeys]; const checkedKeys = [...selectedKeys, ...targetKeys];
return ( return (
<div style={{padding: token.paddingXS}}> <DirectoryTree
<Tree
height={height}
blockNode blockNode
checkable checkable
className={'treeList'}
checkStrictly checkStrictly
defaultExpandAll defaultExpandAll
checkedKeys={checkedKeys} checkedKeys={checkedKeys}
treeData={generateTree(dataSource, targetKeys)} treeData={generateTree(dataSource, targetKeys)}
onCheck={(_, {node: {key}}) => { onCheck={(_, { node: { key } }) => {
onItemSelect(key as string, !isChecked(checkedKeys, key)); onItemSelect(key as string, !isChecked(checkedKeys, key));
}} }}
onSelect={(_, {node: {key}}) => { onSelect={(_, { node: { key } }) => {
onItemSelect(key as string, !isChecked(checkedKeys, key)); onItemSelect(key as string, !isChecked(checkedKeys, key));
}} }}
/> />
</div>
); );
} }
}} }}
......
...@@ -840,7 +840,16 @@ export default { ...@@ -840,7 +840,16 @@ export default {
'rc.template.templateCode': 'Template Code', 'rc.template.templateCode': 'Template Code',
'rc.template.templateCodeLabel': 'Template Code( {language} )', 'rc.template.templateCodeLabel': 'Template Code( {language} )',
'rc.template.templateCodePlaceholder': 'Please edit the template code! ', 'rc.template.templateCodePlaceholder': 'Please edit the template code! ',
'rc.udf.management': 'UDF Template Management', 'rc.udf.template.management': 'UDF Template Management',
'rc.udf.register.management': 'UDF Register Management',
'rc.udf.register.file.name': 'File Name',
'rc.udf.register.parse.count': 'UDF Parse Count',
'rc.udf.register.source': 'Source',
'rc.udf.register.language': 'Language',
'rc.udf.register.name': 'UDF Name',
'rc.udf.register.className': 'Class Name',
'rc.udf.register.deleteConfirm': 'Are you sure you want to delete this UDF? ',
'rc.udf.register': 'Register UDF',
/** /**
* *
* role * role
......
...@@ -802,7 +802,17 @@ export default { ...@@ -802,7 +802,17 @@ export default {
'rc.template.templateCode': '模板代码', 'rc.template.templateCode': '模板代码',
'rc.template.templateCodeLabel': '模板代码({language})', 'rc.template.templateCodeLabel': '模板代码({language})',
'rc.template.templateCodePlaceholder': '请编辑模板代码!', 'rc.template.templateCodePlaceholder': '请编辑模板代码!',
'rc.udf.management': 'UDF 模板管理', 'rc.udf.template.management': 'UDF 模板管理',
'rc.udf.register.management': 'UDF 注册管理',
'rc.udf.register.file.name': '文件名称',
'rc.udf.register.parse.count': 'UDF 解析数量',
'rc.udf.register.source': '来源',
'rc.udf.register.language': '语言',
'rc.udf.register.name': '名称',
'rc.udf.register.className': '类名',
'rc.udf.register.deleteConfirm': '确定删除该 UDF 吗?',
'rc.udf.register': '注册 UDF',
/** /**
* *
* role * role
......
...@@ -57,5 +57,5 @@ export const TASK_VAR_FILTER = [ ...@@ -57,5 +57,5 @@ export const TASK_VAR_FILTER = [
'clusterConfigurationName', 'clusterConfigurationName',
'databaseName', 'databaseName',
'envName', 'envName',
'alertGroupName', 'alertGroupName'
]; ];
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* *
*/ */
import { TagAlignCenter } from '@/components/StyledComponents';
import { ResourceInfo } from '@/types/RegCenter/data'; import { ResourceInfo } from '@/types/RegCenter/data';
import { parseByteStr, renderIcon } from '@/utils/function'; import { parseByteStr, renderIcon } from '@/utils/function';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
...@@ -35,19 +36,67 @@ const buildTitleLabel = (item: ResourceInfo) => { ...@@ -35,19 +36,67 @@ const buildTitleLabel = (item: ResourceInfo) => {
); );
}; };
export const buildResourceTreeData = (data: ResourceInfo[]): any => /**
data.map((item: ResourceInfo) => { * 判断目录是否为空
* @param directory
*/
function isDirectoryEmpty(directory: ResourceInfo): boolean {
if (!directory.children) {
return true;
}
for (let child of directory.children) {
if (child.isDirectory) {
if (!isDirectoryEmpty(child)) {
return false;
}
} else {
return false;
}
}
return true;
}
function filterEmpty(
isFilterEmptyChildren: boolean,
item: ResourceInfo,
filterSuffixList: string[]
) {
if (isFilterEmptyChildren) {
if (item.isDirectory) {
// 如果是目录,则递归遍历看最深处是否是空目录,是的话过滤掉
return !isFilterEmptyChildren || !isDirectoryEmpty(item);
} else {
// 如果是文件,则判断该文件末尾后缀是不是 .jar 文件,是的话留着,不是的话仍然过滤
// 获取文件后缀 , 如果没有后缀则返回空 false
const suffix = item.fileName.split('.').reverse().pop();
if (suffix) {
// 如果有后缀,则判断是否在过滤列表中
return !filterSuffixList.includes(suffix);
}
}
}
return true;
}
export const buildResourceTreeData = (
data: ResourceInfo[],
isFilterEmptyChildren = false,
filterSuffixList: string[] = []
): any =>
data
.filter((item: ResourceInfo) => filterEmpty(isFilterEmptyChildren, item, filterSuffixList))
.map((item: ResourceInfo) => {
return { return {
isLeaf: !item.isDirectory, isLeaf: !item.isDirectory,
name: item.fileName, name: item.fileName,
parentId: item.pid, parentId: item.pid,
label: item.fullName + '/' + item.fileName, label: item.fullName + '/' + item.fileName,
icon: renderIcon(item.fileName, '.', item.isDirectory), icon: <TagAlignCenter>{renderIcon(item.fileName, '.', item.isDirectory)}</TagAlignCenter>,
path: item.fullName, path: item.fullName,
title: buildTitleLabel(item), title: buildTitleLabel(item),
fullInfo: item, fullInfo: item,
key: item.id, key: item.id,
id: item.id, id: item.id,
children: item.children && buildResourceTreeData(item.children) children: item.children && buildResourceTreeData(item.children, isFilterEmptyChildren)
}; };
}); });
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { TreeTransfer } from '@/components/Transfer/TreeTransfer';
import { buildResourceTreeData } from '@/pages/RegCenter/Resource/components/FileTree/function';
import { l } from '@/utils/intl';
import { Modal } from 'antd';
import { TransferDirection } from 'antd/es/transfer';
import React, { Key, memo } from 'react';
type UDFRegisterModalProps = {
showEdit: boolean;
openChange: (showEdit: boolean) => void;
onOk: () => void;
targetKeys: Key[];
targetKeyChange: (targetKeys: Key[], direction: TransferDirection, moveKeys: string[]) => void;
treeData: any[];
};
const UDFRegisterModal: React.FC<UDFRegisterModalProps> = (props) => {
const { showEdit, openChange, treeData, targetKeys, targetKeyChange, onOk } = props;
return (
<>
<Modal
width={'70%'}
bodyStyle={{ height: 600, overflow: 'auto' }}
open={showEdit}
title={l('rc.udf.register')}
destroyOnClose
closable
maskClosable={false}
onCancel={() => openChange(false)}
onOk={() => onOk()}
>
<TreeTransfer
dataSource={buildResourceTreeData(treeData, true, ['jar', 'zip'])}
targetKeys={targetKeys}
onChange={targetKeyChange}
/>
</Modal>
</>
);
};
export default memo(UDFRegisterModal);
...@@ -17,29 +17,33 @@ ...@@ -17,29 +17,33 @@
* *
*/ */
import {ProColumns} from "@ant-design/pro-components"; import { EditBtn } from '@/components/CallBackButton/EditBtn';
import {UDFRegisterInfo, UDFRegisterInfoParent} from "@/types/RegCenter/data"; import { PopconfirmDeleteBtn } from '@/components/CallBackButton/PopconfirmDeleteBtn';
import {EditBtn} from "@/components/CallBackButton/EditBtn"; import UDFRegisterModal from '@/pages/RegCenter/UDF/components/UDFRegister/UDFRegisterModal';
import {PopconfirmDeleteBtn} from "@/components/CallBackButton/PopconfirmDeleteBtn"; import { API_CONSTANTS } from '@/services/endpoints';
import {Key, useEffect, useRef, useState} from "react"; import { UDFRegisterInfo, UDFRegisterInfoParent } from '@/types/RegCenter/data';
import ProTable, {ActionType} from "@ant-design/pro-table"; import { l } from '@/utils/intl';
import {useRequest} from "@@/plugin-request"; import { useRequest } from '@@/plugin-request';
import {API_CONSTANTS} from "@/services/endpoints"; import { ProColumns } from '@ant-design/pro-components';
import {Button, Modal} from "antd"; import ProTable, { ActionType } from '@ant-design/pro-table';
import {PlusOutlined} from "@ant-design/icons"; import React, { Key, useEffect, useRef, useState } from 'react';
import {TreeTransfer} from "@/components/Transfer/TreeTransfer"; import { add, update } from './service';
import {buildResourceTreeData} from "@/pages/RegCenter/Resource/components/FileTree/function";
import {add, update} from "./service";
import {l} from "@/utils/intl";
type UDFRegisterProps = {
showEdit: boolean;
showEditChange: (showEdit: boolean) => void;
};
const UDFRegister = () => { const UDFRegister: React.FC<UDFRegisterProps> = (props) => {
const req = useRequest<{ const { showEdit, showEditChange } = props;
data: UDFRegisterInfo[]
const udfRegisterInfoRequest = useRequest<{
data: UDFRegisterInfo[];
}>({ }>({
url: API_CONSTANTS.UDF_LIST url: API_CONSTANTS.UDF_LIST
}); });
const req_resources = useRequest({
const resourceInfoRequest = useRequest({
url: API_CONSTANTS.UDF_RESOURCES_LIST url: API_CONSTANTS.UDF_RESOURCES_LIST
}); });
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
...@@ -52,25 +56,24 @@ const UDFRegister = () => { ...@@ -52,25 +56,24 @@ const UDFRegister = () => {
editableKeys: [], editableKeys: [],
dataSource: [], dataSource: [],
isEdit: false, isEdit: false,
isAdd: false, isAdd: false
}); });
const [showEdit, setShowEdit] = useState<boolean>(false);
const [targetKeys, setTargetKeys] = useState<Key[]>([]); const [targetKeys, setTargetKeys] = useState<Key[]>([]);
useEffect(() => { useEffect(() => {
setTargetKeys([...new Set(req.data?.map(x => x.resourcesId))]) setTargetKeys([...new Set(udfRegisterInfoRequest.data?.map((x) => x.resourcesId))]);
}, [req.data]) }, [udfRegisterInfoRequest.data]);
const editableKeysChange = (editableKeys: Key[]) => { const editableKeysChange = (editableKeys: Key[]) => {
setUDFRegisterState(prevState => ({...prevState, editableKeys})); setUDFRegisterState((prevState) => ({ ...prevState, editableKeys }));
} };
const groupData: { const groupData: {
[p: string]: UDFRegisterInfo[] | undefined [p: string]: UDFRegisterInfo[] | undefined;
} = Object.fromEntries( } = Object.fromEntries(
Array.from(new Set(req.data?.map(({fileName}) => fileName))).map((type) => [ Array.from(new Set(udfRegisterInfoRequest.data?.map(({ fileName }) => fileName))).map(
type, (type) => [type, udfRegisterInfoRequest.data?.filter((item) => item.fileName === type)]
req.data?.filter((item) => item.fileName === type),
]),
) )
);
const parentData: UDFRegisterInfoParent[] = Object.keys(groupData)?.map((key) => { const parentData: UDFRegisterInfoParent[] = Object.keys(groupData)?.map((key) => {
const d = groupData[key] ?? []; const d = groupData[key] ?? [];
return { return {
...@@ -78,89 +81,97 @@ const UDFRegister = () => { ...@@ -78,89 +81,97 @@ const UDFRegister = () => {
dialect: d[0].dialect, dialect: d[0].dialect,
source: d[0].source, source: d[0].source,
fileName: key, fileName: key,
num: d.length, num: d.length
} };
}) });
const columnsParent: ProColumns<UDFRegisterInfoParent>[] = [ const columnsParent: ProColumns<UDFRegisterInfoParent>[] = [
{ {
title: '文件名称', title: l('rc.udf.register.file.name'),
width: 120, width: '25%',
dataIndex: 'fileName', dataIndex: 'fileName'
}, { },
title: 'udf解析数量', {
width: 120, title: l('rc.udf.register.parse.count'),
dataIndex: 'num', width: '25%',
}, { sorter: true,
title: '来源', dataIndex: 'num'
width: 120, },
{
title: l('rc.udf.register.source'),
width: '25%',
dataIndex: 'source', dataIndex: 'source',
valueEnum: { valueEnum: {
resources: {text: "resources"}, resources: { text: 'resources' },
develop: {text: 'develop'}, develop: { text: 'develop' }
} }
}, { },
title: '语言', {
width: 120, title: l('rc.udf.register.language'),
width: '25%',
dataIndex: 'dialect', dataIndex: 'dialect',
valueEnum: { valueEnum: {
java: {text: "Java"}, java: { text: 'Java' },
python: {text: 'Python'}, python: { text: 'Python' }
} }
} }
] ];
const expandedRowRender = (expandedRow: UDFRegisterInfoParent) => { const expandedRowRender = (expandedRow: UDFRegisterInfoParent) => {
const columns: ProColumns<UDFRegisterInfo>[] = [ const columns: ProColumns<UDFRegisterInfo>[] = [
{ {
title: '名称', title: l('rc.udf.register.name'),
dataIndex: 'name', dataIndex: 'name',
width: '10%', width: '10%'
formItemProps: {
rules: [
{
required: true,
message: '请输入名称',
},
],
},
}, },
{ {
title: '类名', title: l('rc.udf.register.className'),
dataIndex: 'className', dataIndex: 'className',
readonly: true, readonly: true,
width: '15%', width: '15%'
}, },
{ {
title: '更新时间', title: l('global.table.updateTime'),
dataIndex: 'updateTime', dataIndex: 'updateTime',
readonly: true, readonly: true,
valueType: 'dateTime', valueType: 'dateTime',
width: '15%', width: '15%'
}, },
{ {
title: '操作', title: l('global.table.operate'),
valueType: 'option', valueType: 'option',
width: '10%', width: '10%',
render: (_text, record, _, action) => { render: (_text, record, _, action) => {
return [ return [
<EditBtn key={`${record.id}_edit`} onClick={() => { <EditBtn
key={`${record.id}_edit`}
onClick={() => {
action?.startEditable?.(record.id); action?.startEditable?.(record.id);
setUDFRegisterState(prevState => ({...prevState, isEdit: true, isAdd: false})); setUDFRegisterState((prevState) => ({ ...prevState, isEdit: true, isAdd: false }));
}}/> }}
, record.source == "develop" ? />,
<PopconfirmDeleteBtn key={`${record.id}_delete`} onClick={() => { record.source == 'develop' ? (
}} description={"确定删除吗???"}/> <PopconfirmDeleteBtn
: <></> key={`${record.id}_delete`}
] onClick={() => {}}
}, description={l('rc.udf.register.deleteConfirm')}
/>
) : (
<></>
)
];
} }
] }
];
const handleOnSave = async (row: UDFRegisterInfo) => {
await update(row.id, row.name);
await udfRegisterInfoRequest.refresh();
actionRef.current?.reload();
};
return ( return (
<ProTable <ProTable
rowKey={"id"} rowKey={'id'}
columns={columns} columns={columns}
headerTitle={false} headerTitle={false}
search={false} search={false}
...@@ -173,59 +184,51 @@ const UDFRegister = () => { ...@@ -173,59 +184,51 @@ const UDFRegister = () => {
type: 'single', type: 'single',
editableKeys: udfRegisterState.editableKeys, editableKeys: udfRegisterState.editableKeys,
onChange: editableKeysChange, onChange: editableKeysChange,
onSave: async (_, row) => { onSave: async (_, row) => handleOnSave(row),
await update(row.id, row.name); actionRender: (_, _2, defaultDom) => [defaultDom.save, defaultDom.cancel]
await req.refresh();
actionRef.current?.reload();
},
actionRender: (_, _2, defaultDom) => [
defaultDom.save,
defaultDom.cancel
]
}} }}
/> />
); );
}; };
/**
* submit register udf
*/
const handleUdfRefresh = () => {
add(targetKeys).then(() => {
udfRegisterInfoRequest.refresh().then(() => {
showEditChange(false);
});
});
};
return ( return (
<> <>
<ProTable<UDFRegisterInfoParent> <ProTable<UDFRegisterInfoParent>
dataSource={parentData} dataSource={parentData}
columns={columnsParent} columns={columnsParent}
rowKey="resourcesId" rowKey='resourcesId'
size={'small'}
pagination={{ pagination={{
showQuickJumper: true, hideOnSinglePage: true,
showQuickJumper: true
}} }}
expandable={{expandedRowRender}} expandable={{ expandedRowRender }}
search={false} search={false}
dateFormatter="string" dateFormatter='string'
options={false} options={false}
toolBarRender={() => [
<Button
type="primary"
onClick={() => {
setShowEdit(true);
}}
icon={<PlusOutlined/>}
>
{l('button.create')}
</Button>
]}
/> />
<Modal width={1500} open={showEdit} destroyOnClose closable onCancel={() => setShowEdit(false)}
onOk={() => { <UDFRegisterModal
add(targetKeys).then(() => { showEdit={showEdit}
req.refresh().then(() => { openChange={showEditChange}
setShowEdit(false) onOk={() => handleUdfRefresh()}
}) targetKeys={targetKeys}
}) targetKeyChange={setTargetKeys}
}}> treeData={resourceInfoRequest.data ?? []}
<TreeTransfer dataSource={buildResourceTreeData(req_resources.data ?? [])} />
targetKeys={targetKeys} onChange={setTargetKeys} height={500}/>
</Modal>
</> </>
) );
} };
export default UDFRegister export default UDFRegister;
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
* *
*/ */
import {postAll} from "@/services/api"; import { postAll } from '@/services/api';
import {API_CONSTANTS} from "@/services/endpoints"; import { API_CONSTANTS } from '@/services/endpoints';
import {Key} from "react"; import { Key } from 'react';
export const add = (ids:Key[]) => { export const add = (ids: Key[]) => {
return postAll(API_CONSTANTS.UDF_ADD,{data:ids}); return postAll(API_CONSTANTS.UDF_ADD, { data: ids });
} };
export const update = (id:Key,name:string) => { export const update = (id: Key, name: string) => {
return postAll(API_CONSTANTS.UDF_UPDATE,{id,name}); return postAll(API_CONSTANTS.UDF_UPDATE, { id, name });
} };
\ No newline at end of file
...@@ -218,7 +218,7 @@ const TemplateTable: React.FC = () => { ...@@ -218,7 +218,7 @@ const TemplateTable: React.FC = () => {
{...PROTABLE_OPTIONS_PUBLIC} {...PROTABLE_OPTIONS_PUBLIC}
loading={templateState.loading} loading={templateState.loading}
actionRef={actionRef} actionRef={actionRef}
headerTitle={l('rc.udf.management')} headerTitle={l('rc.udf.template.management')}
toolBarRender={() => [ toolBarRender={() => [
<Authorized key='create' path='/registration/udf/template/add'> <Authorized key='create' path='/registration/udf/template/add'>
<CreateBtn <CreateBtn
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
* *
*/ */
import UDFTemplateDesc from '@/pages/RegCenter/UDF/components/UDFTemplate/UDFTemplateDrawer/UDFTemplateDesc';
import { UDFTemplate } from '@/types/RegCenter/data'; import { UDFTemplate } from '@/types/RegCenter/data';
import { Drawer } from 'antd'; import { Drawer } from 'antd';
import React from 'react'; import React from 'react';
import UDFTemplateDesc from "@/pages/RegCenter/UDF/components/UDFTemplate/UDFTemplateDrawer/UDFTemplateDesc";
type UDFTemplateDrawerProps = { type UDFTemplateDrawerProps = {
onCancel: (flag?: boolean) => void; onCancel: (flag?: boolean) => void;
......
...@@ -18,12 +18,23 @@ ...@@ -18,12 +18,23 @@
*/ */
import SlowlyAppear from '@/components/Animation/SlowlyAppear'; import SlowlyAppear from '@/components/Animation/SlowlyAppear';
import { CreateBtn } from '@/components/CallBackButton/CreateBtn';
import UDFRegister from '@/pages/RegCenter/UDF/components/UDFRegister';
import TemplateTable from '@/pages/RegCenter/UDF/components/UDFTemplate/TemplateTable'; import TemplateTable from '@/pages/RegCenter/UDF/components/UDFTemplate/TemplateTable';
import {PageContainer} from '@ant-design/pro-components'; import { l } from '@/utils/intl';
import UDFRegister from "@/pages/RegCenter/UDF/components/UDFRegister"; import { PageContainer } from '@ant-design/pro-components';
import * as React from "react"; import * as React from 'react';
export default () => { export default () => {
const [showEdit, setShowEdit] = React.useState<boolean>(false);
const [activeKey, setActiveKey] = React.useState<string>('udf-register');
const renderExtra = () => {
return activeKey === 'udf-register' ? (
<CreateBtn key={'add'} onClick={() => setShowEdit(true)} />
) : null;
};
return ( return (
<SlowlyAppear> <SlowlyAppear>
<PageContainer <PageContainer
...@@ -31,20 +42,23 @@ export default () => { ...@@ -31,20 +42,23 @@ export default () => {
type: 'card', type: 'card',
size: 'small', size: 'small',
animated: true, animated: true,
tabBarGutter: 10, tabBarGutter: 5,
centered: true, centered: true
}} }}
onTabChange={setActiveKey}
tabActiveKey={activeKey}
tabBarExtraContent={renderExtra()}
tabList={[ tabList={[
{ {
tab: 'UDF 注册管理', tab: l('rc.udf.register.management'),
key: 'udf-register', key: 'udf-register',
children: <UDFRegister />, children: <UDFRegister showEditChange={setShowEdit} showEdit={showEdit} />
}, },
{ {
tab: 'UDF 模版', tab: l('rc.udf.template.management'),
key: 'udf-template', key: 'udf-template',
children: <TemplateTable />, children: <TemplateTable />
}, }
]} ]}
title={false} title={false}
/> />
......
/* /*
*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
...@@ -199,6 +201,7 @@ export const DIALECT = { ...@@ -199,6 +201,7 @@ export const DIALECT = {
PYTHON_LONG: 'python', PYTHON_LONG: 'python',
YML: 'yml', YML: 'yml',
YAML: 'yaml', YAML: 'yaml',
CONF: 'conf',
SH: 'sh', SH: 'sh',
BASH: 'bash', BASH: 'bash',
CMD: 'cmd', CMD: 'cmd',
...@@ -207,6 +210,10 @@ export const DIALECT = { ...@@ -207,6 +210,10 @@ export const DIALECT = {
SQL: 'sql', SQL: 'sql',
JAVASCRIPT: 'javascript', JAVASCRIPT: 'javascript',
FLINKJAR: 'flinkjar', FLINKJAR: 'flinkjar',
JAR: 'jar',
ZIP: 'zip',
TAR: 'tar',
TAR_GZ: 'gz',
FLINKSQLENV: 'flinksqlenv', FLINKSQLENV: 'flinksqlenv',
MYSQL: 'mysql', MYSQL: 'mysql',
ORACLE: 'oracle', ORACLE: 'oracle',
......
...@@ -223,7 +223,6 @@ export type UDFTemplate = BaseBeanColumns & { ...@@ -223,7 +223,6 @@ export type UDFTemplate = BaseBeanColumns & {
templateCode: string; templateCode: string;
}; };
export interface UDFRegisterInfo { export interface UDFRegisterInfo {
id: number; id: number;
resourcesId: number; resourcesId: number;
......
/* /*
*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -13,12 +14,15 @@ ...@@ -13,12 +14,15 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
import { import {
ConfigSvg,
FileIcon, FileIcon,
FlinkSQLSvg, FlinkSQLSvg,
FolderSvgExpand, FolderSvgExpand,
JarSvg,
JavaSvg, JavaSvg,
LogSvg, LogSvg,
MarkDownSvg, MarkDownSvg,
...@@ -26,7 +30,8 @@ import { ...@@ -26,7 +30,8 @@ import {
ScalaSvg, ScalaSvg,
ShellSvg, ShellSvg,
XMLSvg, XMLSvg,
YAMLSvg YAMLSvg,
ZipSvg
} from '@/components/Icons/CodeLanguageIcon'; } from '@/components/Icons/CodeLanguageIcon';
import { import {
DATETIME_FORMAT, DATETIME_FORMAT,
...@@ -279,12 +284,20 @@ export const getIcon = (type: string) => { ...@@ -279,12 +284,20 @@ export const getIcon = (type: string) => {
case DIALECT.YAML: case DIALECT.YAML:
case DIALECT.YML: case DIALECT.YML:
return <YAMLSvg />; return <YAMLSvg />;
case DIALECT.JAR:
return <JarSvg />;
case DIALECT.SH: case DIALECT.SH:
case DIALECT.BASH: case DIALECT.BASH:
case DIALECT.CMD: case DIALECT.CMD:
return <ShellSvg />; return <ShellSvg />;
case DIALECT.CONF:
return <ConfigSvg />;
case DIALECT.LOG: case DIALECT.LOG:
return <LogSvg />; return <LogSvg />;
case DIALECT.ZIP:
case DIALECT.TAR:
case DIALECT.TAR_GZ:
return <ZipSvg />;
case DIALECT.FLINK_SQL: case DIALECT.FLINK_SQL:
return <FlinkSQLSvg />; return <FlinkSQLSvg />;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment