All files / src/components/EditableTableV2 filterTooltip.ts

100% Statements 7/7
100% Branches 18/18
100% Functions 1/1
100% Lines 6/6

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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55      19x           60x                     60x                                                 60x   60x   60x          
import { ComponentStrings } from '../../strings';
import { EditableTableColumnV2 } from './types';
 
export const filterTooltip = <TData extends object>(
  definition: EditableTableColumnV2<TData>,
  value: unknown,
  strings: ComponentStrings
): string => {
  const filterType =
    typeof definition.filterFn === 'string'
      ? definition.filterFn
      : typeof definition.filterFn === 'function'
        ? definition.filterFn.name
        : definition.filterVariant === 'multi-select'
          ? 'arrIncludesSome'
          : definition.filterVariant?.includes('range')
            ? 'betweenInclusive'
            : definition.filterVariant === 'select'
              ? 'equals'
              : 'fuzzy';
  const labels: Record<string, string> = {
    arrIncludes: strings.INCLUDES,
    arrIncludesAll: strings.INCLUDES_ALL,
    arrIncludesSome: strings.INCLUDES,
    between: strings.BETWEEN,
    betweenInclusive: strings.BETWEEN_INCLUSIVE,
    contains: strings.CONTAINS,
    empty: strings.EMPTY,
    endsWith: strings.ENDS_WITH,
    equals: strings.EQUALS,
    equalsString: strings.EQUALS,
    fuzzy: strings.FUZZY,
    greaterThan: strings.GREATER_THAN,
    greaterThanOrEqualTo: strings.GREATER_THAN_OR_EQUAL_TO,
    inNumberRange: strings.BETWEEN,
    includesString: strings.CONTAINS,
    includesStringSensitive: strings.CONTAINS,
    lessThan: strings.LESS_THAN,
    lessThanOrEqualTo: strings.LESS_THAN_OR_EQUAL_TO,
    notEmpty: strings.NOT_EMPTY,
    notEquals: strings.NOT_EQUALS,
    startsWith: strings.STARTS_WITH,
    weakEquals: strings.EQUALS,
  };
  const isRange =
    definition.filterVariant?.includes('range') ||
    ['between', 'betweenInclusive', 'inNumberRange'].includes(filterType);
  const description = Array.isArray(value) ? value.join(`" ${isRange ? strings.AND : strings.OR} "`) : String(value);
 
  return strings.FILTERING_BY_COLUMN_FILTER_TYPE_FILTER_VALUE.replace('{column}', definition.header)
    .replace('{filterType}', labels[filterType] ?? '')
    .replace('{filterValue}', `"${description}"`)
    .replace('" "', '');
};