-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #38916 - Update EditorHostSelect to pf5 #10777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,18 @@ | ||
| import React, { Component } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { Select } from 'patternfly-react-extensions'; | ||
| import { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes are waiting to be integrated to this tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that #10728 should be merged first to leverage its passing tests. Subsequent changes can then be fully integrated with these tested, stable components. |
||
| Select, | ||
| SelectList, | ||
| SelectOption, | ||
| MenuToggle, | ||
| TextInputGroup, | ||
| TextInputGroupMain, | ||
| TextInputGroupUtilities, | ||
| Button, | ||
| Spinner, | ||
| Icon, | ||
| } from '@patternfly/react-core'; | ||
| import { TimesIcon } from '@patternfly/react-icons'; | ||
| import { translate as __ } from '../../../common/I18n'; | ||
| import './editorhostselect.scss'; | ||
|
|
||
|
|
@@ -20,7 +32,9 @@ class EditorHostSelect extends Component { | |
| handleClickOutside = event => { | ||
| if (this.selectRef && !this.selectRef.contains(event.target)) { | ||
| const { open, onToggle } = this.props; | ||
| if (open) onToggle(); | ||
| if (open) { | ||
| onToggle(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -31,38 +45,163 @@ class EditorHostSelect extends Component { | |
| } | ||
| }; | ||
|
|
||
| render() { | ||
| handleInputChange = (_event, value) => { | ||
| const { onSearchChange, selectedItem, onChange } = this.props; | ||
|
|
||
| onSearchChange({ target: { value } }); | ||
|
|
||
| if (selectedItem && selectedItem.name && value !== selectedItem.name) { | ||
| onChange({ id: '', name: '' }); | ||
| } | ||
| }; | ||
|
|
||
| onInputClick = () => { | ||
| const { open, onToggle } = this.props; | ||
|
|
||
| if (!open) { | ||
| onToggle(); | ||
| } | ||
| }; | ||
|
|
||
| toggle = toggleRef => { | ||
| const { | ||
| show, | ||
| isLoading, | ||
| open, | ||
| searchQuery, | ||
| selectedItem, | ||
| onToggle, | ||
| onSearchClear, | ||
| } = this.props; | ||
|
|
||
| const inputValue = searchQuery || (selectedItem && selectedItem.name) || ''; | ||
|
|
||
| return ( | ||
| <MenuToggle | ||
| ref={toggleRef} | ||
| variant="typeahead" | ||
| onClick={onToggle} | ||
| isExpanded={open} | ||
| isFullWidth | ||
| > | ||
| <TextInputGroup isPlain> | ||
| <TextInputGroupMain | ||
| value={inputValue} | ||
| onClick={this.onInputClick} | ||
| onChange={this.handleInputChange} | ||
| onKeyDown={this.onKey} | ||
| placeholder={__('Select Host...')} | ||
| aria-label={__('Filter hosts')} | ||
| /> | ||
|
|
||
| <TextInputGroupUtilities | ||
| {...(!inputValue ? { style: { display: 'none' } } : {})} | ||
| > | ||
| <Button | ||
| variant="plain" | ||
| onClick={onSearchClear} | ||
| aria-label="Clear input value" | ||
| ouiaId="clear-input-value-button" | ||
| > | ||
| <Icon aria-hidden> | ||
| <TimesIcon /> | ||
| </Icon> | ||
| </Button> | ||
| </TextInputGroupUtilities> | ||
| </TextInputGroup> | ||
| </MenuToggle> | ||
| ); | ||
| }; | ||
|
|
||
| handleSelect = (_event, selection) => { | ||
| const { | ||
| options, | ||
| onChange, | ||
| onToggle, | ||
| onSearchChange, | ||
| onSearchClear, | ||
| onToggle, | ||
| } = this.props; | ||
| const normalizedSelection = | ||
| selection === undefined || selection === null | ||
| ? undefined | ||
| : String(selection); | ||
| const selectedHost = | ||
| options.find(option => String(option.id) === normalizedSelection) || | ||
| options.find(option => option.name === normalizedSelection); | ||
|
|
||
| if (selectedHost) { | ||
| onSearchChange({ target: { value: selectedHost.name } }); | ||
| onChange(selectedHost); | ||
|
|
||
| onToggle(); | ||
| onSearchClear(); | ||
| } | ||
| }; | ||
|
|
||
| render() { | ||
| const { | ||
| show, | ||
| isLoading, | ||
| open, | ||
| options, | ||
| searchQuery, | ||
| onToggle, | ||
| selectedItem, | ||
| } = this.props; | ||
|
|
||
| const selectedValue = | ||
| selectedItem && | ||
| selectedItem.id !== undefined && | ||
| selectedItem.id !== null && | ||
| selectedItem.id !== '' | ||
| ? String(selectedItem.id) | ||
| : undefined; | ||
|
|
||
| let selectOptions; | ||
| if (isLoading) { | ||
| selectOptions = ( | ||
| <SelectOption isDisabled key="loading" value="loading"> | ||
| <Spinner | ||
| size="md" | ||
| style={{ marginRight: 'var(--pf-v5-global--spacer--sm)' }} | ||
| /> | ||
| {__('Loading...')} | ||
| </SelectOption> | ||
| ); | ||
| } else if (!options || options.length === 0) { | ||
| selectOptions = ( | ||
| <SelectOption isDisabled key="no-results" value="no-results"> | ||
| {__('No Results')} | ||
| </SelectOption> | ||
| ); | ||
| } else { | ||
| selectOptions = options.map(option => ( | ||
| <SelectOption key={option.id} value={String(option.id)}> | ||
| {option.name || option.id} | ||
| </SelectOption> | ||
| )); | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| ref={this.setWrapperRef} | ||
| id="editor-select-container" | ||
| className={show ? '' : 'hidden'} | ||
| > | ||
| <Select | ||
| options={options} | ||
| placeholder={__('Filter Host...')} | ||
| open={open} | ||
| onToggle={onToggle} | ||
| searchValue={searchQuery} | ||
| onSearchChange={onSearchChange} | ||
| onSearchClear={onSearchClear} | ||
| onKeyDown={this.onKey} | ||
| onItemClick={onChange} | ||
| selectedItem={selectedItem} | ||
| isLoading={isLoading} | ||
| /> | ||
| id="editor-host-select" | ||
| aria-label={__('Host selector')} | ||
| isOpen={open} | ||
| onSelect={this.handleSelect} | ||
| onOpenChange={isOpen => { | ||
| if (!isOpen && open) onToggle(); | ||
| }} | ||
| shouldFocusFirstItemOnOpen={false} | ||
| toggle={this.toggle} | ||
| selected={selectedValue} | ||
| variant="typeahead" | ||
| isScrollable | ||
| ouiaId="editor-host-select" | ||
| > | ||
| <SelectList>{selectOptions}</SelectList> | ||
| </Select> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting things from
package.jsonwill always get you a 📦 ACK from me ;-)