yangdx
commited on
Commit
·
4d5e3ee
1
Parent(s):
74d6dff
Fix linting
Browse files
lightrag_webui/src/features/DocumentManager.tsx
CHANGED
@@ -112,11 +112,11 @@ export default function DocumentManager() {
|
|
112 |
const currentTab = useSettingsStore.use.currentTab()
|
113 |
const showFileName = useSettingsStore.use.showFileName()
|
114 |
const setShowFileName = useSettingsStore.use.setShowFileName()
|
115 |
-
|
116 |
// Sort state
|
117 |
const [sortField, setSortField] = useState<SortField>('updated_at')
|
118 |
const [sortDirection, setSortDirection] = useState<SortDirection>('desc')
|
119 |
-
|
120 |
// Handle sort column click
|
121 |
const handleSort = (field: SortField) => {
|
122 |
if (sortField === field) {
|
@@ -128,12 +128,12 @@ export default function DocumentManager() {
|
|
128 |
setSortDirection('desc')
|
129 |
}
|
130 |
}
|
131 |
-
|
132 |
// Sort documents based on current sort field and direction
|
133 |
const sortDocuments = (documents: DocStatusResponse[]) => {
|
134 |
return [...documents].sort((a, b) => {
|
135 |
let valueA, valueB;
|
136 |
-
|
137 |
// Special handling for ID field based on showFileName setting
|
138 |
if (sortField === 'id' && showFileName) {
|
139 |
valueA = getDisplayFileName(a);
|
@@ -146,10 +146,10 @@ export default function DocumentManager() {
|
|
146 |
valueA = new Date(a[sortField]).getTime();
|
147 |
valueB = new Date(b[sortField]).getTime();
|
148 |
}
|
149 |
-
|
150 |
// Apply sort direction
|
151 |
const sortMultiplier = sortDirection === 'asc' ? 1 : -1;
|
152 |
-
|
153 |
// Compare values
|
154 |
if (typeof valueA === 'string' && typeof valueB === 'string') {
|
155 |
return sortMultiplier * valueA.localeCompare(valueB);
|
@@ -399,7 +399,7 @@ export default function DocumentManager() {
|
|
399 |
<Table className="w-full">
|
400 |
<TableHeader className="sticky top-0 bg-background z-10 shadow-sm">
|
401 |
<TableRow className="border-b bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/75 shadow-[inset_0_-1px_0_rgba(0,0,0,0.1)]">
|
402 |
-
<TableHead
|
403 |
onClick={() => handleSort('id')}
|
404 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
405 |
>
|
@@ -416,7 +416,7 @@ export default function DocumentManager() {
|
|
416 |
<TableHead>{t('documentPanel.documentManager.columns.status')}</TableHead>
|
417 |
<TableHead>{t('documentPanel.documentManager.columns.length')}</TableHead>
|
418 |
<TableHead>{t('documentPanel.documentManager.columns.chunks')}</TableHead>
|
419 |
-
<TableHead
|
420 |
onClick={() => handleSort('created_at')}
|
421 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
422 |
>
|
@@ -429,7 +429,7 @@ export default function DocumentManager() {
|
|
429 |
)}
|
430 |
</div>
|
431 |
</TableHead>
|
432 |
-
<TableHead
|
433 |
onClick={() => handleSort('updated_at')}
|
434 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
435 |
>
|
@@ -448,7 +448,7 @@ export default function DocumentManager() {
|
|
448 |
{Object.entries(docs.statuses).flatMap(([status, documents]) => {
|
449 |
// Apply sorting to documents
|
450 |
const sortedDocuments = sortDocuments(documents);
|
451 |
-
|
452 |
return sortedDocuments.map(doc => (
|
453 |
<TableRow key={doc.id}>
|
454 |
<TableCell className="truncate font-mono overflow-visible max-w-[250px]">
|
|
|
112 |
const currentTab = useSettingsStore.use.currentTab()
|
113 |
const showFileName = useSettingsStore.use.showFileName()
|
114 |
const setShowFileName = useSettingsStore.use.setShowFileName()
|
115 |
+
|
116 |
// Sort state
|
117 |
const [sortField, setSortField] = useState<SortField>('updated_at')
|
118 |
const [sortDirection, setSortDirection] = useState<SortDirection>('desc')
|
119 |
+
|
120 |
// Handle sort column click
|
121 |
const handleSort = (field: SortField) => {
|
122 |
if (sortField === field) {
|
|
|
128 |
setSortDirection('desc')
|
129 |
}
|
130 |
}
|
131 |
+
|
132 |
// Sort documents based on current sort field and direction
|
133 |
const sortDocuments = (documents: DocStatusResponse[]) => {
|
134 |
return [...documents].sort((a, b) => {
|
135 |
let valueA, valueB;
|
136 |
+
|
137 |
// Special handling for ID field based on showFileName setting
|
138 |
if (sortField === 'id' && showFileName) {
|
139 |
valueA = getDisplayFileName(a);
|
|
|
146 |
valueA = new Date(a[sortField]).getTime();
|
147 |
valueB = new Date(b[sortField]).getTime();
|
148 |
}
|
149 |
+
|
150 |
// Apply sort direction
|
151 |
const sortMultiplier = sortDirection === 'asc' ? 1 : -1;
|
152 |
+
|
153 |
// Compare values
|
154 |
if (typeof valueA === 'string' && typeof valueB === 'string') {
|
155 |
return sortMultiplier * valueA.localeCompare(valueB);
|
|
|
399 |
<Table className="w-full">
|
400 |
<TableHeader className="sticky top-0 bg-background z-10 shadow-sm">
|
401 |
<TableRow className="border-b bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/75 shadow-[inset_0_-1px_0_rgba(0,0,0,0.1)]">
|
402 |
+
<TableHead
|
403 |
onClick={() => handleSort('id')}
|
404 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
405 |
>
|
|
|
416 |
<TableHead>{t('documentPanel.documentManager.columns.status')}</TableHead>
|
417 |
<TableHead>{t('documentPanel.documentManager.columns.length')}</TableHead>
|
418 |
<TableHead>{t('documentPanel.documentManager.columns.chunks')}</TableHead>
|
419 |
+
<TableHead
|
420 |
onClick={() => handleSort('created_at')}
|
421 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
422 |
>
|
|
|
429 |
)}
|
430 |
</div>
|
431 |
</TableHead>
|
432 |
+
<TableHead
|
433 |
onClick={() => handleSort('updated_at')}
|
434 |
className="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 select-none"
|
435 |
>
|
|
|
448 |
{Object.entries(docs.statuses).flatMap(([status, documents]) => {
|
449 |
// Apply sorting to documents
|
450 |
const sortedDocuments = sortDocuments(documents);
|
451 |
+
|
452 |
return sortedDocuments.map(doc => (
|
453 |
<TableRow key={doc.id}>
|
454 |
<TableCell className="truncate font-mono overflow-visible max-w-[250px]">
|