// @flow import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { DEFAULT_MAX_APP_COUNT, SECURITY_CONTROLS_FORMAT } from '../constants'; import { getShortSecurityControlsMessage, getFullSecurityControlsMessages } from './utils'; import messages from './messages'; import PlainButton from '../../../components/plain-button'; import Label from '../../../components/label/Label'; import SecurityControlsItem from './SecurityControlsItem'; import SecurityControlsModal from './SecurityControlsModal'; import type { Controls, ControlsFormat } from '../flowTypes'; import './SecurityControls.scss'; const { FULL, SHORT, SHORT_WITH_BTN } = SECURITY_CONTROLS_FORMAT; type Props = { classificationColor?: string, classificationName?: string, controls: Controls, controlsFormat: ControlsFormat, definition?: string, itemName?: string, maxAppCount?: number, shouldRenderLabel?: boolean, shouldDisplayAppsAsIntegrations?: boolean, }; type State = { isSecurityControlsModalOpen: boolean, }; class SecurityControls extends React.Component { static defaultProps = { classificationName: '', definition: '', itemName: '', controls: {}, controlsFormat: SHORT, maxAppCount: DEFAULT_MAX_APP_COUNT, shouldRenderLabel: false, shouldDisplayAppsAsIntegrations: false, }; state = { isSecurityControlsModalOpen: false, }; openModal = () => this.setState({ isSecurityControlsModalOpen: true }); closeModal = () => this.setState({ isSecurityControlsModalOpen: false }); render() { const { classificationColor, classificationName, controls, controlsFormat, definition, itemName, maxAppCount, shouldRenderLabel, shouldDisplayAppsAsIntegrations, } = this.props; let items = []; let modalItems; if (controlsFormat === FULL) { items = getFullSecurityControlsMessages(controls, maxAppCount, shouldDisplayAppsAsIntegrations); } else { items = getShortSecurityControlsMessage(controls, shouldDisplayAppsAsIntegrations); if (items.length && controlsFormat === SHORT_WITH_BTN) { modalItems = getFullSecurityControlsMessages(controls, maxAppCount, shouldDisplayAppsAsIntegrations); } } if (!items.length) { return null; } const { isSecurityControlsModalOpen } = this.state; const shouldShowSecurityControlsModal = controlsFormat === SHORT_WITH_BTN && !!itemName && !!classificationName && !!definition; let itemsList = ( ); if (shouldRenderLabel) { itemsList = ; } return ( <> {itemsList} {shouldShowSecurityControlsModal && ( <> )} ); } } export type { Props as SecurityControlsProps }; export default SecurityControls;