-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
lib: Support headers with TypeaheadSelect #21183
Draft
mvollmer
wants to merge
14
commits into
cockpit-project:main
Choose a base branch
from
mvollmer:lib-typeahead-select-groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
45713dd
lib: Copy TypeaheadSelect into our code
mvollmer 78f27b1
lib: Make c-c-typeahead-select.tsx lint-free
mvollmer 60082fc
lib: Make TypeaheadSelect scrollable
mvollmer 9bac2a8
lib: Keep keys unique with TypeaheadSelect
mvollmer e9185ac
lib: Don't hide current value in TypeaheadSelect
mvollmer cfa1ec9
lib: Support dividers with TypeaheadSelect
mvollmer 32032bf
lib: Hide clear button in TypeaheadSelect when it would do nothing
mvollmer 71ca93c
networking: Use TypeaheadSelect instead of deprecated Select
mvollmer 1133b5b
storage: Use TypeaheadSelect instead of deprecated Select
mvollmer aa6cc08
lib: Use TypeaheadSelect instead of deprecated Select for timezones
mvollmer fe91cc2
systemd: Use TypeaheadSelect instead of deprecated Select
mvollmer 5e6acf0
lib: Use TypeaheadSelect instead of deprecated Select for FileAutoCom…
mvollmer 71bca23
lib: Don't hide current value in TypeaheadSelect
mvollmer 5f5a440
lib: Support headers with TypeaheadSelect
mvollmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -19,9 +19,9 @@ | |
|
||
import cockpit from "cockpit"; | ||
import React from "react"; | ||
import { Select, SelectOption } from "@patternfly/react-core/dist/esm/deprecated/components/Select/index.js"; | ||
import PropTypes from "prop-types"; | ||
import { debounce } from 'throttle-debounce'; | ||
import { TypeaheadSelect } from "cockpit-components-typeahead-select"; | ||
|
||
const _ = cockpit.gettext; | ||
|
||
|
@@ -31,26 +31,18 @@ export class FileAutoComplete extends React.Component { | |
this.state = { | ||
directory: '', // The current directory we list files/dirs from | ||
displayFiles: [], | ||
isOpen: false, | ||
value: this.props.value || null, | ||
}; | ||
|
||
this.typeaheadInputValue = ""; | ||
this.allowFilesUpdate = true; | ||
this.updateFiles = this.updateFiles.bind(this); | ||
this.finishUpdate = this.finishUpdate.bind(this); | ||
this.onToggle = this.onToggle.bind(this); | ||
this.clearSelection = this.clearSelection.bind(this); | ||
this.onCreateOption = this.onCreateOption.bind(this); | ||
|
||
this.onPathChange = (value) => { | ||
if (!value) { | ||
this.clearSelection(); | ||
return; | ||
} | ||
|
||
this.typeaheadInputValue = value; | ||
|
||
const cb = (dirPath) => this.updateFiles(dirPath == '' ? '/' : dirPath); | ||
|
||
let path = value; | ||
|
@@ -89,12 +81,6 @@ export class FileAutoComplete extends React.Component { | |
this.allowFilesUpdate = false; | ||
} | ||
|
||
onCreateOption(newValue) { | ||
this.setState(prevState => ({ | ||
displayFiles: [...prevState.displayFiles, { type: "file", path: newValue }] | ||
})); | ||
} | ||
|
||
updateFiles(path) { | ||
if (this.state.directory == path) | ||
return; | ||
|
@@ -152,50 +138,42 @@ export class FileAutoComplete extends React.Component { | |
}); | ||
} | ||
|
||
onToggle(_, isOpen) { | ||
this.setState({ isOpen }); | ||
} | ||
|
||
clearSelection() { | ||
this.typeaheadInputValue = ""; | ||
this.updateFiles("/"); | ||
this.setState({ | ||
value: null, | ||
isOpen: false | ||
}); | ||
this.setState({ value: null }); | ||
this.props.onChange('', null); | ||
} | ||
|
||
render() { | ||
const placeholder = this.props.placeholder || _("Path to file"); | ||
|
||
const selectOptions = this.state.displayFiles | ||
.map(option => <SelectOption key={option.path} | ||
className={option.type} | ||
value={option.path} />); | ||
.map(option => ({ value: option.path, content: option.path, className: option.type })); | ||
|
||
return ( | ||
<Select | ||
variant="typeahead" | ||
id={this.props.id} | ||
isInputValuePersisted | ||
onTypeaheadInputChanged={this.debouncedChange} | ||
placeholderText={placeholder} | ||
noResultsFoundText={this.state.error || _("No such file or directory")} | ||
selections={this.state.value} | ||
onSelect={(_, value) => { | ||
this.setState({ value, isOpen: false }); | ||
this.debouncedChange(value); | ||
this.props.onChange(value || '', null); | ||
}} | ||
onToggle={this.onToggle} | ||
onClear={this.clearSelection} | ||
isOpen={this.state.isOpen} | ||
isCreatable={this.props.isOptionCreatable} | ||
createText={_("Create")} | ||
onCreateOption={this.onCreateOption} | ||
menuAppendTo="parent"> | ||
{selectOptions} | ||
</Select> | ||
<TypeaheadSelect toggleProps={ { id: this.props.id } } | ||
onInputChange={this.debouncedChange} | ||
placeholder={placeholder} | ||
noOptionsAvailableMessage={this.state.error || _("No such file or directory")} | ||
noOptionsFoundMessage={this.state.error || _("No such file or directory")} | ||
onToggle={isOpen => { | ||
// Try to list again when | ||
// opening. Calling onPathChange here | ||
// usually does nothing, except when | ||
// there was an error earlier. | ||
if (isOpen) | ||
this.onPathChange(this.state.value); | ||
}} | ||
selected={this.state.value} | ||
onSelect={(_, value) => { | ||
this.setState({ value }); | ||
this.onPathChange(value); | ||
this.props.onChange(value || '', null); | ||
}} | ||
onClearSelection={this.clearSelection} | ||
isCreatable={this.props.isOptionCreatable} | ||
createOptionMessage={val => cockpit.format(_("Create $0"), val)} | ||
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. This added line is not executed by any test. |
||
selectOptions={selectOptions} /> | ||
); | ||
} | ||
} | ||
|
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,4 @@ | ||
.ct-typeahead-header .pf-v5-c-menu__item-main { | ||
color: var(--pf-v5-global--primary-color--100); | ||
font-size: var(--pf-v5-global--FontSize--sm); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This added line is not executed by any test.