-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1338 from SURFnet/feature/62_tablefilter
Add the ability to filter the Entity IDP selection list
- Loading branch information
Showing
7 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { filterRow } from './table_filter_logic'; | ||
|
||
(function () { | ||
"use strict"; | ||
|
||
|
||
function dquery(selector: string) { | ||
return Array.prototype.slice.call(document.querySelectorAll(selector)); | ||
} | ||
|
||
function onInputEvent(e: any) { | ||
const input = e.target; | ||
const search = input.value.toLocaleLowerCase(); | ||
|
||
const tableContainer = input.closest('.input-group').parentElement; | ||
const table = tableContainer.querySelector('table'); | ||
const rows = table.querySelectorAll('tbody tr'); | ||
|
||
[].forEach.call(rows, function(row: any) { | ||
filterRow(row, search); | ||
}); | ||
} | ||
|
||
function init() { | ||
const inputs = dquery("input[data-table]"); | ||
[].forEach.call(inputs, function (input: HTMLInputElement) { | ||
input.oninput = onInputEvent; | ||
if (input.value !== "") input.oninput(({ target: input } as unknown) as Event); | ||
}); | ||
} | ||
|
||
init(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { filterRow } from './table_filter_logic'; | ||
|
||
describe('filterRow', () => { | ||
let row: any; | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = ''; // Clear the DOM | ||
row = document.createElement('tr'); | ||
row.style.display = 'table-row'; | ||
document.body.appendChild(row); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
describe('when row has checked inputs', () => { | ||
beforeEach(() => { | ||
const input = document.createElement('input'); | ||
input.type = 'checkbox'; | ||
input.checked = true; | ||
row.appendChild(input); | ||
}); | ||
|
||
it('should always display the row regardless of search term', () => { | ||
filterRow(row, 'nonexistent'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
}); | ||
|
||
describe('when row contains th elements', () => { | ||
beforeEach(() => { | ||
const th = document.createElement('th'); | ||
th.textContent = 'header content'; | ||
row.appendChild(th); | ||
}); | ||
|
||
it('should always display the row regardless of search term', () => { | ||
filterRow(row, 'nonexistent'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
}); | ||
|
||
describe('when filtering regular content', () => { | ||
beforeEach(() => { | ||
row.textContent = 'Test Row Content'; | ||
}); | ||
|
||
it('should show row when search term matches content', () => { | ||
filterRow(row, 'test'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
|
||
it('should hide row when search term does not match content', () => { | ||
filterRow(row, 'nonexistent'); | ||
expect(row.style.display).toBe('none'); | ||
}); | ||
|
||
it('should be case insensitive', () => { | ||
filterRow(row, 'TEST'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
|
||
it('should cache lowercase content after first call', () => { | ||
filterRow(row, 'test'); | ||
const cachedContent = row.lowerTextContent; | ||
filterRow(row, 'row'); | ||
expect(row.lowerTextContent).toBe(cachedContent); | ||
}); | ||
}); | ||
|
||
describe('edge cases', () => { | ||
beforeEach(() => { | ||
row.textContent = 'Test Content'; | ||
}); | ||
|
||
it('should handle empty search string', () => { | ||
filterRow(row, ''); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
|
||
it('should handle special characters in search', () => { | ||
row.textContent = 'Test (Content)'; | ||
filterRow(row, '(content)'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
|
||
it('should handle multiple consecutive calls with different search terms', () => { | ||
filterRow(row, 'test'); | ||
expect(row.style.display).toBe('table-row'); | ||
filterRow(row, 'nonexistent'); | ||
expect(row.style.display).toBe('none'); | ||
filterRow(row, 'content'); | ||
expect(row.style.display).toBe('table-row'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function filterRow(row: any, search: string): void { | ||
if (row.lowerTextContent === undefined) { | ||
row.lowerTextContent = row.textContent.toLocaleLowerCase(); | ||
} | ||
|
||
if (row.querySelectorAll('input:checked').length > 0) { | ||
row.style.display = 'table-row'; | ||
return; | ||
} | ||
|
||
if (row.querySelectorAll('th').length > 0) { | ||
row.style.display = 'table-row'; | ||
return; | ||
} | ||
|
||
row.style.display = row.lowerTextContent.indexOf(search.toLocaleLowerCase()) === -1 ? "none" : "table-row"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters