Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sort repos] added 'sort by name/size/time' to the table header in 'F… #7263

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/components/sort-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SortMenu extends React.Component {
this.sortOptions = [
{ value: 'name-asc', text: gettext('By name ascending') },
{ value: 'name-desc', text: gettext('By name descending') },
{ value: 'size-asc', text: gettext('By size ascending') },
{ value: 'size-desc', text: gettext('By size descending') },
{ value: 'time-asc', text: gettext('By time ascending') },
{ value: 'time-desc', text: gettext('By time descending') }
];
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/pages/libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class Libraries extends Component {

onSelectSortOption = (sortOption) => {
const [sortBy, sortOrder] = sortOption.value.split('-');
this.sortReposByOption(sortBy, sortOrder);
};

sortReposByOption = (sortBy, sortOrder) => {
this.setState({ sortBy, sortOrder }, () => {
localStorage.setItem('sf_repos_sort_by', sortBy);
localStorage.setItem('sf_repos_sort_order', sortOrder);
Expand All @@ -156,6 +160,12 @@ class Libraries extends Component {
});
};

toggleSortOrder = (sortBy, e) => {
e.preventDefault();
const sortOrder = this.state.sortOrder == 'asc' ? 'desc' : 'asc';
this.sortReposByOption(sortBy, sortOrder);
};

sortRepoList = (sortBy, sortOrder) => {
cookie.save('seafile-repo-dir-sort-by', sortBy);
cookie.save('seafile-repo-dir-sort-order', sortOrder);
Expand Down Expand Up @@ -387,6 +397,7 @@ class Libraries extends Component {
render() {
const { isLoading, currentViewMode, sortBy, sortOrder, groupList } = this.state;
const isDesktop = Utils.isDesktop();
const sortIcon = sortOrder === 'asc' ? <span className="sf3-font sf3-font-down rotate-180 d-inline-block"></span> : <span className="sf3-font sf3-font-down"></span>;

return (
<>
Expand All @@ -407,15 +418,15 @@ class Libraries extends Component {
{isLoading ? <Loading /> : (
<>
{(Utils.isDesktop() && currentViewMode == LIST_MODE) && (
<table aria-hidden={true} className="my-3">
<table className="my-3">
<thead>
<tr>
<th width="4%"></th>
<th width="3%"><span className="sr-only">{gettext('Library Type')}</span></th>
<th width="35%">{gettext('Name')}</th>
<th width="35%"><a className="d-block table-sort-op" href="#" onClick={this.toggleSortOrder.bind(this, 'name')}>{gettext('Name')} {sortBy === 'name' && sortIcon}</a></th>
<th width="10%"><span className="sr-only">{gettext('Actions')}</span></th>
<th width="14%">{gettext('Size')}</th>
<th width="17%">{gettext('Last Update')}</th>
<th width="14%"><a className="d-block table-sort-op" href="#" onClick={this.toggleSortOrder.bind(this, 'size')}>{gettext('Size')} {sortBy === 'size' && sortIcon}</a></th>
<th width="17%"><a className="d-block table-sort-op" href="#" onClick={this.toggleSortOrder.bind(this, 'time')}>{gettext('Last Update')} {sortBy === 'time' && sortIcon}</a></th>
<th width="17%">{gettext('Owner')}</th>
</tr>
</thead>
Expand Down
Loading