fix(bookings): enable past date selection for cancelled bookings (#25644)
* refactor(data-table): clean up DateRangeFilter range options - Replace 'past' | 'custom' with 'past' | 'future' | 'any' | 'customOnly' - Add direction field to PresetOption for preset compatibility filtering - Derive presets visibility automatically based on compatible presets - Update bookings list to use new range values: - past -> 'past' - upcoming -> 'future' - unconfirmed/recurring/cancelled -> 'any' Co-Authored-By: [email protected] <[email protected]> * feat(playground): add DateRangeFilter playground page with E2E tests - Add playground page at /settings/admin/playground/date-range-filter - Demonstrate all 4 range options: past, future, any, customOnly - Add link to playground index page - Add E2E tests for presets visibility and date restrictions Co-Authored-By: [email protected] <[email protected]> * fix(playground): use correct meta.filter pattern for column filter config Co-Authored-By: [email protected] <[email protected]> * clean up the playground esign * add unit tests instead of e2e * fix the implementation --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
dd27d077ca
commit
aaaff0705b
9 files changed
+283
-30
No files matched your search
+150
@@ -0,0 +1,150 @@
|
||||
"use client";
|
||||
|
||||
import { useReactTable, getCoreRowModel, createColumnHelper } from "@tanstack/react-table";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { ColumnFilterType, DateRangeFilter, DataTableProvider } from "@calcom/features/data-table";
|
||||
import type { DateRangeFilterOptions } from "@calcom/features/data-table/lib/types";
|
||||
|
||||
type DemoRow = {
|
||||
id: number;
|
||||
name: string;
|
||||
date: string;
|
||||
};
|
||||
|
||||
const columnHelper = createColumnHelper<DemoRow>();
|
||||
|
||||
type ScenarioProps = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
expected: string;
|
||||
range: DateRangeFilterOptions["range"];
|
||||
};
|
||||
|
||||
const scenarios: ScenarioProps[] = [
|
||||
{
|
||||
id: "past",
|
||||
title: 'Range: "past"',
|
||||
description: "Restricts date selection to past dates only. Shows presets that are past-compatible.",
|
||||
expected:
|
||||
"Presets visible: Today, Last 7 days, Last 30 days, Month to date, Year to date, Custom. Calendar maxDate = today.",
|
||||
range: "past",
|
||||
},
|
||||
{
|
||||
id: "future",
|
||||
title: 'Range: "future"',
|
||||
description: "Restricts date selection to future dates only. Shows only future-compatible presets.",
|
||||
expected: "Presets visible: Custom only (presets with direction 'any'). Calendar minDate = today.",
|
||||
range: "future",
|
||||
},
|
||||
{
|
||||
id: "any",
|
||||
title: 'Range: "any"',
|
||||
description: "No date restrictions. Shows all presets.",
|
||||
expected: "All presets visible. No calendar date restrictions.",
|
||||
range: "any",
|
||||
},
|
||||
{
|
||||
id: "customOnly",
|
||||
title: 'Range: "customOnly"',
|
||||
description: "Forces custom date picker only. Always hides presets dropdown.",
|
||||
expected: "No presets dropdown. Only calendar picker visible when opened. No date restrictions.",
|
||||
range: "customOnly",
|
||||
},
|
||||
];
|
||||
|
||||
function ScenarioCard({ scenario }: { scenario: ScenarioProps }) {
|
||||
const columns = useMemo(
|
||||
() => [
|
||||
columnHelper.accessor("name", {
|
||||
header: "Name",
|
||||
cell: (info) => info.getValue(),
|
||||
}),
|
||||
columnHelper.accessor("date", {
|
||||
id: "dateRange",
|
||||
header: "Date Range",
|
||||
cell: (info) => info.getValue(),
|
||||
enableColumnFilter: true,
|
||||
meta: {
|
||||
filter: {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
dateRangeOptions: {
|
||||
range: scenario.range,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
[scenario.range]
|
||||
);
|
||||
|
||||
const data = useMemo<DemoRow[]>(
|
||||
() => [
|
||||
{ id: 1, name: "Demo Item 1", date: "2024-01-15" },
|
||||
{ id: 2, name: "Demo Item 2", date: "2024-02-20" },
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
});
|
||||
|
||||
// Get the column definition to pass to DateRangeFilter
|
||||
const dateRangeColumn = table.getAllColumns().find((col) => col.id === "dateRange");
|
||||
const columnMeta = dateRangeColumn?.columnDef.meta as
|
||||
| { filter?: { type: string; dateRangeOptions?: DateRangeFilterOptions } }
|
||||
| undefined;
|
||||
const dateRangeOptions = columnMeta?.filter?.dateRangeOptions;
|
||||
|
||||
return (
|
||||
<div className="border-subtle mb-8 rounded-lg border p-6" data-testid={`drf-scenario-${scenario.id}`}>
|
||||
<h3 className="text-emphasis mb-2 text-lg font-semibold">{scenario.title}</h3>
|
||||
<p className="text-default mb-2 text-sm">{scenario.description}</p>
|
||||
<p className="text-subtle mb-4 text-xs">
|
||||
<strong>Expected:</strong> {scenario.expected}
|
||||
</p>
|
||||
|
||||
<div className="mt-4">
|
||||
<DataTableProvider tableIdentifier={`playground-date-range-${scenario.id}`}>
|
||||
{dateRangeColumn && (
|
||||
<DateRangeFilter
|
||||
column={{
|
||||
id: dateRangeColumn.id,
|
||||
title: dateRangeColumn.columnDef.header as string,
|
||||
type: "dr",
|
||||
}}
|
||||
options={dateRangeOptions}
|
||||
showColumnName={false}
|
||||
showClearButton={false}
|
||||
/>
|
||||
)}
|
||||
</DataTableProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DateRangeFilterPlayground() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-emphasis text-2xl font-bold">DateRangeFilter Playground</h1>
|
||||
<p className="text-default mt-2">
|
||||
This page demonstrates the different <code>range</code> options for the DateRangeFilter component.
|
||||
</p>
|
||||
<p className="text-subtle mt-1 text-sm">
|
||||
The <code>range</code> option controls both date restrictions and presets visibility. Presets
|
||||
visibility is derived automatically based on compatible presets.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{scenarios.map((scenario) => (
|
||||
<ScenarioCard key={scenario.id} scenario={scenario} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,19 +2,32 @@ import { _generateMetadata, getTranslate } from "app/_utils";
|
||||
import Link from "next/link";
|
||||
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
|
||||
const LINKS = [
|
||||
{
|
||||
title: "Routing Funnel",
|
||||
description: "Visualize booking conversion flow and routing patterns",
|
||||
href: "/settings/admin/playground/routing-funnel",
|
||||
icon: "filter" as const,
|
||||
},
|
||||
{
|
||||
title: "Bookings by Hour",
|
||||
description: "View booking distribution across different hours",
|
||||
href: "/settings/admin/playground/bookings-by-hour",
|
||||
icon: "chart-bar" as const,
|
||||
},
|
||||
{
|
||||
title: "Weekly Calendar",
|
||||
description: "Interactive weekly calendar view for scheduling",
|
||||
href: "/settings/admin/playground/weekly-calendar",
|
||||
icon: "calendar" as const,
|
||||
},
|
||||
{
|
||||
title: "Date Range Filter",
|
||||
description: "Test date range selection and filtering components",
|
||||
href: "/settings/admin/playground/date-range-filter",
|
||||
icon: "calendar-days" as const,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -31,16 +44,27 @@ const Page = async () => {
|
||||
const t = await getTranslate();
|
||||
return (
|
||||
<SettingsHeader title={t("playground")} description={t("admin_playground_description")}>
|
||||
<div>
|
||||
<ul className="mt-8">
|
||||
<div className="mt-6">
|
||||
<div className="bg-default border-subtle divide-subtle flex flex-col divide-y rounded-md border">
|
||||
{LINKS.map((link) => (
|
||||
<li key={link.title}>
|
||||
<Link href={link.href} className="list-item list-disc font-medium underline">
|
||||
{link.title} →
|
||||
</Link>
|
||||
</li>
|
||||
<Link
|
||||
key={link.title}
|
||||
href={link.href}
|
||||
className="hover:bg-muted group flex items-center gap-4 p-5 transition-colors">
|
||||
<div className="bg-emphasis/10 group-hover:bg-emphasis/20 flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-md transition-colors">
|
||||
<Icon name={link.icon} className="text-emphasis h-5 w-5" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h3 className="text-emphasis text-sm font-semibold leading-none">{link.title}</h3>
|
||||
<p className="text-subtle mt-2 text-sm">{link.description}</p>
|
||||
</div>
|
||||
<Icon
|
||||
name="arrow-right"
|
||||
className="text-subtle group-hover:text-emphasis h-4 w-4 flex-shrink-0 transition-colors"
|
||||
/>
|
||||
</Link>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</SettingsHeader>
|
||||
);
|
||||
|
||||
@@ -109,7 +109,7 @@ export function buildFilterColumns({ t, permissions, status }: BuildFilterColumn
|
||||
filter: {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
dateRangeOptions: {
|
||||
range: status === "past" ? "past" : "custom",
|
||||
range: status === "past" ? "past" : status === "cancelled" ? "any" : "future", // upcoming, unconfirmed, recurring are all future-only
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -98,7 +98,7 @@ export function useBookingListColumns({
|
||||
filter: {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
dateRangeOptions: {
|
||||
range: status === "past" ? "past" : "custom",
|
||||
range: status === "past" ? "past" : status === "cancelled" ? "any" : "future", // upcoming, unconfirmed, recurring are all future-only
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user