feat(ui): standardize collapsible filters and date selection UI
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-20 14:03:59 +08:00
parent daae429cd4
commit 74728c47b9
6 changed files with 517 additions and 222 deletions

View File

@@ -4,13 +4,14 @@ import { Head, router } from '@inertiajs/react';
import { PageProps } from '@/types/global';
import Pagination from '@/Components/shared/Pagination';
import { SearchableSelect } from "@/Components/ui/searchable-select";
import { FileText, Search, RotateCcw, Calendar } from 'lucide-react';
import { FileText, Search, RotateCcw, Calendar, ChevronDown, ChevronUp } from 'lucide-react';
import LogTable, { Activity } from '@/Components/ActivityLog/LogTable';
import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog';
import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select";
import { getDateRange } from "@/utils/format";
interface PaginationLinks {
url: string | null;
@@ -54,6 +55,21 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
const [event, setEvent] = useState(filters.event || 'all');
const [subjectType, setSubjectType] = useState(filters.subject_type || 'all');
const [causer, setCauser] = useState(filters.causer_id || 'all');
const [dateRangeType, setDateRangeType] = useState('custom');
// Advanced Filter Toggle
const [showAdvancedFilter, setShowAdvancedFilter] = useState(
!!(filters.date_start || filters.date_end)
);
const handleDateRangeChange = (type: string) => {
setDateRangeType(type);
if (type === 'custom') return;
const { start, end } = getDateRange(type);
setDateStart(start);
setDateEnd(end);
};
const handleFilter = () => {
router.get(
@@ -79,6 +95,7 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
setEvent('all');
setSubjectType('all');
setCauser('all');
setDateRangeType('custom');
router.get(
route('activity-logs.index'),
@@ -144,44 +161,29 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
</div>
{/* 篩選區塊 */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
<div className="bg-white p-5 rounded-lg shadow-sm border border-grey-4 mb-6">
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 mb-4">
{/* 關鍵字搜尋 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="md:col-span-4 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
<Input
placeholder="搜尋描述、內容..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-9"
className="pl-10 h-9 block"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/>
</div>
</div>
{/* 操作人員 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect
value={causer}
onValueChange={setCauser}
options={[
{ label: "所有人員", value: "all" },
...users
]}
placeholder="選擇操作人員"
className="w-full"
/>
</div>
{/* 事件類型 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="md:col-span-2 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<Select value={event} onValueChange={setEvent}>
<SelectTrigger>
<SelectValue placeholder="選擇事件類型" />
<SelectTrigger className="h-9">
<SelectValue placeholder="所有事件" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
@@ -193,8 +195,8 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
</div>
{/* 操作對象 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="md:col-span-3 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<SearchableSelect
value={subjectType}
onValueChange={setSubjectType}
@@ -202,55 +204,128 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
{ label: "所有對象", value: "all" },
...subject_types
]}
placeholder="選擇操作對象"
className="w-full"
placeholder="選擇對象"
className="w-full h-9"
/>
</div>
{/* 日期範圍 - 開始 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateStart}
onChange={(e) => setDateStart(e.target.value)}
className="pl-9 block w-full"
/>
</div>
</div>
{/* 日期範圍 - 結束 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateEnd}
onChange={(e) => setDateEnd(e.target.value)}
className="pl-9 block w-full text-left"
/>
</div>
{/* 操作人員 */}
<div className="md:col-span-3 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<SearchableSelect
value={causer}
onValueChange={setCauser}
options={[
{ label: "所有人員", value: "all" },
...users
]}
placeholder="選擇人員"
className="w-full h-9"
/>
</div>
</div>
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
{/* Row 2: Date Filters (Collapsible) */}
{showAdvancedFilter && (
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 items-end animate-in fade-in slide-in-from-top-2 duration-200">
<div className="md:col-span-6 space-y-2">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="flex flex-wrap gap-2">
{[
{ label: "今日", value: "today" },
{ label: "昨日", value: "yesterday" },
{ label: "本週", value: "this_week" },
{ label: "本月", value: "this_month" },
{ label: "上月", value: "last_month" },
].map((opt) => (
<Button
key={opt.value}
size="sm"
onClick={() => handleDateRangeChange(opt.value)}
className={
dateRangeType === opt.value
? 'button-filled-primary h-9 px-4 shadow-sm'
: 'button-outlined-primary h-9 px-4 bg-white'
}
>
{opt.label}
</Button>
))}
</div>
</div>
<div className="md:col-span-6">
<div className="grid grid-cols-2 gap-4 items-end">
<div className="space-y-1">
<Label className="text-xs font-medium text-grey-2"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => {
setDateStart(e.target.value);
setDateRangeType('custom');
}}
// block w-full to ensure it fills space
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
<div className="space-y-1">
<Label className="text-xs font-medium text-grey-2"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => {
setDateEnd(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
</div>
</div>
</div>
)}
{/* Action Bar */}
<div className="flex items-center justify-end border-t border-grey-4 pt-5 gap-3 mt-4">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAdvancedFilter(!showAdvancedFilter)}
className="mr-auto text-gray-500 hover:text-gray-900 h-9"
>
{showAdvancedFilter ? (
<>
<ChevronUp className="h-4 w-4 mr-1" />
</>
) : (
<>
<ChevronDown className="h-4 w-4 mr-1" />
{(dateStart || dateEnd) && (
<span className="ml-2 w-2 h-2 rounded-full bg-primary-main" />
)}
</>
)}
</Button>
<Button
variant="outline"
onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary"
className="flex items-center gap-2 button-outlined-primary h-9"
>
<RotateCcw className="h-4 w-4" />
</Button>
<Button
onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary"
>
<Button onClick={handleFilter} className="button-filled-primary h-9 px-6 gap-2">
<Search className="h-4 w-4" />
</Button>
</div>
</div>
@@ -264,32 +339,21 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
from={activities.from}
/>
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
value={perPage}
onValueChange={handlePerPageChange}
options={[
{ label: "10", value: "10" },
{ label: "20", value: "20" },
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={activities.links} />
</div>
<div className="mt-6">
<Pagination
links={activities.links}
total={activities.total}
current_page={activities.current_page}
last_page={activities.last_page}
per_page={perPage}
onPerPageChange={handlePerPageChange}
/>
</div>
</div>
<ActivityDetailDialog
open={detailOpen}
onOpenChange={setDetailOpen}
isOpen={detailOpen}
onClose={() => setDetailOpen(false)}
activity={selectedActivity}
/>
</AuthenticatedLayout>