Skip to content

Commit

Permalink
frontend: Adds filter feature for app catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent T <[email protected]>
  • Loading branch information
vyncent-t committed Aug 26, 2024
1 parent 24382c9 commit e7fb884
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 173 deletions.
2 changes: 2 additions & 0 deletions app-catalog/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/.pnp
.pnp.js

/dist

# testing
/coverage

Expand Down
33 changes: 21 additions & 12 deletions app-catalog/src/api/charts.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { PAGE_OFFSET_COUNT_FOR_CHARTS } from '../components/charts/List';

export function fetchChartsFromArtifact(
export async function fetchChartsFromArtifact(
search: string = '',
verified: boolean,
category: { title: string; value: number },
page: number,
limit: number = PAGE_OFFSET_COUNT_FOR_CHARTS
) {
if (!category || category.value === 0) {
return fetch(
`https://artifacthub.io/api/v1/packages/search?kind=0&ts_query_web=${search}&sort=relevance&facets=true&limit=${limit}&offset=${
(page - 1) * limit
}`
).then(response => response.json());
// note: we are currently defaulting to search by verified and official as default
const url = new URL('https://artifacthub.io/api/v1/packages/search');
url.searchParams.set('offset', ((page - 1) * limit).toString());
url.searchParams.set('limit', limit.toString());
url.searchParams.set('facets', 'true');
url.searchParams.set('kind', '0');
url.searchParams.set('ts_query_web', search);
if (category.value) {
url.searchParams.set('category', category.value.toString());
}
return fetch(
`https://artifacthub.io/api/v1/packages/search?kind=0&ts_query_web=${search}&category=${
category.value
}&sort=relevance&facets=true&limit=${limit}&offset=${(page - 1) * limit}`
).then(response => response.json());
url.searchParams.set('sort', 'relevance');
url.searchParams.set('deprecated', 'false');
url.searchParams.set('verified_publisher', verified.toString());

const response = await fetch(url.toString());
const total = response.headers.get('pagination-total-count');

const dataResponse = await response.json();

return { dataResponse, total };
}

export function fetchChartDetailFromArtifact(chartName: string, repoName: string) {
Expand Down
Loading

0 comments on commit e7fb884

Please sign in to comment.