1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 13:50:07 +00:00

12.0 add sort button in lib content view (#6355)

* feature - add sort button on content page

* remove seahub/wiki2/migrations/0001_initial.py

* add default option for sort options

* modify shallow compare to strict compare
This commit is contained in:
Aries
2024-07-17 11:09:53 +08:00
committed by GitHub
parent ab56b68887
commit 2b1cace1b8
3 changed files with 31 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import TextTranslation from '../../utils/text-translation';
import SeahubPopover from '../common/seahub-popover'; import SeahubPopover from '../common/seahub-popover';
import ListTagPopover from '../popover/list-tag-popover'; import ListTagPopover from '../popover/list-tag-popover';
import ViewModes from '../../components/view-modes'; import ViewModes from '../../components/view-modes';
import ReposSortMenu from '../../components/repos-sort-menu';
import { PRIVATE_FILE_TYPE } from '../../constants'; import { PRIVATE_FILE_TYPE } from '../../constants';
import MetadataViewToolBar from '../../metadata/metadata-view/components/view-toolbar'; import MetadataViewToolBar from '../../metadata/metadata-view/components/view-toolbar';
@@ -19,6 +20,9 @@ const propTypes = {
currentMode: PropTypes.string.isRequired, currentMode: PropTypes.string.isRequired,
switchViewMode: PropTypes.func.isRequired, switchViewMode: PropTypes.func.isRequired,
isCustomPermission: PropTypes.bool, isCustomPermission: PropTypes.bool,
sortBy: PropTypes.string,
sortOrder: PropTypes.string,
sortItems: PropTypes.func,
}; };
class DirTool extends React.Component { class DirTool extends React.Component {
@@ -27,8 +31,15 @@ class DirTool extends React.Component {
super(props); super(props);
this.state = { this.state = {
isRepoTagDialogOpen: false, 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 = () => { toggleDropdownMenu = () => {
@@ -78,13 +89,25 @@ class DirTool extends React.Component {
} }
}; };
onSelectSortOption = (item) => {
const [sortBy, sortOrder] = item.value.split('-');
this.props.sortItems(sortBy, sortOrder);
};
render() { render() {
const menuItems = this.getMenu(); const menuItems = this.getMenu();
const { isDropdownMenuOpen } = this.state; const { isDropdownMenuOpen } = this.state;
const { repoID, currentMode, currentPath } = this.props; const { repoID, currentMode, currentPath, sortBy, sortOrder } = this.props;
const propertiesText = TextTranslation.PROPERTIES.value; const propertiesText = TextTranslation.PROPERTIES.value;
const isFileExtended = currentPath === '/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES; const isFileExtended = currentPath === '/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES;
const sortOptions = this.sortOptions.map(item => {
return {
...item,
isSelected: item.value === `${sortBy}-${sortOrder}`
};
});
if (isFileExtended) { if (isFileExtended) {
return ( return (
<div className="d-flex"> <div className="d-flex">
@@ -97,6 +120,7 @@ class DirTool extends React.Component {
<React.Fragment> <React.Fragment>
<div className="d-flex"> <div className="d-flex">
<ViewModes currentViewMode={currentMode} switchViewMode={this.props.switchViewMode} /> <ViewModes currentViewMode={currentMode} switchViewMode={this.props.switchViewMode} />
<ReposSortMenu sortOptions={sortOptions} onSelectSortOption={this.onSelectSortOption}/>
{(!this.props.isCustomPermission) && {(!this.props.isCustomPermission) &&
<span className="cur-view-path-btn ml-2" onClick={() => this.props.switchViewMode('detail')}> <span className="cur-view-path-btn ml-2" onClick={() => this.props.switchViewMode('detail')}>
<span className="sf3-font sf3-font-info" aria-label={propertiesText} title={propertiesText}></span> <span className="sf3-font sf3-font-info" aria-label={propertiesText} title={propertiesText}></span>

View File

@@ -93,6 +93,9 @@ class CurDirPath extends React.Component {
currentMode={this.props.currentMode} currentMode={this.props.currentMode}
switchViewMode={this.props.switchViewMode} switchViewMode={this.props.switchViewMode}
isCustomPermission={this.props.isCustomPermission} isCustomPermission={this.props.isCustomPermission}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}
/>} />}
{!isDesktop && this.props.direntList.length > 0 && {!isDesktop && this.props.direntList.length > 0 &&
<span className="sf3-font sf3-font-sort action-icon" onClick={this.toggleSortOptionsDialog}></span>} <span className="sf3-font sf3-font-sort action-icon" onClick={this.toggleSortOptionsDialog}></span>}

View File

@@ -34,8 +34,8 @@ class ReposSortMenu extends React.Component {
<DropdownToggle <DropdownToggle
tag="div" tag="div"
data-toggle="dropdown" data-toggle="dropdown"
title={gettext('Switch view mode')} title={gettext('Switch sort mode')}
aria-label={gettext('Switch view mode')} aria-label={gettext('Switch sort mode')}
aria-expanded={isDropdownMenuOpen} aria-expanded={isDropdownMenuOpen}
> >
<span className="cur-view-path-btn px-1" role="button"> <span className="cur-view-path-btn px-1" role="button">