Skip to content

Commit

Permalink
Merge pull request #6859 from haiwen/feat-add-article-info-icon
Browse files Browse the repository at this point in the history
feat: add info icon into toolbar
  • Loading branch information
YangGuoXuan-0503 authored Oct 11, 2024
2 parents dc15190 + d0ebb9e commit 8d7b172
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@seafile/resumablejs": "1.1.16",
"@seafile/sdoc-editor": "1.0.95",
"@seafile/seafile-calendar": "0.0.28",
"@seafile/seafile-editor": "^1.0.116",
"@seafile/seafile-editor": "^1.0.118",
"@seafile/sf-metadata-ui-component": "^0.0.40",
"@uiw/codemirror-extensions-langs": "^4.19.4",
"@uiw/react-codemirror": "^4.19.4",
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import { I18nextProvider } from 'react-i18next';
import i18n from './_i18n/i18n-seafile-editor';
import MarkdownEditor from './pages/markdown-editor';
import Loading from './components/loading';
import { CollaboratorsProvider, EnableMetadataProvider } from './metadata';

import './index.css';

const { repoID } = window.app.pageOptions;

ReactDom.render(
<I18nextProvider i18n={ i18n } >
<Suspense fallback={<Loading />}>
<MarkdownEditor />
<EnableMetadataProvider repoID={repoID} >
<CollaboratorsProvider repoID={repoID}>
<MarkdownEditor />
</CollaboratorsProvider>
</EnableMetadataProvider>
</Suspense>
</I18nextProvider>,
document.getElementById('root')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

class ButtonGroup extends React.PureComponent {
render() {
return (
<div className={'btn-group ' + this.props.className} role={'group'}>
<div className={classnames('btn-group', this.props.className)} role={'group'}>
{this.props.children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import { EXTERNAL_EVENTS, EventBus } from '@seafile/seafile-editor';
import { gettext, canGenerateShareLink, isPro, mediaUrl, canLockUnlockFile } from '../../../utils/constants';
import ButtonGroup from './button-group';
import ButtonItem from './button-item';
import CollabUsersButton from './collab-users-button';
import MoreMenu from './more-menu';
import FileInfo from './file-info';
import Icon from '../../../components/icon';
import EmbeddedFileDetails from '../../../components/dirent-detail/embedded-file-details';
import { seafileAPI } from '../../../utils/seafile-api';
import { Utils } from '../../../utils/utils';
import Dirent from '../../../../src/models/dirent';

import '../css/header-toolbar.css';

const { seafileCollabServer } = window.app.config;
const { canDownloadFile } = window.app.pageOptions;
const { canDownloadFile, repoID, filePath } = window.app.pageOptions;

const propTypes = {
editorApi: PropTypes.object.isRequired,
Expand All @@ -37,6 +42,10 @@ class HeaderToolbar extends React.Component {

constructor(props) {
super(props);
this.dirPath = filePath.substring(0, filePath.lastIndexOf('/') || 0) || '/';
this.isFileInfoShow = false;
this.currentDirent = null;
this.helpInfoToggleSubscribe = null;
}

downloadFile = () => {
Expand All @@ -53,6 +62,60 @@ class HeaderToolbar extends React.Component {
window.location.href = editorApi.getParentDictionaryUrl();
};

componentDidMount() {
this.getDirentList();

const eventBus = EventBus.getInstance();
this.helpInfoToggleSubscribe = eventBus.subscribe(EXTERNAL_EVENTS.ON_HELP_INFO_TOGGLE, this.handleHelpClick);
}

componentWillUnmount() {
this.helpInfoToggleSubscribe && this.helpInfoToggleSubscribe();
}

handleHelpClick = () => {
this.isFileInfoShow = false;
};

getDirentList = () => {
return seafileAPI.listDir(repoID, this.dirPath, { 'with_thumbnail': true }).then(res => {
const direntList = res.data.dirent_list || [];
for (let i = 0; i < direntList.length; i++) {
const item = direntList[i];
const dirent = new Dirent(item);
if (Utils.joinPath(item.parent_dir, item.name) === filePath) {
this.currentDirent = dirent;
break;
}
}
}).catch((err) => {
Utils.getErrorMsg(err, true);
});
};

onArticleInfoToggle = () => {
const repoInfo = { permission: this.currentDirent.permission };
const eventBus = EventBus.getInstance();

eventBus.dispatch(EXTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE, this.isFileInfoShow ? null : {
component: EmbeddedFileDetails,
props: {
repoID: repoID,
repoInfo: repoInfo,
dirent: this.currentDirent,
path: filePath,
onClose: this.onArticleInfoToggle,
width: 300,
component: {
headerComponent: {
closeIcon: (<i className="iconfont icon-x"></i>)
}
}
}
});
this.isFileInfoShow = !this.isFileInfoShow;
};

render() {
let { contentChanged, saving, isLocked, lockedByMe } = this.props;

Expand Down Expand Up @@ -94,6 +157,12 @@ class HeaderToolbar extends React.Component {
onMouseDown={this.props.toggleLockFile}
/>
)}
<ButtonItem
id="file-info"
text={gettext('Info')}
icon='info'
onMouseDown={this.onArticleInfoToggle}
/>
{canGenerateShareLink && (
<ButtonItem
id='shareBtn'
Expand Down
1 change: 1 addition & 0 deletions seahub/templates/markdown_file_view_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
canLockUnlockFile: {% if can_lock_unlock_file %}true{% else %}false{% endif %},
canDownloadFile: {% if can_download_file %}true{% else %}false{% endif %},
fileDownloadURL: {% if file_download_url %}'{{ file_download_url|escapejs }}'{% else %}''{% endif %},
enableMetadataManagement: {% if enable_metadata_management %} true {% else %} false {% endif %},
},
userInfo: {
username: '{{ user.username }}',
Expand Down

0 comments on commit 8d7b172

Please sign in to comment.