* WIP restored from .git cache * fix exports * sortable row model * feat column visibility component * wip filters with nuqs * pull in unique values from table into filters * correctly assign filters via v/f * inital selection bar refactor * data-table selection bar + optmistic update of delete * dynamic link * migrate member list table to new data-table * total list shows filtered value > db valuie * add filters for attributes * type errors * make content bigger on lg * add mb-6 to teams user datatable to match spacing spec * correctly render multi-badge * fix: masss asignment optimistic UI * fix type errors * remove log * fix toolbar type error * chore: Remove debug artifact * type errors * Update apps/web/public/static/locales/en/common.json * use max-w-fit * chore: Remove unused translation now we don't specify 'mass' in assign * perf: fix: use the onBlur event to prevent focus loss whilst the list is rerendering * Move the data-table exports together in the main barrel, then import * fix exports that were lost in a merge * fix exports that were lost in a merge * fix groupteammapping/availbilityslider * fix overflow problems * add scrollbar-thin class * fix type error * user serverside values for faceted filters * pass filters to serverside * filter serverside * fix team server side filter * add loaded x of y * attributes icon change * correct implementation for text/input attr optimistic * type check fixes * fix platform checks * fix types again * fix types again * fix types again * add use client * add use client * fix-types * fix: Add missing translation in EN * fix e2e tests via testid * fix e2e tests via testid * fix: Member invite popup not popping up * Update copyInviteLink to new-member-button testid * Hopefully fix test ids this time * fix: Use the right buttons on the right pages --------- Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
127 lines
3.4 KiB
TypeScript
127 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import type { Table } from "@tanstack/react-table";
|
|
import { useEffect, useState, forwardRef } from "react";
|
|
import type { ComponentPropsWithoutRef } from "react";
|
|
|
|
import { classNames } from "@calcom/lib";
|
|
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import type { ButtonProps } from "../button";
|
|
import { Button } from "../button";
|
|
import { Input } from "../form";
|
|
|
|
interface DataTableToolbarProps extends ComponentPropsWithoutRef<"div"> {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const Root = forwardRef<HTMLDivElement, DataTableToolbarProps>(function DataTableToolbar(
|
|
{ children, className },
|
|
ref
|
|
) {
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
className={classNames("grid w-full items-center gap-2 py-4", className)}
|
|
style={{ gridArea: "header" }}>
|
|
{children}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
interface SearchBarProps<TData> {
|
|
table: Table<TData>;
|
|
searchKey?: string;
|
|
onSearch?: (value: string) => void;
|
|
}
|
|
|
|
function SearchBarComponent<TData>(
|
|
{ table, searchKey, onSearch }: SearchBarProps<TData>,
|
|
ref: React.Ref<HTMLInputElement>
|
|
) {
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
const debouncedSearchTerm = useDebounce(searchTerm, 500);
|
|
|
|
useEffect(() => {
|
|
onSearch?.(debouncedSearchTerm);
|
|
}, [debouncedSearchTerm, onSearch]);
|
|
|
|
if (onSearch) {
|
|
return (
|
|
<Input
|
|
ref={ref}
|
|
className="max-w-64 mb-0 mr-auto rounded-md"
|
|
placeholder="Search"
|
|
value={searchTerm}
|
|
onChange={(event) => setSearchTerm(event.target.value.trim())}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (!searchKey) {
|
|
console.error("searchKey is required if onSearch is not provided");
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Input
|
|
ref={ref}
|
|
className="max-w-64 mb-0 mr-auto rounded-md"
|
|
placeholder="Search"
|
|
value={(table.getColumn(searchKey)?.getFilterValue() as string) ?? ""}
|
|
onChange={(event) => {
|
|
return table.getColumn(searchKey)?.setFilterValue(event.target.value.trim());
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const SearchBar = forwardRef(SearchBarComponent) as <TData>(
|
|
props: SearchBarProps<TData> & { ref?: React.Ref<HTMLInputElement> }
|
|
) => ReturnType<typeof SearchBarComponent>;
|
|
|
|
interface ClearFiltersButtonProps<TData> {
|
|
table: Table<TData>;
|
|
}
|
|
|
|
function ClearFiltersButtonComponent<TData>(
|
|
{ table }: ClearFiltersButtonProps<TData>,
|
|
ref: React.Ref<HTMLButtonElement>
|
|
) {
|
|
const { t } = useLocale();
|
|
const isFiltered = table.getState().columnFilters.length > 0;
|
|
if (!isFiltered) return null;
|
|
return (
|
|
<Button
|
|
ref={ref}
|
|
color="minimal"
|
|
EndIcon="x"
|
|
onClick={() => table.resetColumnFilters()}
|
|
className="h-8 px-2 lg:px-3">
|
|
{t("clear")}
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
const ClearFiltersButton = forwardRef(ClearFiltersButtonComponent) as <TData>(
|
|
props: ClearFiltersButtonProps<TData> & { ref?: React.Ref<HTMLButtonElement> }
|
|
) => ReturnType<typeof ClearFiltersButtonComponent>;
|
|
|
|
function CTAComponent(
|
|
{ children, onClick, color = "primary", ...rest }: ButtonProps,
|
|
ref: React.Ref<HTMLButtonElement>
|
|
) {
|
|
return (
|
|
<Button ref={ref} color={color} onClick={onClick} {...rest}>
|
|
{children}
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
const CTA = forwardRef(CTAComponent) as (
|
|
props: ButtonProps & { ref?: React.Ref<HTMLButtonElement> }
|
|
) => ReturnType<typeof CTAComponent>;
|
|
|
|
export const DataTableToolbar = { Root, SearchBar, ClearFiltersButton, CTA };
|