passbolt-styleguide
Version:
Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.
124 lines (113 loc) • 4.54 kB
JavaScript
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) 2020 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) 2020 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, { Component } from "react";
import { withRouter } from "react-router-dom";
import PropTypes from "prop-types";
import Breadcrumbs from "../../Common/Navigation/Breadcrumbs/Breadcrumbs";
import { UserWorkspaceFilterTypes, withUserWorkspace } from "../../../contexts/UserWorkspaceContext";
import Breadcrumb from "../../Common/Navigation/Breadcrumbs/Breadcrumb";
import { withNavigationContext } from "../../../contexts/NavigationContext";
import { Trans, withTranslation } from "react-i18next";
/**
* The component displays a navigation breadcrumb given the applied users filter
*/
class FilterUsersByBreadcrumb extends Component {
/**
* Returns the current list of breadcrumb items
*/
get items() {
const items = [this.allUsersBreadcrumb];
switch (this.props.userWorkspaceContext.filter.type) {
case UserWorkspaceFilterTypes.NONE:
return [];
case UserWorkspaceFilterTypes.ALL:
return [...items, this.getLastBreadcrumb(this.translate("Home"))];
case UserWorkspaceFilterTypes.TEXT: {
const isEmptySearchText = !this.props.userWorkspaceContext.filter.payload;
const currentSearchText = this.props.userWorkspaceContext.filter.payload;
return isEmptySearchText
? items
: [...items, this.getLastBreadcrumb(`${this.translate("Search:")} ${currentSearchText}`)];
}
case UserWorkspaceFilterTypes.SUSPENDED_USER:
return [...items, this.getLastBreadcrumb(this.translate("Suspended users"))];
case UserWorkspaceFilterTypes.ACCOUNT_RECOVERY_REQUEST:
return [...items, this.getLastBreadcrumb(this.translate("Account Recovery Requests"))];
case UserWorkspaceFilterTypes.MISSING_METADATA_KEY:
return [...items, this.getLastBreadcrumb(this.translate("Missing Metadata Key"))];
case UserWorkspaceFilterTypes.RECENTLY_MODIFIED:
return [...items, this.getLastBreadcrumb(this.translate("Recently modified"))];
case UserWorkspaceFilterTypes.GROUP: {
const group = this.props.userWorkspaceContext.filter.payload.group;
const currentGroupName = (group && group.name) || this.translate("N/A");
return [...items, this.getLastBreadcrumb(`${currentGroupName} ${this.translate("(group)")}`)];
}
}
return [];
}
/**
* Returns the home breadcrumb items
* @return {JSX.Element}
*/
get allUsersBreadcrumb() {
return (
<Breadcrumb name={this.translate("All users")} onClick={this.props.navigationContext.onGoToUsersRequested} />
);
}
/**
* Return the last breadcrumb
* @param {string} name the breadcrumb name
* @return {JSX.Element}
*/
getLastBreadcrumb(name) {
return <Breadcrumb name={name} onClick={this.onLastBreadcrumbClick.bind(this)} />;
}
/**
* Whenever the user click on the last breadcrumb
* @returns {Promise<void>}
*/
async onLastBreadcrumbClick() {
const pathname = this.props.location.pathname;
this.props.history.push({ pathname });
}
/**
* Get the translate function
* @returns {function(...[*]=)}
*/
get translate() {
return this.props.t;
}
/**
* Render the component
* @returns {JSX}
*/
render() {
const count = this.props.userWorkspaceContext.filteredUsers.length;
return (
<Breadcrumbs items={this.items}>
<span className="counter">
<Trans count={count}>{{ count }} items</Trans>
</span>
</Breadcrumbs>
);
}
}
FilterUsersByBreadcrumb.propTypes = {
userWorkspaceContext: PropTypes.object, // The user workspace context
location: PropTypes.object, // The router location
history: PropTypes.object, // The router history
navigationContext: PropTypes.any, // The application navigation context
t: PropTypes.func, // The translation function
};
export default withRouter(withNavigationContext(withUserWorkspace(withTranslation("common")(FilterUsersByBreadcrumb))));