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'},
|
min: {value: 'min', label: 'Min', displayName: 'Min'},
|
||||||
max: {value: 'max', label: 'Max', displayName: 'Max'},
|
max: {value: 'max', label: 'Max', displayName: 'Max'},
|
||||||
range: {value: 'range', label: 'Range', displayName: 'Range'},
|
range: {value: 'range', label: 'Range', displayName: 'Range'},
|
||||||
earliest: {value: 'earliest', label: 'Earliest', displayName: 'Earliest'},
|
earliest: {value: 'earliest', label: 'Earliest Date', displayName: 'Earliest'},
|
||||||
latest: {value: 'latest', label: 'Latest', displayName: 'Latest'},
|
latest: {value: 'latest', label: 'Latest Date', displayName: 'Latest'},
|
||||||
dateRange: {value: 'dateRange', label: 'Range', displayName: 'Range'},
|
dateRange: {value: 'dateRange', label: 'Date Range', displayName: 'Range'},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const optionsByType: Map<string, Option[]> = new Map([
|
export const optionsByType: Map<string, Option[]> = new Map([
|
||||||
|
|
|
@ -60,4 +60,35 @@ describe('components/kanban/calculations/KanbanCalculationOptions', () => {
|
||||||
userEvent.hover(countUniqueValuesOption)
|
userEvent.hover(countUniqueValuesOption)
|
||||||
expect(container).toMatchSnapshot()
|
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.
|
const seen: Record<string, boolean> = {}
|
||||||
map((property) => optionsByType.get(property.type) || []).
|
props.cardProperties.forEach((property) => {
|
||||||
forEach((typeOptions) => {
|
// skip already processed property types
|
||||||
typeOptions.forEach((typeOption) => {
|
if (seen[property.type]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
(optionsByType.get(property.type) || []).
|
||||||
|
forEach((typeOption) => {
|
||||||
options.push({
|
options.push({
|
||||||
...typeOption,
|
...typeOption,
|
||||||
cardProperties: props.cardProperties,
|
cardProperties: props.cardProperties,
|
||||||
|
@ -46,7 +51,9 @@ export const KanbanCalculationOptions = (props: Props): JSX.Element => {
|
||||||
activeProperty: props.property!,
|
activeProperty: props.property!,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
seen[property.type] = true
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CalculationOptions
|
<CalculationOptions
|
||||||
|
|
Loading…
Reference in a new issue