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
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
......@@ -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 { Transfer } from 'antd';
import { TableRowSelection } from 'antd/es/table/interface';
......
......@@ -17,74 +17,74 @@
*
*/
import React, {Key} from 'react';
import {theme, Transfer, Tree} from 'antd';
import type {TransferDirection, TransferItem} from 'antd/es/transfer';
import type {DataNode} from 'antd/es/tree';
import { Transfer, Tree } from 'antd';
import type { TransferDirection, TransferItem } from 'antd/es/transfer';
import type { DataNode } from 'antd/es/tree';
import React, { Key } from 'react';
const { DirectoryTree } = Tree;
interface TreeTransferProps {
dataSource: DataNode[];
targetKeys: Key[];
onChange?: (targetKeys: Key[], direction: TransferDirection, moveKeys: string[]) => void;
height?: number;
dataSource: DataNode[];
targetKeys: Key[];
onChange?: (targetKeys: Key[], direction: TransferDirection, moveKeys: string[]) => void;
}
const isChecked = (selectedKeys: React.Key[], eventKey: React.Key) =>
selectedKeys.includes(eventKey);
selectedKeys.includes(eventKey);
const generateTree = (treeNodes: DataNode[] = [], checkedKeys: Key[] = []): DataNode[] =>
treeNodes.map(({children, ...props}) => ({
...props,
disabled: checkedKeys.includes(props.key as string),
children: generateTree(children, checkedKeys),
}));
export const TreeTransfer: React.FC<TreeTransferProps> = ({dataSource, targetKeys,height, ...restProps}) => {
const {token} = theme.useToken();
treeNodes.map(({ children, ...props }) => ({
...props,
disabled: checkedKeys.includes(props.key as string),
children: generateTree(children, checkedKeys)
}));
export const TreeTransfer: React.FC<TreeTransferProps> = ({
dataSource,
targetKeys,
...restProps
}) => {
const transferDataSource: TransferItem[] = [];
const transferDataSource: TransferItem[] = [];
function flatten(list: DataNode[] = []) {
list.forEach((item) => {
transferDataSource.push(item as TransferItem);
flatten(item.children);
});
}
function flatten(list: DataNode[] = []) {
list.forEach((item) => {
transferDataSource.push(item as TransferItem);
flatten(item.children);
});
}
flatten(dataSource);
flatten(dataSource);
return (
<Transfer
{...restProps}
// @ts-ignore Don't worry about it here
targetKeys={targetKeys}
dataSource={transferDataSource}
className="tree-transfer"
render={(item) => item.path}
showSelectAll={false}
>
{({direction, onItemSelect, selectedKeys}) => {
if (direction === 'left') {
const checkedKeys = [...selectedKeys, ...targetKeys];
return (
<div style={{padding: token.paddingXS}}>
<Tree
height={height}
blockNode
checkable
checkStrictly
defaultExpandAll
checkedKeys={checkedKeys}
treeData={generateTree(dataSource, targetKeys)}
onCheck={(_, {node: {key}}) => {
onItemSelect(key as string, !isChecked(checkedKeys, key));
}}
onSelect={(_, {node: {key}}) => {
onItemSelect(key as string, !isChecked(checkedKeys, key));
}}
/>
</div>
);
}
}}
</Transfer>
);
return (
<Transfer
{...restProps}
rowKey={(record) => record.id as string}
targetKeys={targetKeys as string[]}
dataSource={transferDataSource}
className={'treeList'}
render={(item) => item.path}
showSelectAll={true}
>
{({ direction, onItemSelect, selectedKeys }) => {
if (direction === 'left') {
const checkedKeys = [...selectedKeys, ...targetKeys];
return (
<DirectoryTree
blockNode
checkable
className={'treeList'}
checkStrictly
defaultExpandAll
checkedKeys={checkedKeys}
treeData={generateTree(dataSource, targetKeys)}
onCheck={(_, { node: { key } }) => {
onItemSelect(key as string, !isChecked(checkedKeys, key));
}}
onSelect={(_, { node: { key } }) => {
onItemSelect(key as string, !isChecked(checkedKeys, key));
}}
/>
);
}
}}
</Transfer>
);
};
......@@ -840,7 +840,16 @@ export default {
'rc.template.templateCode': 'Template Code',
'rc.template.templateCodeLabel': 'Template Code( {language} )',
'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
......
......@@ -802,7 +802,17 @@ export default {
'rc.template.templateCode': '模板代码',
'rc.template.templateCodeLabel': '模板代码({language})',
'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
......
......@@ -57,5 +57,5 @@ export const TASK_VAR_FILTER = [
'clusterConfigurationName',
'databaseName',
'envName',
'alertGroupName',
'alertGroupName'
];
/*
*
* 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
* 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
* 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.
* 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 { TagAlignCenter } from '@/components/StyledComponents';
import { ResourceInfo } from '@/types/RegCenter/data';
import { parseByteStr, renderIcon } from '@/utils/function';
import { l } from '@/utils/intl';
......@@ -35,19 +36,67 @@ const buildTitleLabel = (item: ResourceInfo) => {
);
};
export const buildResourceTreeData = (data: ResourceInfo[]): any =>
data.map((item: ResourceInfo) => {
return {
isLeaf: !item.isDirectory,
name: item.fileName,
parentId: item.pid,
label: item.fullName + '/' + item.fileName,
icon: renderIcon(item.fileName, '.', item.isDirectory),
path: item.fullName,
title: buildTitleLabel(item),
fullInfo: item,
key: item.id,
id: item.id,
children: item.children && buildResourceTreeData(item.children)
};
});
/**
* 判断目录是否为空
* @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 {
isLeaf: !item.isDirectory,
name: item.fileName,
parentId: item.pid,
label: item.fullName + '/' + item.fileName,
icon: <TagAlignCenter>{renderIcon(item.fileName, '.', item.isDirectory)}</TagAlignCenter>,
path: item.fullName,
title: buildTitleLabel(item),
fullInfo: item,
key: item.id,
id: item.id,
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,13 +17,13 @@
*
*/
import {postAll} from "@/services/api";
import {API_CONSTANTS} from "@/services/endpoints";
import {Key} from "react";
import { postAll } from '@/services/api';
import { API_CONSTANTS } from '@/services/endpoints';
import { Key } from 'react';
export const add = (ids:Key[]) => {
return postAll(API_CONSTANTS.UDF_ADD,{data:ids});
}
export const update = (id:Key,name:string) => {
return postAll(API_CONSTANTS.UDF_UPDATE,{id,name});
}
\ No newline at end of file
export const add = (ids: Key[]) => {
return postAll(API_CONSTANTS.UDF_ADD, { data: ids });
};
export const update = (id: Key, name: string) => {
return postAll(API_CONSTANTS.UDF_UPDATE, { id, name });
};
......@@ -218,7 +218,7 @@ const TemplateTable: React.FC = () => {
{...PROTABLE_OPTIONS_PUBLIC}
loading={templateState.loading}
actionRef={actionRef}
headerTitle={l('rc.udf.management')}
headerTitle={l('rc.udf.template.management')}
toolBarRender={() => [
<Authorized key='create' path='/registration/udf/template/add'>
<CreateBtn
......
......@@ -17,10 +17,10 @@
*
*/
import UDFTemplateDesc from '@/pages/RegCenter/UDF/components/UDFTemplate/UDFTemplateDrawer/UDFTemplateDesc';
import { UDFTemplate } from '@/types/RegCenter/data';
import { Drawer } from 'antd';
import React from 'react';
import UDFTemplateDesc from "@/pages/RegCenter/UDF/components/UDFTemplate/UDFTemplateDrawer/UDFTemplateDesc";
type UDFTemplateDrawerProps = {
onCancel: (flag?: boolean) => void;
......
......@@ -18,12 +18,23 @@
*/
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 {PageContainer} from '@ant-design/pro-components';
import UDFRegister from "@/pages/RegCenter/UDF/components/UDFRegister";
import * as React from "react";
import { l } from '@/utils/intl';
import { PageContainer } from '@ant-design/pro-components';
import * as React from 'react';
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 (
<SlowlyAppear>
<PageContainer
......@@ -31,20 +42,23 @@ export default () => {
type: 'card',
size: 'small',
animated: true,
tabBarGutter: 10,
centered: true,
tabBarGutter: 5,
centered: true
}}
onTabChange={setActiveKey}
tabActiveKey={activeKey}
tabBarExtraContent={renderExtra()}
tabList={[
{
tab: 'UDF 注册管理',
key: 'udf-register',
children: <UDFRegister />,
},
{
tab: 'UDF 模版',
key: 'udf-template',
children: <TemplateTable />,
tab: l('rc.udf.register.management'),
key: 'udf-register',
children: <UDFRegister showEditChange={setShowEdit} showEdit={showEdit} />
},
{
tab: l('rc.udf.template.management'),
key: 'udf-template',
children: <TemplateTable />
}
]}
title={false}
/>
......
/*
* 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
* 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.
*
* 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 { l } from '@/utils/intl';
......@@ -199,6 +201,7 @@ export const DIALECT = {
PYTHON_LONG: 'python',
YML: 'yml',
YAML: 'yaml',
CONF: 'conf',
SH: 'sh',
BASH: 'bash',
CMD: 'cmd',
......@@ -207,6 +210,10 @@ export const DIALECT = {
SQL: 'sql',
JAVASCRIPT: 'javascript',
FLINKJAR: 'flinkjar',
JAR: 'jar',
ZIP: 'zip',
TAR: 'tar',
TAR_GZ: 'gz',
FLINKSQLENV: 'flinksqlenv',
MYSQL: 'mysql',
ORACLE: 'oracle',
......
......@@ -223,7 +223,6 @@ export type UDFTemplate = BaseBeanColumns & {
templateCode: string;
};
export interface UDFRegisterInfo {
id: number;
resourcesId: number;
......
/*
* 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
* 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.
*
* 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 {
ConfigSvg,
FileIcon,
FlinkSQLSvg,
FolderSvgExpand,
JarSvg,
JavaSvg,
LogSvg,
MarkDownSvg,
......@@ -26,7 +30,8 @@ import {
ScalaSvg,
ShellSvg,
XMLSvg,
YAMLSvg
YAMLSvg,
ZipSvg
} from '@/components/Icons/CodeLanguageIcon';
import {
DATETIME_FORMAT,
......@@ -279,12 +284,20 @@ export const getIcon = (type: string) => {
case DIALECT.YAML:
case DIALECT.YML:
return <YAMLSvg />;
case DIALECT.JAR:
return <JarSvg />;
case DIALECT.SH:
case DIALECT.BASH:
case DIALECT.CMD:
return <ShellSvg />;
case DIALECT.CONF:
return <ConfigSvg />;
case DIALECT.LOG:
return <LogSvg />;
case DIALECT.ZIP:
case DIALECT.TAR:
case DIALECT.TAR_GZ:
return <ZipSvg />;
case DIALECT.FLINK_SQL:
return <FlinkSQLSvg />;
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