// 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 Menu from '../widgets/menu' import propsRegistry from '../properties' import {PropertyType} from '../properties/types' import './propertyMenu.scss' type Props = { propertyId: string propertyName: string propertyType: PropertyType onTypeAndNameChanged: (newType: PropertyType, newName: string) => void onDelete: (id: string) => void } function typeMenuTitle(intl: IntlShape, type: PropertyType): string { return `${intl.formatMessage({id: 'PropertyMenu.typeTitle', defaultMessage: 'Type'})}: ${type.displayName(intl)}` } type TypesProps = { label: string onTypeSelected: (type: PropertyType) => void } export const PropertyTypes = (props: TypesProps): JSX.Element => { const intl = useIntl() return ( <> {props.label} { propsRegistry.list().map((p) => ( props.onTypeSelected(p)} /> )) } ) } 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)