Skip to content

Commit

Permalink
Wizard: Update description fetching for recommended packages
Browse files Browse the repository at this point in the history
This update the way recommended packages' descriptions are fetched.

contentSources API was updated to accept an array of packages as a searchRpm argument, meaning we can now send a request to fetch all package descriptions at once.
  • Loading branch information
regexowl authored and lucasgarfield committed Nov 20, 2024
1 parent ad784b9 commit 54f482b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import { useDispatch } from 'react-redux';

import PackageRecommendationDescription from './components/PackageRecommendationDescription';
import { RedHatRepository } from './Packages';

import { AMPLITUDE_MODULE_NAME, ContentOrigin } from '../../../../constants';
import { useListRepositoriesQuery } from '../../../../store/contentSourcesApi';
import {
useListRepositoriesQuery,
useSearchRpmMutation,
} from '../../../../store/contentSourcesApi';
import { useAppSelector } from '../../../../store/hooks';
import { useRecommendPackageMutation } from '../../../../store/imageBuilderApi';
import {
Expand Down Expand Up @@ -67,6 +69,15 @@ const PackageRecommendations = () => {
const [fetchRecommendedPackages, { data, isSuccess, isLoading, isError }] =
useRecommendPackageMutation();

const [
fetchRecommendationDescriptions,
{
data: dataDescriptions,
isSuccess: isSuccessDescriptions,
isLoading: isLoadingDescriptions,
},
] = useSearchRpmMutation();

useEffect(() => {
if (isExpanded && packages.length > 0) {
(async () => {
Expand All @@ -92,6 +103,17 @@ const PackageRecommendations = () => {
}
}, [fetchRecommendedPackages, packages, isExpanded]);

Check warning on line 104 in src/Components/CreateImageWizard/steps/Packages/PackageRecommendations.tsx

View workflow job for this annotation

GitHub Actions / dev-check

React Hook useEffect has missing dependencies: 'analytics' and 'isBeta'. Either include them or remove the dependency array

useEffect(() => {
if (isSuccess && data.packages.length > 0) {
fetchRecommendationDescriptions({
apiContentUnitSearchRequest: {
exact_names: data?.packages,
urls: distroRepoUrls,
},
});
}
}, [fetchRecommendationDescriptions, isSuccess, data?.packages]);

Check warning on line 115 in src/Components/CreateImageWizard/steps/Packages/PackageRecommendations.tsx

View workflow job for this annotation

GitHub Actions / dev-check

React Hook useEffect has a missing dependency: 'distroRepoUrls'. Either include it or remove the dependency array

const addAllPackages = () => {
if (data?.packages?.length) {
data.packages.forEach((pkg) =>
Expand Down Expand Up @@ -213,14 +235,18 @@ const PackageRecommendations = () => {
{data.packages.map((pkg) => (
<Tr key={pkg}>
<Td>{pkg}</Td>
<Td>
{distroRepoUrls && (
<PackageRecommendationDescription
pkg={pkg}
urls={distroRepoUrls}
/>
)}
</Td>
{isLoadingDescriptions && (
<Td>
<Spinner size="md" />
</Td>
)}
{isSuccessDescriptions && (
<Td>
{dataDescriptions
.filter((p) => p.package_name === pkg)
.map((p) => p.summary)}
</Td>
)}
<Td>
<RedHatRepository />
</Td>
Expand Down

This file was deleted.

0 comments on commit 54f482b

Please sign in to comment.