Skip to content

Commit

Permalink
Catalog View Sorted by Statues
Browse files Browse the repository at this point in the history
  • Loading branch information
mavenzer committed Sep 15, 2024
1 parent 545306e commit a250e5e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions odd-platform-ui/src/components/Search/Results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ const Results: React.FC = () => {
return S.gridSizes[key];
}, [searchClass, searchTotals]);

// Define the desired status order[As described in the github ISSue]
const statusOrder = ['STABLE', 'DEPRECATED', 'DRAFT', 'UNASSIGNED', 'DELETED'];

// Sort search results by status
const sortedSearchResults = React.useMemo(() => {
return [...searchResults].sort((a, b) => {
const statusA = a.status?.status ?? 'UNASSIGNED'; // Default to 'UNASSIGNED' if undefined
const statusB = b.status?.status ?? 'UNASSIGNED';

const indexA = statusOrder.indexOf(statusA);
const indexB = statusOrder.indexOf(statusB);


const orderA = indexA !== -1 ? indexA : statusOrder.length;
const orderB = indexB !== -1 ? indexB : statusOrder.length;

return orderA - orderB;
});
}, [searchResults]);

return (
<Grid sx={{ mt: 2 }}>
<SearchResultsTabs
Expand Down Expand Up @@ -141,14 +161,14 @@ const Results: React.FC = () => {
{!isSearchCreatingAndFetching && !isSearchResultsNotLoaded && (
<S.ListContainer id='results-list'>
<InfiniteScroll
dataLength={searchResults.length}
dataLength={sortedSearchResults.length}
next={fetchNextPage}
hasMore={hasNext}
loader={isSearchFetching && <SearchResultsSkeleton grid={grid} />}
scrollThreshold='200px'
scrollableTarget='results-list'
>
{searchResults.map(searchResult => (
{sortedSearchResults.map(searchResult => (
<ResultItem
key={searchResult.id}
searchResult={searchResult}
Expand All @@ -160,7 +180,7 @@ const Results: React.FC = () => {
</InfiniteScroll>
<EmptyContentPlaceholder
isContentLoaded={!isSearchFetching}
isContentEmpty={!searchResults.length}
isContentEmpty={!sortedSearchResults.length}
text={t('No matches found')}
/>
</S.ListContainer>
Expand Down

0 comments on commit a250e5e

Please sign in to comment.