Files
calendar/packages/features/data-table/lib/server.ts
T
1404581f78 feat: add text filter on org member list (#17632)
* feat: improve text filters (WIP)

* move function to bottom

* apply some styles

* fix selection of TextFilterOptions

* rename value to operand

* remove unused file

* merge filters/filters into filters/utils

* fix regression of not putting url params correctly

* move makeWhereClause to filters/utils

* fix negative, empty, and not empty operators

* fix initial filtering from search state (url)

* fix type errors

* do not send an empty array to query

* update yarn.lock

* i18n for text filter operators

* extract logic as useColumnFilters()

* add missing import

* fix type error

* revert yarn.lock

* use i18n

* insensitive text match

* move data-table to @calcom/features

* fix type errors

* fix type errors

* fix type errors

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
2024-11-20 09:38:10 +00:00

75 lines
1.6 KiB
TypeScript

import type { FilterValue } from "./types";
import { isSelectFilterValue, isTextFilterValue } from "./utils";
export function makeWhereClause(columnName: string, filterValue: FilterValue) {
if (isSelectFilterValue(filterValue)) {
return {
[columnName]: {
in: filterValue,
},
};
} else if (isTextFilterValue(filterValue)) {
const { operator, operand } = filterValue.data;
switch (operator) {
case "equals":
return {
[columnName]: {
equals: operand,
},
};
case "notEquals":
return {
[columnName]: {
not: operand,
},
};
case "contains":
return {
[columnName]: {
contains: operand,
mode: "insensitive",
},
};
case "notContains":
return {
NOT: {
[columnName]: {
contains: operand,
mode: "insensitive",
},
},
};
case "startsWith":
return {
[columnName]: {
startsWith: operand,
mode: "insensitive",
},
};
case "endsWith":
return {
[columnName]: {
endsWith: operand,
mode: "insensitive",
},
};
case "isEmpty":
return {
[columnName]: {
equals: "",
},
};
case "isNotEmpty":
return {
NOT: {
[columnName]: {
equals: "",
},
},
};
}
}
return {};
}