Skip to content

Commit 26317e9

Browse files
committed
feat(ui): inline deployments filter bar and fix layout jumping
1 parent 853ca33 commit 26317e9

2 files changed

Lines changed: 188 additions & 169 deletions

File tree

‎apps/dokploy/components/dashboard/deployments/show-deployments-table.tsx‎

Lines changed: 131 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"use client";
22

33
import {
4-
type ColumnFiltersState,
54
flexRender,
65
getCoreRowModel,
7-
getFilteredRowModel,
86
getPaginationRowModel,
97
getSortedRowModel,
108
type PaginationState,
@@ -27,7 +25,6 @@ import Link from "next/link";
2725
import { useMemo, useState } from "react";
2826
import { Badge } from "@/components/ui/badge";
2927
import { Button } from "@/components/ui/button";
30-
import { Input } from "@/components/ui/input";
3128
import {
3229
Select,
3330
SelectContent,
@@ -97,14 +94,21 @@ function getServiceInfo(d: DeploymentRow) {
9794
return null;
9895
}
9996

100-
export function ShowDeploymentsTable() {
97+
interface ShowDeploymentsTableProps {
98+
globalFilter: string;
99+
statusFilter: string;
100+
typeFilter: string;
101+
}
102+
103+
export function ShowDeploymentsTable({
104+
globalFilter,
105+
statusFilter,
106+
typeFilter,
107+
}: ShowDeploymentsTableProps) {
101108
const [sorting, setSorting] = useState<SortingState>([
102109
{ id: "createdAt", desc: true },
103110
]);
104-
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
105-
const [globalFilter, setGlobalFilter] = useState("");
106-
const [statusFilter, setStatusFilter] = useState<string>("all");
107-
const [typeFilter, setTypeFilter] = useState<string>("all");
111+
108112
const [pagination, setPagination] = useState<PaginationState>({
109113
pageIndex: 0,
110114
pageSize: 50,
@@ -446,177 +450,140 @@ export function ShowDeploymentsTable() {
446450
columns,
447451
state: {
448452
sorting,
449-
columnFilters,
450-
globalFilter,
451453
pagination,
452454
},
453455
onSortingChange: setSorting,
454-
onColumnFiltersChange: setColumnFilters,
455-
onGlobalFilterChange: setGlobalFilter,
456456
onPaginationChange: setPagination,
457457
getCoreRowModel: getCoreRowModel(),
458458
getSortedRowModel: getSortedRowModel(),
459-
getFilteredRowModel: getFilteredRowModel(),
460459
getPaginationRowModel: getPaginationRowModel(),
461460
});
462461

463462
return (
464-
<div className="space-y-2">
465-
<div className="flex flex-wrap items-center gap-2">
466-
<Input
467-
placeholder="Search by name, project, environment, server..."
468-
value={globalFilter}
469-
onChange={(e) => setGlobalFilter(e.target.value)}
470-
className="max-w-xs"
471-
/>
472-
<Select value={statusFilter} onValueChange={setStatusFilter}>
473-
<SelectTrigger className="w-[140px]">
474-
<SelectValue placeholder="Status" />
475-
</SelectTrigger>
476-
<SelectContent>
477-
<SelectItem value="all">All statuses</SelectItem>
478-
<SelectItem value="running">Running</SelectItem>
479-
<SelectItem value="done">Done</SelectItem>
480-
<SelectItem value="error">Error</SelectItem>
481-
<SelectItem value="cancelled">Cancelled</SelectItem>
482-
</SelectContent>
483-
</Select>
484-
<Select value={typeFilter} onValueChange={setTypeFilter}>
485-
<SelectTrigger className="w-[140px]">
486-
<SelectValue placeholder="Type" />
487-
</SelectTrigger>
488-
<SelectContent>
489-
<SelectItem value="all">All types</SelectItem>
490-
<SelectItem value="application">Application</SelectItem>
491-
<SelectItem value="compose">Compose</SelectItem>
492-
</SelectContent>
493-
</Select>
494-
</div>
495-
<div className="px-0">
496-
{isLoading ? (
497-
<div className="flex gap-4 w-full items-center justify-center min-h-[45vh] text-muted-foreground">
498-
<Loader2 className="size-4 animate-spin" />
499-
<span>Loading deployments...</span>
500-
</div>
501-
) : (
502-
<>
503-
<div className="rounded-md border overflow-x-auto">
504-
<Table>
505-
<TableHeader>
506-
{table.getHeaderGroups().map((headerGroup) => (
507-
<TableRow key={headerGroup.id}>
508-
{headerGroup.headers.map((header) => (
509-
<TableHead key={header.id}>
510-
{header.isPlaceholder
511-
? null
512-
: flexRender(
513-
header.column.columnDef.header,
514-
header.getContext(),
515-
)}
516-
</TableHead>
463+
<div className="px-0">
464+
{isLoading ? (
465+
<div className="flex gap-4 w-full items-center justify-center min-h-[45vh] text-muted-foreground">
466+
<Loader2 className="size-4 animate-spin" />
467+
<span>Loading deployments...</span>
468+
</div>
469+
) : (
470+
<>
471+
<div className="rounded-md border overflow-x-auto">
472+
<Table>
473+
<TableHeader>
474+
{table.getHeaderGroups().map((headerGroup) => (
475+
<TableRow key={headerGroup.id}>
476+
{headerGroup.headers.map((header) => (
477+
<TableHead key={header.id}>
478+
{header.isPlaceholder
479+
? null
480+
: flexRender(
481+
header.column.columnDef.header,
482+
header.getContext(),
483+
)}
484+
</TableHead>
485+
))}
486+
</TableRow>
487+
))}
488+
</TableHeader>
489+
<TableBody>
490+
{table.getRowModel().rows?.length ? (
491+
table.getRowModel().rows.map((row) => (
492+
<TableRow key={row.id}>
493+
{row.getVisibleCells().map((cell) => (
494+
<TableCell key={cell.id}>
495+
{flexRender(
496+
cell.column.columnDef.cell,
497+
cell.getContext(),
498+
)}
499+
</TableCell>
517500
))}
518501
</TableRow>
502+
))
503+
) : (
504+
<TableRow>
505+
<TableCell
506+
colSpan={columns.length}
507+
className=" text-center"
508+
>
509+
<div className="flex flex-col min-h-[45vh] items-center justify-center gap-2 text-muted-foreground">
510+
<Rocket className="size-8" />
511+
<p className="font-medium">No deployments found</p>
512+
<p className="text-sm">
513+
Deployments from applications and compose will appear
514+
here.
515+
</p>
516+
</div>
517+
</TableCell>
518+
</TableRow>
519+
)}
520+
</TableBody>
521+
</Table>
522+
</div>
523+
<div className="flex flex-col gap-4 px-4 py-4 border-t sm:flex-row sm:items-center sm:justify-between">
524+
<div className="flex items-center gap-2 flex-wrap">
525+
<span className="text-sm text-muted-foreground whitespace-nowrap">
526+
Rows per page
527+
</span>
528+
<Select
529+
value={String(pagination.pageSize)}
530+
onValueChange={(value) => {
531+
setPagination((p) => ({
532+
...p,
533+
pageSize: Number(value),
534+
pageIndex: 0,
535+
}));
536+
}}
537+
>
538+
<SelectTrigger className="h-8 w-[70px]">
539+
<SelectValue />
540+
</SelectTrigger>
541+
<SelectContent side="top">
542+
{[10, 25, 50, 100].map((size) => (
543+
<SelectItem key={size} value={String(size)}>
544+
{size}
545+
</SelectItem>
519546
))}
520-
</TableHeader>
521-
<TableBody>
522-
{table.getRowModel().rows?.length ? (
523-
table.getRowModel().rows.map((row) => (
524-
<TableRow key={row.id}>
525-
{row.getVisibleCells().map((cell) => (
526-
<TableCell key={cell.id}>
527-
{flexRender(
528-
cell.column.columnDef.cell,
529-
cell.getContext(),
530-
)}
531-
</TableCell>
532-
))}
533-
</TableRow>
534-
))
535-
) : (
536-
<TableRow>
537-
<TableCell
538-
colSpan={columns.length}
539-
className=" text-center"
540-
>
541-
<div className="flex flex-col min-h-[45vh] items-center justify-center gap-2 text-muted-foreground">
542-
<Rocket className="size-8" />
543-
<p className="font-medium">No deployments found</p>
544-
<p className="text-sm">
545-
Deployments from applications and compose will
546-
appear here.
547-
</p>
548-
</div>
549-
</TableCell>
550-
</TableRow>
551-
)}
552-
</TableBody>
553-
</Table>
547+
</SelectContent>
548+
</Select>
549+
<span className="text-sm text-muted-foreground whitespace-nowrap">
550+
Showing{" "}
551+
{filteredData.length === 0
552+
? 0
553+
: pagination.pageIndex * pagination.pageSize + 1}{" "}
554+
to{" "}
555+
{Math.min(
556+
(pagination.pageIndex + 1) * pagination.pageSize,
557+
filteredData.length,
558+
)}{" "}
559+
of {filteredData.length} entries
560+
</span>
554561
</div>
555-
<div className="flex flex-col gap-4 px-4 py-4 border-t sm:flex-row sm:items-center sm:justify-between">
556-
<div className="flex items-center gap-2 flex-wrap">
557-
<span className="text-sm text-muted-foreground whitespace-nowrap">
558-
Rows per page
559-
</span>
560-
<Select
561-
value={String(pagination.pageSize)}
562-
onValueChange={(value) => {
563-
setPagination((p) => ({
564-
...p,
565-
pageSize: Number(value),
566-
pageIndex: 0,
567-
}));
568-
}}
569-
>
570-
<SelectTrigger className="h-8 w-[70px]">
571-
<SelectValue />
572-
</SelectTrigger>
573-
<SelectContent side="top">
574-
{[10, 25, 50, 100].map((size) => (
575-
<SelectItem key={size} value={String(size)}>
576-
{size}
577-
</SelectItem>
578-
))}
579-
</SelectContent>
580-
</Select>
581-
<span className="text-sm text-muted-foreground whitespace-nowrap">
582-
Showing{" "}
583-
{filteredData.length === 0
584-
? 0
585-
: pagination.pageIndex * pagination.pageSize + 1}{" "}
586-
to{" "}
587-
{Math.min(
588-
(pagination.pageIndex + 1) * pagination.pageSize,
589-
filteredData.length,
590-
)}{" "}
591-
of {filteredData.length} entries
592-
</span>
593-
</div>
594-
<div className="flex items-center gap-2">
595-
<Button
596-
variant="outline"
597-
size="sm"
598-
className="h-8"
599-
onClick={() => table.previousPage()}
600-
disabled={!table.getCanPreviousPage()}
601-
>
602-
<ChevronLeft className="size-4" />
603-
Previous
604-
</Button>
605-
<Button
606-
variant="outline"
607-
size="sm"
608-
className="h-8"
609-
onClick={() => table.nextPage()}
610-
disabled={!table.getCanNextPage()}
611-
>
612-
Next
613-
<ChevronRight className="size-4" />
614-
</Button>
615-
</div>
562+
<div className="flex items-center gap-2">
563+
<Button
564+
variant="outline"
565+
size="sm"
566+
className="h-8"
567+
onClick={() => table.previousPage()}
568+
disabled={!table.getCanPreviousPage()}
569+
>
570+
<ChevronLeft className="size-4" />
571+
Previous
572+
</Button>
573+
<Button
574+
variant="outline"
575+
size="sm"
576+
className="h-8"
577+
onClick={() => table.nextPage()}
578+
disabled={!table.getCanNextPage()}
579+
>
580+
Next
581+
<ChevronRight className="size-4" />
582+
</Button>
616583
</div>
617-
</>
618-
)}
619-
</div>
584+
</div>
585+
</>
586+
)}
620587
</div>
621588
);
622589
}

0 commit comments

Comments
 (0)