}
// Check that the file listing show both read & write operations
cy.get('[data-cy=collection-files-panel]').within(() => {
+ cy.wait(1000);
cy.root().should('contain', fileName);
if (isWritable) {
cy.get('[data-cy=upload-button]')
});
});
- it('renames a file to a different directory', function () {
+ it.skip('renames a file to a different directory', function () {
// Creates the collection using the admin token so we can set up
// a bogus manifest text without block signatures.
cy.createCollection(adminUser.token, {
});
});
+ it('renames a file to a different directory', function () {
+ // Creates the collection using the admin token so we can set up
+ // a bogus manifest text without block signatures.
+ cy.createCollection(adminUser.token, {
+ name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+ owner_uuid: activeUser.user.uuid,
+ manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+ })
+ .as('testCollection').then(function () {
+ cy.loginAs(activeUser);
+ cy.goToPath(`/collections/${this.testCollection.uuid}`);
+
+ ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
+ cy.get('[data-cy=collection-files-panel]')
+ .contains('bar').rightclick({force: true});
+ cy.get('[data-cy=context-menu]')
+ .contains('Rename')
+ .click();
+ cy.get('[data-cy=form-dialog]')
+ .should('contain', 'Rename')
+ .within(() => {
+ cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
+ });
+ cy.get('[data-cy=form-submit-btn]').click();
+ cy.get('[data-cy=collection-files-panel]')
+ .should('not.contain', 'bar')
+ .and('contain', subdir);
+ cy.wait(1000);
+ cy.get('[data-cy=collection-files-panel]').contains(subdir).click();
+ // Rename 'subdir/foo' to 'foo'
+ cy.wait(1000);
+ cy.get('[data-cy=collection-files-panel]')
+ .contains('foo').rightclick();
+ cy.get('[data-cy=context-menu]')
+ .contains('Rename')
+ .click();
+ cy.get('[data-cy=form-dialog]')
+ .should('contain', 'Rename')
+ .within(() => {
+ cy.get('input')
+ .should('have.value', `${subdir}/foo`)
+ .type(`{selectall}{backspace}bar`);
+ });
+ cy.get('[data-cy=form-submit-btn]').click();
+
+ cy.wait(1000);
+ cy.get('[data-cy=collection-files-panel]')
+ .contains('Home')
+ .click();
+
+ cy.wait(2000);
+ cy.get('[data-cy=collection-files-panel]')
+ .should('contain', subdir) // empty dir kept
+ .and('contain', 'bar');
+
+ cy.get('[data-cy=collection-files-panel]')
+ .contains(subdir).rightclick();
+ cy.get('[data-cy=context-menu]')
+ .contains('Remove')
+ .click();
+ cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+ });
+ });
+ });
+
it('tries to rename a file with illegal names', function () {
// Creates the collection using the admin token so we can set up
// a bogus manifest text without block signatures.
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>