From 0ac68864f49c8d624f7e2b6097efe4f276b997e2 Mon Sep 17 00:00:00 2001 From: regexowl Date: Wed, 19 Jun 2024 09:32:49 +0200 Subject: [PATCH] Wizard: Cleanup after removing V1 This removes files that are no longer needed and uninstalls DDF dependencies. --- package.json | 3 - .../checkRepositoriesAvailability.ts | 76 ------------------- src/api.js | 45 ----------- 3 files changed, 124 deletions(-) delete mode 100644 src/Utilities/checkRepositoriesAvailability.ts delete mode 100644 src/api.js diff --git a/package.json b/package.json index 5122e07b..17f1b2db 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,6 @@ "npm": ">=7.0.0" }, "dependencies": { - "@data-driven-forms/pf4-component-mapper": "3.22.4", - "@data-driven-forms/react-form-renderer": "3.22.4", "@patternfly/patternfly": "5.3.1", "@patternfly/react-core": "5.3.3", "@patternfly/react-code-editor": "5.3.3", @@ -104,7 +102,6 @@ "msw": "1.2.3", "npm-run-all": "4.1.5", "postcss-scss": "4.0.9", - "prop-types": "15.8.1", "react-chartjs-2": "5.2.0", "redux-mock-store": "1.5.4", "sass": "1.77.6", diff --git a/src/Utilities/checkRepositoriesAvailability.ts b/src/Utilities/checkRepositoriesAvailability.ts deleted file mode 100644 index 0365875c..00000000 --- a/src/Utilities/checkRepositoriesAvailability.ts +++ /dev/null @@ -1,76 +0,0 @@ -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 arch = getState().values?.arch; - 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: arch, - availableForVersion: version, - contentType: 'rpm', - origin: 'external', - }); - - 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: arch, - availableForVersion: version, - contentType: 'rpm', - origin: 'external', - limit: firstRequest?.data?.meta?.count, - offset: 0, - }, - { - skip: skip, - } - ); - - const { data: freshRepos, isSuccess } = useMemo(() => { - if (firstRequest?.data?.meta?.count) { - 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; -}; diff --git a/src/api.js b/src/api.js deleted file mode 100644 index 14dd6096..00000000 --- a/src/api.js +++ /dev/null @@ -1,45 +0,0 @@ -import axios from 'axios'; - -import { CONTENT_SOURCES_API, IMAGE_BUILDER_API } from './constants'; - -const postHeaders = { headers: { 'Content-Type': 'application/json' } }; - -async function getPackages(distribution, architecture, search, limit) { - const params = new URLSearchParams({ - distribution, - architecture, - search, - }); - limit && params.append('limit', limit); - const path = '/packages?' + params.toString(); - const request = await axios.get(IMAGE_BUILDER_API.concat(path)); - return request.data; -} - -async function getPackagesContentSources(repoUrls, search) { - // content-sources expects an array of urls but we store the whole repo object - // so map the urls into an array to send to the content-sources api - const body = { - urls: repoUrls, - search, - }; - const path = '/rpms/names'; - const request = await axios.post( - CONTENT_SOURCES_API.concat(path), - body, - postHeaders - ); - // map `package_name` key to just `name` since that's what we use across the UI - const packages = request.data.map(({ package_name: name, ...rest }) => ({ - name, - ...rest, - })); - return packages; -} - -const apiCalls = { - getPackages, - getPackagesContentSources, -}; - -export default apiCalls;