passbolt-styleguide
Version:
Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.
155 lines (144 loc) • 5.52 kB
JavaScript
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 2.13.0
*/
import React from "react";
import PropTypes from "prop-types";
import DisplayResourceFolderDetailsInformation from "./DisplayResourceFolderDetailsInformation";
import DisplayResourceFolderDetailsPermissions from "./DisplayResourceFolderDetailsPermissions";
import DisplayResourceFolderDetailsActivity from "./DisplayResourceFolderDetailsActivity";
import { withAppContext } from "../../../../shared/context/AppContext/AppContext";
import { withResourceWorkspace } from "../../../contexts/ResourceWorkspaceContext";
import { withActionFeedback } from "../../../contexts/ActionFeedbackContext";
import { Trans, withTranslation } from "react-i18next";
import { uiActions } from "../../../../shared/services/rbacs/uiActionEnumeration";
import { withRbac } from "../../../../shared/context/Rbac/RbacContext";
import FolderSidebarSVG from "../../../../img/svg/folder-sidebar.svg";
import LinkSVG from "../../../../img/svg/link.svg";
import Tabs from "../../Common/Tab/Tabs";
import Tab from "../../Common/Tab/Tab";
import { withClipboard } from "../../../contexts/Clipboard/ManagedClipboardServiceProvider";
class DisplayResourceFolderDetails extends React.Component {
/**
* Constructor
* @param {Object} props
*/
constructor(props) {
super(props);
this.bindCallbacks();
}
/**
* Bind callbacks methods
*/
bindCallbacks() {
this.handlePermalinkClick = this.handlePermalinkClick.bind(this);
}
/**
* Handle when the user copies the permalink.
*/
async handlePermalinkClick() {
const baseUrl = this.props.context.userSettings.getTrustedDomain();
const permalink = `${baseUrl}/app/folders/view/${this.props.resourceWorkspaceContext.details.folder.id}`;
await this.props.clipboardContext.copy(permalink, this.translate("The permalink has been copied to clipboard."));
}
/**
* Get the translate function
* @returns {function(...[*]=)}
*/
get translate() {
return this.props.t;
}
/**
* Renders the "Details" section tab of a folder.
* @returns {JSX}
*/
renderFolderDetail() {
const canViewShare = this.props.rbacContext.canIUseAction(uiActions.SHARE_VIEW_LIST);
return (
<>
<DisplayResourceFolderDetailsInformation />
{canViewShare && <DisplayResourceFolderDetailsPermissions />}
</>
);
}
/**
* Render the component
* @returns {JSX}
*/
render() {
const canUseAuditLog =
(this.props.context.siteSettings.canIUse("auditLog") || this.props.context.siteSettings.canIUse("audit_log")) && // @deprecated remove with v4
this.props.rbacContext.canIUseAction(uiActions.RESOURCES_SEE_ACTIVITIES);
return (
<div className="sidebar resource">
<div className={`sidebar-header ${canUseAuditLog ? "" : "with-separator"}`}>
<div className="teaser-image">
<FolderSidebarSVG />
</div>
<div className="title-area">
<h3>
<div className="title-wrapper">
<span className="name">{this.props.resourceWorkspaceContext.details.folder.name}</span>
</div>
<span className="subtitle">
<Trans>folder</Trans>
</span>
</h3>
<button
type="button"
className="title-link button-transparent inline"
title={this.translate("Copy the link to this folder")}
onClick={this.handlePermalinkClick}
>
<LinkSVG />
<span className="visuallyhidden">
<Trans>Copy the link to this folder</Trans>
</span>
</button>
</div>
</div>
<div className="sidebar-content">
{!canUseAuditLog ? (
this.renderFolderDetail()
) : (
<Tabs activeTabName="Details">
<Tab key="Details" name={this.props.t("Details")} type="Details">
{this.renderFolderDetail()}
</Tab>
<Tab key="Activity" name={this.props.t("Activity")} type="Activity">
<DisplayResourceFolderDetailsActivity />
</Tab>
</Tabs>
)}
</div>
</div>
);
}
}
DisplayResourceFolderDetails.propTypes = {
context: PropTypes.any, // The application context
groups: PropTypes.array,
onSelectFolderParent: PropTypes.func,
onSelectRoot: PropTypes.func,
onEditPermissions: PropTypes.func,
users: PropTypes.array,
resourceWorkspaceContext: PropTypes.object,
actionFeedbackContext: PropTypes.any, // The action feedback context
clipboardContext: PropTypes.object,
t: PropTypes.func, // The translation function
rbacContext: PropTypes.any, // The role based access control context
};
export default withAppContext(
withRbac(
withResourceWorkspace(withClipboard(withActionFeedback(withTranslation("common")(DisplayResourceFolderDetails)))),
),
);