Skip to content

Commit

Permalink
share wiki
Browse files Browse the repository at this point in the history
update leave and return
  • Loading branch information
孙永强 committed Jul 20, 2024
1 parent add4689 commit b7c972a
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 40 deletions.
8 changes: 7 additions & 1 deletion frontend/src/components/dialog/share-to-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const propTypes = {
itemPath: PropTypes.string.isRequired,
itemType: PropTypes.string.isRequired,
repoID: PropTypes.string.isRequired,
repoType: PropTypes.string.isRequired,
isRepoOwner: PropTypes.bool.isRequired,
onAddCustomPermissionToggle: PropTypes.func,
};
Expand All @@ -126,7 +127,8 @@ class ShareToGroup extends React.Component {
selectedOption: null,
errorMsg: [],
permission: 'rw',
sharedItems: []
sharedItems: [],
isWiki: this.props.repoType === 'wiki'
};
this.permissions = [];
let { itemType, isRepoOwner } = props;
Expand All @@ -141,6 +143,9 @@ class ShareToGroup extends React.Component {
if (this.props.isGroupOwnedRepo) {
this.permissions = ['rw', 'r', 'cloud-edit', 'preview'];
}
if (this.state.isWiki) {
this.permissions = ['rw', 'r'];
}
}

handleSelectChange = (option) => {
Expand Down Expand Up @@ -344,6 +349,7 @@ class ShareToGroup extends React.Component {
permissions={this.permissions}
onPermissionChanged={this.setPermission}
enableAddCustomPermission={isPro}
isWiki={this.state.isWiki}
onAddCustomPermissionToggle={this.props.onAddCustomPermissionToggle}
/>
</td>
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/dialog/share-to-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const propTypes = {
itemType: PropTypes.string.isRequired,
repoID: PropTypes.string.isRequired,
isRepoOwner: PropTypes.bool.isRequired,
repoType: PropTypes.string.isRequired,
onAddCustomPermissionToggle: PropTypes.func,
};

Expand All @@ -164,7 +165,8 @@ class ShareToUser extends React.Component {
selectedOption: null,
errorMsg: [],
permission: 'rw',
sharedItems: []
sharedItems: [],
isWiki: this.props.repoType === 'wiki'
};
this.options = [];
this.permissions = [];
Expand All @@ -180,6 +182,9 @@ class ShareToUser extends React.Component {
if (this.props.isGroupOwnedRepo) {
this.permissions = ['rw', 'r', 'cloud-edit', 'preview'];
}
if (this.state.isWiki) {
this.permissions = ['rw', 'r'];
}
}

handleSelectChange = (option) => {
Expand Down Expand Up @@ -369,6 +374,7 @@ class ShareToUser extends React.Component {
permissions={this.permissions}
onPermissionChanged={this.setPermission}
enableAddCustomPermission={isPro}
isWiki={this.state.isWiki}
onAddCustomPermissionToggle={this.props.onAddCustomPermissionToggle}
/>
</td>
Expand Down
176 changes: 176 additions & 0 deletions frontend/src/components/dialog/share-wiki-dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody, TabContent, TabPane, Nav, NavItem, NavLink } from 'reactstrap';
import { gettext, username, additionalShareDialogNote, canShareRepo } from '../../utils/constants';
import ShareToUser from './share-to-user';
import ShareToGroup from './share-to-group';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import Loading from '../loading';
import toaster from '../toast';

import '../../css/share-link-dialog.css';

const propTypes = {
isGroupOwnedRepo: PropTypes.bool,
itemType: PropTypes.string.isRequired, // there will be three choose: ['library', 'dir', 'file']
itemName: PropTypes.string.isRequired,
itemPath: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired,
repoID: PropTypes.string.isRequired,
repoEncrypted: PropTypes.bool,
enableDirPrivateShare: PropTypes.bool,
};

class ShareWikiDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
activeTab: 'shareToUser',
isRepoJudgemented: false,
isRepoOwner: false,
isGroupOwnedRepo: false,
};
}

componentDidMount() {
let repoID = this.props.repoID;
seafileAPI.getRepoInfo(repoID).then(res => {
const isGroupOwnedRepo = res.data.owner_email.indexOf('@seafile_group') > -1;
let isRepoOwner = res.data.owner_email === username;
this.setState({
isRepoJudgemented: true,
isRepoOwner: isRepoOwner,
repoType: res.data.repo_type,
isGroupOwnedRepo: isGroupOwnedRepo,
});
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}

toggle = (tab) => {
if (this.state.activeTab !== tab) {
this.setState({ activeTab: tab });
}
};

onAddCustomPermissionToggle = () => {
this.toggle('customSharePermission');
};

renderDirContent = () => {

if (!this.state.isRepoJudgemented) {
return <Loading />;
}

let activeTab = this.state.activeTab;
let { repoEncrypted, enableDirPrivateShare, itemType } = this.props;
// for encrypted repo, 'dir private share' is only enabled for the repo itself,
// not for the folders in it.
if (repoEncrypted) {
enableDirPrivateShare = itemType == 'library';
}
return (
<Fragment>
<div className="share-dialog-side">
<Nav pills>
{enableDirPrivateShare &&
<Fragment>
{ canShareRepo && (
<NavItem role="tab" aria-selected={activeTab === 'shareToUser'} aria-controls="share-to-user-panel">
<NavLink className={activeTab === 'shareToUser' ? 'active' : ''} onClick={this.toggle.bind(this, 'shareToUser')} tabIndex="0" onKeyDown={this.onTabKeyDown}>
{gettext('Share to user')}
</NavLink>
</NavItem>
)}
{ canShareRepo && (
<NavItem role="tab" aria-selected={activeTab === 'shareToGroup'} aria-controls="share-to-group-panel">
<NavLink className={activeTab === 'shareToGroup' ? 'active' : ''} onClick={this.toggle.bind(this, 'shareToGroup')} tabIndex="0" onKeyDown={this.onTabKeyDown}>
{gettext('Share to group')}
</NavLink>
</NavItem>
)}
</Fragment>
}
</Nav>
</div>
<div className="share-dialog-main">
<TabContent activeTab={this.state.activeTab}>
{enableDirPrivateShare &&
<Fragment>
{(activeTab === 'shareToUser' && canShareRepo) &&
<TabPane tabId="shareToUser" role="tabpanel" id="share-to-user-panel">
<ShareToUser
itemType={this.props.itemType}
isGroupOwnedRepo={this.state.isGroupOwnedRepo}
itemPath={this.props.itemPath}
repoID={this.props.repoID}
isRepoOwner={this.state.isRepoOwner}
repoType={this.state.repoType}
onAddCustomPermissionToggle={this.onAddCustomPermissionToggle}
/>
</TabPane>
}
{(activeTab === 'shareToGroup' && canShareRepo) &&
<TabPane tabId="shareToGroup" role="tabpanel" id="share-to-group-panel">
<ShareToGroup
itemType={this.props.itemType}
isGroupOwnedRepo={this.state.isGroupOwnedRepo}
itemPath={this.props.itemPath}
repoID={this.props.repoID}
isRepoOwner={this.state.isRepoOwner}
repoType={this.state.repoType}
onAddCustomPermissionToggle={this.onAddCustomPermissionToggle}
/>
</TabPane>
}
</Fragment>
}
</TabContent>
</div>
</Fragment>
);
};

onTabKeyDown = (e) => {
if (e.key == 'Enter' || e.key == 'Space') {
e.target.click();
}
};

renderExternalShareMessage = () => {
if (additionalShareDialogNote && (typeof additionalShareDialogNote) === 'object') {
return (
<div className="external-share-message mt-2">
<h6>{additionalShareDialogNote.title}</h6>
<p style={{ fontSize: '14px', color: '#666' }} className="text-wrap m-0">{additionalShareDialogNote.content}</p>
</div>
);
}
return null;
};

render() {
const { itemType, itemName } = this.props;
return (
<div>
<Modal isOpen={true} style={{ maxWidth: '760px' }} className="share-dialog" toggle={this.props.toggleDialog}>
<ModalHeader toggle={this.props.toggleDialog} tag="div">
<h5 className="text-truncate">{gettext('Share')} <span className="op-target" title={itemName}>{itemName}</span></h5>
{this.renderExternalShareMessage()}
</ModalHeader>
<ModalBody className="share-dialog-content" role="tablist">
{(itemType === 'library') && this.renderDirContent()}
</ModalBody>
</Modal>
</div>
);
}
}

ShareWikiDialog.propTypes = propTypes;

export default ShareWikiDialog;
3 changes: 2 additions & 1 deletion frontend/src/components/select-editor/select-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const propTypes = {
isTextMode: PropTypes.bool.isRequired, // there will be two mode. first: text and select. second: just select
isEditing: PropTypes.bool,
isEditIconShow: PropTypes.bool.isRequired,
isWiki: PropTypes.bool,
autoFocus: PropTypes.bool,
options: PropTypes.array.isRequired,
currentOption: PropTypes.string.isRequired,
Expand Down Expand Up @@ -56,7 +57,7 @@ class SelectEditor extends React.Component {
}

const { enableAddCustomPermission } = this.props;
if (enableAddCustomPermission) {
if (enableAddCustomPermission && !this.props.isWiki) {
const option = {
value: gettext('Add custom permission'),
isDisabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const propTypes = {
repoID: PropTypes.string,
isTextMode: PropTypes.bool.isRequired,
isEditing: PropTypes.bool,
isWiki: PropTypes.bool,
autoFocus: PropTypes.bool,
isEditIconShow: PropTypes.bool.isRequired,
permissions: PropTypes.array.isRequired,
Expand Down Expand Up @@ -136,6 +137,7 @@ class SharePermissionEditor extends React.Component {
translateOption={this.translatePermission}
translateExplanation={this.translateExplanation}
enableAddCustomPermission={this.props.enableAddCustomPermission}
isWiki={this.props.isWiki}
onAddCustomPermissionToggle={this.props.onAddCustomPermissionToggle}
/>
);
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/components/wiki-card-view/wiki-card-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { SIDE_PANEL_FOLDED_WIDTH } from '../../constants';

const propTypes = {
wikis: PropTypes.array.isRequired,
group: PropTypes.object,
deleteWiki: PropTypes.func.isRequired,
unshareGroupWiki: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
isDepartment: PropTypes.bool.isRequired,
isShowAvatar: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -48,10 +50,14 @@ class WikiCardGroup extends Component {
};

render() {
const { wikis, title, isDepartment, toggelAddWikiDialog } = this.props;
const { wikis, title, isDepartment, toggelAddWikiDialog, group } = this.props;
const containerWidth = this.getContainerWidth();
const numberOfWiki = Math.floor(containerWidth / 180);
const grids = (Math.floor((containerWidth - (numberOfWiki + 1) * 16) / numberOfWiki) + 'px ').repeat(numberOfWiki);
let isGroup = false;
if (group){
isGroup = true;
}
return (
<div className='wiki-card-group mb-4'>
<h4 className="sf-heading">
Expand All @@ -60,11 +66,21 @@ class WikiCardGroup extends Component {
</h4>
<div className='wiki-card-group-items' style={{ gridTemplateColumns: isMobile ? '48% 48%' : grids }} ref={this.groupItemsRef}>
{wikis.map((wiki, index) => {
return (
return (isGroup ?
<WikiCardItem
key={index + wiki.id + wiki.name}
group={group}
wiki={wiki}
deleteWiki={this.props.deleteWiki}
unshareGroupWiki={this.props.unshareGroupWiki}
isDepartment={isDepartment}
isShowAvatar={this.props.isShowAvatar}
renameWiki={this.props.renameWiki}
/> : <WikiCardItem
key={index + wiki.id + wiki.name}
wiki={wiki}
deleteWiki={this.props.deleteWiki}
unshareGroupWiki={this.props.unshareGroupWiki}
isDepartment={isDepartment}
isShowAvatar={this.props.isShowAvatar}
renameWiki={this.props.renameWiki}
Expand Down
Loading

0 comments on commit b7c972a

Please sign in to comment.