function isFilterCanBeMerged()

in dashboard/new-dashboard/src/components/common/DataQueryExecutor.ts [192:214]


function isFilterCanBeMerged(filter1: DataQueryFilter, filter2: DataQueryFilter, fields: (string | DataQueryDimension)[]): boolean {
  // Check if both filters have a field 'f' and they are equal
  if (filter1.f !== filter2.f) return false

  const filter1Value = filter1.v
  const filter2Value = filter2.v

  // Check if filter1.v and filter2.v are either strings or arrays of strings
  if (!(typeof filter1Value === "string" ? true : Array.isArray(filter1Value)) || !(typeof filter2Value === "string" ? true : Array.isArray(filter2Value))) return false

  //Check that filters are different
  if (Array.isArray(filter1Value) && Array.isArray(filter2Value) && filter1Value.length === filter2Value.length && filter1Value.every((v, i) => v === filter2Value[i])) {
    return false
  }
  if (filter1.v == filter2.v) return false

  //We only support combining filters with no operator and without sql
  if (filter1.o !== undefined || filter2.o !== undefined) return false
  if (filter1.q !== undefined || filter2.q !== undefined) return false

  //We need filter name to be present in fields to later split the data
  return fields.some((field) => (typeof field === "string" ? field === filter1.f : field.n + "." + (field.subName ?? "") === filter1.f))
}