Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor datatable component to include filter clearing functionality #270

Merged
merged 28 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
034c95d
Merge pull request #111 from lmnr-ai/dev
dinmukhamedm Oct 30, 2024
3641ee2
Merge pull request #117 from lmnr-ai/dev
dinmukhamedm Oct 31, 2024
5e25639
Merge pull request #126 from lmnr-ai/dev
dinmukhamedm Nov 1, 2024
67a36ba
Merge pull request #137 from lmnr-ai/dev
dinmukhamedm Nov 2, 2024
b73967f
Merge pull request #165 from lmnr-ai/dev
dinmukhamedm Nov 6, 2024
28e698b
Merge pull request #170 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
7ae1f99
Merge pull request #172 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
11842e4
Merge pull request #175 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
e27801d
Merge pull request #177 from lmnr-ai/dev
dinmukhamedm Nov 8, 2024
00ab4ef
Merge pull request #184 from lmnr-ai/dev
dinmukhamedm Nov 9, 2024
6a4ce29
Merge pull request #186 from lmnr-ai/dev
skull8888888 Nov 9, 2024
9cccb42
Merge pull request #193 from lmnr-ai/dev
dinmukhamedm Nov 10, 2024
8553e63
Merge pull request #198 from lmnr-ai/dev
dinmukhamedm Nov 12, 2024
c7681e5
Merge pull request #206 from lmnr-ai/dev
dinmukhamedm Nov 14, 2024
124fd0d
eval time progression (#210)
skull8888888 Nov 15, 2024
d9e7d65
Merge pull request #212 from lmnr-ai/dev
skull8888888 Nov 15, 2024
f3a0450
Merge pull request #214 from lmnr-ai/dev
dinmukhamedm Nov 15, 2024
b30e993
Merge pull request #216 from lmnr-ai/dev
dinmukhamedm Nov 15, 2024
2bd68d8
Merge pull request #221 from lmnr-ai/dev
dinmukhamedm Nov 18, 2024
4a0dc5e
Merge pull request #227 from lmnr-ai/dev
skull8888888 Nov 20, 2024
74960f1
Merge pull request #235 from lmnr-ai/dev
skull8888888 Nov 22, 2024
65de466
Merge pull request #245 from lmnr-ai/dev
dinmukhamedm Dec 2, 2024
ce2dac1
Merge pull request #247 from lmnr-ai/dev
dinmukhamedm Dec 2, 2024
d244713
Merge pull request #253 from lmnr-ai/dev
dinmukhamedm Dec 3, 2024
8b91d3a
Merge pull request #259 from lmnr-ai/dev
dinmukhamedm Dec 4, 2024
09c42ce
Merge pull request #264 from lmnr-ai/dev
dinmukhamedm Dec 5, 2024
8f65322
Refactor datatable component to include filter clearing functionality
devansh-m12 Dec 6, 2024
92c2a23
fix requested changes
devansh-m12 Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions frontend/components/ui/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DataTablePagination } from './datatable-pagination';
import { Label } from './label';
import { ScrollArea, ScrollBar } from './scroll-area';
import { Skeleton } from './skeleton';

import { usePathname, useRouter, useSearchParams } from 'next/navigation';
const DEFAULT_PAGE_SIZE = 50;

interface DataTableProps<TData> {
Expand Down Expand Up @@ -92,6 +92,18 @@ export function DataTable<TData>({
const [allRowsAcrossAllPagesSelected, setAllRowsAcrossAllPagesSelected] = useState(false);
const [expandedRows, setExpandedRows] = useState<ExpandedState>({});

const searchParams = new URLSearchParams(useSearchParams().toString());
dinmukhamedm marked this conversation as resolved.
Show resolved Hide resolved
const pathName = usePathname();
const router = useRouter();

const clearFilters = () => {
// clear all filters
if (searchParams !== null && searchParams.get('filter') !== null) {
searchParams.delete('filter');
router.push(`${pathName}?${searchParams.toString()}`);
}
};

useEffect(() => {
onSelectedRowsChange?.(Object.keys(rowSelection));
}, [rowSelection]);
Expand Down Expand Up @@ -284,7 +296,12 @@ export function DataTable<TData>({
colSpan={columns.length}
className="text-center p-4 text-secondary-foreground"
>
No results
{searchParams.get('filter') !== null ? 'Applied filters returned no results. ' : 'No results'}
{searchParams.get('filter') !== null && (
<span className="text-primary hover:cursor-pointer" onClick={clearFilters}>
Clear filters
</span>
)}
</TableCell>
</TableRow>
))
Expand Down