fix: refactor filter UIs on /bookings (#19532)
* Reapply "fix: replace filter implementations on bookings (#19445)" (#19506)
This reverts commit f6af6e34bd.
* force custom date range selector for bookings except for Past tab
* fix e2e test
* add e2e tests
* fix e2e test
This commit is contained in:
1 parent
ca1f84c827
commit
3d3acba82a
19 files changed
+658
-215
No files matched your search
@@ -265,7 +265,6 @@ function DataTableBody<TData>({
|
||||
className={classNames(onRowMouseclick && "hover:cursor-pointer", "group")}>
|
||||
{row.getVisibleCells().map((cell) => {
|
||||
const column = cell.column;
|
||||
const meta = column?.columnDef.meta;
|
||||
return (
|
||||
<TableCell
|
||||
key={cell.id}
|
||||
|
||||
@@ -5,12 +5,12 @@ import { useEffect, useRef } from "react";
|
||||
|
||||
import {
|
||||
DataTable,
|
||||
DataTableToolbar,
|
||||
DataTablePagination,
|
||||
useFetchMoreOnBottomReached,
|
||||
useDataTable,
|
||||
useColumnFilters,
|
||||
} from "@calcom/features/data-table";
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export type DataTableWrapperProps<TData, TValue> = {
|
||||
testId?: string;
|
||||
@@ -25,6 +25,8 @@ export type DataTableWrapperProps<TData, TValue> = {
|
||||
totalDBRowCount?: number;
|
||||
ToolbarLeft?: React.ReactNode;
|
||||
ToolbarRight?: React.ReactNode;
|
||||
EmptyView?: React.ReactNode;
|
||||
LoaderView?: React.ReactNode;
|
||||
className?: string;
|
||||
containerClassName?: string;
|
||||
children?: React.ReactNode;
|
||||
@@ -44,6 +46,8 @@ export function DataTableWrapper<TData, TValue>({
|
||||
hideHeader,
|
||||
ToolbarLeft,
|
||||
ToolbarRight,
|
||||
EmptyView,
|
||||
LoaderView,
|
||||
className,
|
||||
containerClassName,
|
||||
children,
|
||||
@@ -79,21 +83,17 @@ export function DataTableWrapper<TData, TValue>({
|
||||
}));
|
||||
}, [table, sorting, columnFilters, columnVisibility]);
|
||||
|
||||
let view: "loader" | "empty" | "table" = "table";
|
||||
if (isPending && LoaderView) {
|
||||
view = "loader";
|
||||
} else if (table.getRowCount() === 0 && EmptyView) {
|
||||
view = "empty";
|
||||
}
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
testId={testId}
|
||||
bodyTestId={bodyTestId}
|
||||
table={table}
|
||||
tableContainerRef={tableContainerRef}
|
||||
isPending={isPending}
|
||||
enableColumnResizing={true}
|
||||
hideHeader={hideHeader}
|
||||
variant={variant}
|
||||
className={className}
|
||||
containerClassName={containerClassName}
|
||||
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
||||
<>
|
||||
{(ToolbarLeft || ToolbarRight || children) && (
|
||||
<DataTableToolbar.Root>
|
||||
<div className={classNames("grid w-full items-center gap-2 py-4", className)}>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<div className="flex w-full flex-wrap justify-between gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">{ToolbarLeft}</div>
|
||||
@@ -102,14 +102,30 @@ export function DataTableWrapper<TData, TValue>({
|
||||
</div>
|
||||
|
||||
{children}
|
||||
</DataTableToolbar.Root>
|
||||
)}
|
||||
|
||||
{totalDBRowCount && (
|
||||
<div style={{ gridArea: "footer", marginTop: "1rem" }}>
|
||||
<DataTablePagination table={table} totalDbDataCount={totalDBRowCount} />
|
||||
</div>
|
||||
)}
|
||||
</DataTable>
|
||||
{view === "loader" && LoaderView}
|
||||
{view === "empty" && EmptyView}
|
||||
{view === "table" && (
|
||||
<DataTable
|
||||
testId={testId}
|
||||
bodyTestId={bodyTestId}
|
||||
table={table}
|
||||
tableContainerRef={tableContainerRef}
|
||||
isPending={isPending}
|
||||
enableColumnResizing={true}
|
||||
hideHeader={hideHeader}
|
||||
variant={variant}
|
||||
className={className}
|
||||
containerClassName={containerClassName}
|
||||
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
||||
{totalDBRowCount && (
|
||||
<div style={{ gridArea: "footer", marginTop: "1rem" }}>
|
||||
<DataTablePagination table={table} totalDbDataCount={totalDBRowCount} />
|
||||
</div>
|
||||
)}
|
||||
</DataTable>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import { type Table } from "@tanstack/react-table";
|
||||
import { Fragment } from "react";
|
||||
|
||||
import { useDataTable, useFilterableColumns } from "../../hooks";
|
||||
import { ColumnFilterType } from "../../lib/types";
|
||||
import { DateRangeFilter } from "./DateRangeFilter";
|
||||
import { FilterPopover } from "./FilterPopover";
|
||||
|
||||
// Add the new ActiveFilters component
|
||||
@@ -21,7 +23,19 @@ export function ActiveFilters<TData>({ table }: ActiveFiltersProps<TData>) {
|
||||
{activeFilters.map((filter) => {
|
||||
const column = filterableColumns.find((col) => col.id === filter.f);
|
||||
if (!column) return null;
|
||||
return <FilterPopover key={column.id} column={column} />;
|
||||
|
||||
if (column.type === ColumnFilterType.DATE_RANGE) {
|
||||
return (
|
||||
<DateRangeFilter
|
||||
key={column.id}
|
||||
column={column}
|
||||
options={column.dateRangeOptions}
|
||||
showClearButton
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return <FilterPopover key={column.id} column={column} />;
|
||||
}
|
||||
})}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -62,7 +62,10 @@ function AddFilterButtonComponent<TData>(
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_columns_found")}</CommandEmpty>
|
||||
{filterableColumns.map((column) => {
|
||||
const isVisible = table.getColumn(column.id)?.getIsVisible();
|
||||
const showHiddenIndicator =
|
||||
!table.getColumn(column.id)?.getIsVisible() &&
|
||||
table.initialState.columnVisibility?.[column.id] !== false;
|
||||
|
||||
if (activeFilters?.some((filter) => filter.f === column.id)) return null;
|
||||
return (
|
||||
<CommandItem
|
||||
@@ -71,7 +74,7 @@ function AddFilterButtonComponent<TData>(
|
||||
className="flex items-center justify-between px-4 py-2"
|
||||
data-testid={`add-filter-item-${column.id}`}>
|
||||
<span>{startCase(column.title)}</span>
|
||||
{!isVisible && <Icon name="eye-off" className="h-4 w-4 opacity-50" />}
|
||||
{showHiddenIndicator && <Icon name="eye-off" className="h-4 w-4 opacity-50" />}
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { format } from "date-fns";
|
||||
import type { Dayjs } from "dayjs";
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { classNames } from "@calcom/lib";
|
||||
@@ -15,6 +15,9 @@ import {
|
||||
Command,
|
||||
CommandList,
|
||||
CommandItem,
|
||||
CommandGroup,
|
||||
CommandSeparator,
|
||||
buttonClasses,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
@@ -27,11 +30,13 @@ import {
|
||||
getDefaultEndDate,
|
||||
type PresetOption,
|
||||
} from "../../lib/dateRange";
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import type { FilterableColumn, DateRangeFilterOptions } from "../../lib/types";
|
||||
import { ZDateRangeFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
type DateRangeFilterProps = {
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.DATE_RANGE }>;
|
||||
options?: DateRangeFilterOptions;
|
||||
showClearButton?: boolean;
|
||||
};
|
||||
|
||||
const getDateRangeFromPreset = (val: string | null) => {
|
||||
@@ -72,44 +77,60 @@ const getDateRangeFromPreset = (val: string | null) => {
|
||||
return { startDate, endDate, preset };
|
||||
};
|
||||
|
||||
export const DateRangeFilter = ({ column }: DateRangeFilterProps) => {
|
||||
export const DateRangeFilter = ({ column, options, showClearButton = false }: DateRangeFilterProps) => {
|
||||
const filterValue = useFilterValue(column.id, ZDateRangeFilterValue);
|
||||
const { updateFilter } = useDataTable();
|
||||
const { updateFilter, removeFilter } = useDataTable();
|
||||
const range = options?.range ?? "past";
|
||||
const forceCustom = range === "custom";
|
||||
const forcePast = range === "past";
|
||||
|
||||
const { t } = useLocale();
|
||||
const currentDate = dayjs();
|
||||
const [startDate, setStartDate] = useState<Dayjs>(
|
||||
filterValue?.data.startDate ? dayjs(filterValue.data.startDate) : getDefaultStartDate()
|
||||
const [startDate, setStartDate] = useState<Dayjs | undefined>(
|
||||
filterValue?.data.startDate ? dayjs(filterValue.data.startDate) : undefined
|
||||
);
|
||||
const [endDate, setEndDate] = useState<Dayjs | undefined>(
|
||||
filterValue?.data.endDate ? dayjs(filterValue.data.endDate) : getDefaultEndDate()
|
||||
filterValue?.data.endDate ? dayjs(filterValue.data.endDate) : undefined
|
||||
);
|
||||
const [selectedPreset, setSelectedPreset] = useState<PresetOption>(
|
||||
forceCustom
|
||||
? CUSTOM_PRESET
|
||||
: filterValue?.data.preset
|
||||
? PRESET_OPTIONS.find((o) => o.value === filterValue.data.preset) ?? DEFAULT_PRESET
|
||||
: DEFAULT_PRESET
|
||||
);
|
||||
const [selectedPreset, setSelectedPreset] = useState<PresetOption>(DEFAULT_PRESET);
|
||||
|
||||
const updateValues = ({
|
||||
preset,
|
||||
startDate,
|
||||
endDate,
|
||||
}: {
|
||||
preset: PresetOption;
|
||||
startDate: Dayjs;
|
||||
endDate?: Dayjs;
|
||||
}) => {
|
||||
setSelectedPreset(preset);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
const updateValues = useCallback(
|
||||
({ preset, startDate, endDate }: { preset: PresetOption; startDate?: Dayjs; endDate?: Dayjs }) => {
|
||||
setSelectedPreset(preset);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
|
||||
if (startDate && endDate) {
|
||||
updateFilter(column.id, {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
data: {
|
||||
startDate: startDate.toDate().toISOString(),
|
||||
endDate: endDate.toDate().toISOString(),
|
||||
preset: preset.value,
|
||||
},
|
||||
if (startDate && endDate) {
|
||||
updateFilter(column.id, {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
data: {
|
||||
startDate: startDate.toDate().toISOString(),
|
||||
endDate: endDate.toDate().toISOString(),
|
||||
preset: preset.value,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
[column.id]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// initially apply the default value
|
||||
// if the query param is not set yet
|
||||
if (!filterValue && !forceCustom) {
|
||||
updateValues({
|
||||
preset: DEFAULT_PRESET,
|
||||
startDate: getDefaultStartDate(),
|
||||
endDate: getDefaultEndDate(),
|
||||
});
|
||||
}
|
||||
};
|
||||
}, [filterValue, forceCustom, updateValues]);
|
||||
|
||||
const updateDateRangeFromPreset = (val: string | null) => {
|
||||
if (val === CUSTOM_PRESET_VALUE) {
|
||||
@@ -144,19 +165,27 @@ export const DateRangeFilter = ({ column }: DateRangeFilterProps) => {
|
||||
|
||||
const isCustomPreset = selectedPreset.value === CUSTOM_PRESET_VALUE;
|
||||
|
||||
let customButtonLabel = t("date_range");
|
||||
if (startDate && endDate) {
|
||||
customButtonLabel = `${format(startDate.toDate(), "LLL dd, y")} - ${format(
|
||||
endDate.toDate(),
|
||||
"LLL dd, y"
|
||||
)}`;
|
||||
} else if (startDate) {
|
||||
customButtonLabel = `${format(startDate.toDate(), "LLL dd, y")} - ?`;
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button color="secondary" className="items-center capitalize" EndIcon="chevron-down">
|
||||
<Button
|
||||
color="secondary"
|
||||
className="items-center capitalize"
|
||||
StartIcon="calendar-range"
|
||||
EndIcon="chevron-down"
|
||||
data-testid={`filter-popover-trigger-${column.id}`}>
|
||||
{!isCustomPreset && <span>{t(selectedPreset.labelKey, selectedPreset.i18nOptions)}</span>}
|
||||
{isCustomPreset &&
|
||||
(endDate ? (
|
||||
<span>
|
||||
{format(startDate.toDate(), "LLL dd, y")} - {format(endDate.toDate(), "LLL dd, y")}
|
||||
</span>
|
||||
) : (
|
||||
<span>{format(startDate.toDate(), "LLL dd, y")} - End</span>
|
||||
))}
|
||||
{isCustomPreset && <span>{customButtonLabel}</span>}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="flex w-fit p-0" align="end">
|
||||
@@ -164,35 +193,66 @@ export const DateRangeFilter = ({ column }: DateRangeFilterProps) => {
|
||||
<div className="border-subtle border-r">
|
||||
<DateRangePicker
|
||||
dates={{
|
||||
startDate: startDate.toDate(),
|
||||
startDate: startDate?.toDate(),
|
||||
endDate: endDate?.toDate(),
|
||||
}}
|
||||
minDate={currentDate.subtract(2, "year").toDate()}
|
||||
maxDate={currentDate.toDate()}
|
||||
data-testid="date-range-calendar"
|
||||
minDate={forcePast ? currentDate.subtract(2, "year").toDate() : null}
|
||||
maxDate={forcePast ? currentDate.toDate() : undefined}
|
||||
disabled={false}
|
||||
onDatesChange={updateDateRangeFromPicker}
|
||||
withoutPopover={true}
|
||||
/>
|
||||
{forceCustom && (
|
||||
<div className="border-subtle border-t px-2 py-3">
|
||||
<Button
|
||||
color="secondary"
|
||||
className="w-full justify-center"
|
||||
onClick={() => removeFilter(column.id)}>
|
||||
{t("clear")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<Command className={classNames("w-40", isCustomPreset && "rounded-b-none")}>
|
||||
<CommandList>
|
||||
{PRESET_OPTIONS.map((option) => (
|
||||
<CommandItem
|
||||
key={option.value}
|
||||
className={classNames(
|
||||
"cursor-pointer justify-between px-3 py-2",
|
||||
selectedPreset.value === option.value && "bg-emphasis"
|
||||
)}
|
||||
onSelect={() => {
|
||||
updateDateRangeFromPreset(option.value);
|
||||
}}>
|
||||
<span className="capitalize">{t(option.labelKey, option.i18nOptions)}</span>
|
||||
{selectedPreset.value === option.value && <Icon name="check" />}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandList>
|
||||
</Command>
|
||||
{!forceCustom && (
|
||||
<Command className={classNames("w-40", isCustomPreset && "rounded-b-none")}>
|
||||
<CommandList>
|
||||
{PRESET_OPTIONS.map((option) => (
|
||||
<CommandItem
|
||||
key={option.value}
|
||||
data-testid={`date-range-options-${option.value}`}
|
||||
className={classNames(
|
||||
"cursor-pointer justify-between px-3 py-2",
|
||||
selectedPreset.value === option.value && "bg-emphasis"
|
||||
)}
|
||||
onSelect={() => {
|
||||
updateDateRangeFromPreset(option.value);
|
||||
}}>
|
||||
<span className="capitalize">{t(option.labelKey, option.i18nOptions)}</span>
|
||||
{selectedPreset.value === option.value && <Icon name="check" />}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandList>
|
||||
{showClearButton && (
|
||||
<>
|
||||
<CommandSeparator />
|
||||
<CommandGroup>
|
||||
<CommandItem
|
||||
onSelect={() => {
|
||||
removeFilter(column.id);
|
||||
}}
|
||||
className={classNames(
|
||||
"w-full justify-center text-center",
|
||||
buttonClasses({ color: "secondary" })
|
||||
)}>
|
||||
{t("clear")}
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
</>
|
||||
)}
|
||||
</Command>
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ColumnFilterType } from "../../lib/types";
|
||||
import { DateRangeFilter } from "./DateRangeFilter";
|
||||
import { MultiSelectFilterOptions } from "./MultiSelectFilterOptions";
|
||||
import { NumberFilterOptions } from "./NumberFilterOptions";
|
||||
import { SingleSelectFilterOptions } from "./SingleSelectFilterOptions";
|
||||
@@ -21,8 +20,6 @@ export function FilterOptions({ column }: FilterOptionsProps) {
|
||||
return <SingleSelectFilterOptions column={column} />;
|
||||
} else if (column.type === ColumnFilterType.NUMBER) {
|
||||
return <NumberFilterOptions column={column} />;
|
||||
} else if (column.type === ColumnFilterType.DATE_RANGE) {
|
||||
return <DateRangeFilter column={column} />;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -32,31 +32,42 @@ export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsPro
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
{column.options.map((option) => {
|
||||
{column.options.map((option, index) => {
|
||||
if (!option) return null;
|
||||
const { label: optionLabel, value: optionValue } =
|
||||
typeof option === "string" ? { label: option, value: option } : option;
|
||||
const {
|
||||
label: optionLabel,
|
||||
value: optionValue,
|
||||
section,
|
||||
} = typeof option === "string" ? { label: option, value: option, section: undefined } : option;
|
||||
|
||||
return (
|
||||
<CommandItem
|
||||
key={optionValue}
|
||||
onSelect={() => {
|
||||
const newFilterValue = filterValue?.data.includes(optionValue)
|
||||
? filterValue?.data.filter((value) => value !== optionValue)
|
||||
: [...(filterValue?.data || []), optionValue];
|
||||
updateFilter(column.id, { type: ColumnFilterType.MULTI_SELECT, data: newFilterValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
||||
filterValue?.data.includes(optionValue) ? "bg-primary" : "opacity-50"
|
||||
)}>
|
||||
{filterValue?.data.includes(optionValue) && (
|
||||
<Icon name="check" className="text-primary-foreground h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{optionLabel}
|
||||
</CommandItem>
|
||||
<>
|
||||
{section && index !== 0 && <hr className="border-subtle my-1" />}
|
||||
{section && (
|
||||
<div className="text-subtle px-4 py-2 text-xs font-medium uppercase leading-none">
|
||||
{section}
|
||||
</div>
|
||||
)}
|
||||
<CommandItem
|
||||
key={optionValue}
|
||||
onSelect={() => {
|
||||
const newFilterValue = filterValue?.data.includes(optionValue)
|
||||
? filterValue?.data.filter((value) => value !== optionValue)
|
||||
: [...(filterValue?.data || []), optionValue];
|
||||
updateFilter(column.id, { type: ColumnFilterType.MULTI_SELECT, data: newFilterValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
||||
filterValue?.data.includes(optionValue) ? "bg-primary" : "opacity-50"
|
||||
)}>
|
||||
{filterValue?.data.includes(optionValue) && (
|
||||
<Icon name="check" className="text-primary-foreground h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{optionLabel}
|
||||
</CommandItem>
|
||||
</>
|
||||
);
|
||||
})}
|
||||
</CommandList>
|
||||
|
||||
@@ -32,28 +32,39 @@ export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsP
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
{column.options.map((option) => {
|
||||
{column.options.map((option, index) => {
|
||||
if (!option) return null;
|
||||
const { label: optionLabel, value: optionValue } =
|
||||
typeof option === "string" ? { label: option, value: option } : option;
|
||||
const {
|
||||
label: optionLabel,
|
||||
value: optionValue,
|
||||
section,
|
||||
} = typeof option === "string" ? { label: option, value: option, section: undefined } : option;
|
||||
|
||||
return (
|
||||
<CommandItem
|
||||
key={optionValue}
|
||||
onSelect={() => {
|
||||
updateFilter(column.id, { type: ColumnFilterType.SINGLE_SELECT, data: optionValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
||||
filterValue?.data === optionValue ? "bg-primary" : "opacity-50"
|
||||
)}>
|
||||
{filterValue?.data === optionValue && (
|
||||
<Icon name="check" className="text-primary-foreground h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{optionLabel}
|
||||
</CommandItem>
|
||||
<>
|
||||
{section && index !== 0 && <hr className="border-subtle my-1" />}
|
||||
{section && (
|
||||
<div className="text-subtle px-4 py-2 text-xs font-medium uppercase leading-none">
|
||||
{section}
|
||||
</div>
|
||||
)}
|
||||
<CommandItem
|
||||
key={optionValue}
|
||||
onSelect={() => {
|
||||
updateFilter(column.id, { type: ColumnFilterType.SINGLE_SELECT, data: optionValue });
|
||||
}}>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
||||
filterValue?.data === optionValue ? "bg-primary" : "opacity-50"
|
||||
)}>
|
||||
{filterValue?.data === optionValue && (
|
||||
<Icon name="check" className="text-primary-foreground h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
{optionLabel}
|
||||
</CommandItem>
|
||||
</>
|
||||
);
|
||||
})}
|
||||
</CommandList>
|
||||
|
||||
@@ -116,11 +116,21 @@ export const ZFilterValue = z.union([
|
||||
ZDateRangeFilterValue,
|
||||
]);
|
||||
|
||||
export type ColumnFilterMeta = {
|
||||
type?: ColumnFilterType;
|
||||
icon?: IconName;
|
||||
export type DateRangeFilterOptions = {
|
||||
range: "past" | "custom";
|
||||
};
|
||||
|
||||
export type ColumnFilterMeta =
|
||||
| {
|
||||
type: ColumnFilterType.DATE_RANGE;
|
||||
icon?: IconName;
|
||||
dateRangeOptions: DateRangeFilterOptions;
|
||||
}
|
||||
| {
|
||||
type?: Exclude<ColumnFilterType, ColumnFilterType.DATE_RANGE>;
|
||||
icon?: IconName;
|
||||
};
|
||||
|
||||
export type FilterableColumn = {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -128,11 +138,11 @@ export type FilterableColumn = {
|
||||
} & (
|
||||
| {
|
||||
type: ColumnFilterType.SINGLE_SELECT;
|
||||
options: Array<{ label: string; value: string | number }>;
|
||||
options: FacetedValue[];
|
||||
}
|
||||
| {
|
||||
type: ColumnFilterType.MULTI_SELECT;
|
||||
options: Array<{ label: string; value: string | number }>;
|
||||
options: FacetedValue[];
|
||||
}
|
||||
| {
|
||||
type: ColumnFilterType.TEXT;
|
||||
@@ -142,6 +152,7 @@ export type FilterableColumn = {
|
||||
}
|
||||
| {
|
||||
type: ColumnFilterType.DATE_RANGE;
|
||||
dateRangeOptions?: DateRangeFilterOptions;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -186,4 +197,5 @@ export const ZColumnVisibility = z.record(z.string(), z.boolean());
|
||||
export type FacetedValue = {
|
||||
label: string;
|
||||
value: string | number;
|
||||
section?: string;
|
||||
};
|
||||
@@ -151,7 +151,7 @@ export const dataTableFilter = (cellValue: unknown, filterValue: FilterValue) =>
|
||||
|
||||
export const convertFacetedValuesToMap = (array: FacetedValue[]) => {
|
||||
return new Map<FacetedValue, number>(
|
||||
array.map((option) => [{ label: option.label, value: option.value }, 1])
|
||||
array.map((option) => [{ label: option.label, value: option.value, section: option.section }, 1])
|
||||
);
|
||||
};
|
||||
|
||||
@@ -161,8 +161,8 @@ export const convertMapToFacetedValues = (map: Map<FacetedValue, number> | undef
|
||||
}
|
||||
return Array.from(map.keys()).map((option) => {
|
||||
if (typeof option === "string") {
|
||||
return { label: option, value: option };
|
||||
return { label: option, value: option, section: undefined };
|
||||
}
|
||||
return { label: option.label as string, value: option.value as string | number };
|
||||
return { label: option.label as string, value: option.value as string | number, section: option.section };
|
||||
});
|
||||
};
|
||||
@@ -56,7 +56,7 @@ export function RoutingFormResponsesTable() {
|
||||
|
||||
const { sorting } = useDataTable();
|
||||
|
||||
const { data, fetchNextPage, isFetching, hasNextPage, isLoading } =
|
||||
const { data, fetchNextPage, isFetching, isPending, hasNextPage, isLoading } =
|
||||
trpc.viewer.insights.routingFormResponses.useInfiniteQuery(
|
||||
{
|
||||
teamId,
|
||||
@@ -113,7 +113,7 @@ export function RoutingFormResponsesTable() {
|
||||
<div className="flex-1">
|
||||
<DataTableWrapper
|
||||
table={table}
|
||||
isPending={isFetching && !data}
|
||||
isPending={isPending}
|
||||
hasNextPage={hasNextPage}
|
||||
fetchNextPage={fetchNextPage}
|
||||
isFetching={isFetching}
|
||||
|
||||
@@ -123,6 +123,13 @@ export const viewerTeamsRouter = router({
|
||||
const handler = await importHandler(namespaced("listMembers"), () => import("./listMembers.handler"));
|
||||
return handler(opts);
|
||||
}),
|
||||
listSimpleMembers: authedProcedure.query(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("listSimpleMembers"),
|
||||
() => import("./listSimpleMembers.handler")
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
legacyListMembers: authedProcedure.input(ZLegacyListMembersInputSchema).query(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("legacyListMembers"),
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Simplified version of legacyListMembers.handler.ts that returns basic member info.
|
||||
* Used for filtering people on /bookings.
|
||||
*/
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
type ListSimpleMembersOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
prisma: PrismaClient;
|
||||
};
|
||||
};
|
||||
|
||||
export const listSimpleMembers = async ({ ctx }: ListSimpleMembersOptions) => {
|
||||
const { prisma } = ctx;
|
||||
const { isOrgAdmin } = ctx.user.organization;
|
||||
const hasPermsToView = !ctx.user.organization.isPrivate || isOrgAdmin;
|
||||
|
||||
if (!hasPermsToView) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// query all teams the user is a member of
|
||||
const teamsToQuery = (
|
||||
await prisma.membership.findMany({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
accepted: true,
|
||||
},
|
||||
select: { teamId: true },
|
||||
})
|
||||
).map((membership) => membership.teamId);
|
||||
|
||||
if (!teamsToQuery.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Fetch unique users through memberships
|
||||
const members = (
|
||||
await prisma.membership.findMany({
|
||||
where: {
|
||||
accepted: true,
|
||||
teamId: { in: teamsToQuery },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
accepted: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
username: true,
|
||||
avatarUrl: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
distinct: ["userId"],
|
||||
orderBy: [
|
||||
{ userId: "asc" }, // First order by userId to ensure consistent ordering
|
||||
{ id: "asc" }, // Then by id as secondary sort
|
||||
],
|
||||
})
|
||||
).map((membership) => membership.user);
|
||||
|
||||
return members;
|
||||
};
|
||||
|
||||
export default listSimpleMembers;
|
||||
@@ -16,6 +16,7 @@ type DatePickerWithRangeProps = {
|
||||
minDate?: Date | null;
|
||||
maxDate?: Date;
|
||||
withoutPopover?: boolean;
|
||||
"data-testid"?: string;
|
||||
};
|
||||
|
||||
export function DatePickerWithRange({
|
||||
@@ -26,6 +27,7 @@ export function DatePickerWithRange({
|
||||
onDatesChange,
|
||||
disabled,
|
||||
withoutPopover,
|
||||
"data-testid": testId,
|
||||
}: React.HTMLAttributes<HTMLDivElement> & DatePickerWithRangeProps) {
|
||||
function handleDayClick(date: Date) {
|
||||
if (dates?.endDate) {
|
||||
@@ -50,6 +52,7 @@ export function DatePickerWithRange({
|
||||
onDayClick={(day) => handleDayClick(day)}
|
||||
numberOfMonths={1}
|
||||
disabled={disabled}
|
||||
data-testid={testId}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user