@create-lft-app/nextjs 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/.claude/skills/anti-patterns.md +150 -0
- package/template/.claude/skills/drizzle-schema.md +178 -0
- package/template/.claude/skills/formatting.md +56 -0
- package/template/.claude/skills/module-architecture.md +143 -0
- package/template/.claude/skills/supabase-server-actions.md +199 -0
- package/template/.claude/skills/ui-patterns.md +161 -0
- package/template/CLAUDE.md +74 -239
- package/template/src/components/layout/sidebar.tsx +4 -9
- package/template/src/components/tables/data-table-date-filter.tsx +203 -0
- package/template/src/components/tables/data-table-faceted-filter.tsx +185 -0
- package/template/src/components/tables/data-table-filters-dropdown.tsx +130 -0
- package/template/src/components/tables/data-table-number-filter.tsx +295 -0
- package/template/src/components/tables/data-table-toolbar.tsx +115 -25
- package/template/src/components/tables/data-table-view-options.tsx +10 -6
- package/template/src/components/tables/data-table.tsx +41 -21
- package/template/src/components/tables/index.ts +5 -1
- package/template/src/components/ui/alert-dialog.tsx +1 -1
- package/template/src/components/ui/avatar.tsx +2 -2
- package/template/src/components/ui/badge.tsx +2 -2
- package/template/src/components/ui/button.tsx +1 -1
- package/template/src/components/ui/card.tsx +1 -1
- package/template/src/components/ui/command.tsx +4 -4
- package/template/src/components/ui/dropdown-menu.tsx +4 -4
- package/template/src/components/ui/form.tsx +1 -1
- package/template/src/components/ui/icons.tsx +1 -1
- package/template/src/components/ui/popover.tsx +1 -1
- package/template/src/components/ui/progress.tsx +1 -1
- package/template/src/components/ui/select.tsx +3 -3
- package/template/src/components/ui/sonner.tsx +1 -1
- package/template/src/components/ui/spinner.tsx +1 -1
- package/template/src/components/ui/table.tsx +3 -3
- package/template/src/components/ui/tooltip.tsx +2 -2
- package/template/src/config/navigation.ts +1 -11
- package/template/src/config/roles.ts +27 -0
- package/template/src/lib/date/config.ts +4 -2
- package/template/src/lib/date/formatters.ts +7 -0
- package/template/src/lib/date/index.ts +8 -1
- package/template/src/lib/supabase/admin.ts +23 -0
- package/template/src/lib/supabase/proxy.ts +1 -1
- package/template/src/modules/users/actions/users-actions.ts +106 -34
- package/template/src/modules/users/columns.tsx +29 -9
- package/template/src/modules/users/components/users-list.tsx +27 -1
- package/template/src/modules/users/hooks/useUsersMutations.ts +3 -3
- package/template/src/modules/users/index.ts +20 -2
- package/template/src/modules/users/schemas/users.schema.ts +29 -1
- package/template/src/modules/users/types/auth-user.types.ts +42 -0
- package/template/src/modules/users/utils/user-mapper.ts +32 -0
- package/template/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Column } from '@tanstack/react-table'
|
|
5
|
+
import { Check, PlusCircle } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
import { Badge } from '@/components/ui/badge'
|
|
9
|
+
import { Button } from '@/components/ui/button'
|
|
10
|
+
import {
|
|
11
|
+
Command,
|
|
12
|
+
CommandEmpty,
|
|
13
|
+
CommandGroup,
|
|
14
|
+
CommandInput,
|
|
15
|
+
CommandItem,
|
|
16
|
+
CommandList,
|
|
17
|
+
CommandSeparator,
|
|
18
|
+
} from '@/components/ui/command'
|
|
19
|
+
import {
|
|
20
|
+
Popover,
|
|
21
|
+
PopoverContent,
|
|
22
|
+
PopoverTrigger,
|
|
23
|
+
} from '@/components/ui/popover'
|
|
24
|
+
import { Separator } from '@/components/ui/separator'
|
|
25
|
+
|
|
26
|
+
export interface FacetedFilterOption {
|
|
27
|
+
label: string
|
|
28
|
+
value: string
|
|
29
|
+
icon?: React.ComponentType<{ className?: string }>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
33
|
+
column?: Column<TData, TValue>
|
|
34
|
+
title?: string
|
|
35
|
+
options: FacetedFilterOption[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function DataTableFacetedFilter<TData, TValue>({
|
|
39
|
+
column,
|
|
40
|
+
title,
|
|
41
|
+
options,
|
|
42
|
+
}: DataTableFacetedFilterProps<TData, TValue>) {
|
|
43
|
+
const facets = column?.getFacetedUniqueValues()
|
|
44
|
+
const filterValue = column?.getFilterValue() as string[] | undefined
|
|
45
|
+
const [open, setOpen] = React.useState(false)
|
|
46
|
+
const [selectedValues, setSelectedValues] = React.useState<Set<string>>(
|
|
47
|
+
new Set(filterValue)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
// Sincronizar estado local con el filtro de la columna
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
setSelectedValues(new Set(filterValue))
|
|
53
|
+
}, [filterValue])
|
|
54
|
+
|
|
55
|
+
const handleApply = () => {
|
|
56
|
+
const filterValues = Array.from(selectedValues)
|
|
57
|
+
column?.setFilterValue(filterValues.length ? filterValues : undefined)
|
|
58
|
+
setOpen(false)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const handleClear = () => {
|
|
62
|
+
setSelectedValues(new Set())
|
|
63
|
+
column?.setFilterValue(undefined)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const handleOpenChange = (isOpen: boolean) => {
|
|
67
|
+
if (!isOpen) {
|
|
68
|
+
// Al cerrar sin aplicar, resetear al valor actual del filtro
|
|
69
|
+
setSelectedValues(new Set(filterValue))
|
|
70
|
+
}
|
|
71
|
+
setOpen(isOpen)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<Popover open={open} onOpenChange={handleOpenChange}>
|
|
76
|
+
<PopoverTrigger asChild>
|
|
77
|
+
<Button
|
|
78
|
+
variant="outline"
|
|
79
|
+
size="sm"
|
|
80
|
+
className="h-8 border-dashed"
|
|
81
|
+
>
|
|
82
|
+
<PlusCircle className="mr-2 h-4 w-4" />
|
|
83
|
+
{title}
|
|
84
|
+
{selectedValues.size > 0 && (
|
|
85
|
+
<>
|
|
86
|
+
<Separator orientation="vertical" className="mx-2 h-4" />
|
|
87
|
+
<Badge
|
|
88
|
+
variant="secondary"
|
|
89
|
+
className="rounded-sm px-1 font-normal lg:hidden"
|
|
90
|
+
>
|
|
91
|
+
{selectedValues.size}
|
|
92
|
+
</Badge>
|
|
93
|
+
<div className="hidden space-x-1 lg:flex">
|
|
94
|
+
{selectedValues.size > 2 ? (
|
|
95
|
+
<Badge
|
|
96
|
+
variant="secondary"
|
|
97
|
+
className="rounded-sm px-1 font-normal"
|
|
98
|
+
>
|
|
99
|
+
{selectedValues.size} seleccionados
|
|
100
|
+
</Badge>
|
|
101
|
+
) : (
|
|
102
|
+
options
|
|
103
|
+
.filter((option) => selectedValues.has(option.value))
|
|
104
|
+
.map((option) => (
|
|
105
|
+
<Badge
|
|
106
|
+
variant="secondary"
|
|
107
|
+
key={option.value}
|
|
108
|
+
className="rounded-sm px-1 font-normal"
|
|
109
|
+
>
|
|
110
|
+
{option.label}
|
|
111
|
+
</Badge>
|
|
112
|
+
))
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
</>
|
|
116
|
+
)}
|
|
117
|
+
</Button>
|
|
118
|
+
</PopoverTrigger>
|
|
119
|
+
<PopoverContent className="w-[200px] p-0" side="bottom" align="start" sideOffset={4}>
|
|
120
|
+
<Command>
|
|
121
|
+
<CommandInput placeholder={title} />
|
|
122
|
+
<CommandList>
|
|
123
|
+
<CommandEmpty>Sin resultados.</CommandEmpty>
|
|
124
|
+
<CommandGroup>
|
|
125
|
+
{options.map((option) => {
|
|
126
|
+
const isSelected = selectedValues.has(option.value)
|
|
127
|
+
return (
|
|
128
|
+
<CommandItem
|
|
129
|
+
key={option.value}
|
|
130
|
+
onSelect={() => {
|
|
131
|
+
const newSelected = new Set(selectedValues)
|
|
132
|
+
if (isSelected) {
|
|
133
|
+
newSelected.delete(option.value)
|
|
134
|
+
} else {
|
|
135
|
+
newSelected.add(option.value)
|
|
136
|
+
}
|
|
137
|
+
setSelectedValues(newSelected)
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<div
|
|
141
|
+
className={cn(
|
|
142
|
+
'mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary',
|
|
143
|
+
isSelected
|
|
144
|
+
? 'bg-primary text-primary-foreground'
|
|
145
|
+
: 'opacity-50 [&_svg]:invisible'
|
|
146
|
+
)}
|
|
147
|
+
>
|
|
148
|
+
<Check className="h-4 w-4" />
|
|
149
|
+
</div>
|
|
150
|
+
{option.icon && (
|
|
151
|
+
<option.icon className="mr-2 h-4 w-4 text-muted-foreground" />
|
|
152
|
+
)}
|
|
153
|
+
<span>{option.label}</span>
|
|
154
|
+
{facets?.get(option.value) && (
|
|
155
|
+
<span className="ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs">
|
|
156
|
+
{facets.get(option.value)}
|
|
157
|
+
</span>
|
|
158
|
+
)}
|
|
159
|
+
</CommandItem>
|
|
160
|
+
)
|
|
161
|
+
})}
|
|
162
|
+
</CommandGroup>
|
|
163
|
+
</CommandList>
|
|
164
|
+
</Command>
|
|
165
|
+
<div className="flex gap-2 border-t border-border p-2">
|
|
166
|
+
<Button
|
|
167
|
+
variant="outline"
|
|
168
|
+
size="sm"
|
|
169
|
+
className="flex-1"
|
|
170
|
+
onClick={handleClear}
|
|
171
|
+
>
|
|
172
|
+
Limpiar
|
|
173
|
+
</Button>
|
|
174
|
+
<Button
|
|
175
|
+
size="sm"
|
|
176
|
+
className="flex-1"
|
|
177
|
+
onClick={handleApply}
|
|
178
|
+
>
|
|
179
|
+
Aplicar
|
|
180
|
+
</Button>
|
|
181
|
+
</div>
|
|
182
|
+
</PopoverContent>
|
|
183
|
+
</Popover>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Table } from '@tanstack/react-table'
|
|
5
|
+
import { Filter, X } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
import { Badge } from '@/components/ui/badge'
|
|
9
|
+
import { Button } from '@/components/ui/button'
|
|
10
|
+
import {
|
|
11
|
+
Popover,
|
|
12
|
+
PopoverContent,
|
|
13
|
+
PopoverTrigger,
|
|
14
|
+
} from '@/components/ui/popover'
|
|
15
|
+
import { Separator } from '@/components/ui/separator'
|
|
16
|
+
import { DataTableFacetedFilter } from './data-table-faceted-filter'
|
|
17
|
+
import { DataTableDateFilter } from './data-table-date-filter'
|
|
18
|
+
import { DataTableNumberFilter } from './data-table-number-filter'
|
|
19
|
+
import type { FilterConfig } from './data-table'
|
|
20
|
+
|
|
21
|
+
interface DataTableFiltersDropdownProps<TData> {
|
|
22
|
+
table: Table<TData>
|
|
23
|
+
filters: FilterConfig[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function DataTableFiltersDropdown<TData>({
|
|
27
|
+
table,
|
|
28
|
+
filters,
|
|
29
|
+
}: DataTableFiltersDropdownProps<TData>) {
|
|
30
|
+
const [open, setOpen] = React.useState(false)
|
|
31
|
+
|
|
32
|
+
// Contar filtros activos (excluyendo el search)
|
|
33
|
+
const activeFiltersCount = table.getState().columnFilters.filter(
|
|
34
|
+
(filter) => filters.some((f) => f.columnId === filter.id)
|
|
35
|
+
).length
|
|
36
|
+
|
|
37
|
+
const handleClearAll = () => {
|
|
38
|
+
// Solo limpiar los filtros configurados, no el search
|
|
39
|
+
filters.forEach((filter) => {
|
|
40
|
+
table.getColumn(filter.columnId)?.setFilterValue(undefined)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
46
|
+
<PopoverTrigger asChild>
|
|
47
|
+
<Button
|
|
48
|
+
variant="outline"
|
|
49
|
+
size="sm"
|
|
50
|
+
className={cn(
|
|
51
|
+
'h-8 border-dashed',
|
|
52
|
+
activeFiltersCount > 0 && 'border-solid'
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
<Filter className="mr-2 h-4 w-4" />
|
|
56
|
+
Filtros
|
|
57
|
+
{activeFiltersCount > 0 && (
|
|
58
|
+
<Badge
|
|
59
|
+
variant="secondary"
|
|
60
|
+
className="ml-2 rounded-sm px-1 font-normal"
|
|
61
|
+
>
|
|
62
|
+
{activeFiltersCount}
|
|
63
|
+
</Badge>
|
|
64
|
+
)}
|
|
65
|
+
</Button>
|
|
66
|
+
</PopoverTrigger>
|
|
67
|
+
<PopoverContent className="w-[320px] p-0" align="start">
|
|
68
|
+
<div className="flex flex-col">
|
|
69
|
+
{/* Header */}
|
|
70
|
+
<div className="flex items-center justify-between border-b border-border px-4 py-3">
|
|
71
|
+
<span className="text-sm font-medium">Filtros</span>
|
|
72
|
+
{activeFiltersCount > 0 && (
|
|
73
|
+
<Button
|
|
74
|
+
variant="ghost"
|
|
75
|
+
size="sm"
|
|
76
|
+
className="h-7 px-2 text-xs"
|
|
77
|
+
onClick={handleClearAll}
|
|
78
|
+
>
|
|
79
|
+
Limpiar todo
|
|
80
|
+
<X className="ml-1 h-3 w-3" />
|
|
81
|
+
</Button>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
{/* Filters */}
|
|
86
|
+
<div className="flex flex-col gap-3 p-4">
|
|
87
|
+
{filters.map((filter, index) => {
|
|
88
|
+
const column = table.getColumn(filter.columnId)
|
|
89
|
+
if (!column) return null
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div key={filter.columnId} className="flex flex-col gap-2">
|
|
93
|
+
{index > 0 && <Separator className="my-1" />}
|
|
94
|
+
<label className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
|
95
|
+
{filter.title}
|
|
96
|
+
</label>
|
|
97
|
+
|
|
98
|
+
{filter.type === 'faceted' && filter.options && (
|
|
99
|
+
<DataTableFacetedFilter
|
|
100
|
+
column={column}
|
|
101
|
+
title={filter.title}
|
|
102
|
+
options={filter.options}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
{filter.type === 'date-range' && (
|
|
107
|
+
<DataTableDateFilter
|
|
108
|
+
column={column}
|
|
109
|
+
title={filter.title}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
{filter.type === 'number-range' && (
|
|
114
|
+
<DataTableNumberFilter
|
|
115
|
+
column={column}
|
|
116
|
+
title={filter.title}
|
|
117
|
+
format={filter.format}
|
|
118
|
+
currencySymbol={filter.currencySymbol}
|
|
119
|
+
step={filter.step}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
})}
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</PopoverContent>
|
|
128
|
+
</Popover>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Column } from '@tanstack/react-table'
|
|
5
|
+
import { DollarSign, X } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
import { DEFAULT_LOCALE } from '@/lib/date'
|
|
9
|
+
import { Button } from '@/components/ui/button'
|
|
10
|
+
import { Input } from '@/components/ui/input'
|
|
11
|
+
import {
|
|
12
|
+
Popover,
|
|
13
|
+
PopoverContent,
|
|
14
|
+
PopoverTrigger,
|
|
15
|
+
} from '@/components/ui/popover'
|
|
16
|
+
|
|
17
|
+
export interface NumberRange {
|
|
18
|
+
min?: number
|
|
19
|
+
max?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface DataTableNumberFilterProps<TData> {
|
|
23
|
+
column?: Column<TData, unknown>
|
|
24
|
+
title?: string
|
|
25
|
+
/** Formato para mostrar el número (ej: 'currency', 'number') */
|
|
26
|
+
format?: 'currency' | 'number'
|
|
27
|
+
/** Símbolo de moneda (default: '$') */
|
|
28
|
+
currencySymbol?: string
|
|
29
|
+
/** Paso para los inputs (default: 1) */
|
|
30
|
+
step?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function DataTableNumberFilter<TData>({
|
|
34
|
+
column,
|
|
35
|
+
title = 'Monto',
|
|
36
|
+
format = 'number',
|
|
37
|
+
currencySymbol = '$',
|
|
38
|
+
step = 1,
|
|
39
|
+
}: DataTableNumberFilterProps<TData>) {
|
|
40
|
+
const filterValue = column?.getFilterValue() as NumberRange | undefined
|
|
41
|
+
const [open, setOpen] = React.useState(false)
|
|
42
|
+
|
|
43
|
+
// Sincronizar estado local con el filtro de la columna
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (!filterValue) {
|
|
46
|
+
setRange({ min: undefined, max: undefined })
|
|
47
|
+
}
|
|
48
|
+
}, [filterValue])
|
|
49
|
+
|
|
50
|
+
const [range, setRange] = React.useState<NumberRange>({
|
|
51
|
+
min: filterValue?.min,
|
|
52
|
+
max: filterValue?.max,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const handleMinChange = (value: string) => {
|
|
56
|
+
const min = value === '' ? undefined : Number(value)
|
|
57
|
+
const newRange = { ...range, min }
|
|
58
|
+
setRange(newRange)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const handleMaxChange = (value: string) => {
|
|
62
|
+
const max = value === '' ? undefined : Number(value)
|
|
63
|
+
const newRange = { ...range, max }
|
|
64
|
+
setRange(newRange)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleApply = () => {
|
|
68
|
+
if (range.min === undefined && range.max === undefined) {
|
|
69
|
+
column?.setFilterValue(undefined)
|
|
70
|
+
} else {
|
|
71
|
+
column?.setFilterValue(range)
|
|
72
|
+
}
|
|
73
|
+
setOpen(false)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const handleClear = () => {
|
|
77
|
+
setRange({ min: undefined, max: undefined })
|
|
78
|
+
column?.setFilterValue(undefined)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const handleOpenChange = (isOpen: boolean) => {
|
|
82
|
+
if (!isOpen) {
|
|
83
|
+
// Al cerrar sin aplicar, resetear al valor actual del filtro
|
|
84
|
+
setRange({
|
|
85
|
+
min: filterValue?.min,
|
|
86
|
+
max: filterValue?.max,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
setOpen(isOpen)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const formatNumber = (num: number) => {
|
|
93
|
+
if (format === 'currency') {
|
|
94
|
+
return `${currencySymbol}${num.toLocaleString(DEFAULT_LOCALE)}`
|
|
95
|
+
}
|
|
96
|
+
return num.toLocaleString(DEFAULT_LOCALE)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hasFilter = filterValue?.min !== undefined || filterValue?.max !== undefined
|
|
100
|
+
|
|
101
|
+
const getDisplayText = () => {
|
|
102
|
+
if (!hasFilter) return title
|
|
103
|
+
|
|
104
|
+
const { min, max } = filterValue!
|
|
105
|
+
if (min !== undefined && max !== undefined) {
|
|
106
|
+
return `${formatNumber(min)} - ${formatNumber(max)}`
|
|
107
|
+
}
|
|
108
|
+
if (min !== undefined) {
|
|
109
|
+
return `≥ ${formatNumber(min)}`
|
|
110
|
+
}
|
|
111
|
+
if (max !== undefined) {
|
|
112
|
+
return `≤ ${formatNumber(max)}`
|
|
113
|
+
}
|
|
114
|
+
return title
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const Icon = format === 'currency' ? DollarSign : () => <span className="text-xs font-medium">#</span>
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Popover open={open} onOpenChange={handleOpenChange}>
|
|
121
|
+
<PopoverTrigger asChild>
|
|
122
|
+
<Button
|
|
123
|
+
variant="outline"
|
|
124
|
+
size="sm"
|
|
125
|
+
className={cn(
|
|
126
|
+
'h-8 border-dashed',
|
|
127
|
+
hasFilter && 'border-solid'
|
|
128
|
+
)}
|
|
129
|
+
>
|
|
130
|
+
<Icon className="mr-2 h-4 w-4" />
|
|
131
|
+
<span className="max-w-[150px] truncate">{getDisplayText()}</span>
|
|
132
|
+
{hasFilter && (
|
|
133
|
+
<span
|
|
134
|
+
role="button"
|
|
135
|
+
tabIndex={0}
|
|
136
|
+
onClick={(e) => {
|
|
137
|
+
e.stopPropagation()
|
|
138
|
+
handleClear()
|
|
139
|
+
}}
|
|
140
|
+
onKeyDown={(e) => {
|
|
141
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
142
|
+
e.stopPropagation()
|
|
143
|
+
handleClear()
|
|
144
|
+
}
|
|
145
|
+
}}
|
|
146
|
+
className="ml-2 rounded-full p-0.5 hover:bg-muted"
|
|
147
|
+
>
|
|
148
|
+
<X className="h-3 w-3" />
|
|
149
|
+
</span>
|
|
150
|
+
)}
|
|
151
|
+
</Button>
|
|
152
|
+
</PopoverTrigger>
|
|
153
|
+
<PopoverContent className="w-[280px] p-4" side="bottom" align="start" sideOffset={4}>
|
|
154
|
+
<div className="flex flex-col gap-4">
|
|
155
|
+
<div className="flex flex-col gap-2">
|
|
156
|
+
<label className="text-sm font-medium text-foreground">
|
|
157
|
+
Rango de {title.toLowerCase()}
|
|
158
|
+
</label>
|
|
159
|
+
<div className="flex items-center gap-2">
|
|
160
|
+
<div className="relative flex-1">
|
|
161
|
+
{format === 'currency' && (
|
|
162
|
+
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground">
|
|
163
|
+
{currencySymbol}
|
|
164
|
+
</span>
|
|
165
|
+
)}
|
|
166
|
+
<Input
|
|
167
|
+
type="number"
|
|
168
|
+
placeholder="Mín"
|
|
169
|
+
value={range.min ?? ''}
|
|
170
|
+
onChange={(e) => handleMinChange(e.target.value)}
|
|
171
|
+
step={step}
|
|
172
|
+
className={cn(
|
|
173
|
+
'h-9',
|
|
174
|
+
format === 'currency' && 'pl-7'
|
|
175
|
+
)}
|
|
176
|
+
/>
|
|
177
|
+
</div>
|
|
178
|
+
<span className="text-muted-foreground">-</span>
|
|
179
|
+
<div className="relative flex-1">
|
|
180
|
+
{format === 'currency' && (
|
|
181
|
+
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground">
|
|
182
|
+
{currencySymbol}
|
|
183
|
+
</span>
|
|
184
|
+
)}
|
|
185
|
+
<Input
|
|
186
|
+
type="number"
|
|
187
|
+
placeholder="Máx"
|
|
188
|
+
value={range.max ?? ''}
|
|
189
|
+
onChange={(e) => handleMaxChange(e.target.value)}
|
|
190
|
+
step={step}
|
|
191
|
+
className={cn(
|
|
192
|
+
'h-9',
|
|
193
|
+
format === 'currency' && 'pl-7'
|
|
194
|
+
)}
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
{/* Presets rápidos */}
|
|
201
|
+
<div className="flex flex-wrap gap-1">
|
|
202
|
+
<Button
|
|
203
|
+
variant="ghost"
|
|
204
|
+
size="sm"
|
|
205
|
+
className="h-7 text-xs"
|
|
206
|
+
onClick={() => {
|
|
207
|
+
setRange({ min: 0, max: 100 })
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
0-100
|
|
211
|
+
</Button>
|
|
212
|
+
<Button
|
|
213
|
+
variant="ghost"
|
|
214
|
+
size="sm"
|
|
215
|
+
className="h-7 text-xs"
|
|
216
|
+
onClick={() => {
|
|
217
|
+
setRange({ min: 100, max: 500 })
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
100-500
|
|
221
|
+
</Button>
|
|
222
|
+
<Button
|
|
223
|
+
variant="ghost"
|
|
224
|
+
size="sm"
|
|
225
|
+
className="h-7 text-xs"
|
|
226
|
+
onClick={() => {
|
|
227
|
+
setRange({ min: 500, max: 1000 })
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
500-1K
|
|
231
|
+
</Button>
|
|
232
|
+
<Button
|
|
233
|
+
variant="ghost"
|
|
234
|
+
size="sm"
|
|
235
|
+
className="h-7 text-xs"
|
|
236
|
+
onClick={() => {
|
|
237
|
+
setRange({ min: 1000, max: undefined })
|
|
238
|
+
}}
|
|
239
|
+
>
|
|
240
|
+
+1K
|
|
241
|
+
</Button>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<div className="flex gap-2">
|
|
245
|
+
<Button
|
|
246
|
+
variant="outline"
|
|
247
|
+
size="sm"
|
|
248
|
+
className="flex-1"
|
|
249
|
+
onClick={handleClear}
|
|
250
|
+
>
|
|
251
|
+
Limpiar
|
|
252
|
+
</Button>
|
|
253
|
+
<Button
|
|
254
|
+
size="sm"
|
|
255
|
+
className="flex-1"
|
|
256
|
+
onClick={handleApply}
|
|
257
|
+
>
|
|
258
|
+
Aplicar
|
|
259
|
+
</Button>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
</PopoverContent>
|
|
263
|
+
</Popover>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Filter function para usar con TanStack Table
|
|
268
|
+
export function numberRangeFilterFn<TData>(
|
|
269
|
+
row: { getValue: (id: string) => unknown },
|
|
270
|
+
columnId: string,
|
|
271
|
+
filterValue: NumberRange | undefined
|
|
272
|
+
): boolean {
|
|
273
|
+
if (!filterValue) return true
|
|
274
|
+
if (filterValue.min === undefined && filterValue.max === undefined) return true
|
|
275
|
+
|
|
276
|
+
const cellValue = row.getValue(columnId)
|
|
277
|
+
if (cellValue === null || cellValue === undefined) return false
|
|
278
|
+
|
|
279
|
+
const value = Number(cellValue)
|
|
280
|
+
if (isNaN(value)) return false
|
|
281
|
+
|
|
282
|
+
const { min, max } = filterValue
|
|
283
|
+
|
|
284
|
+
if (min !== undefined && max !== undefined) {
|
|
285
|
+
return value >= min && value <= max
|
|
286
|
+
}
|
|
287
|
+
if (min !== undefined) {
|
|
288
|
+
return value >= min
|
|
289
|
+
}
|
|
290
|
+
if (max !== undefined) {
|
|
291
|
+
return value <= max
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return true
|
|
295
|
+
}
|