From 17ec1e71c94db0dda272dacede09d6f5c015fa9c Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Thu, 22 Aug 2024 13:13:33 +0200 Subject: [PATCH] rename placeholder text, remove unused variable --- src/lib/components/ComponentLogic/tableLogic.js | 10 +++++----- src/lib/components/ComponentLogic/tableLogic.test.js | 10 +++++----- src/lib/components/DataDisplay/TableDisplay.svelte | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib/components/ComponentLogic/tableLogic.js b/src/lib/components/ComponentLogic/tableLogic.js index 85eaaefa..4d4501ec 100644 --- a/src/lib/components/ComponentLogic/tableLogic.js +++ b/src/lib/components/ComponentLogic/tableLogic.js @@ -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; diff --git a/src/lib/components/ComponentLogic/tableLogic.test.js b/src/lib/components/ComponentLogic/tableLogic.test.js index 636a3a61..2615a93a 100644 --- a/src/lib/components/ComponentLogic/tableLogic.test.js +++ b/src/lib/components/ComponentLogic/tableLogic.test.js @@ -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'); }); }); diff --git a/src/lib/components/DataDisplay/TableDisplay.svelte b/src/lib/components/DataDisplay/TableDisplay.svelte index 38003093..4c1b6466 100644 --- a/src/lib/components/DataDisplay/TableDisplay.svelte +++ b/src/lib/components/DataDisplay/TableDisplay.svelte @@ -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);