Fixed a bug causing duplicate date related menues to appear in kanban calculations (#1834)

This commit is contained in:
Harshil Sharma 2021-11-23 16:09:04 +05:30 committed by GitHub
parent 5730fb4bfe
commit 470be213ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 3 deletions

View File

@ -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(
<KanbanCalculationOptions
value={'count'}
property={boardWithProps.fields.cardProperties[1]}
menuOpen={true}
onChange={() => {}}
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)
})
})

View File

@ -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<PropertyType, PropertyType>([
['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<string, boolean> = {}
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 (