-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The functionality for the group of checkboxes needs to be implemented and applied to the following field: 'User authentication types' (`ipauserauthtype`). Signed-off-by: Carla Martinez <carlmart@redhat.com>
- Loading branch information
Showing
3 changed files
with
191 additions
and
60 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,78 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { Checkbox } from "@patternfly/react-core"; | ||
// Utils | ||
import { | ||
IPAParamDefinitionCheckboxes, | ||
getParamPropertiesCheckBoxes, | ||
updateIpaObject, | ||
} from "src/utils/ipaObjectUtils"; | ||
|
||
export interface CheckboxOption { | ||
value: string; | ||
text: string; | ||
className?: string; | ||
} | ||
|
||
const IpaCheckboxes = (props: IPAParamDefinitionCheckboxes) => { | ||
const { required, readOnly, checkedValues } = | ||
getParamPropertiesCheckBoxes(props); | ||
|
||
const [checkedList, setCheckedList] = React.useState(checkedValues); | ||
|
||
// Updates the 'checkedList' when 'checkedValues' changes | ||
React.useEffect(() => { | ||
setCheckedList(checkedValues); | ||
}, [checkedValues]); | ||
|
||
// Updates the list of checked values when a specific checkbox is clicked | ||
// - This is implemented here because we need to know which specific | ||
// value (option.value) to add/remove from the list | ||
const updateList = (checked: boolean, elementToChange: string) => { | ||
if ( | ||
props.ipaObject !== undefined && | ||
props.ipaObject[props.name] !== undefined && | ||
props.onChange !== undefined | ||
) { | ||
const updatedList = [...(props.ipaObject[props.name] as string[])]; | ||
if (checked) { | ||
updatedList.push(elementToChange); | ||
} else { | ||
const index = updatedList.indexOf(elementToChange); | ||
if (index > -1) { | ||
updatedList.splice(index, 1); | ||
} | ||
} | ||
// Update the list of checked values | ||
setCheckedList(updatedList); | ||
// Update the IPA object | ||
updateIpaObject(props.ipaObject, props.onChange, updatedList, props.name); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{props.options.map((option) => ( | ||
<Checkbox | ||
key={props.name + "-" + option.value} | ||
id={props.name + "-" + option.value} // Mandatory | ||
name={props.name} | ||
label={option.text} | ||
onChange={(checked) => updateList(checked, option.value)} | ||
isRequired={required} | ||
readOnly={readOnly} | ||
isChecked={ | ||
checkedList.find((val) => val === option.value) !== undefined | ||
? true | ||
: false | ||
} | ||
aria-label={props.name} | ||
className={option.className} | ||
isDisabled={readOnly} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default IpaCheckboxes; |
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