-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add text & numeric filters to insights routing responses (#18016)
* 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 * feat: support DataTable filters for Insights Routing WIP * remove unused filters * remove additionalFilters and fix types * clean up filter components * support icons for ActiveFilters * support filters on json * fix filter ui * fix type error and clean up * revert changes * revert change * clean up * revert change * fix compatibility with insights booking page * remove unused params * fix type errors * update yarn.lock * fix field filter and adjust ui * chore: update yarn.lock * fix text filter * add Clear Filters button * add more test data * feat: support numeric filter WIP * feat: support numeric filter * feat: move People to an external filter * fixing query states * rename state to activeFilters * add useDataTable * fix ResponseCellValue bug and enable resizing for RoutingFormResponsesTable * fix response values * truncate attribute text * seed booking attendees * fix accessor (no actual change though) * add a gap * rename * use pathname as default identifier for DataTable * fix type error * support text filter for assignment reason * Apply suggestions from code review Co-authored-by: Alex van Andel <[email protected]> * rename fields to headers * use safeParse * fix type error * push yarn.lock with faker * fix MemberList --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: sean-brydon <[email protected]>
- Loading branch information
1 parent
e366c10
commit a7e7561
Showing
36 changed files
with
1,170 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 11 additions & 48 deletions
59
packages/features/data-table/components/filters/FilterOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/features/data-table/components/filters/NumberFilterOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
"use client"; | ||
|
||
import { useForm, Controller } from "react-hook-form"; | ||
|
||
import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
import { Form, Input, Select, Button } from "@calcom/ui"; | ||
|
||
import type { FilterableColumn, NumberFilterOperator } from "../../lib/types"; | ||
import { ZNumberFilterValue } from "../../lib/types"; | ||
import { useFilterValue, useDataTable } from "../../lib/utils"; | ||
|
||
export type NumberFilterOperatorOption = { | ||
label: string; | ||
value: NumberFilterOperator; | ||
}; | ||
|
||
const numberFilterOperatorOptions: NumberFilterOperatorOption[] = [ | ||
{ value: "eq", label: "=" }, | ||
{ value: "neq", label: "≠" }, | ||
{ value: "gt", label: ">" }, | ||
{ value: "gte", label: "≥" }, | ||
{ value: "lt", label: "<" }, | ||
{ value: "lte", label: "≤" }, | ||
]; | ||
|
||
export type NumberFilterOptionsProps = { | ||
column: Extract<FilterableColumn, { type: "number" }>; | ||
}; | ||
|
||
export function NumberFilterOptions({ column }: NumberFilterOptionsProps) { | ||
const { t } = useLocale(); | ||
const filterValue = useFilterValue(column.id, ZNumberFilterValue); | ||
const { updateFilter, removeFilter } = useDataTable(); | ||
|
||
const form = useForm({ | ||
defaultValues: { | ||
operatorOption: filterValue | ||
? numberFilterOperatorOptions.find((o) => o.value === filterValue.data.operator) | ||
: numberFilterOperatorOptions[0], | ||
operand: filterValue?.data.operand || "", | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="mx-3 my-2"> | ||
<Form | ||
form={form} | ||
handleSubmit={({ operatorOption, operand }) => { | ||
if (operatorOption) { | ||
updateFilter(column.id, { | ||
type: "number", | ||
data: { | ||
operator: operatorOption.value, | ||
operand: Number(operand), | ||
}, | ||
}); | ||
} | ||
}}> | ||
<div> | ||
<Controller | ||
name="operatorOption" | ||
control={form.control} | ||
render={({ field: { value } }) => ( | ||
<div className="-mt-2 flex items-center gap-2"> | ||
<Select | ||
className="basis-1/3" | ||
options={numberFilterOperatorOptions} | ||
value={value} | ||
isSearchable={false} | ||
onChange={(event) => { | ||
if (event) { | ||
form.setValue("operatorOption", { ...event }, { shouldDirty: true }); | ||
} | ||
}} | ||
/> | ||
<Input type="number" className="mt-2 basis-2/3" {...form.register("operand")} /> | ||
</div> | ||
)} | ||
/> | ||
|
||
<div className="bg-subtle -mx-3 mb-2 h-px" role="separator" /> | ||
|
||
<div className="flex items-center justify-between"> | ||
<Button | ||
type="button" | ||
color="secondary" | ||
disabled={form.formState.isSubmitting} | ||
onClick={() => removeFilter(column.id)}> | ||
{t("clear")} | ||
</Button> | ||
<Button | ||
type="submit" | ||
color="primary" | ||
loading={form.formState.isSubmitting} | ||
disabled={form.formState.isSubmitting}> | ||
{t("apply")} | ||
</Button> | ||
</div> | ||
</div> | ||
</Form> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.