import React from 'react'; import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { gettext, siteRoot, canAddGroup, canAddRepo, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, enableTC, sideNavFooterCustomHtml, additionalAppBottomLinks, canViewOrg, isDocs, isPro, isDBSqlite3, customNavItems } from '../utils/constants'; import { seafileAPI } from '../utils/seafile-api'; import { Utils } from '../utils/utils'; import Group from '../models/group'; import toaster from './toast'; import CreateGroupDialog from '../components/dialog/create-group-dialog'; const propTypes = { currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, tabItemClick: PropTypes.func.isRequired, }; const SUB_NAV_ITEM_HEIGHT = 28; class MainSideNav extends React.Component { constructor(props) { super(props); this.state = { filesNavUnfolded: false, sharedExtended: false, closeSideBar:false, groupItems: [], isCreateGroupDialogOpen: false }; this.adminHeight = 0; this.filesNavHeight = 0; } shExtend = () => { this.setState({ sharedExtended: !this.state.sharedExtended, }); }; loadGroups = () => { let _this = this; seafileAPI.listGroups().then(res =>{ let groupList = res.data.map(item => { let group = new Group(item); return group; }); this.filesNavHeight = (groupList.length + (canAddGroup ? 1 : 0) + (canAddRepo ? 1 : 0) + (canViewOrg ? 1 : 0) + 1) * SUB_NAV_ITEM_HEIGHT; _this.setState({ groupItems: groupList.sort((a, b) => { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; }) }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); }; tabItemClick = (e, param, id) => { if (window.uploader && window.uploader.isUploadProgressDialogShow && window.uploader.totalProgress !== 100) { if (!window.confirm(gettext('A file is being uploaded. Are you sure you want to leave this page?'))) { e.preventDefault(); return false; } window.uploader.isUploadProgressDialogShow = false; } this.props.tabItemClick(param, id); }; getActiveClass = (tab) => { return this.props.currentTab === tab ? 'active' : ''; }; onCreateGroup = (groupData) => { const newGroup = new Group(groupData); const { groupItems: newList } = this.state; newList.push(newGroup); this.filesNavHeight += SUB_NAV_ITEM_HEIGHT; this.setState({ groupItems: newList }); }; toggleCreateGroupDialog = () => { this.setState({ isCreateGroupDialogOpen: !this.state.isCreateGroupDialogOpen }); }; renderSharedGroups() { return ( <> {this.state.groupItems.map(item => { return (
  • this.tabItemClick(e, item.name, item.id)} > {item.name}
  • ); })} {canAddGroup && ( <>
  • {gettext('New Group')}
  • {this.state.isCreateGroupDialogOpen && } )} ); } renderSharedAdmin() { let height = 0; if (this.state.sharedExtended) { if (!this.adminHeight) { this.adminHeight = 3 * SUB_NAV_ITEM_HEIGHT; } height = this.adminHeight; } let style = {height: height}; let linksNavItem = null; if (canGenerateShareLink) { linksNavItem = (
  • this.tabItemClick(e, 'share-admin-share-links')}> {gettext('Links')}
  • ); } else if (canGenerateUploadLink) { linksNavItem = (
  • this.tabItemClick(e, 'share-admin-upload-links')}> {gettext('Links')}
  • ); } return ( ); } renderCustomNavItems() { return ( customNavItems.map((item, idx) => { return (
  • {item.desc}
  • ); }) ); } toggleFilesNav = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ filesNavUnfolded: !this.state.filesNavUnfolded }, () => { if (this.state.filesNavUnfolded) { this.loadGroups(); } }); }; render() { let showActivity = isDocs || isPro || !isDBSqlite3; const { filesNavUnfolded } = this.state; return (

    {gettext('Workspace')}

    • this.tabItemClick(e, 'libraries')}> {gettext('Files')}
        {canAddRepo && (
      • this.tabItemClick(e, 'my-libs')}> {gettext('My Libraries')}
      • )}
      • this.tabItemClick(e, 'shared-libs')}> {gettext('Shared with me')}
      • {canViewOrg &&
      • this.tabItemClick(e, 'org')}> {gettext('Shared with all')}
      • } {this.renderSharedGroups()}
    • this.tabItemClick(e, 'starred')}> {gettext('Favorites')}
    • {showActivity &&
    • this.tabItemClick(e, 'dashboard')}> {gettext('Activities')}
    • }
    • this.tabItemClick(e, 'published')}> {gettext('Wikis')}
    • {canInvitePeople &&
    • this.tabItemClick(e, 'invitations')}> {gettext('Invite Guest')}
    • }
    • {gettext('Share Admin')} {this.renderSharedAdmin()}
    • {customNavItems && this.renderCustomNavItems()}

    {gettext('Help and resources')}

    {sideNavFooterCustomHtml ? (
    ) : ( ) }
    ); } } MainSideNav.propTypes = propTypes; export default MainSideNav;