All files / src/components/tek-grid columns-searcher.ts

100% Statements 12/12
100% Branches 3/3
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23      112x   8x 5x   5x 4x 5x   5x 6x     4x     5x      
import { IDictionary } from '@zeedhi/core';
import { IColumnsSearcher, ITekGridColumn } from './interfaces';
 
export class ColumnsSearcher implements IColumnsSearcher {
	async searchColumn(columns: ITekGridColumn[], search: string): Promise<IDictionary<(string | number)[]>> {
		const lookupColumns = columns.filter((column) => !!column.componentProps?.datasource && !column.skipLookupSearch);
		const searchJoin: IDictionary<Array<string | number>> = {};
 
		if (search) {
			const promises = lookupColumns.map(async (column) => {
				const searchData = await column.memorySearch(search);
 
				const lookupId = column.componentProps!.datasource.uniqueKey;
				searchJoin[column.name] = searchData.map((row: IDictionary) => row[lookupId]);
			});
 
			await Promise.all(promises);
		}
 
		return searchJoin;
	}
}