Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/webpack.vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module.exports = [
* Patternfly related
*/
'patternfly-react',
'patternfly-react-extensions',
'@patternfly/react-core',
'@patternfly/react-icons',
'@patternfly/react-table',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"multiselect": "~0.9.12",
"number_helpers": "^0.1.1",
"os-browserify": "^0.3.0",
"patternfly-react-extensions": "^3.0.15",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting things from package.json will always get you a 📦 ACK from me ;-)

"patternfly-react": "^2.40.0",
"patternfly": "^3.59.5",
"prop-types": "^15.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

// patternfly v3
@import '~patternfly-react/dist/sass/_patternfly-react.scss';
@import '~patternfly-react-extensions/dist/sass/_select.scss';
@import '~patternfly/dist/sass/patternfly/_loading-state';

// patternfly v5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
selectValue,
selectShowError,
selectIsSelectOpen,
selectHosts,
} from './EditorSelectors';

import { parseDocs } from './EditorHelpers';
Expand Down Expand Up @@ -230,11 +229,7 @@ export const fetchAndPreview = (
}

await dispatch(fetchHosts());
const hosts = selectHosts(getState());

if (hosts.length > 0)
dispatch(previewTemplate({ host: hosts[0], renderPath, templateKindId }));
else dispatch({ type: EDITOR_HIDE_LOADING });
dispatch({ type: EDITOR_HIDE_LOADING });
};

export const toggleModal = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export default (state = initialState, action) => {
}

case EDITOR_HOST_SELECT_CLEAR: {
return state.set('searchQuery', '').set('isSearchingHosts', false);
return state
.set('searchQuery', '')
.set('isSearchingHosts', false)
.set('selectedHost', { id: '', name: '' });
}

case EDITOR_MODAL_TOGGLE: {
Expand Down Expand Up @@ -141,9 +144,7 @@ export default (state = initialState, action) => {
}

case EDITOR_HOST_SELECT_TOGGLE: {
return state
.set('isSelectOpen', !state.isSelectOpen)
.set('searchQuery', '');
return state.set('isSelectOpen', !state.isSelectOpen);
}

case EDITOR_HOST_SELECT_RESET: {
Expand Down
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are waiting to be integrated to this tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PRs do indeed seem intertwined. Do you think this PR should be rebased on #10728 or should this PR go first, then #10728 should be rebased on top of it?

Copy link
Contributor

Choose a reason for hiding this comment

The 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';

Expand All @@ -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();
}
}
};

Expand All @@ -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>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ const EditorNavbar = ({
show={selectedView === 'preview'}
open={isSelectOpen}
selectedItem={selectedHost}
placeholder={__('Select Host...')}
isLoading={isFetchingHosts}
onChange={host =>
previewTemplate({
host,
renderPath: selectedRenderPath,
templateKindId,
})
}
onChange={host => {
if (host && host.id && host.id !== '' && host.name) {
previewTemplate({
host,
renderPath: selectedRenderPath,
templateKindId,
});
}
}}
searchQuery={searchQuery}
onToggle={onHostSelectToggle}
onSearchChange={onHostSearch}
Expand Down
Loading
Loading