import React from 'react'; import { useFormApi } from '@data-driven-forms/react-form-renderer'; import { Alert, Panel, PanelMain, Spinner } from '@patternfly/react-core'; import { TableComposable, Tbody, Td, Th, Thead, Tr, } from '@patternfly/react-table'; import PropTypes from 'prop-types'; import { UNIT_GIB, UNIT_MIB } from '../../../constants'; import { useListRepositoriesQuery } from '../../../store/contentSourcesApi'; const RepoName = ({ repoUrl }) => { const { data, isSuccess, isFetching, isError } = useListRepositoriesQuery({ url: repoUrl, }); const errorLoading = () => { return ( ); }; return ( <> {/* this might be a tad bit hacky "isSuccess" indicates only that the query fetched successfuly, but it doesn't differentiate between a scenario when the repository was found in the response and when it was not for this reason I've split the "isSuccess" into two paths: - query finished and the repo was found -> render the name of the repo - query finished, but the repo was not found -> render an error */} {isSuccess && data.data?.[0]?.name &&

{data.data?.[0].name}

} {isSuccess && !data.data?.[0]?.name && errorLoading()} {isFetching && } {isError && errorLoading()} ); }; export const FSReviewTable = () => { const { getState } = useFormApi(); const fsc = getState().values['file-system-configuration']; return ( Mount point File system type Minimum size {fsc.map((partition, partitionIndex) => ( {partition.mountpoint} xfs {partition.size}{' '} {partition.unit === UNIT_GIB ? 'GiB' : partition.unit === UNIT_MIB ? 'MiB' : 'KiB'} ))} ); }; export const PackagesTable = () => { const { getState } = useFormApi(); const packages = getState()?.values['selected-packages']; return ( Name {packages.map((pkg, pkgIndex) => ( {pkg.name} ))} ); }; export const RepositoriesTable = () => { const { getState } = useFormApi(); const repositories = getState()?.values?.['payload-repositories']; return ( Name {repositories.map((repo, repoIndex) => ( ))} ); }; RepoName.propTypes = { repoUrl: PropTypes.string, };