forked from kubevirt-ui/kubevirt-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt-ui#2059 from pcbailey/bug-fix-project-sel…
…ect-in-add-volume-modal CNV-43176: Allow user to select namespace in Add volume modal
- Loading branch information
Showing
16 changed files
with
143 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.project-dropdown { | ||
width: 220px; | ||
padding: 0 var(--pf-global--spacer--sm); | ||
margin-bottom: var(--pf-global--spacer--md); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { modelToGroupVersionKind, ProjectModel } from '@kubevirt-ui/kubevirt-api/console'; | ||
import InlineFilterSelect from '@kubevirt-utils/components/FilterSelect/InlineFilterSelect'; | ||
import { getProjectOptions } from '@kubevirt-utils/components/ProjectDropdown/utils/utils'; | ||
import { ALL_PROJECTS } from '@kubevirt-utils/hooks/constants'; | ||
import { K8sResourceCommon, useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
type ProjectDropdownProps = { | ||
includeAllProjects?: boolean; | ||
onChange: (project: string) => void; | ||
selectedProject: string; | ||
}; | ||
|
||
const ProjectDropdown: FC<ProjectDropdownProps> = ({ | ||
includeAllProjects = true, | ||
onChange, | ||
selectedProject, | ||
}) => { | ||
const [projects] = useK8sWatchResource<K8sResourceCommon[]>({ | ||
groupVersionKind: modelToGroupVersionKind(ProjectModel), | ||
isList: true, | ||
namespaced: false, | ||
}); | ||
|
||
const onSelect = (value: string) => { | ||
onChange(value === ALL_PROJECTS ? '' : value); | ||
}; | ||
|
||
return ( | ||
<div className="project-dropdown"> | ||
<InlineFilterSelect | ||
options={getProjectOptions(includeAllProjects, projects)} | ||
selected={selectedProject || ALL_PROJECTS} | ||
setSelected={onSelect} | ||
toggleProps={{ isFullWidth: true }} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProjectDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { modelToGroupVersionKind, ProjectModel } from '@kubevirt-ui/kubevirt-api/console'; | ||
import { ALL_PROJECTS } from '@kubevirt-utils/hooks/constants'; | ||
import { getName } from '@kubevirt-utils/resources/shared'; | ||
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
export const getProjectOptions = (includeAllProjects: boolean, projects: K8sResourceCommon[]) => { | ||
const projectOptions = projects | ||
.sort((a, b) => getName(a).localeCompare(getName(b))) | ||
.map((proj) => { | ||
const name = getName(proj); | ||
return { | ||
children: name, | ||
groupVersionKind: modelToGroupVersionKind(ProjectModel), | ||
value: name, | ||
}; | ||
}); | ||
|
||
const allProjects = includeAllProjects | ||
? [ | ||
{ | ||
children: ALL_PROJECTS, | ||
groupVersionKind: modelToGroupVersionKind(ProjectModel), | ||
value: ALL_PROJECTS, | ||
}, | ||
].concat(projectOptions) | ||
: projectOptions; | ||
|
||
return allProjects; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const ALL_NAMESPACES_SESSION_KEY = '#ALL_NS#'; | ||
export const ALL_NAMESPACES = 'all-namespaces'; | ||
export const ALL_PROJECTS = 'All projects'; | ||
|
||
export const EVENT_LOCALSTORAGE = 'event_localstorage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.