diff --git a/webapp/src/components/kanban/calculation/calculationOptions.test.tsx b/webapp/src/components/kanban/calculation/calculationOptions.test.tsx index a7e9e82ec..81e03803e 100644 --- a/webapp/src/components/kanban/calculation/calculationOptions.test.tsx +++ b/webapp/src/components/kanban/calculation/calculationOptions.test.tsx @@ -92,4 +92,53 @@ describe('components/kanban/calculations/KanbanCalculationOptions', () => { expect(sumOptions).toBeDefined() expect(sumOptions.length).toBe(1) }) + + test('effectively date fields', () => { + // date, created time and updated time are effectively date fields. + // Only one set of date related menus should show up for all of them. + + const boardWithProps = TestBlockFactory.createBoard() + boardWithProps.fields.cardProperties.push({ + id: 'date', + name: 'Date', + type: 'date', + options: [], + }) + boardWithProps.fields.cardProperties.push({ + id: 'created-time', + name: 'Created Time', + type: 'createdTime', + options: [], + }) + boardWithProps.fields.cardProperties.push({ + id: 'updated-time', + name: 'Updated Time', + type: 'updatedTime', + options: [], + }) + + const component = wrapIntl( + {}} + cardProperties={boardWithProps.fields.cardProperties} + />, + ) + + const {getAllByText} = render(component) + + const earliestDateMenu = getAllByText('Earliest Date') + expect(earliestDateMenu).toBeDefined() + expect(earliestDateMenu.length).toBe(1) + + const latestDateMenu = getAllByText('Latest Date') + expect(latestDateMenu).toBeDefined() + expect(latestDateMenu.length).toBe(1) + + const dateRangeMenu = getAllByText('Date Range') + expect(dateRangeMenu).toBeDefined() + expect(dateRangeMenu.length).toBe(1) + }) }) diff --git a/webapp/src/components/kanban/calculation/calculationOptions.tsx b/webapp/src/components/kanban/calculation/calculationOptions.tsx index e6333b7b4..27a695613 100644 --- a/webapp/src/components/kanban/calculation/calculationOptions.tsx +++ b/webapp/src/components/kanban/calculation/calculationOptions.tsx @@ -7,7 +7,7 @@ import { CommonCalculationOptionProps, optionsByType, } from '../../calculations/options' -import {IPropertyTemplate} from '../../../blocks/board' +import {IPropertyTemplate, PropertyType} from '../../../blocks/board' import './calculationOption.scss' import {Option, OptionProps} from './kanbanOption' @@ -17,6 +17,16 @@ type Props = CommonCalculationOptionProps & { onChange: (data: {calculation: string, propertyId: string}) => void } +// contains mapping of property types which are effectly the same as other property type. +const equivalentPropertyType = new Map([ + ['createdTime', 'date'], + ['updatedTime', 'date'], +]) + +export function getEquivalentPropertyType(propertyType: PropertyType): PropertyType { + return equivalentPropertyType.get(propertyType) || propertyType +} + export const KanbanCalculationOptions = (props: Props): JSX.Element => { const options: OptionProps[] = [] @@ -37,7 +47,7 @@ export const KanbanCalculationOptions = (props: Props): JSX.Element => { const seen: Record = {} props.cardProperties.forEach((property) => { // skip already processed property types - if (seen[property.type]) { + if (seen[getEquivalentPropertyType(property.type)]) { return } @@ -52,7 +62,7 @@ export const KanbanCalculationOptions = (props: Props): JSX.Element => { }) }) - seen[property.type] = true + seen[getEquivalentPropertyType(property.type)] = true }) return (