Skip to content

Commit 81dda1f

Browse files
akashsonunespike-rabbit
authored andcommitted
refactor(filtered-search): drop unnecessary value assignment
BREAKING CHANGE: Empty `value` fields of criterion options are no longer replaced with the value from the `label`. Always provide a correct `value`.
1 parent 41535ca commit 81dda1f

File tree

2 files changed

+1
-33
lines changed

2 files changed

+1
-33
lines changed

projects/element-ng/filtered-search/si-filtered-search.component.spec.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,37 +1997,6 @@ describe('SiFilteredSearchComponent', () => {
19971997
});
19981998
});
19991999

2000-
// TODO: this is non-sense. Our interface does not allow empty value for options.
2001-
// TODO: remove with v47
2002-
it('should emit criterion with value = label from config', async () => {
2003-
component.doSearchOnInputChange = true;
2004-
component.criteria.set([
2005-
{ name: 'company', label: 'Company', options: ['Foo', 'Bar'] },
2006-
{ name: 'Location', label: 'Location', options: ['Munich', 'Zug'] },
2007-
{
2008-
name: 'country',
2009-
label: 'Country',
2010-
options: [{ value: 'DE', label: 'Germany' }, { label: 'Switzerland' } as any]
2011-
}
2012-
]);
2013-
component.searchCriteria.set({
2014-
criteria: [{ name: 'country', value: 'Switzerland' }],
2015-
value: 'Max'
2016-
});
2017-
spyOn(component, 'doSearch');
2018-
2019-
const filteredSearch = await loader.getHarness(SiFilteredSearchHarness);
2020-
const freeTextSearch = await filteredSearch.freeTextSearch();
2021-
await freeTextSearch.focus();
2022-
await freeTextSearch.sendKeys(':');
2023-
await tick();
2024-
2025-
expect(component.doSearch).toHaveBeenCalledWith({
2026-
criteria: jasmine.arrayContaining([{ name: 'country', value: 'Switzerland' }]),
2027-
value: ''
2028-
});
2029-
});
2030-
20312000
it('should work when only value is defined', async () => {
20322001
component.doSearchOnInputChange = true;
20332002
component.criteria.set([

projects/element-ng/filtered-search/values/typeahead/si-filtered-search-typeahead.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ export class SiFilteredSearchTypeaheadComponent
133133
// We should consider dropping this, but there is currently a unit test checking this behavior.
134134
const optionValue = this.optionValue();
135135
if (optionValue) {
136-
// TODO: The last ?? optionValue.label is non-sense, but we have a unit test checking this behavior.
137-
this.criterionValue().value = optionValue.value ?? optionValue.label;
136+
this.criterionValue().value = optionValue.value;
138137
}
139138
}
140139

0 commit comments

Comments
 (0)