This reverts commit 641193bd61.
This commit is contained in:
1 parent
5f5cfaf7c7
commit
f6af6e34bd
16 files changed
+147
-478
No files matched your search
@@ -265,6 +265,7 @@ 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,7 +25,6 @@ export type DataTableWrapperProps<TData, TValue> = {
|
||||
totalDBRowCount?: number;
|
||||
ToolbarLeft?: React.ReactNode;
|
||||
ToolbarRight?: React.ReactNode;
|
||||
EmptyView?: React.ReactNode;
|
||||
className?: string;
|
||||
containerClassName?: string;
|
||||
children?: React.ReactNode;
|
||||
@@ -45,7 +44,6 @@ export function DataTableWrapper<TData, TValue>({
|
||||
hideHeader,
|
||||
ToolbarLeft,
|
||||
ToolbarRight,
|
||||
EmptyView,
|
||||
className,
|
||||
containerClassName,
|
||||
children,
|
||||
@@ -81,12 +79,21 @@ export function DataTableWrapper<TData, TValue>({
|
||||
}));
|
||||
}, [table, sorting, columnFilters, columnVisibility]);
|
||||
|
||||
const showEmptyView = table.getRowCount() === 0 && EmptyView;
|
||||
|
||||
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) && (
|
||||
<div className={classNames("grid w-full items-center gap-2 py-4", className)}>
|
||||
<DataTableToolbar.Root>
|
||||
<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>
|
||||
@@ -95,29 +102,14 @@ export function DataTableWrapper<TData, TValue>({
|
||||
</div>
|
||||
|
||||
{children}
|
||||
</DataTableToolbar.Root>
|
||||
)}
|
||||
|
||||
{totalDBRowCount && (
|
||||
<div style={{ gridArea: "footer", marginTop: "1rem" }}>
|
||||
<DataTablePagination table={table} totalDbDataCount={totalDBRowCount} />
|
||||
</div>
|
||||
)}
|
||||
{showEmptyView && EmptyView}
|
||||
{!showEmptyView && (
|
||||
<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>
|
||||
)}
|
||||
</>
|
||||
</DataTable>
|
||||
);
|
||||
}
|
||||
@@ -5,8 +5,6 @@ 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
|
||||
@@ -23,12 +21,7 @@ export function ActiveFilters<TData>({ table }: ActiveFiltersProps<TData>) {
|
||||
{activeFilters.map((filter) => {
|
||||
const column = filterableColumns.find((col) => col.id === filter.f);
|
||||
if (!column) return null;
|
||||
|
||||
if (column.type === ColumnFilterType.DATE_RANGE) {
|
||||
return <DateRangeFilter key={column.id} column={column} showClearButton />;
|
||||
} else {
|
||||
return <FilterPopover key={column.id} column={column} />;
|
||||
}
|
||||
return <FilterPopover key={column.id} column={column} />;
|
||||
})}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -62,10 +62,7 @@ function AddFilterButtonComponent<TData>(
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_columns_found")}</CommandEmpty>
|
||||
{filterableColumns.map((column) => {
|
||||
const showHiddenIndicator =
|
||||
!table.getColumn(column.id)?.getIsVisible() &&
|
||||
table.initialState.columnVisibility?.[column.id] !== false;
|
||||
|
||||
const isVisible = table.getColumn(column.id)?.getIsVisible();
|
||||
if (activeFilters?.some((filter) => filter.f === column.id)) return null;
|
||||
return (
|
||||
<CommandItem
|
||||
@@ -74,7 +71,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>
|
||||
{showHiddenIndicator && <Icon name="eye-off" className="h-4 w-4 opacity-50" />}
|
||||
{!isVisible && <Icon name="eye-off" className="h-4 w-4 opacity-50" />}
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -15,9 +15,6 @@ import {
|
||||
Command,
|
||||
CommandList,
|
||||
CommandItem,
|
||||
CommandGroup,
|
||||
CommandSeparator,
|
||||
buttonClasses,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
@@ -35,7 +32,6 @@ import { ZDateRangeFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
type DateRangeFilterProps = {
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.DATE_RANGE }>;
|
||||
showClearButton?: boolean;
|
||||
};
|
||||
|
||||
const getDateRangeFromPreset = (val: string | null) => {
|
||||
@@ -76,9 +72,9 @@ const getDateRangeFromPreset = (val: string | null) => {
|
||||
return { startDate, endDate, preset };
|
||||
};
|
||||
|
||||
export const DateRangeFilter = ({ column, showClearButton = false }: DateRangeFilterProps) => {
|
||||
export const DateRangeFilter = ({ column }: DateRangeFilterProps) => {
|
||||
const filterValue = useFilterValue(column.id, ZDateRangeFilterValue);
|
||||
const { updateFilter, removeFilter } = useDataTable();
|
||||
const { updateFilter } = useDataTable();
|
||||
|
||||
const { t } = useLocale();
|
||||
const currentDate = dayjs();
|
||||
@@ -88,11 +84,7 @@ export const DateRangeFilter = ({ column, showClearButton = false }: DateRangeFi
|
||||
const [endDate, setEndDate] = useState<Dayjs | undefined>(
|
||||
filterValue?.data.endDate ? dayjs(filterValue.data.endDate) : getDefaultEndDate()
|
||||
);
|
||||
const [selectedPreset, setSelectedPreset] = useState<PresetOption>(
|
||||
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,
|
||||
@@ -200,23 +192,6 @@ export const DateRangeFilter = ({ column, showClearButton = false }: DateRangeFi
|
||||
</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,6 +2,7 @@
|
||||
|
||||
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";
|
||||
@@ -20,6 +21,8 @@ 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,42 +32,31 @@ export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsPro
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
{column.options.map((option, index) => {
|
||||
{column.options.map((option) => {
|
||||
if (!option) return null;
|
||||
const {
|
||||
label: optionLabel,
|
||||
value: optionValue,
|
||||
section,
|
||||
} = typeof option === "string" ? { label: option, value: option, section: undefined } : option;
|
||||
const { label: optionLabel, value: optionValue } =
|
||||
typeof option === "string" ? { label: option, value: option } : option;
|
||||
|
||||
return (
|
||||
<>
|
||||
{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>
|
||||
</>
|
||||
<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,39 +32,28 @@ export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsP
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
{column.options.map((option, index) => {
|
||||
{column.options.map((option) => {
|
||||
if (!option) return null;
|
||||
const {
|
||||
label: optionLabel,
|
||||
value: optionValue,
|
||||
section,
|
||||
} = typeof option === "string" ? { label: option, value: option, section: undefined } : option;
|
||||
const { label: optionLabel, value: optionValue } =
|
||||
typeof option === "string" ? { label: option, value: option } : option;
|
||||
|
||||
return (
|
||||
<>
|
||||
{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>
|
||||
</>
|
||||
<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>
|
||||
|
||||
@@ -128,11 +128,11 @@ export type FilterableColumn = {
|
||||
} & (
|
||||
| {
|
||||
type: ColumnFilterType.SINGLE_SELECT;
|
||||
options: FacetedValue[];
|
||||
options: Array<{ label: string; value: string | number }>;
|
||||
}
|
||||
| {
|
||||
type: ColumnFilterType.MULTI_SELECT;
|
||||
options: FacetedValue[];
|
||||
options: Array<{ label: string; value: string | number }>;
|
||||
}
|
||||
| {
|
||||
type: ColumnFilterType.TEXT;
|
||||
@@ -186,5 +186,4 @@ 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, section: option.section }, 1])
|
||||
array.map((option) => [{ label: option.label, value: option.value }, 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, section: undefined };
|
||||
return { label: option, value: option };
|
||||
}
|
||||
return { label: option.label as string, value: option.value as string | number, section: option.section };
|
||||
return { label: option.label as string, value: option.value as string | number };
|
||||
});
|
||||
};
|
||||
@@ -123,13 +123,6 @@ 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"),
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
Reference in new issue
Block a user