fix: replace filter implementations on /insights (#19033)
* fix: replace filter implementations on /insights * add authorization for teamIds * replace all the implementations * provide eventTypeId * remove log * fix teamId for isAll * fix Download button * remove legacy implementations * clean up * nullish check * remove unusable filters * revert style * fix type error * fix e2e test * fix type error * fix type error * fix e2e * extract util method * fix type error * fix type error * fix type error --------- Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
1 parent
9bf3732717
commit
720136fcf9
55 files changed
+1037
-1829
No files matched your search
@@ -63,7 +63,8 @@ function AddFilterButtonComponent<TData>(
|
||||
<CommandItem
|
||||
key={column.id}
|
||||
onSelect={() => handleAddFilter(column.id)}
|
||||
className="px-4 py-2">
|
||||
className="px-4 py-2"
|
||||
data-testid={`add-filter-item-${column.id}`}>
|
||||
{startCase(column.title)}
|
||||
</CommandItem>
|
||||
);
|
||||
|
||||
@@ -13,6 +13,7 @@ export const ClearFiltersButton = ({ exclude }: { exclude?: string[] }) => {
|
||||
return (
|
||||
<Tooltip content={t("clear_filters")}>
|
||||
<Button
|
||||
data-testid="clear-filters-button"
|
||||
variant="icon"
|
||||
color="secondary"
|
||||
target="_blank"
|
||||
|
||||
@@ -18,37 +18,22 @@ import {
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { useDataTable, useFilterValue } from "../../hooks";
|
||||
import {
|
||||
CUSTOM_PRESET,
|
||||
CUSTOM_PRESET_VALUE,
|
||||
DEFAULT_PRESET,
|
||||
PRESET_OPTIONS,
|
||||
getDefaultStartDate,
|
||||
getDefaultEndDate,
|
||||
type PresetOption,
|
||||
} from "../../lib/dateRange";
|
||||
import type { FilterableColumn } from "../../lib/types";
|
||||
import { ZDateRangeFilterValue, ColumnFilterType } from "../../lib/types";
|
||||
|
||||
type PresetOption = {
|
||||
labelKey: string;
|
||||
i18nOptions?: Record<string, string | number>;
|
||||
value: string;
|
||||
};
|
||||
|
||||
type DateRangeFilterProps = {
|
||||
column: Extract<FilterableColumn, { type: ColumnFilterType.DATE_RANGE }>;
|
||||
};
|
||||
|
||||
const CUSTOM_PRESET_VALUE = "c" as const;
|
||||
|
||||
const DEFAULT_PRESET: PresetOption = {
|
||||
labelKey: "last_number_of_days",
|
||||
i18nOptions: { count: 7 },
|
||||
value: "w",
|
||||
};
|
||||
const CUSTOM_PRESET: PresetOption = { labelKey: "custom_range", value: CUSTOM_PRESET_VALUE };
|
||||
|
||||
const PRESET_OPTIONS: PresetOption[] = [
|
||||
{ labelKey: "today", value: "tdy" },
|
||||
DEFAULT_PRESET,
|
||||
{ labelKey: "last_number_of_days", i18nOptions: { count: 30 }, value: "t" },
|
||||
{ labelKey: "month_to_date", value: "m" },
|
||||
{ labelKey: "year_to_date", value: "y" },
|
||||
CUSTOM_PRESET,
|
||||
];
|
||||
|
||||
const getDateRangeFromPreset = (val: string | null) => {
|
||||
let startDate;
|
||||
let endDate;
|
||||
@@ -87,10 +72,6 @@ const getDateRangeFromPreset = (val: string | null) => {
|
||||
return { startDate, endDate, preset };
|
||||
};
|
||||
|
||||
const getDefaultStartDate = () => dayjs().subtract(1, "week").startOf("day");
|
||||
|
||||
const getDefaultEndDate = () => dayjs().endOf("day");
|
||||
|
||||
export const DateRangeFilter = ({ column }: DateRangeFilterProps) => {
|
||||
const filterValue = useFilterValue(column.id, ZDateRangeFilterValue);
|
||||
const { updateFilter } = useDataTable();
|
||||
|
||||
@@ -134,7 +134,10 @@ export function FilterPopover({ column }: FilterPopoverProps) {
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button color="secondary" className="items-center">
|
||||
<Button
|
||||
color="secondary"
|
||||
className="items-center"
|
||||
data-testid={`filter-popover-trigger-${column.id}`}>
|
||||
<Icon name={icon} className="mr-2 h-4 w-4" />
|
||||
<span>{startCase(column.title)}</span>
|
||||
<AppliedFilterValue column={column} filterValue={filterValue} />
|
||||
|
||||
@@ -28,7 +28,7 @@ export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsPro
|
||||
const { updateFilter, removeFilter } = useDataTable();
|
||||
|
||||
return (
|
||||
<Command>
|
||||
<Command data-testid={`multi-select-options-${column.id}`}>
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
|
||||
@@ -28,7 +28,7 @@ export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsP
|
||||
const { updateFilter, removeFilter } = useDataTable();
|
||||
|
||||
return (
|
||||
<Command>
|
||||
<Command data-testid={`single-select-options-${column.id}`}>
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
||||
|
||||
Reference in new issue
Block a user