Web: Files: fix context menu action

This commit is contained in:
Artem Tarasov 2021-04-01 12:22:07 +03:00
parent c6a462168c
commit 4bfcf39410
3 changed files with 31 additions and 11 deletions

View File

@ -21,6 +21,7 @@ const FileTile = (props) => {
getContextOptions, getContextOptions,
checked, checked,
selectRowAction, selectRowAction,
onSelectItem,
} = props; } = props;
const { const {
id, id,
@ -62,6 +63,10 @@ const FileTile = (props) => {
selectRowAction(checked, file); selectRowAction(checked, file);
}; };
const rowContextClick = () => {
onSelectItem(item);
};
let classNameProp = let classNameProp =
isFolder && access < 2 && !props.isRecycleBin isFolder && access < 2 && !props.isRecycleBin
? { className: " dropable" } ? { className: " dropable" }
@ -103,6 +108,7 @@ const FileTile = (props) => {
isFolder={isFolder} isFolder={isFolder}
element={element} element={element}
onSelect={onContentRowSelect} onSelect={onContentRowSelect}
rowContextClick={rowContextClick}
//editing={editingId} //editing={editingId}
//viewAs={viewAs} //viewAs={viewAs}
{...checkedProps} {...checkedProps}
@ -135,7 +141,7 @@ export default inject(
const { dragging, setDragging } = initFilesStore; const { dragging, setDragging } = initFilesStore;
const { getContextOptions } = contextOptionsStore; const { getContextOptions } = contextOptionsStore;
const { selectRowAction } = filesActionsStore; const { selectRowAction, onSelectItem } = filesActionsStore;
const { selection } = filesStore; const { selection } = filesStore;
@ -147,6 +153,7 @@ export default inject(
getContextOptions, getContextOptions,
checked: selection.some((el) => el.id === item.id), checked: selection.some((el) => el.id === item.id),
selectRowAction, selectRowAction,
onSelectItem,
}; };
} }
)(withTranslation("Home")(observer(withRouter(FileTile)))); )(withTranslation("Home")(observer(withRouter(FileTile))));

View File

@ -102,9 +102,9 @@ class FilesTileContent extends React.PureComponent {
}; };
} }
completeAction = (e) => { completeAction = (id) => {
//this.setState({ loading: false }, () =>) console.log(id);
this.props.onEditComplete(e); this.props.editCompleteAction(id, this.props.item);
}; };
updateItem = (e) => { updateItem = (e) => {
@ -114,20 +114,21 @@ class FilesTileContent extends React.PureComponent {
renameFolder, renameFolder,
item, item,
setIsLoading, setIsLoading,
fileActionId,
} = this.props; } = this.props;
const { itemTitle } = this.state; const { itemTitle } = this.state;
const originalTitle = getTitleWithoutExst(item); const originalTitle = getTitleWithoutExst(item);
setIsLoading(true); setIsLoading(true);
if (originalTitle === itemTitle) return this.completeAction(e); if (originalTitle === itemTitle) return this.completeAction(fileActionId);
item.fileExst item.fileExst
? updateFile(fileAction.id, itemTitle) ? updateFile(fileAction.id, itemTitle)
.then(() => this.completeAction(e)) .then(() => this.completeAction(fileActionId))
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
: renameFolder(fileAction.id, itemTitle) : renameFolder(fileAction.id, itemTitle)
.then(() => this.completeAction(e)) .then(() => this.completeAction(fileActionId))
.finally(() => setIsLoading(false)); .finally(() => setIsLoading(false));
}; };
@ -135,13 +136,15 @@ class FilesTileContent extends React.PureComponent {
const { createFile, item, setIsLoading, createFolder } = this.props; const { createFile, item, setIsLoading, createFolder } = this.props;
const { itemTitle } = this.state; const { itemTitle } = this.state;
const itemId = e.currentTarget.dataset.itemid;
setIsLoading(true); setIsLoading(true);
if (itemTitle.trim() === "") return this.completeAction(); if (itemTitle.trim() === "") return this.completeAction(itemId);
!item.fileExst !item.fileExst
? createFolder(item.parentId, itemTitle) ? createFolder(item.parentId, itemTitle)
.then(() => this.completeAction(e)) .then(() => this.completeAction(itemId))
.finally(() => { .finally(() => {
toastr.success( toastr.success(
<Trans i18nKey="FolderCreated" ns="Home"> <Trans i18nKey="FolderCreated" ns="Home">
@ -151,7 +154,7 @@ class FilesTileContent extends React.PureComponent {
return setIsLoading(false); return setIsLoading(false);
}) })
: createFile(item.parentId, `${itemTitle}.${item.fileExst}`) : createFile(item.parentId, `${itemTitle}.${item.fileExst}`)
.then(() => this.completeAction(e)) .then(() => this.completeAction(itemId))
.finally(() => { .finally(() => {
const exst = item.fileExst; const exst = item.fileExst;
toastr.success( toastr.success(
@ -434,6 +437,7 @@ export default inject(
formatsStore, formatsStore,
treeFoldersStore, treeFoldersStore,
selectedFolderStore, selectedFolderStore,
filesActionsStore,
}, },
{ item } { item }
) => { ) => {
@ -472,6 +476,8 @@ export default inject(
const isImage = iconFormatsStore.isImage(item.fileExst); const isImage = iconFormatsStore.isImage(item.fileExst);
const isSound = iconFormatsStore.isSound(item.fileExst); const isSound = iconFormatsStore.isSound(item.fileExst);
const { editCompleteAction } = filesActionsStore;
return { return {
culture, culture,
homepage: config.homepage, homepage: config.homepage,
@ -502,6 +508,8 @@ export default inject(
updateFile, updateFile,
renameFolder, renameFolder,
addExpandedKeys, addExpandedKeys,
editCompleteAction,
}; };
} }
)(withRouter(withTranslation("Home")(observer(FilesTileContent)))); )(withRouter(withTranslation("Home")(observer(FilesTileContent))));

View File

@ -127,6 +127,7 @@ class Tile extends React.Component {
indeterminate, indeterminate,
onSelect, onSelect,
isFolder, isFolder,
rowContextClick,
} = this.props; } = this.props;
console.log(isFolder, "tile"); console.log(isFolder, "tile");
@ -149,7 +150,10 @@ class Tile extends React.Component {
onSelect && onSelect(e.target.checked, item); onSelect && onSelect(e.target.checked, item);
}; };
const getOptions = () => contextOptions; const getOptions = () => {
rowContextClick && rowContextClick();
return contextOptions;
};
return ( return (
<StyledTile {...this.props}> <StyledTile {...this.props}>
@ -243,6 +247,7 @@ Tile.propTypes = {
onSelect: PropTypes.func, onSelect: PropTypes.func,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
viewAs: PropTypes.string, viewAs: PropTypes.string,
rowContextClick: PropTypes.func,
}; };
Tile.defaultProps = { Tile.defaultProps = {