chore: clean up ColumnFilterType (#18915)
This commit is contained in:
1 parent
f06bac7129
commit
61a2a3ef5a
13 files changed
+84
-71
No files matched your search
@@ -10,7 +10,7 @@ import { Select } from "@calcom/ui";
|
||||
import "../../../insights/filters/DateSelect.css";
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ZDateRangeFilterValue } from "../../lib/types";
|
||||
import { ZDateRangeFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
type PresetOption = {
|
||||
labelKey: string;
|
||||
@@ -20,7 +20,7 @@ type PresetOption = {
|
||||
|
||||
type DateRangeFilterProps = {
|
||||
className?: string;
|
||||
column: Extract<FilterableColumn, { type: "date_range" }>;
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.DATE_RANGE }>;
|
||||
};
|
||||
|
||||
const CUSTOM_PRESET_VALUE = "c" as const;
|
||||
@@ -112,7 +112,7 @@ export const DateRangeFilter = ({ className, column }: DateRangeFilterProps) =>
|
||||
|
||||
if (startDate && endDate) {
|
||||
updateFilter(column.id, {
|
||||
type: "date_range",
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
data: {
|
||||
startDate: startDate.toDate().toISOString(),
|
||||
endDate: endDate.toDate().toISOString(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ColumnFilterType } from "../../lib/types";
|
||||
import { DateRangeFilter } from "./DateRangeFilter";
|
||||
import { MultiSelectFilterOptions } from "./MultiSelectFilterOptions";
|
||||
import { NumberFilterOptions } from "./NumberFilterOptions";
|
||||
@@ -12,15 +13,15 @@ export type FilterOptionsProps = {
|
||||
};
|
||||
|
||||
export function FilterOptions({ column }: FilterOptionsProps) {
|
||||
if (column.type === "text") {
|
||||
if (column.type === ColumnFilterType.TEXT) {
|
||||
return <TextFilterOptions column={column} />;
|
||||
} else if (column.type === "multi_select") {
|
||||
} else if (column.type === ColumnFilterType.MULTI_SELECT) {
|
||||
return <MultiSelectFilterOptions column={column} />;
|
||||
} else if (column.type === "single_select") {
|
||||
} else if (column.type === ColumnFilterType.SINGLE_SELECT) {
|
||||
return <SingleSelectFilterOptions column={column} />;
|
||||
} else if (column.type === "number") {
|
||||
} else if (column.type === ColumnFilterType.NUMBER) {
|
||||
return <NumberFilterOptions column={column} />;
|
||||
} else if (column.type === "date_range") {
|
||||
} else if (column.type === ColumnFilterType.DATE_RANGE) {
|
||||
return <DateRangeFilter column={column} />;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { IconName } from "@calcom/ui";
|
||||
import { Button, Icon, Popover, PopoverContent, PopoverTrigger } from "@calcom/ui";
|
||||
|
||||
import { useFilterValue } from "../../hooks";
|
||||
import { type FilterableColumn, type FilterValue, ZFilterValue } from "../../lib/types";
|
||||
import { type FilterableColumn, type FilterValue, ZFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
import {
|
||||
isSingleSelectFilterValue,
|
||||
isMultiSelectFilterValue,
|
||||
@@ -14,12 +14,12 @@ import {
|
||||
} from "../../lib/utils";
|
||||
import { FilterOptions } from "./FilterOptions";
|
||||
|
||||
const FILTER_ICONS: Record<FilterableColumn["type"], IconName> = {
|
||||
text: "file-text",
|
||||
number: "binary",
|
||||
multi_select: "layers",
|
||||
single_select: "disc",
|
||||
date_range: "calendar-range",
|
||||
const FILTER_ICONS: Record<ColumnFilterType, IconName> = {
|
||||
[ColumnFilterType.TEXT]: "file-text",
|
||||
[ColumnFilterType.NUMBER]: "binary",
|
||||
[ColumnFilterType.MULTI_SELECT]: "layers",
|
||||
[ColumnFilterType.SINGLE_SELECT]: "disc",
|
||||
[ColumnFilterType.DATE_RANGE]: "calendar-range",
|
||||
};
|
||||
|
||||
type FilterPopoverProps = {
|
||||
@@ -38,11 +38,11 @@ const useSelectedLabels = ({
|
||||
} else if (isNumberFilterValue(filterValue)) {
|
||||
return { text: filterValue.data.operand, moreCount: 0 };
|
||||
} else if (isSingleSelectFilterValue(filterValue)) {
|
||||
const options = (column as Extract<FilterableColumn, { type: "single_select" }>).options;
|
||||
const options = (column as Extract<FilterableColumn, { type: ColumnFilterType.SINGLE_SELECT }>).options;
|
||||
const text = options.find((opt) => opt.value === filterValue.data)?.label;
|
||||
return { text, moreCount: 0 };
|
||||
} else if (isMultiSelectFilterValue(filterValue)) {
|
||||
const options = (column as Extract<FilterableColumn, { type: "multi_select" }>).options;
|
||||
const options = (column as Extract<FilterableColumn, { type: ColumnFilterType.MULTI_SELECT }>).options;
|
||||
const text = options.find((opt) => opt.value === filterValue.data[0])?.label;
|
||||
return { text, moreCount: filterValue.data.length - 1 };
|
||||
} else {
|
||||
@@ -54,6 +54,11 @@ export function FilterPopover({ column }: FilterPopoverProps) {
|
||||
const icon = column.icon || FILTER_ICONS[column.type];
|
||||
const filterValue = useFilterValue(column.id, ZFilterValue);
|
||||
const { text, moreCount } = useSelectedLabels({ column, filterValue });
|
||||
console.log("💡 icon", {
|
||||
icon: column.icon,
|
||||
type: column.type,
|
||||
FILTER_ICONS,
|
||||
});
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ZMultiSelectFilterValue } from "../../lib/types";
|
||||
import { ZMultiSelectFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
export type MultiSelectFilterOptionsProps = {
|
||||
column: Extract<FilterableColumn, { type: "multi_select" }>;
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.MULTI_SELECT }>;
|
||||
};
|
||||
|
||||
export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsProps) {
|
||||
@@ -44,7 +44,7 @@ export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsPro
|
||||
const newFilterValue = filterValue?.data.includes(optionValue)
|
||||
? filterValue?.data.filter((value) => value !== optionValue)
|
||||
: [...(filterValue?.data || []), optionValue];
|
||||
updateFilter(column.id, { type: "multi_select", data: newFilterValue });
|
||||
updateFilter(column.id, { type: ColumnFilterType.MULTI_SELECT, data: newFilterValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Form, Input, Select, Button } from "@calcom/ui";
|
||||
|
||||
import { useFilterValue, useDataTable } from "../../hooks";
|
||||
import type { FilterableColumn, NumberFilterOperator } from "../../lib/types";
|
||||
import { ZNumberFilterValue } from "../../lib/types";
|
||||
import { ZNumberFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
export type NumberFilterOperatorOption = {
|
||||
label: string;
|
||||
@@ -24,7 +24,7 @@ const numberFilterOperatorOptions: NumberFilterOperatorOption[] = [
|
||||
];
|
||||
|
||||
export type NumberFilterOptionsProps = {
|
||||
column: Extract<FilterableColumn, { type: "number" }>;
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.NUMBER }>;
|
||||
};
|
||||
|
||||
export function NumberFilterOptions({ column }: NumberFilterOptionsProps) {
|
||||
@@ -48,7 +48,7 @@ export function NumberFilterOptions({ column }: NumberFilterOptionsProps) {
|
||||
handleSubmit={({ operatorOption, operand }) => {
|
||||
if (operatorOption) {
|
||||
updateFilter(column.id, {
|
||||
type: "number",
|
||||
type: ColumnFilterType.NUMBER,
|
||||
data: {
|
||||
operator: operatorOption.value,
|
||||
operand: Number(operand),
|
||||
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ZSingleSelectFilterValue } from "../../lib/types";
|
||||
import { ZSingleSelectFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
export type SingleSelectFilterOptionsProps = {
|
||||
column: Extract<FilterableColumn, { type: "single_select" }>;
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.SINGLE_SELECT }>;
|
||||
};
|
||||
|
||||
export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsProps) {
|
||||
@@ -41,7 +41,7 @@ export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsP
|
||||
<CommandItem
|
||||
key={optionValue}
|
||||
onSelect={() => {
|
||||
updateFilter(column.id, { type: "single_select", data: optionValue });
|
||||
updateFilter(column.id, { type: ColumnFilterType.SINGLE_SELECT, data: optionValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Form, Input, Select, Button } from "@calcom/ui";
|
||||
|
||||
import { useFilterValue, useDataTable } from "../../hooks";
|
||||
import type { FilterableColumn, TextFilterOperator } from "../../lib/types";
|
||||
import { ZTextFilterValue } from "../../lib/types";
|
||||
import { ZTextFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
export type TextFilterOperatorOption = {
|
||||
label: string;
|
||||
@@ -30,7 +30,7 @@ const useTextFilterOperatorOptions = (): TextFilterOperatorOption[] => {
|
||||
};
|
||||
|
||||
export type TextFilterOptionsProps = {
|
||||
column: Extract<FilterableColumn, { type: "text" }>;
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.TEXT }>;
|
||||
};
|
||||
|
||||
export function TextFilterOptions({ column }: TextFilterOptionsProps) {
|
||||
@@ -55,7 +55,7 @@ export function TextFilterOptions({ column }: TextFilterOptionsProps) {
|
||||
handleSubmit={({ operatorOption, operand }) => {
|
||||
if (operatorOption) {
|
||||
updateFilter(column.id, {
|
||||
type: "text",
|
||||
type: ColumnFilterType.TEXT,
|
||||
data: {
|
||||
operator: operatorOption.value,
|
||||
operand: operatorOption.requiresOperand ? operand : "",
|
||||
|
||||
Reference in new issue
Block a user