balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

airtable.js (719B)


      1 export function createTemplatesFilterFormula(filters) {
      2     const { taxonomies, search, type } = filters
      3     const formula = []
      4 
      5     // Builds the taxonomy list by looping over all supplied taxonomies
      6     const taxFormula = Object.entries(taxonomies)
      7         .filter((tax) => Boolean(tax[1].length))
      8         .map((tax) => `${tax[0]} = "${tax[1]}"`)
      9         .join(', ')
     10 
     11     taxFormula.length && formula.push(taxFormula)
     12     search?.length && formula.push(`OR(FIND(LOWER("${search}"), LOWER(title))!= 0, FIND(LOWER("${search}"), LOWER({tax_categories})) != 0)`)
     13     type.length && formula.push(`{type}="${type}"`)
     14 
     15     return formula.length
     16         ? `AND(${formula.join(', ')})`.replace(/\r?\n|\r/g, '')
     17         : ''
     18 }