// Copyright (C) 2020 Intel Corporation // // SPDX-License-Identifier: MIT import './styles.scss'; import React from 'react'; import Tabs from 'antd/lib/tabs'; import Input from 'antd/lib/input'; import Text from 'antd/lib/typography/Text'; import Paragraph from 'antd/lib/typography/Paragraph'; import Upload, { RcFile } from 'antd/lib/upload'; import Empty from 'antd/lib/empty'; import Tree, { AntTreeNode, TreeNodeNormal } from 'antd/lib/tree/Tree'; import { InboxOutlined } from '@ant-design/icons'; import consts from 'consts'; export interface Files { local: File[]; share: string[]; remote: string[]; } interface State { files: Files; expandedKeys: string[]; active: 'local' | 'share' | 'remote'; } interface Props { withRemote: boolean; treeData: TreeNodeNormal[]; onLoadData: (key: string, success: () => void, failure: () => void) => void; onChangeActiveKey(key: string): void; } export default class FileManager extends React.PureComponent { public constructor(props: Props) { super(props); this.state = { files: { local: [], share: [], remote: [], }, expandedKeys: [], active: 'local', }; this.loadData('/'); } public getFiles(): Files { const { active, files } = this.state; return { local: active === 'local' ? files.local : [], share: active === 'share' ? files.share : [], remote: active === 'remote' ? files.remote : [], }; } private loadData = (key: string): Promise => new Promise((resolve, reject): void => { const { onLoadData } = this.props; const success = (): void => resolve(); const failure = (): void => reject(); onLoadData(key, success, failure); }); public reset(): void { this.setState({ expandedKeys: [], active: 'local', files: { local: [], share: [], remote: [], }, }); } private renderLocalSelector(): JSX.Element { const { files } = this.state; return ( { this.setState({ files: { ...files, local: newLocalFiles, }, }); return false; }} >

Click or drag files to this area

Support for a bulk images or a single video

{files.local.length >= 5 && ( <>
{`${files.local.length} files selected`} )}
); } private renderShareSelector(): JSX.Element { function renderTreeNodes(data: TreeNodeNormal[]): JSX.Element[] { // sort alphabetically data.sort((a: TreeNodeNormal, b: TreeNodeNormal): number => a.key.localeCompare(b.key)); return data.map((item: TreeNodeNormal) => { if (item.children) { return ( {renderTreeNodes(item.children)} ); } return ; }); } const { SHARE_MOUNT_GUIDE_URL } = consts; const { treeData } = this.props; const { expandedKeys, files } = this.state; return ( {treeData[0].children && treeData[0].children.length ? ( => this.loadData(node.props.dataRef.key)} onExpand={(newExpandedKeys: string[]): void => { this.setState({ expandedKeys: newExpandedKeys, }); }} onCheck={( checkedKeys: | string[] | { checked: string[]; halfChecked: string[]; }, ): void => { const keys = checkedKeys as string[]; this.setState({ files: { ...files, share: keys, }, }); }} > {renderTreeNodes(treeData)} ) : (
Please, be sure you had mounted share before you built CVAT and the shared storage contains files
)}
); } private renderRemoteSelector(): JSX.Element { const { files } = this.state; return ( ): void => { this.setState({ files: { ...files, remote: event.target.value.split('\n'), }, }); }} /> ); } public render(): JSX.Element { const { withRemote, onChangeActiveKey } = this.props; const { active } = this.state; return ( <> { onChangeActiveKey(activeKey); this.setState({ active: activeKey as any, }); }} > {this.renderLocalSelector()} {this.renderShareSelector()} {withRemote && this.renderRemoteSelector()} ); } }