@@ -29,6 +29,19 @@ export default function DataTable<T extends DataType>({
2929 const { settings, activeProject, setActiveProject, setCurrentView,
3030 searchTerm, clearSearchTerm} = useGlobalContext ( )
3131
32+ const hasStoredData = ( ) => {
33+ const stored = localStorage . getItem ( 'Cookify' )
34+ if ( ! stored ) return false
35+ try {
36+ const data = JSON . parse ( stored )
37+ return ( data . cookies && data . cookies . length > 0 ) || ( data . swaggers && data . swaggers . length > 0 )
38+ } catch {
39+ return false
40+ }
41+ }
42+
43+ const shouldShowNoResults = data . length === 0 && ( ! hasStoredData ( ) || searchTerm || activeProject )
44+
3245 const handleDragEnd = ( result : any ) => {
3346 if ( ! result . destination || ! onReorder ) return
3447 onReorder ( result . source . index , result . destination . index )
@@ -54,91 +67,88 @@ export default function DataTable<T extends DataType>({
5467 setCurrentView ( type === 'cookie' ? 'add-cookie' : 'add-swagger' ) ;
5568 }
5669
57-
5870 return (
59- < div className = "w-full h-full flex flex-col" >
60- < div className = "sticky top-0 z-20 bg-background" >
61- < Table >
62- < TableHeader >
63- { renderHeaders ( ) }
64- </ TableHeader >
65- </ Table >
66- </ div >
71+ < div className = "w-full h-full flex flex-col overflow-hidden" >
6772 < DragDropContext onDragEnd = { handleDragEnd } >
68- < Table >
69- < Droppable droppableId = { type === 'cookie' ? 'cookies' : 'swaggers' } >
70- { ( provided ) => (
71- < TableBody
72- { ...provided . droppableProps }
73- ref = { provided . innerRef }
74- >
75- { data . length === 0 ? (
76- < TableRow >
77- < TableCell colSpan = { 5 } className = "text-center py-4 text-muted-foreground" >
78- < div className = "flex flex-col items-center justify-center gap-2" >
79- < div className = "flex items-center gap-2" >
80- < Search className = "w-4 h-4" />
81- No results found.
73+ < div className = "relative overflow-auto" >
74+ < Table >
75+ < TableHeader className = "sticky top-0 z-20 bg-background" >
76+ { renderHeaders ( ) }
77+ </ TableHeader >
78+ < Droppable droppableId = { type === 'cookie' ? 'cookies' : 'swaggers' } >
79+ { ( provided ) => (
80+ < TableBody
81+ { ...provided . droppableProps }
82+ ref = { provided . innerRef }
83+ >
84+ { shouldShowNoResults ? (
85+ < TableRow >
86+ < TableCell colSpan = { 5 } className = "text-center py-4 text-muted-foreground" >
87+ < div className = "flex flex-col items-center justify-center gap-2" >
88+ < div className = "flex items-center gap-2" >
89+ < Search className = "w-4 h-4" />
90+ No results found.
91+ </ div >
92+ { searchTerm && clearSearchTerm ? (
93+ < Button
94+ variant = "outline"
95+ size = "sm"
96+ onClick = { clearSearchTerm }
97+ className = "mt-2 text-xs w-40 flex items-center gap-1"
98+ >
99+ < BrushCleaning className = "w-4 h-4 mr-1" />
100+ Clear < b > Search</ b > filter
101+ </ Button >
102+ ) : activeProject ? (
103+ < Button
104+ variant = "outline"
105+ size = "sm"
106+ onClick = { handleClearProjectFilter }
107+ className = "mt-2 text-xs w-40 flex items-center gap-1"
108+ >
109+ < BrushCleaning className = "w-4 h-4 mr-1" />
110+ Clear < b > Project</ b > filter
111+ </ Button >
112+ ) : originalDataLength === 0 ? (
113+ < Button
114+ variant = "default"
115+ size = "sm"
116+ onClick = { handleAddNew }
117+ className = "mt-2 flex items-center gap-2 text-xs w-40"
118+ >
119+ < PlusCircle className = "w-4 h-4" />
120+ Add new { type }
121+ </ Button >
122+ ) : null }
82123 </ div >
83- { activeProject ? (
84- < Button
85- variant = "outline"
86- size = "sm"
87- onClick = { handleClearProjectFilter }
88- className = "mt-2 text-xs w-40 flex items-center gap-1"
89- >
90- < BrushCleaning className = "w-4 h-4 mr-1" />
91- Clear < b > Project</ b > filter
92- </ Button >
93- ) : searchTerm && clearSearchTerm ? (
94- < Button
95- variant = "outline"
96- size = "sm"
97- onClick = { clearSearchTerm }
98- className = "mt-2 text-xs w-40 flex items-center gap-1"
99- >
100- < BrushCleaning className = "w-4 h-4 mr-1" />
101- Clear < b > Search</ b > filter
102- </ Button >
103- ) : originalDataLength === 0 ? (
104- < Button
105- variant = "default"
106- size = "sm"
107- onClick = { handleAddNew }
108- className = "mt-2 flex items-center gap-2 text-xs w-40"
124+ </ TableCell >
125+ </ TableRow >
126+ ) : (
127+ data . map ( ( item , index ) => (
128+ < Draggable
129+ key = { item . project + "-" + item . alias }
130+ draggableId = { item . alias }
131+ index = { index }
132+ >
133+ { ( provided ) => (
134+ < TableRow
135+ ref = { provided . innerRef }
136+ { ...provided . draggableProps }
137+ className = { `${ settings . applyOnClick ? "cursor-pointer" : "cursor-default" } transition-colors hover:bg-accent/50` }
138+ onClick = { ( ) => handleRowClick ( item ) }
109139 >
110- < PlusCircle className = "w-4 h-4" />
111- Add new { type }
112- </ Button >
113- ) : null }
114- </ div >
115- </ TableCell >
116- </ TableRow >
117- ) : (
118- data . map ( ( item , index ) => (
119- < Draggable
120- key = { item . project + "-" + item . alias }
121- draggableId = { item . alias }
122- index = { index }
123- >
124- { ( provided ) => (
125- < TableRow
126- ref = { provided . innerRef }
127- { ...provided . draggableProps }
128- className = { `${ settings . applyOnClick ? "cursor-pointer" : "cursor-default" } transition-colors hover:bg-accent/50` }
129- onClick = { ( ) => handleRowClick ( item ) }
130- >
131- { renderCells ( item , index , provided . dragHandleProps ) }
132- </ TableRow >
133- ) }
134- </ Draggable >
135- ) )
136- ) }
137- { provided . placeholder }
138- </ TableBody >
139- ) }
140- </ Droppable >
141- </ Table >
140+ { renderCells ( item , index , provided . dragHandleProps ) }
141+ </ TableRow >
142+ ) }
143+ </ Draggable >
144+ ) )
145+ ) }
146+ { provided . placeholder }
147+ </ TableBody >
148+ ) }
149+ </ Droppable >
150+ </ Table >
151+ </ div >
142152 </ DragDropContext >
143153 </ div >
144154 )
0 commit comments