diff --git a/webapp/src/components/calculations/options.tsx b/webapp/src/components/calculations/options.tsx index e70f68073..af23e6000 100644 --- a/webapp/src/components/calculations/options.tsx +++ b/webapp/src/components/calculations/options.tsx @@ -35,9 +35,9 @@ export const Options:Record = { min: {value: 'min', label: 'Min', displayName: 'Min'}, max: {value: 'max', label: 'Max', displayName: 'Max'}, range: {value: 'range', label: 'Range', displayName: 'Range'}, - earliest: {value: 'earliest', label: 'Earliest', displayName: 'Earliest'}, - latest: {value: 'latest', label: 'Latest', displayName: 'Latest'}, - dateRange: {value: 'dateRange', label: 'Range', displayName: 'Range'}, + earliest: {value: 'earliest', label: 'Earliest Date', displayName: 'Earliest'}, + latest: {value: 'latest', label: 'Latest Date', displayName: 'Latest'}, + dateRange: {value: 'dateRange', label: 'Date Range', displayName: 'Range'}, } export const optionsByType: Map = new Map([ diff --git a/webapp/src/components/kanban/calculation/calculationOptions.test.tsx b/webapp/src/components/kanban/calculation/calculationOptions.test.tsx index 9d0f3cf8b..1250ae909 100644 --- a/webapp/src/components/kanban/calculation/calculationOptions.test.tsx +++ b/webapp/src/components/kanban/calculation/calculationOptions.test.tsx @@ -60,4 +60,35 @@ describe('components/kanban/calculations/KanbanCalculationOptions', () => { userEvent.hover(countUniqueValuesOption) expect(container).toMatchSnapshot() }) + + test('duplicate property types', () => { + const boardWithProps = TestBlockFactory.createBoard() + boardWithProps.fields.cardProperties.push({ + id: 'number-property-1', + name: 'A Number Property - 1', + type: 'number', + options: [], + }) + boardWithProps.fields.cardProperties.push({ + id: 'number-property-2', + name: 'A Number Propert - 2y', + type: 'number', + options: [], + }) + + const component = ( + {}} + cardProperties={boardWithProps.fields.cardProperties} + /> + ) + + const {getAllByText} = render(component) + const sumOptions = getAllByText('Sum') + expect(sumOptions).toBeDefined() + expect(sumOptions.length).toBe(1) + }) }) diff --git a/webapp/src/components/kanban/calculation/calculationOptions.tsx b/webapp/src/components/kanban/calculation/calculationOptions.tsx index 9f82f0b63..e6333b7b4 100644 --- a/webapp/src/components/kanban/calculation/calculationOptions.tsx +++ b/webapp/src/components/kanban/calculation/calculationOptions.tsx @@ -34,10 +34,15 @@ export const KanbanCalculationOptions = (props: Props): JSX.Element => { } }) - props.cardProperties. - map((property) => optionsByType.get(property.type) || []). - forEach((typeOptions) => { - typeOptions.forEach((typeOption) => { + const seen: Record = {} + props.cardProperties.forEach((property) => { + // skip already processed property types + if (seen[property.type]) { + return + } + + (optionsByType.get(property.type) || []). + forEach((typeOption) => { options.push({ ...typeOption, cardProperties: props.cardProperties, @@ -46,7 +51,9 @@ export const KanbanCalculationOptions = (props: Props): JSX.Element => { activeProperty: props.property!, }) }) - }) + + seen[property.type] = true + }) return (