// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {injectIntl, IntlShape} from 'react-intl' import {Card} from '../blocks/card' import {IContentBlock} from '../blocks/contentBlock' import mutator from '../mutator' import {Utils} from '../utils' import IconButton from '../widgets/buttons/iconButton' import AddIcon from '../widgets/icons/add' import DeleteIcon from '../widgets/icons/delete' import OptionsIcon from '../widgets/icons/options' import SortDownIcon from '../widgets/icons/sortDown' import SortUpIcon from '../widgets/icons/sortUp' import Menu from '../widgets/menu' import MenuWrapper from '../widgets/menuWrapper' import ContentElement from './content/contentElement' import AddContentMenuItem from './addContentMenuItem' import {contentRegistry} from './content/contentRegistry' import './contentBlock.scss' type Props = { block: IContentBlock card: Card contents: readonly IContentBlock[] readonly: boolean intl: IntlShape } class ContentBlock extends React.PureComponent { public render(): JSX.Element | null { const {intl, card, contents, block, readonly} = this.props const index = contents.indexOf(block) return (
{!this.props.readonly && }/> {index > 0 && } onClick={() => { const contentOrder = contents.map((o) => o.id) Utils.arrayMove(contentOrder, index, index - 1) mutator.changeCardContentOrder(card, contentOrder) }} />} {index < (contents.length - 1) && } onClick={() => { const contentOrder = contents.map((o) => o.id) Utils.arrayMove(contentOrder, index, index + 1) mutator.changeCardContentOrder(card, contentOrder) }} />} } > {contentRegistry.contentTypes.map((type) => ( ))} } id='delete' name={intl.formatMessage({id: 'ContentBlock.Delete', defaultMessage: 'Delete'})} onClick={() => { const description = intl.formatMessage({id: 'ContentBlock.DeleteAction', defaultMessage: 'delete'}) const contentOrder = contents.map((o) => o.id).filter((o) => o !== block.id) mutator.performAsUndoGroup(async () => { await mutator.deleteBlock(block, description) await mutator.changeCardContentOrder(card, contentOrder, description) }) }} /> }
) } } export default injectIntl(ContentBlock)