-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Select[1] components need to be adapted to take data from the metadata. This will be applied for the fields 'Radius proxy configuration' and 'External IdP configuration'. [1]- http://v4-archive.patternfly.org/v4/components/select Signed-off-by: Carla Martinez <[email protected]>
- Loading branch information
Showing
11 changed files
with
244 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { | ||
Select, | ||
SelectOption, | ||
SelectOptionObject, | ||
SelectVariant, | ||
} from "@patternfly/react-core"; | ||
// Utils | ||
import { | ||
IPAParamDefinition, | ||
getParamProperties, | ||
} from "src/utils/ipaObjectUtils"; | ||
import { updateIpaObject } from "src/utils/userUtils"; | ||
import { NO_SELECTION_OPTION } from "src/utils/constUtils"; | ||
|
||
interface IPAParamDefinitionSelect extends IPAParamDefinition { | ||
id?: string; | ||
value?: string; | ||
setIpaObject?: (ipaObject: Record<string, unknown>) => void; | ||
variant?: "single" | "checkbox" | "typeahead" | "typeaheadmulti"; | ||
options: string[]; | ||
selections?: string | SelectOptionObject | (string | SelectOptionObject)[]; | ||
ariaLabelledBy?: string; | ||
} | ||
|
||
const IpaSelect = (props: IPAParamDefinitionSelect) => { | ||
// Obtains the metadata of the parameter | ||
const { required, readOnly, value } = getParamProperties(props); | ||
|
||
// Handle selected value | ||
let valueSelected = NO_SELECTION_OPTION; | ||
if (value !== undefined && value && value !== "") { | ||
valueSelected = value.toString(); | ||
} | ||
|
||
const ipaObject = props.ipaObject || {}; | ||
|
||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const onSelect = (selection: any) => { | ||
let valueToUpdate = ""; | ||
|
||
if (selection.target.textContent !== NO_SELECTION_OPTION) { | ||
valueToUpdate = selection.target.textContent as string; | ||
} | ||
|
||
if (ipaObject && props.setIpaObject !== undefined) { | ||
updateIpaObject(ipaObject, props.setIpaObject, valueToUpdate, props.name); | ||
} | ||
|
||
setIsOpen(false); | ||
}; | ||
|
||
// Provide empty option at the beginning of the list | ||
const optionsToSelect: string[] = props.options; | ||
React.useEffect(() => { | ||
const optionsToSelect: string[] = props.options; | ||
if (optionsToSelect.length > 0) { | ||
optionsToSelect.unshift(NO_SELECTION_OPTION); | ||
} | ||
}, [props.options]); | ||
// const optionsToSelect: string[] = props.elementsOptions || []; | ||
// console.log("optionsToSelect: ", optionsToSelect); | ||
// optionsToSelect.unshift(NO_SELECTION_OPTION); | ||
// console.log("---------------"); | ||
|
||
return ( | ||
<Select | ||
id={props.id} | ||
name={props.name} | ||
variant={props.variant || SelectVariant.single} | ||
aria-label={props.name} | ||
onToggle={setIsOpen} | ||
onSelect={onSelect} | ||
selections={valueSelected} | ||
isOpen={isOpen} | ||
aria-labelledby={props.ariaLabelledBy || props.id} | ||
readOnly={readOnly} | ||
isDisabled={readOnly} | ||
required={required} | ||
> | ||
{optionsToSelect.map((option, index) => { | ||
return <SelectOption key={index} value={option} />; | ||
})} | ||
</Select> | ||
); | ||
}; | ||
|
||
export default IpaSelect; |
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
Oops, something went wrong.