Skip to content

Commit eb211b8

Browse files
committed
fix filters in listing pages
1 parent 457d804 commit eb211b8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/[locale]/(user)/components/ListingComponent.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use client'
22

3-
import React, { useEffect, useReducer, useRef, useState } from 'react';
3+
import GraphqlPagination from '@/app/[locale]/dashboard/components/GraphqlPagination/graphqlPagination';
44
import Image from 'next/image';
55
import { useRouter } from 'next/navigation';
6-
import GraphqlPagination from '@/app/[locale]/dashboard/components/GraphqlPagination/graphqlPagination';
76
import {
87
Button,
98
ButtonGroup,
@@ -15,14 +14,15 @@ import {
1514
Text,
1615
Tray,
1716
} from 'opub-ui';
17+
import React, { useEffect, useReducer, useRef, useState } from 'react';
1818

19-
import { cn, formatDate } from '@/lib/utils';
2019
import BreadCrumbs from '@/components/BreadCrumbs';
2120
import { Icons } from '@/components/icons';
2221
import { Loading } from '@/components/loading';
22+
import { fetchData } from '@/fetch';
23+
import { cn, formatDate } from '@/lib/utils';
2324
import Filter from '../datasets/components/FIlter/Filter';
2425
import Styles from '../datasets/dataset.module.scss';
25-
import { fetchData } from '@/fetch';
2626

2727
// Interfaces
2828
interface Bucket {
@@ -281,12 +281,19 @@ const ListingComponent: React.FC<ListingProps> = ({
281281

282282
const filterOptions = Object.entries(aggregations).reduce(
283283
(acc: Record<string, { label: string; value: string }[]>, [key, value]) => {
284-
// Check if value exists and has buckets array
284+
// Check if value exists and has buckets array (Elasticsearch format)
285285
if (value && value.buckets && Array.isArray(value.buckets)) {
286286
acc[key] = value.buckets.map((bucket) => ({
287287
label: bucket.key,
288288
value: bucket.key,
289289
}));
290+
}
291+
// Handle key-value object format (current backend format)
292+
else if (value && typeof value === 'object' && !Array.isArray(value)) {
293+
acc[key] = Object.entries(value).map(([label, count]) => ({
294+
label: label,
295+
value: label,
296+
}));
290297
}
291298
return acc;
292299
},

0 commit comments

Comments
 (0)