Fix: prevent duplicated text query with multiple date queries (#13522)

This commit is contained in:
shamoon
2026-08-03 06:52:44 -07:00
committed by GitHub
parent 2a50425902
commit 41d5d86637
2 changed files with 25 additions and 12 deletions
@@ -1697,6 +1697,24 @@ describe('FilterEditorComponent', () => {
])
})
it('should carry over text filtering once with created and added relative dates', () => {
component.textFilter = 'foo'
const datesDropdown = fixture.debugElement.query(
By.directive(DatesDropdownComponent)
)
component.dateCreatedRelativeDate = RelativeDate.WITHIN_1_WEEK
component.dateAddedRelativeDate = RelativeDate.WITHIN_1_MONTH
datesDropdown.triggerEventHandler('datesSet')
fixture.detectChanges()
tick(400)
expect(component.filterRules).toEqual([
{
rule_type: FILTER_FULLTEXT_QUERY,
value: 'foo,created:[-1 week to now],added:[-1 month to now]',
},
])
})
it('should convert legacy title filters into full text query when adding a created relative date', () => {
component.filterRules = [
{
@@ -1016,7 +1016,6 @@ export class FilterEditorComponent
this.dateAddedRelativeDate !== null ||
this.dateCreatedRelativeDate !== null
) {
let queryArgs: Array<string> = []
let existingRule = filterRules.find(
(fr) => fr.rule_type == FILTER_FULLTEXT_QUERY
)
@@ -1038,32 +1037,28 @@ export class FilterEditorComponent
existingRule.rule_type = FILTER_FULLTEXT_QUERY
}
let existingRuleArgs = existingRule?.value.split(',')
let queryArgs = existingRule?.value.split(',') ?? []
if (this.dateCreatedRelativeDate !== null) {
const rd = RELATIVE_DATE_QUERYSTRINGS.find(
(qS) => qS.relativeDate == this.dateCreatedRelativeDate
)
queryArgs = queryArgs.filter(
(arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_CREATED)
)
queryArgs.push(
`created:${rd.isRange ? `[${rd.dateQuery}]` : `"${rd.dateQuery}"`}`
)
if (existingRule) {
queryArgs = existingRuleArgs
.filter((arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_CREATED))
.concat(queryArgs)
}
}
if (this.dateAddedRelativeDate !== null) {
const rd = RELATIVE_DATE_QUERYSTRINGS.find(
(qS) => qS.relativeDate == this.dateAddedRelativeDate
)
queryArgs = queryArgs.filter(
(arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)
)
queryArgs.push(
`added:${rd.isRange ? `[${rd.dateQuery}]` : `"${rd.dateQuery}"`}`
)
if (existingRule) {
queryArgs = existingRuleArgs
.filter((arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED))
.concat(queryArgs)
}
}
if (existingRule) {