-
Notifications
You must be signed in to change notification settings - Fork 617
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 #10504 from karthikjeeyar/topology-namelabel-filter
Add filter by label in topology
- Loading branch information
Showing
19 changed files
with
259 additions
and
43 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
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
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
90 changes: 90 additions & 0 deletions
90
frontend/packages/topology/src/filters/NameLabelFilterDropdown.tsx
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,90 @@ | ||
import * as React from 'react'; | ||
import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core'; | ||
import { CaretDownIcon, FilterIcon } from '@patternfly/react-icons'; | ||
import { useTranslation } from 'react-i18next'; | ||
import AutocompleteInput from '@console/internal/components/autocomplete'; | ||
import { TextFilter } from '@console/internal/components/factory'; | ||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { NameLabelFilterValues } from './filter-utils'; | ||
|
||
type NameLabelFilterDropdownProps = { | ||
isDisabled: boolean; | ||
data: K8sResourceKind[]; | ||
onChange: (type: string, value: string, endOfString: boolean) => void; | ||
nameFilterInput: string; | ||
labelFilterInput: string; | ||
}; | ||
|
||
const NameLabelFilterDropdown: React.FC<NameLabelFilterDropdownProps> = (props) => { | ||
const { data, onChange, nameFilterInput, labelFilterInput, isDisabled } = props; | ||
|
||
const [isOpen, setOpen] = React.useState(false); | ||
const [selected, setSelected] = React.useState(NameLabelFilterValues.Name); | ||
|
||
const { t } = useTranslation(); | ||
|
||
const onToggle = (open: boolean) => setOpen(open); | ||
const onSelect = (event: React.SyntheticEvent) => { | ||
setSelected((event.target as HTMLInputElement).name as NameLabelFilterValues); | ||
setOpen(!isOpen); | ||
}; | ||
const dropdownItems = [ | ||
<DropdownItem key="name-action" name={NameLabelFilterValues.Name} component="button"> | ||
{t(NameLabelFilterValues.Name)} | ||
</DropdownItem>, | ||
<DropdownItem key="label-action" name={NameLabelFilterValues.Label} component="button"> | ||
{t(NameLabelFilterValues.Label)} | ||
</DropdownItem>, | ||
]; | ||
|
||
const handleInputValue = (value: string) => { | ||
onChange(selected, value, false); | ||
}; | ||
|
||
return ( | ||
<div className="pf-c-input-group"> | ||
<Dropdown | ||
onSelect={onSelect} | ||
toggle={ | ||
<DropdownToggle | ||
isDisabled={isDisabled} | ||
id="toggle-id" | ||
onToggle={onToggle} | ||
toggleIndicator={CaretDownIcon} | ||
> | ||
<> | ||
<FilterIcon className="span--icon__right-margin" /> {t(selected)} | ||
</> | ||
</DropdownToggle> | ||
} | ||
isOpen={isOpen} | ||
dropdownItems={dropdownItems} | ||
/> | ||
{selected === NameLabelFilterValues.Label ? ( | ||
<AutocompleteInput | ||
onSuggestionSelect={(label) => { | ||
onChange(NameLabelFilterValues.Label, label, true); | ||
}} | ||
showSuggestions | ||
textValue={labelFilterInput} | ||
setTextValue={handleInputValue} | ||
placeholder={t('topology~Find by label...')} | ||
data={data} | ||
className="co-text-node" | ||
labelPath={'metadata.labels'} | ||
/> | ||
) : ( | ||
<TextFilter | ||
onChange={handleInputValue} | ||
placeholder={t('topology~Find by name...')} | ||
value={nameFilterInput} | ||
aria-labelledby="toggle-id" | ||
isDisabled={isDisabled} | ||
autoFocus | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default NameLabelFilterDropdown; |
Oops, something went wrong.