Skip to content

Commit

Permalink
fix marketplace categories
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaleks committed Feb 9, 2024
1 parent c15859e commit fd11d55
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ui/marketplace/useMarketplaceCategories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useQuery } from '@tanstack/react-query';
import _groudBy from 'lodash/groupBy';
import React from 'react';

import type { MarketplaceAppOverview } from 'types/client/marketplace';
Expand Down Expand Up @@ -31,7 +30,16 @@ export default function useMarketplaceCategories(apps: Array<MarketplaceAppOverv
}

let categoryNames: Array<string> = [];
const grouped = _groudBy(apps, app => app.categories);
const grouped: { [key: string]: number } = {};

apps?.forEach(app => {
app.categories.forEach(category => {
if (grouped[category] === undefined) {
grouped[category] = 0;
}
grouped[category]++;
});
});

if (data?.length && !isPlaceholderData && isExperiment) {
categoryNames = data;
Expand All @@ -40,7 +48,7 @@ export default function useMarketplaceCategories(apps: Array<MarketplaceAppOverv
}

return categoryNames
.map(category => ({ name: category, count: grouped[category]?.length || 0 }))
.map(category => ({ name: category, count: grouped[category] || 0 }))
.filter(c => c.count > 0);
}, [ apps, isAppsPlaceholderData, data, isPlaceholderData, isExperiment ]);

Expand Down

0 comments on commit fd11d55

Please sign in to comment.