Wizard: Update the Repositories step
This updates the Repositories and Review step as per [mocks](https://www.sketch.com/s/d7aa6d29-fca0-4283-a846-09cc5fd10612/a/MyEbDz7). Repositories with the unavailable or invalid status have a popover that allows for further inspection. The time of the last introspection and the counter of failed attempts was added to the popover, together with the "Go to Repositories" button. On Recreate the payload repositories are checked against "freshly" fetched list of repositories. In case any of the previously checked repositories is no longer available in content sources an Alert is rendered on both Repositories and Review steps. The unavailable repository is checked, but the checkbox is disabled and the information is dashed out. Since the information about the repository is stored in the Repository type, the only information available to be rendered is the baseurl. Create image button is also disabled when recreating an image with unavailable repositories.
This commit is contained in:
parent
0822a69619
commit
9f5a0af826
12 changed files with 748 additions and 138 deletions
69
src/Utilities/checkRepositoriesAvailability.js
Normal file
69
src/Utilities/checkRepositoriesAvailability.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import { useMemo } from 'react';
|
||||
|
||||
import { useFormApi } from '@data-driven-forms/react-form-renderer';
|
||||
|
||||
import { releaseToVersion } from './releaseToVersion';
|
||||
|
||||
import { useListRepositoriesQuery } from '../store/contentSourcesApi';
|
||||
|
||||
/**
|
||||
* This checks the list of the payload repositories against a list of repos freshly
|
||||
* fetched from content source API and returns true whether there are some
|
||||
* repositories that are no longer available in the Repositories service.
|
||||
*
|
||||
* (The payload repositories are comming from the useFormApi hook).
|
||||
*/
|
||||
export const useCheckRepositoriesAvailability = () => {
|
||||
const { getState } = useFormApi();
|
||||
|
||||
const release = getState().values?.release;
|
||||
const version = releaseToVersion(release);
|
||||
|
||||
// There needs to be two requests because the default limit for the
|
||||
// useListRepositoriesQuery is a 100 elements, and a first request is
|
||||
// necessary to know the total amount of elements to fetch.
|
||||
const firstRequest = useListRepositoriesQuery({
|
||||
availableForArch: 'x86_64',
|
||||
availableForVersion: version,
|
||||
});
|
||||
|
||||
const skip =
|
||||
firstRequest?.data?.meta?.count === undefined ||
|
||||
firstRequest?.data?.meta?.count <= 100;
|
||||
|
||||
// Fetch *all* repositories if there are more than 100
|
||||
const followupRequest = useListRepositoriesQuery(
|
||||
{
|
||||
availableForArch: 'x86_64',
|
||||
availableForVersion: version,
|
||||
limit: firstRequest?.data?.meta?.count,
|
||||
offset: 0,
|
||||
},
|
||||
{
|
||||
skip: skip,
|
||||
}
|
||||
);
|
||||
|
||||
const { data: freshRepos, isSuccess } = useMemo(() => {
|
||||
if (firstRequest?.data?.meta?.count > 100) {
|
||||
return { ...followupRequest };
|
||||
}
|
||||
return { ...firstRequest };
|
||||
}, [firstRequest, followupRequest]);
|
||||
|
||||
const payloadRepositories = getState()?.values?.['payload-repositories'];
|
||||
// payloadRepositories existing === we came here from Recreate
|
||||
if (isSuccess && payloadRepositories) {
|
||||
// Transform the fresh repos array into a Set to access its elements in O(1)
|
||||
// complexity later in the for loop.
|
||||
const freshReposUrls = new Set(
|
||||
freshRepos.data.map((freshRepo) => freshRepo.url)
|
||||
);
|
||||
for (const payloadRepo of payloadRepositories) {
|
||||
if (!freshReposUrls.has(payloadRepo.baseurl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue