Skip to content

Commit

Permalink
[repo 'share admin' dialog] removed 'internal links'; fixup & improve…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
llj committed Aug 23, 2023
1 parent 58f7263 commit e055587
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 685 deletions.
30 changes: 6 additions & 24 deletions frontend/src/components/dialog/repo-share-admin-dialog.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import toaster from '../toast';
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api';
import { Modal, ModalHeader, ModalBody, TabContent, TabPane, Nav, NavItem, NavLink } from 'reactstrap';
import { gettext, username, canGenerateShareLink, canGenerateUploadLink } from '../../utils/constants';
import { gettext, canGenerateShareLink, canGenerateUploadLink } from '../../utils/constants';
import RepoShareAdminShareLinks from './repo-share-admin/share-links';
import RepoShareAdminUploadLinks from './repo-share-admin/upload-links';
import RepoShareAdminUserShares from './repo-share-admin/user-shares';
import RepoShareAdminGroupShares from './repo-share-admin/group-shares';
import RepoShareAdminInternalLinks from './repo-share-admin/internal-links';

const propTypes = {
repo: PropTypes.object.isRequired,
Expand All @@ -20,14 +16,13 @@ class RepoShareAdminDialog extends React.Component {

constructor(props) {
super(props);
this.enableShareLink = !this.props.repo.encrypted && canGenerateShareLink;
this.enableUploadLink = !this.props.repo.encrypted && canGenerateUploadLink;
this.state = {
activeTab: this.getInitialActiveTab(),
activeTab: this.getInitialActiveTab()
};
}

enableShareLink = !this.props.repo.encrypted && canGenerateShareLink;
enableUploadLink = !this.props.repo.encrypted && canGenerateUploadLink;

getInitialActiveTab = () => {
if (this.enableShareLink) {
return 'shareLink';
Expand All @@ -51,9 +46,8 @@ class RepoShareAdminDialog extends React.Component {
}

render() {

let activeTab = this.state.activeTab;
let repoName = this.props.repo.repo_name;
const { activeTab } = this.state;
const { repoName } = this.props.repo;

return (
<div>
Expand Down Expand Up @@ -89,11 +83,6 @@ class RepoShareAdminDialog extends React.Component {
{gettext('Group Shares')}
</NavLink>
</NavItem>
<NavItem role="tab" aria-selected={activeTab === 'internalLink'} aria-controls="internal-link-panel">
<NavLink className={activeTab === 'internalLink' ? 'active' : ''} onClick={this.toggle.bind(this, 'internalLink')} tabIndex="0" onKeyDown={this.onTabKeyDown}>
{gettext('Internal Links')}
</NavLink>
</NavItem>
</Nav>
</div>
<div className="share-dialog-main">
Expand Down Expand Up @@ -126,13 +115,6 @@ class RepoShareAdminDialog extends React.Component {
/>
</TabPane>
}
{activeTab === 'internalLink' &&
<TabPane tabId="internalLink" role="tabpanel" id="internal-link-panel">
<RepoShareAdminInternalLinks
repo={this.props.repo}
/>
</TabPane>
}
</TabContent>
</div>
</Fragment>
Expand Down
94 changes: 46 additions & 48 deletions frontend/src/components/dialog/repo-share-admin/group-shares.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';

import { Link } from '@gatsbyjs/reach-router';
import { Utils } from '../../../utils/utils';
import { seafileAPI } from '../../../utils/seafile-api';
import { gettext, siteRoot, isPro } from '../../../utils/constants';

import { gettext, siteRoot, isPro, username } from '../../../utils/constants';
import Loading from '../../../components/loading';
import toaster from '../../../components/toast';
import EmptyTip from '../../../components/empty-tip';
import SharePermissionEditor from '../../../components/select-editor/share-permission-editor';

const itemPropTypes = {
item: PropTypes.object.isRequired,
deleteItem: PropTypes.func.isRequired
deleteItem: PropTypes.func.isRequired,
isRepoOwner: PropTypes.bool.isRequired
};

class Item extends Component {
Expand All @@ -25,10 +25,10 @@ class Item extends Component {
isShowPermEditor: false,
};
this.permissions = ['rw', 'r'];
if (isPro && this.props.item.path === '/') {
this.permissions.push('admin');
}
if (isPro) {
if (this.props.item.path === '/' && this.props.isRepoOwner) {
this.permissions.push('admin');
}
this.permissions.push('cloud-edit', 'preview');
}
}
Expand Down Expand Up @@ -74,10 +74,10 @@ class Item extends Component {
return (
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} onFocus={this.onMouseEnter}>
<td>
<a href={objUrl} target="_blank">{Utils.getFolderName(item.path)}</a>
<Link to={objUrl}>{Utils.getFolderName(item.path)}</Link>
</td>
<td className="name">{item.share_to_name}</td>
<td className="name">
<td>
{!this.state.isShowPermEditor && (
<div>
<span>{item.permission_name || Utils.sharePerms(this.state.permission)}</span>
Expand All @@ -103,7 +103,7 @@ class Item extends Component {
onPermissionChanged={this.changePerm}
/>
)}
</td>
</td>
<td>
<span
tabIndex="0"
Expand All @@ -113,7 +113,8 @@ class Item extends Component {
onKeyDown={Utils.onKeyDown}
title={gettext('Delete')}
aria-label={gettext('Delete')}
/>
>
</span>
</td>
</tr>
);
Expand Down Expand Up @@ -155,7 +156,7 @@ class RepoShareAdminGroupShares extends Component {
seafileAPI.deleteShareToGroupItem(item.repo_id, item.path, 'group', item.share_to).then(res => {
let items = this.state.items.filter(shareItem => {
return shareItem.path + shareItem.share_to !== item.path + item.share_to;
})
});
this.setState({items: items});
let message = gettext('Successfully deleted 1 item');
toaster.success(message);
Expand All @@ -167,44 +168,41 @@ class RepoShareAdminGroupShares extends Component {

render() {
const { loading, errorMsg, items } = this.state;
const { repo } = this.props;
const isRepoOwner = repo.owner_email === username;
return (
<Fragment>
<div className="main-panel-center">
<div className="cur-view-container">
<div className="cur-view-content">
{loading && <Loading />}
{!loading && errorMsg && <p className="error text-center mt-8">{errorMsg}</p>}
{!loading && !errorMsg && !items.length &&
<EmptyTip forDialog={true}>
<p className="text-secondary">{gettext('No share links')}</p>
</EmptyTip>
}
{!loading && !errorMsg && items.length > 0 &&
<table>
<thead>
<tr>
<th width="30%">{gettext('Name')}</th>
<th width="30%">{gettext('Group')}</th>
<th width="30%">{gettext('Permission')}</th>
<th width="10%"></th>
</tr>
</thead>
<tbody>
{items.map((item, index) => {
return (
<Item
key={index}
item={item}
deleteItem={this.deleteItem}
/>
);
})}
</tbody>
</table>
}
</div>
</div>
</div>
{loading && <Loading />}
{!loading && errorMsg && <p className="error text-center mt-8">{errorMsg}</p>}
{!loading && !errorMsg && !items.length &&
<EmptyTip forDialog={true}>
<p className="text-secondary">{gettext('No group shares')}</p>
</EmptyTip>
}
{!loading && !errorMsg && items.length > 0 &&
<table className="table-hover">
<thead>
<tr>
<th width="30%">{gettext('Name')}</th>
<th width="30%">{gettext('Group')}</th>
<th width="30%">{gettext('Permission')}</th>
<th width="10%"></th>
</tr>
</thead>
<tbody>
{items.map((item, index) => {
return (
<Item
key={index}
item={item}
deleteItem={this.deleteItem}
isRepoOwner={isRepoOwner}
/>
);
})}
</tbody>
</table>
}
</Fragment>
);
}
Expand Down
Loading

0 comments on commit e055587

Please sign in to comment.