diff --git a/frontend/src/components/cur-dir-path/dir-tool.js b/frontend/src/components/cur-dir-path/dir-tool.js index c95677895c..b4b1f6f3ad 100644 --- a/frontend/src/components/cur-dir-path/dir-tool.js +++ b/frontend/src/components/cur-dir-path/dir-tool.js @@ -7,6 +7,7 @@ import TextTranslation from '../../utils/text-translation'; import SeahubPopover from '../common/seahub-popover'; import ListTagPopover from '../popover/list-tag-popover'; import ViewModes from '../../components/view-modes'; +import ReposSortMenu from '../../components/repos-sort-menu'; import { PRIVATE_FILE_TYPE } from '../../constants'; import MetadataViewToolBar from '../../metadata/metadata-view/components/view-toolbar'; @@ -19,6 +20,9 @@ const propTypes = { currentMode: PropTypes.string.isRequired, switchViewMode: PropTypes.func.isRequired, isCustomPermission: PropTypes.bool, + sortBy: PropTypes.string, + sortOrder: PropTypes.string, + sortItems: PropTypes.func, }; class DirTool extends React.Component { @@ -27,8 +31,15 @@ class DirTool extends React.Component { super(props); this.state = { isRepoTagDialogOpen: false, - isDropdownMenuOpen: false + isDropdownMenuOpen: false, }; + + this.sortOptions = [ + {value: 'name-asc', text: gettext('By name ascending')}, + {value: 'name-desc', text: gettext('By name descending')}, + {value: 'time-asc', text: gettext('By time ascending')}, + {value: 'time-desc', text: gettext('By time descending')} + ]; } toggleDropdownMenu = () => { @@ -78,13 +89,25 @@ class DirTool extends React.Component { } }; + onSelectSortOption = (item) => { + const [sortBy, sortOrder] = item.value.split('-'); + this.props.sortItems(sortBy, sortOrder); + }; + render() { const menuItems = this.getMenu(); const { isDropdownMenuOpen } = this.state; - const { repoID, currentMode, currentPath } = this.props; + const { repoID, currentMode, currentPath, sortBy, sortOrder } = this.props; const propertiesText = TextTranslation.PROPERTIES.value; const isFileExtended = currentPath === '/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES; + const sortOptions = this.sortOptions.map(item => { + return { + ...item, + isSelected: item.value === `${sortBy}-${sortOrder}` + }; + }); + if (isFileExtended) { return (
@@ -97,6 +120,7 @@ class DirTool extends React.Component {
+ {(!this.props.isCustomPermission) && this.props.switchViewMode('detail')}> diff --git a/frontend/src/components/cur-dir-path/index.js b/frontend/src/components/cur-dir-path/index.js index f864747f14..5df14e8207 100644 --- a/frontend/src/components/cur-dir-path/index.js +++ b/frontend/src/components/cur-dir-path/index.js @@ -93,6 +93,9 @@ class CurDirPath extends React.Component { currentMode={this.props.currentMode} switchViewMode={this.props.switchViewMode} isCustomPermission={this.props.isCustomPermission} + sortBy={this.props.sortBy} + sortOrder={this.props.sortOrder} + sortItems={this.props.sortItems} />} {!isDesktop && this.props.direntList.length > 0 && } diff --git a/frontend/src/components/repos-sort-menu.js b/frontend/src/components/repos-sort-menu.js index cf6db8985c..13bcb66a82 100644 --- a/frontend/src/components/repos-sort-menu.js +++ b/frontend/src/components/repos-sort-menu.js @@ -34,8 +34,8 @@ class ReposSortMenu extends React.Component {