-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add language options from providers & select by app tags
Move to simple multi select menu in set targets step Drive target selection options from targets list Add kind support for tasks Address missing checkbox on deselect Add provider to target card header Signed-off-by: Ian Bolton <[email protected]>
- Loading branch information
1 parent
460fded
commit 9a17217
Showing
9 changed files
with
226 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React from "react"; | ||
import { | ||
Select, | ||
SelectOption, | ||
SelectList, | ||
MenuToggle, | ||
Badge, | ||
SelectOptionProps, | ||
MenuToggleElement, | ||
} from "@patternfly/react-core"; | ||
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing"; | ||
|
||
export interface ISimpleSelectBasicProps { | ||
onChange: (selection: string | string[]) => void; | ||
options: SelectOptionProps[]; | ||
value?: string[]; | ||
placeholderText?: string; | ||
id?: string; | ||
toggleId?: string; | ||
toggleAriaLabel?: string; | ||
selectMultiple?: boolean; | ||
width?: number; | ||
noResultsFoundText?: string; | ||
hideClearButton?: false; | ||
} | ||
|
||
export const SimpleSelectCheckbox: React.FC<ISimpleSelectBasicProps> = ({ | ||
onChange, | ||
options, | ||
value, | ||
placeholderText = "Select...", | ||
id, | ||
toggleId, | ||
toggleAriaLabel, | ||
width, | ||
}) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [selectedItems, setSelectedItems] = React.useState<string[]>([]); | ||
const [selectOptions, setSelectOptions] = React.useState<SelectOptionProps[]>( | ||
[ | ||
{ value: "select-all", label: "Select All", children: "Select All" }, | ||
...options, | ||
] | ||
); | ||
|
||
React.useEffect(() => { | ||
setSelectedItems(value || []); | ||
}, [value]); | ||
|
||
React.useEffect(() => { | ||
const updatedOptions = [ | ||
{ value: "select-all", label: "Select All", children: "Select All" }, | ||
...options, | ||
]; | ||
setSelectOptions(updatedOptions); | ||
}, [options]); | ||
|
||
const onToggleClick = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const onSelect = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
selectionValue: string | number | undefined | ||
) => { | ||
const value = selectionValue as string; | ||
if (value === "select-all") { | ||
if (selectedItems.length === options.length) { | ||
setSelectedItems([]); | ||
onChange([]); | ||
} else { | ||
const allItemValues = options.map((option) => option.value as string); | ||
setSelectedItems(allItemValues); | ||
onChange(allItemValues); | ||
} | ||
} else { | ||
if (selectedItems.includes(value)) { | ||
const newSelections = selectedItems.filter((item) => item !== value); | ||
setSelectedItems(newSelections); | ||
onChange(newSelections); | ||
} else { | ||
const newSelections = [...selectedItems, value]; | ||
setSelectedItems(newSelections); | ||
onChange(newSelections); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Select | ||
role="menu" | ||
id={id} | ||
isOpen={isOpen} | ||
selected={selectedItems} | ||
onSelect={onSelect} | ||
onOpenChange={setIsOpen} | ||
toggle={(toggleref: React.Ref<MenuToggleElement>) => ( | ||
<MenuToggle | ||
ref={toggleref} | ||
onClick={onToggleClick} | ||
style={{ width: width && width + "px" }} | ||
isExpanded={isOpen} | ||
id={toggleId} | ||
> | ||
<span className={spacing.mrSm}>{placeholderText}</span> | ||
{selectedItems.length > 0 && ( | ||
<Badge isRead>{selectedItems.length}</Badge> | ||
)} | ||
</MenuToggle> | ||
)} | ||
aria-label={toggleAriaLabel} | ||
> | ||
<SelectList> | ||
{selectOptions.map((option, index) => ( | ||
<SelectOption | ||
hasCheckbox | ||
key={option.value} | ||
isFocused={index === 0} | ||
onClick={() => onSelect(undefined, option.value)} | ||
isSelected={ | ||
option.value === "select-all" | ||
? selectedItems.length === options.length | ||
: selectedItems.includes(option.value as string) | ||
} | ||
{...option} | ||
> | ||
{option.children || option.value} | ||
</SelectOption> | ||
))} | ||
</SelectList> | ||
</Select> | ||
); | ||
}; |
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
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.