Commit 484ca2a4 authored by Bryce Johnson's avatar Bryce Johnson

Use canEdit for clearSearch removal logic.

parent 852ea20a
......@@ -334,19 +334,20 @@ class FilteredSearchManager {
this.clearSearch();
}
removalValidator(token) {
const isToken = token.classList.contains('js-visual-token');
return this.customRemovalValidator ? (this.customRemovalValidator(token) && isToken) : isToken;
}
clearSearch() {
this.filteredSearchInput.value = '';
const removeElements = [];
[].forEach.call(this.tokensContainer.children, (t) => {
if (this.removalValidator(t)) {
let canClearToken = t.classList.contains('js-visual-token');
if (canClearToken) {
const tokenKey = t.querySelector('.name').textContent.trim();
canClearToken = this.canEdit && this.canEdit(tokenKey);
}
if (canClearToken) {
removeElements.push(t);
}
});
......
......@@ -9,13 +9,6 @@ export default class FilteredSearchServiceDesk extends gl.FilteredSearchManager
this.supportBotData = supportBotData;
}
customRemovalValidator(token) {
const tokenValue = token.querySelector('.value-container');
return tokenValue ?
tokenValue.getAttribute('data-original-value') !== `@${this.supportBotData.username}` : true;
}
canEdit(tokenName) {
return tokenName !== 'author';
}
......
......@@ -412,31 +412,6 @@ describe('Filtered Search Manager', () => {
});
});
describe('removalValidator', () => {
beforeEach(() => {
Object.assign(gl.FilteredSearchManager.prototype, {
customRemovalValidator: () => true,
});
spyOn(gl.FilteredSearchManager.prototype, 'removalValidator').and.callThrough();
spyOn(gl.FilteredSearchManager.prototype, 'customRemovalValidator').and.callThrough();
initializeManager();
});
it('is called on clearSearch', () => {
manager.clearSearch();
expect(manager.removalValidator).toHaveBeenCalled();
});
it('calls the customRemovalValidator when present', () => {
manager.clearSearch();
expect(manager.customRemovalValidator).toHaveBeenCalled();
});
});
describe('getAllParams', () => {
beforeEach(() => {
this.paramsArr = ['key=value', 'otherkey=othervalue'];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment