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

Use canEdit for clearSearch removal logic.

parent 852ea20a
...@@ -334,19 +334,20 @@ class FilteredSearchManager { ...@@ -334,19 +334,20 @@ class FilteredSearchManager {
this.clearSearch(); this.clearSearch();
} }
removalValidator(token) {
const isToken = token.classList.contains('js-visual-token');
return this.customRemovalValidator ? (this.customRemovalValidator(token) && isToken) : isToken;
}
clearSearch() { clearSearch() {
this.filteredSearchInput.value = ''; this.filteredSearchInput.value = '';
const removeElements = []; const removeElements = [];
[].forEach.call(this.tokensContainer.children, (t) => { [].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); removeElements.push(t);
} }
}); });
......
...@@ -9,13 +9,6 @@ export default class FilteredSearchServiceDesk extends gl.FilteredSearchManager ...@@ -9,13 +9,6 @@ export default class FilteredSearchServiceDesk extends gl.FilteredSearchManager
this.supportBotData = supportBotData; this.supportBotData = supportBotData;
} }
customRemovalValidator(token) {
const tokenValue = token.querySelector('.value-container');
return tokenValue ?
tokenValue.getAttribute('data-original-value') !== `@${this.supportBotData.username}` : true;
}
canEdit(tokenName) { canEdit(tokenName) {
return tokenName !== 'author'; return tokenName !== 'author';
} }
......
...@@ -412,31 +412,6 @@ describe('Filtered Search Manager', () => { ...@@ -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', () => { describe('getAllParams', () => {
beforeEach(() => { beforeEach(() => {
this.paramsArr = ['key=value', 'otherkey=othervalue']; 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