-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement option buttons configuration
The configuration of the 'Anyone' and 'Specified Users and Groups' option buttons should be implemented to match the following behavior: - When 'Anyone' option is selected and 'Save' button is clicked, 'usercategory' parameter should change to "all" and all users and user groups should be removed from the lists. - When 'Specified ...' option button is selected, the 'usercategory' should be changed to empty string (""). - At this point, the user can either save the changes or add new users / groups and save afterwards. Signed-off-by: Carla Martinez <[email protected]>
- Loading branch information
Showing
7 changed files
with
373 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,80 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { ToggleGroup, ToggleGroupItem } from "@patternfly/react-core"; | ||
// Utils | ||
import { | ||
IPAParamDefinition, | ||
getParamProperties, | ||
updateIpaObject, | ||
} from "src/utils/ipaObjectUtils"; | ||
|
||
/** | ||
* This component provides functionality to handle a set of two toggle | ||
* groups with idempotent logic (i.e., when one option is selected, the other | ||
* is deselected). | ||
*/ | ||
|
||
interface ToggleOptions { | ||
label: string; | ||
value: string; | ||
} | ||
|
||
interface ToggleOptionProps extends IPAParamDefinition { | ||
options: ToggleOptions[]; | ||
optionSelected: string; | ||
setOptionSelected: (value: string) => void; | ||
className?: string; | ||
isCompact?: boolean | false; | ||
} | ||
|
||
const IpaToggleGroup = (props: ToggleOptionProps) => { | ||
const { value, required, readOnly } = getParamProperties(props); | ||
|
||
React.useEffect(() => { | ||
for (const option of props.options) { | ||
if (option.value === value) { | ||
props.setOptionSelected(option.label); | ||
return; | ||
} | ||
} | ||
}, [props.ipaObject]); | ||
|
||
const handleItemClick = (event) => { | ||
const id = event.currentTarget.id; | ||
let newValue = value; | ||
|
||
if (props.optionSelected === id) { | ||
// No change | ||
return; | ||
} | ||
|
||
if (props.ipaObject !== undefined && props.onChange !== undefined) { | ||
for (const option of props.options) { | ||
if (option.label === id) { | ||
newValue = option.value; | ||
break; | ||
} | ||
} | ||
props.setOptionSelected(id); | ||
updateIpaObject(props.ipaObject, props.onChange, newValue, props.name); | ||
} | ||
}; | ||
|
||
return ( | ||
<ToggleGroup isCompact={props.isCompact} className={props.className}> | ||
{props.options.map((option) => ( | ||
<ToggleGroupItem | ||
key={option.label} | ||
text={option.label} | ||
buttonId={option.label} | ||
isSelected={props.optionSelected === option.label} | ||
onChange={handleItemClick} | ||
isDisabled={readOnly || false} | ||
required={required || false} | ||
/> | ||
))} | ||
</ToggleGroup> | ||
); | ||
}; | ||
|
||
export default IpaToggleGroup; |
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.