diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/create/components/ProjectNameSelect.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/create/components/ProjectNameSelect.tsx index abd50ab4b..e01ef68de 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/create/components/ProjectNameSelect.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/create/components/ProjectNameSelect.tsx @@ -2,6 +2,11 @@ import React from 'react'; import { useForkliftTranslation } from 'src/utils'; import { FormGroupWithHelpText, TypeaheadSelect, TypeaheadSelectOption } from '@kubev2v/common'; +import { + K8sResourceKind, + useFlag, + useK8sWatchResource, +} from '@openshift-console/dynamic-plugin-sdk'; import { Popover } from '@patternfly/react-core'; import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; @@ -46,3 +51,20 @@ export const ProjectNameSelect: React.FC = ({ ); }; + +export const projectNameSelectOptions = (defaultProject: string): TypeaheadSelectOption[] => { + const isUseProjects = useFlag('OPENSHIFT'); // OCP or Kind installations + + const [projects, projectsLoaded, projectsLoadError] = useK8sWatchResource({ + kind: isUseProjects ? 'Project' : 'Namespace', + isList: true, + }); + + return !projects || !projectsLoaded || projectsLoadError + ? // In case of an error or an empty list, returns the active namespace + [{ value: defaultProject, content: defaultProject }] + : projects.map((project) => ({ + value: project.metadata?.name, + content: project.metadata?.name, + })); +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx index d572fe78e..8aa9f1f1c 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx @@ -44,7 +44,7 @@ export const ProvidersCreatePage: React.FC<{ const [activeNamespace, setActiveNamespace] = useActiveNamespace(); const [providerNames] = useK8sWatchProviderNames({ namespace }); const defaultNamespace = process?.env?.DEFAULT_NAMESPACE || 'default'; - const projectName = activeNamespace === '#ALL_NS#' ? 'openshift-mtv' : activeNamespace; + const projectName = activeNamespace === '#ALL_NS#' ? defaultNamespace : activeNamespace; const initialNamespace = namespace || projectName || defaultNamespace; const initialState: ProvidersCreatePageState = { diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/ProviderCreateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/ProviderCreateForm.tsx index af5ce9fa5..7a496b3c1 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/ProviderCreateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/ProviderCreateForm.tsx @@ -1,6 +1,9 @@ import React, { useReducer } from 'react'; import { Base64 } from 'js-base64'; -import { ProjectNameSelect } from 'src/modules/Plans/views/create/components/ProjectNameSelect'; +import { + ProjectNameSelect, + projectNameSelectOptions, +} from 'src/modules/Plans/views/create/components/ProjectNameSelect'; import { ModalHOC } from 'src/modules/Providers/modals'; import { validateK8sName, ValidationMsg } from 'src/modules/Providers/utils'; import { SelectableCard } from 'src/modules/Providers/utils/components/Gallery/SelectableCard'; @@ -8,13 +11,7 @@ import { SelectableGallery } from 'src/modules/Providers/utils/components/Galler import { ForkliftTrans, useForkliftTranslation } from 'src/utils/i18n'; import { FormGroupWithHelpText } from '@kubev2v/common'; -import { - IoK8sApiCoreV1Secret, - K8sResourceCommon, - ProviderType, - V1beta1Provider, -} from '@kubev2v/types'; -import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; +import { IoK8sApiCoreV1Secret, ProviderType, V1beta1Provider } from '@kubev2v/types'; import { Flex, FlexItem, @@ -50,14 +47,7 @@ export const ProvidersCreateForm: React.FC = ({ }) => { const { t } = useForkliftTranslation(); - const [projects, projectsLoaded] = useK8sWatchResource({ - groupVersionKind: { - version: 'v1', - group: 'project.openshift.io', - kind: 'Project', - }, - isList: true, - }); + const projects = projectNameSelectOptions(projectName); const initialState = { validation: { @@ -126,11 +116,7 @@ export const ProvidersCreateForm: React.FC = ({
({ - value: project.metadata?.name, - content: project.metadata?.name, - }))} - isDisabled={!projectsLoaded || !projects.length} + options={projects} onSelect={onProjectNameChange} popoverHelpContent={ The project that your provider will be created in.