import { connect } from 'react-redux';
import { FixedSizeList } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
-import { CustomizeTableIcon } from 'components/icon/icon';
+import { CustomizeTableIcon, DownloadIcon } from 'components/icon/icon';
import { SearchInput } from 'components/search-input/search-input';
-import { ListItemIcon, StyleRulesCallback, Theme, WithStyles, withStyles, Tooltip, IconButton, Checkbox, CircularProgress } from '@material-ui/core';
+import { ListItemIcon, StyleRulesCallback, Theme, WithStyles, withStyles, Tooltip, IconButton, Checkbox, CircularProgress, Button } from '@material-ui/core';
import { FileTreeData } from '../file-tree/file-tree-data';
import { TreeItem, TreeItemStatus } from '../tree/tree';
import { RootState } from 'store/store';
collectionPanel: any;
}
-type CssRules = "loader" | "wrapper" | "dataWrapper" | "row" | "rowEmpty" | "leftPanel" | "rightPanel" | "pathPanel" | "pathPanelItem" | "rowName" | "listItemIcon" | "rowActive" | "pathPanelMenu" | "rowSelection" | "leftPanelHidden" | "leftPanelVisible" | "searchWrapper" | "searchWrapperHidden";
+type CssRules = "pathPanelPathWrapper" | "uploadButton" | "uploadIcon" | "loader" | "wrapper" | "dataWrapper" | "row" | "rowEmpty" | "leftPanel" | "rightPanel" | "pathPanel" | "pathPanelItem" | "rowName" | "listItemIcon" | "rowActive" | "pathPanelMenu" | "rowSelection" | "leftPanelHidden" | "leftPanelVisible" | "searchWrapper" | "searchWrapperHidden";
const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
wrapper: {
justifyContent: 'center'
},
searchWrapper: {
- width: '100%',
+ display: 'inline-block',
marginBottom: '1rem'
},
searchWrapperHidden: {
backgroundColor: '#fff',
boxShadow: '0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 2px 1px -1px rgb(0 0 0 / 12%)',
},
+ pathPanelPathWrapper: {
+ display: 'inline-block',
+ },
leftPanel: {
flex: 0,
padding: '1rem',
},
pathPanelItem: {
cursor: 'pointer',
+ },
+ uploadIcon: {
+ transform: 'rotate(180deg)'
+ },
+ uploadButton: {
+ float: 'right',
}
});
collectionPanel: state.collectionPanel,
collectionPanelFiles: state.collectionPanelFiles,
}))((props: CollectionPanelFilesProps & WithStyles<CssRules> & { auth: AuthState }) => {
- const { classes, onItemMenuOpen, isWritable, dispatch, collectionPanelFiles, collectionPanel } = props;
+ const { classes, onItemMenuOpen, onUploadDataClick, isWritable, dispatch, collectionPanelFiles, collectionPanel } = props;
const { apiToken, config } = props.auth;
const webdavClient = new WebDAV();
}
}, [props.currentItemUuid]);
- const fetchData = (rightKey, ignoreCache = false) => {
- const dataExists = !!pathData[rightKey];
- const runningRequest = pathPromise[rightKey];
+ const fetchData = (keys, ignoreCache = false) => {
+ const keyArray = Array.isArray(keys) ? keys : [keys];
- if ((!dataExists || ignoreCache) && !runningRequest) {
- setIsLoading(true);
+ Promise.all(keyArray
+ .map((key) => {
+ const dataExists = !!pathData[key];
+ const runningRequest = pathPromise[key];
- webdavClient.propfind(`c=${rightKey}`, webDAVRequestConfig)
- .then((request) => {
- if (request.responseXML != null) {
+ if ((!dataExists || ignoreCache) && (!runningRequest || ignoreCache)) {
+ if (!isLoading) {
+ setIsLoading(true);
+ }
+
+ pathPromise[key] = true;
+
+ return webdavClient.propfind(`c=${key}`, webDAVRequestConfig);
+ }
+
+ return Promise.resolve(null);
+ })
+ .filter((promise) => !!promise)
+ )
+ .then((requests) => {
+ const newState = requests.map((request, index) => {
+ if (request && request.responseXML != null) {
+ const key = keyArray[index];
const result: any = extractFilesData(request.responseXML);
const sortedResult = sortBy(result, (n) => n.name).sort((n1, n2) => {
if (n1.type === 'directory' && n2.type !== 'directory') {
}
return 0;
});
- const newPathData = { ...pathData, [rightKey]: sortedResult };
- setPathData(newPathData);
+
+ return { [key]: sortedResult };
}
- })
- .finally(() => {
- setIsLoading(false);
- delete pathPromise[rightKey];
- });
-
- pathPromise[rightKey] = true;
- } else {
- setTimeout(() => setIsLoading(false), 0);
- }
+ return {};
+ }).reduce((prev, next) => {
+ return { ...next, ...prev };
+ }, {});
+
+ setPathData({ ...pathData, ...newState });
+ })
+ .finally(() => {
+ setIsLoading(false);
+ keyArray.forEach(key => delete pathPromise[key]);
+ });
};
React.useEffect(() => {
const hash = (collectionPanel.item || {}).portableDataHash;
if (hash && rightClickUsed) {
- fetchData(rightKey, true);
+ fetchData([leftKey, rightKey], true);
}
}, [(collectionPanel.item || {}).portableDataHash]); // eslint-disable-line react-hooks/exhaustive-deps
const handleRightClick = React.useCallback(
(event) => {
event.preventDefault();
-
- if (!rightClickUsed) {
- setRightClickUsed(true);
- }
-
let elem = event.target;
while (elem && elem.dataset && !elem.dataset.item) {
if (id) {
onItemMenuOpen(event, item, isWritable);
+
+ if (!rightClickUsed) {
+ setRightClickUsed(true);
+ }
}
},
[onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps
return (
<div data-cy="collection-files-panel" onClick={handleClick} ref={parentRef}>
<div className={classes.pathPanel}>
- {
- path
- .map((p: string, index: number) => <span
- key={`${index}-${p}`}
- data-item="true"
- className={classes.pathPanelItem}
- data-breadcrumb-path={p}
- >
- {index === 0 ? 'Home' : p} /
- </span>)
- }
+ <div className={classes.pathPanelPathWrapper}>
+ {
+ path
+ .map((p: string, index: number) => <span
+ key={`${index}-${p}`}
+ data-item="true"
+ className={classes.pathPanelItem}
+ data-breadcrumb-path={p}
+ >
+ {index === 0 ? 'Home' : p} /
+ </span>)
+ }
+ </div>
<Tooltip className={classes.pathPanelMenu} title="More options" disableFocusListener>
<IconButton
data-cy='collection-files-panel-options-btn'
<div className={classes.searchWrapper}>
<SearchInput label="Search" value={rightSearch} onSearch={setRightSearch} />
</div>
+ {
+ isWritable &&
+ <Button
+ className={classes.uploadButton}
+ data-cy='upload-button'
+ onClick={onUploadDataClick}
+ variant='contained'
+ color='primary'
+ size='small'>
+ <DownloadIcon className={classes.uploadIcon} />
+ Upload data
+ </Button>
+ }
<div className={classes.dataWrapper}>
{
rightData && !isLoading ?
{getItemIcon(type, null)} <div className={classes.rowName}>
{name}
</div>
- <span className={classes.rowName} style={{marginLeft: 'auto', marginRight: '1rem'}}>
+ <span className={classes.rowName} style={{ marginLeft: 'auto', marginRight: '1rem' }}>
{formatFileSize(size)}
</span>
</div>