property.tsx
TLDR
This file contains the implementation of the SelectProperty
class, which is a subclass of PropertyType
. It includes methods and properties related to the "Select" property type used in the application.
Classes
SelectProperty
This class represents the "Select" property type. It extends the PropertyType
class and inherits its methods and properties. It provides implementation for the following methods:
-
displayName
: Returns the display name of the property type in the specified language. -
displayValue
: Returns the display value of a given property value for a card and property template. It retrieves the corresponding option value from the template's options and returns it, or '(Unknown)' if not found. -
valueLength
: Returns the length of the formatted display value of a property value for a card and property template. It calculates the width of the display value in the specified font.
Methods
None
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {IntlShape} from 'react-intl'
import {IPropertyTemplate} from '../../blocks/board'
import {Card} from '../../blocks/card'
import {Utils} from '../../utils'
import {PropertyType, PropertyTypeEnum, FilterValueType} from '../types'
import Select from './select'
export default class SelectProperty extends PropertyType {
Editor = Select
name = 'Select'
type = 'select' as PropertyTypeEnum
canGroup = true
canFilter = true
filterValueType = 'options' as FilterValueType
displayName = (intl: IntlShape) => intl.formatMessage({id: 'PropertyType.Select', defaultMessage: 'Select'})
displayValue = (propertyValue: string | string[] | undefined, card: Card, propertyTemplate: IPropertyTemplate) => {
if (propertyValue) {
const option = propertyTemplate.options.find((o) => o.id === propertyValue)
if (!option) {
Utils.assertFailure(`Invalid select option ID ${propertyValue}, block.title: ${card.title}`)
}
return option?.value || '(Unknown)'
}
return ''
}
valueLength = (value: string | string[] | undefined, card: Card, template: IPropertyTemplate, _: IntlShape, fontDescriptor: string): number => {
const displayValue = this.displayValue(value, card, template) || ''
return Utils.getTextWidth(displayValue.toString().toUpperCase(), fontDescriptor)
}
}