Fixed a bug causing duplicate options to appear in board calculations (#1711)
* Fixed a bug causing duplicate options to appear in board calculations * Updated ate option names to avoid ambiguity with number functions
This commit is contained in:
parent
e4b570e6aa
commit
f0ae9630ed
3 changed files with 46 additions and 8 deletions
|
@ -35,9 +35,9 @@ export const Options:Record<string, Option> = {
|
|||
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<string, Option[]> = new Map([
|
||||
|
|
|
@ -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 = (
|
||||
<KanbanCalculationOptions
|
||||
value={'count'}
|
||||
property={boardWithProps.fields.cardProperties[1]}
|
||||
menuOpen={true}
|
||||
onChange={() => {}}
|
||||
cardProperties={boardWithProps.fields.cardProperties}
|
||||
/>
|
||||
)
|
||||
|
||||
const {getAllByText} = render(component)
|
||||
const sumOptions = getAllByText('Sum')
|
||||
expect(sumOptions).toBeDefined()
|
||||
expect(sumOptions.length).toBe(1)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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<string, boolean> = {}
|
||||
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 (
|
||||
<CalculationOptions
|
||||
|
|
Loading…
Reference in a new issue