// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {useIntl, IntlShape} from 'react-intl' import {PropertyType} from '../blocks/board' import {Utils} from '../utils' import Menu from '../widgets/menu' import './propertyMenu.scss' type Props = { propertyId: string propertyName: string propertyType: PropertyType onTypeAndNameChanged: (newType: PropertyType, newName: string) => void onDelete: (id: string) => void } export function typeDisplayName(intl: IntlShape, type: PropertyType): string { switch (type) { case 'text': return intl.formatMessage({id: 'PropertyType.Text', defaultMessage: 'Text'}) case 'number': return intl.formatMessage({id: 'PropertyType.Number', defaultMessage: 'Number'}) case 'select': return intl.formatMessage({id: 'PropertyType.Select', defaultMessage: 'Select'}) case 'multiSelect': return intl.formatMessage({id: 'PropertyType.MultiSelect', defaultMessage: 'Multi select'}) case 'person': return intl.formatMessage({id: 'PropertyType.Person', defaultMessage: 'Person'}) case 'file': return intl.formatMessage({id: 'PropertyType.File', defaultMessage: 'File or media'}) case 'checkbox': return intl.formatMessage({id: 'PropertyType.Checkbox', defaultMessage: 'Checkbox'}) case 'url': return intl.formatMessage({id: 'PropertyType.URL', defaultMessage: 'URL'}) case 'email': return intl.formatMessage({id: 'PropertyType.Email', defaultMessage: 'Email'}) case 'phone': return intl.formatMessage({id: 'PropertyType.Phone', defaultMessage: 'Phone'}) case 'createdTime': return intl.formatMessage({id: 'PropertyType.CreatedTime', defaultMessage: 'Created time'}) case 'createdBy': return intl.formatMessage({id: 'PropertyType.CreatedBy', defaultMessage: 'Created by'}) case 'updatedTime': return intl.formatMessage({id: 'PropertyType.UpdatedTime', defaultMessage: 'Last updated time'}) case 'updatedBy': return intl.formatMessage({id: 'PropertyType.UpdatedBy', defaultMessage: 'Last updated by'}) case 'date': return intl.formatMessage({id: 'PropertyType.Date', defaultMessage: 'Date'}) default: { Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`) return type } } } function typeMenuTitle(intl: IntlShape, type: PropertyType): string { return `${intl.formatMessage({id: 'PropertyMenu.typeTitle', defaultMessage: 'Type'})}: ${typeDisplayName(intl, type)}` } export const propertyTypesList: PropertyType[] = [ 'text', 'number', 'email', 'phone', 'url', 'select', 'multiSelect', 'date', 'person', 'checkbox', 'createdTime', 'createdBy', 'updatedTime', 'updatedBy', ] type TypesProps = { label: string onTypeSelected: (type: PropertyType) => void } export const PropertyTypes = (props: TypesProps): JSX.Element => { const intl = useIntl() return ( <> {props.label} { propertyTypesList.map((type) => ( props.onTypeSelected(type)} /> )) } ) } const PropertyMenu = (props: Props) => { const intl = useIntl() let currentPropertyName = props.propertyName const deleteText = intl.formatMessage({ id: 'PropertyMenu.Delete', defaultMessage: 'Delete', }) return ( { props.onTypeAndNameChanged(props.propertyType, n) currentPropertyName = n }} onValueChanged={(n) => currentPropertyName = n} /> props.onTypeAndNameChanged(type, currentPropertyName)} /> props.onDelete(props.propertyId)} /> ) } export default React.memo(PropertyMenu)