Skip to content

Commit

Permalink
rename placeholder text, remove unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
MaHaWo committed Aug 22, 2024
1 parent 1acff8f commit 17ec1e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/lib/components/ComponentLogic/tableLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ export function filterItems(data, searchTerm, searchableColumns) {

export function makePlaceholderText(data, searchableColumns) {
const numCols = Object.keys(data[0]).length;
let placeholderText = 'Search ';
let placeholderText = 'Filter ';

if (searchableColumns.length === 1) {
placeholderText = placeholderText + searchableColumns[0];
} else if (searchableColumns.length > 1 && searchableColumns.length <= numCols / 2) {
placeholderText = 'Search ' + `any of ${searchableColumns.join(', ')}`;
placeholderText = 'Filter ' + `any of ${searchableColumns.join(', ')}`;
} else if (searchableColumns.length > numCols / 2 && searchableColumns.length < numCols) {
const difference = Object.keys(data[0]).filter((key) => !searchableColumns.includes(key));
placeholderText = 'Search all columns except ' + `${difference.join(', ')}`;
placeholderText = 'Filter all columns except ' + `${difference.join(', ')}`;
} else if (searchableColumns.length === numCols) {
placeholderText = 'Search all columns';
placeholderText = 'Filter all columns';
} else {
placeholderText = 'Search disabled';
placeholderText = 'Filter disabled';
}

return placeholderText;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/ComponentLogic/tableLogic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ describe('makePlaceholderText: should return a placeholder text based on the num
it('should return colname when only one searchable columns', () => {
const searchableColumns = ['name'];
const result = makePlaceholderText(data, searchableColumns);
expect(result).toEqual('Search name');
expect(result).toEqual('Filter name');
});
it('should return with except when searchable colnames are more than half of the colnames', () => {
const searchableColumns = ['name', 'age', 'income'];
const result = makePlaceholderText(data, searchableColumns);
expect(result).toEqual('Search all columns except id');
expect(result).toEqual('Filter all columns except id');
});
it('should return with list when searchable colnames are less than half of the colnames', () => {
const searchableColumns = ['name', 'age'];
const result = makePlaceholderText(data, searchableColumns);
expect(result).toEqual('Search any of name, age');
expect(result).toEqual('Filter any of name, age');
});
it('should return with all when searchable colnames are less than half of the colnames', () => {
const searchableColumns = ['name', 'age', 'income', 'id'];
const result = makePlaceholderText(data, searchableColumns);
expect(result).toEqual('Search all columns');
expect(result).toEqual('Filter all columns');
});

it('should return with all when searchable colnames are less than half of the colnames', () => {
const searchableColumns = [];
const result = makePlaceholderText(data, searchableColumns);
expect(result).toEqual('Search disabled');
expect(result).toEqual('Filter disabled');
});
});
1 change: 0 additions & 1 deletion src/lib/components/DataDisplay/TableDisplay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
$: filteredItems = filterItems(data, searchTerm, searchableColumns);
// make the placeholdertext for the searchbar dynamic
const numCols = Object.keys(data[0]).length;
const placeholderText = makePlaceholderText(data, searchableColumns);
</script>

Expand Down

0 comments on commit 17ec1e7

Please sign in to comment.