Skip to content

Commit

Permalink
[wip]: add package search
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleyzissou committed Jan 31, 2025
1 parent ae7f87e commit 08a2a5b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
40 changes: 25 additions & 15 deletions src/Components/CreateImageWizard/steps/Packages/Packages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,31 @@ const Packages = () => {
return;
}
if (debouncedSearchTerm.length > 1 && isSuccessDistroRepositories) {
searchDistroRpms({
apiContentUnitSearchRequest: {
search: debouncedSearchTerm,
urls: distroRepositories
?.filter((archItem) => {
return archItem.arch === arch;
})[0]
.repositories.flatMap((repo) => {
if (!repo.baseurl) {
throw new Error(`Repository ${repo} missing baseurl`);
}
return repo.baseurl;
}),
},
});
if (process.env.IS_ON_PREMISE) {
searchDistroRpms({
apiContentUnitSearchRequest: {
packages: [debouncedSearchTerm],
architecture: arch,
distribution,
},
});
} else {
searchDistroRpms({
apiContentUnitSearchRequest: {
search: debouncedSearchTerm,
urls: distroRepositories
?.filter((archItem) => {
return archItem.arch === arch;
})[0]
.repositories.flatMap((repo) => {
if (!repo.baseurl) {
throw new Error(`Repository ${repo} missing baseurl`);
}
return repo.baseurl;
}),
},
});
}
}
if (debouncedSearchTerm.length > 2) {
if (
Expand Down
47 changes: 46 additions & 1 deletion src/store/cockpit/contentSourcesApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import { emptyCockpitApi } from './emptyCockpitApi';
import type { Package, SearchRpmApiArg } from './types';

import type {
ListSnapshotsByDateApiArg,
ListSnapshotsByDateApiResponse,
SearchRpmApiResponse,
} from '../service/contentSourcesApi';

export const contentSourcesApi = emptyCockpitApi.injectEndpoints({
endpoints: (builder) => ({
searchRpm: builder.mutation<SearchRpmApiResponse, SearchRpmApiArg>({
queryFn: async (queryArgs, _, __, baseQuery) => {
const { architecture, distribution, packages } =
queryArgs.apiContentUnitSearchRequest;

if (!architecture || !distribution || !packages) {
return { data: [] };
}

const body = {
packages,
distribution,
architecture,
};

const result = await baseQuery({
url: '/search/packages',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});

if (result?.error) {
return { error: result.error };
}

const resultPackages = result.data.packages?.map(
({ name, summary, version, release }: Package) => ({
package_name: name,
// TODO: maybe we should add columns to the
// package table for this?
summary: `${summary} (${version}.${release})`,
})
);

return {
data: resultPackages,
};
},
}),
// add an empty response for now
// just so we can step through the create
// image wizard for on prem
Expand All @@ -24,4 +68,5 @@ export const contentSourcesApi = emptyCockpitApi.injectEndpoints({
overrideExisting: false,
});

export const { useListSnapshotsByDateMutation } = contentSourcesApi;
export const { useSearchRpmMutation, useListSnapshotsByDateMutation } =
contentSourcesApi;
15 changes: 15 additions & 0 deletions src/store/cockpit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
export type Params = Record<string, any>;
export type Method = 'GET' | 'DELETE' | 'POST' | 'PUT' | 'PATCH'; // We can add more if we need
export type Headers = { [name: string]: string };

export type SearchRpmApiArg = {
apiContentUnitSearchRequest: {
architecture?: string | undefined;
distribution?: string | undefined;
packages?: string[] | undefined;
};
};

export type Package = {
name: string;
summary: string;
version: string;
release: string;
};
5 changes: 4 additions & 1 deletion src/store/contentSourcesApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as cockpitQueries from './cockpit/contentSourcesApi';
import * as serviceQueries from './service/contentSourcesApi';

export const useSearchRpmMutation = process.env.IS_ON_PREMISE
? cockpitQueries.useSearchRpmMutation
: serviceQueries.useSearchRpmMutation;

export const useListSnapshotsByDateMutation = process.env.IS_ON_PREMISE
? cockpitQueries.useListSnapshotsByDateMutation
: serviceQueries.useListSnapshotsByDateMutation;

export const {
useListFeaturesQuery,
useSearchRpmMutation,
useSearchPackageGroupMutation,
useListRepositoriesQuery,
useCreateRepositoryMutation,
Expand Down

0 comments on commit 08a2a5b

Please sign in to comment.