Skip to content
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: Introduce our own TypeaheadSelect and use it everywhere #21175

Merged
merged 12 commits into from
Oct 31, 2024

Conversation

mvollmer
Copy link
Member

@mvollmer mvollmer commented Oct 28, 2024

Pixel changes

  • Keep isScrollable=false as default, and explicitly pass isScrollable=true everywhere. This matches the PF APIs better.
  • l10n for Message props

@mvollmer mvollmer added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Oct 28, 2024
@mvollmer mvollmer force-pushed the lib-typeahead-select branch 4 times, most recently from c483dff to f59da49 Compare October 28, 2024 12:35
pkg/storaged/dialog.jsx Fixed Show fixed Hide fixed
pkg/storaged/dialog.jsx Fixed Show fixed Hide fixed
@mvollmer mvollmer force-pushed the lib-typeahead-select branch 6 times, most recently from cb132d7 to 2f4974d Compare October 29, 2024 09:51
@mvollmer mvollmer removed the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Oct 29, 2024
@mvollmer mvollmer force-pushed the lib-typeahead-select branch 2 times, most recently from 48f1985 to 5e6acf0 Compare October 29, 2024 11:51
@mvollmer mvollmer marked this pull request as ready for review October 29, 2024 12:16
@mvollmer mvollmer marked this pull request as draft October 29, 2024 12:16
@mvollmer mvollmer force-pushed the lib-typeahead-select branch 2 times, most recently from 3d62c7d to b116924 Compare October 29, 2024 17:56
@mvollmer
Copy link
Member Author

I am happy with the huge coverage holes. shrug

@mvollmer mvollmer marked this pull request as ready for review October 30, 2024 07:26
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks for the courage and work to address this long-outstanding porting!

I'm not thrilled by the code copy, but I agree it's a nice way to see what we need, and then spoon-feed it to upstream PRs. One hard blocker, and a bunch of nitpicks/questions.

pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
Comment on lines 428 to 433
{...(!(isFiltering && filterValue) && !selected ? { style: { display: 'none' } } : {})}
{...(!(isFiltering && filterValue) && !(props.selected && onClearSelection) ? { style: { display: 'none' } } : {})}
Copy link
Member

Choose a reason for hiding this comment

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

Also feels like a straight upstreamable fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it's a fix... I have to admit I am not super sure how the Clear button is supposed to behave... I'll submit it.

Comment on lines -959 to +955
b.set_file_autocomplete_val("#demo-upload", "/root/")
b.set_file_autocomplete_val("#demo-upload", "/var/")
Copy link
Member

Choose a reason for hiding this comment

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

Why the path change?

Copy link
Member Author

@mvollmer mvollmer Oct 30, 2024

Choose a reason for hiding this comment

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

/root is not listable by admin, and our FileAutocomplete widget shows an error and doesn't let us select /root. Previously, it was possible to make any value stick as the selected value just by closing the dropdown (regardless of whether it exists, or an error occurred, even for !isCreatable). I consider that a bug, actually.

Now this is no longer possible and we need to use something that can be selected from the dropdown, but not be written to by admin. Also, we need to use something that is not a read-only filesystem on CoreOs.

So there are bugs here still to be fixed, I guess:

  • FileAutocomplete should probably not prevent the user from selecting a directory that can't be listed.
  • The upload machinery or the test here don't react correctly to a read-only filesystem, only to read-only permission bits.

test/verify/check-shell-keys Show resolved Hide resolved
@mvollmer mvollmer force-pushed the lib-typeahead-select branch 2 times, most recently from 0186e3b to 5a2b13d Compare October 30, 2024 16:10
from gratuitous upstream changes.
*/

/* eslint-disable */
Copy link
Member

Choose a reason for hiding this comment

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

Can this be restricted to whitespace errors, or is that too messy? Most other eslint complaints are rather useful

pkg/lib/cockpit-components-typeahead-select.tsx Outdated Show resolved Hide resolved
onSelect={(_, value) => {
this.setState({ value });
this.onPathChange(value);
this.props.onChange(value || '', null);
Copy link
Contributor

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.

}}
onClearSelection={this.clearSelection}
isCreatable={this.props.isOptionCreatable}
createOptionMessage={val => cockpit.format(_("Create $0"), val)}
Copy link
Contributor

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.

const NO_RESULTS = 'no results';

if (isCreatable && !createOptionMessage)
throw "isCreatable requires createOptionMessage";
Copy link
Contributor

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.

!newSelectOptions.find((o) => String(o.content).toLowerCase() === filterValue.toLowerCase())
) {
const createOption = {
content: typeof createOptionMessage === 'string' ? createOptionMessage : createOptionMessage(filterValue),
Copy link
Contributor

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.

value: filterValue
};
newSelectOptions = isCreateOptionOnTop
? [createOption, ...newSelectOptions]
Copy link
Contributor

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.

isOpen={isOpen}
selected={selected}
onSelect={_onSelect}
onOpenChange={(isOpen) => !isOpen && closeMenu()}
Copy link
Contributor

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.

<SelectList>
{filteredSelections.map((option, index) => {
if (option.divider)
return <Divider key={option.key || index} component="li" />;
Copy link
Contributor

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.

<TypeaheadSelect toggleProps={ { id: "systime-timezones" } }
isScrollable
selected={time_zone}
onSelect={(event, value) => { change("time_zone", value) }}
Copy link
Contributor

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.

createOptionMessage={val => cockpit.format(_("Use $0"), val)}
selected={value}
onSelect={(_, value) => change(value)}
onClearSelection={() => change("")}
Copy link
Contributor

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.

selected={identifiersFilter}
selectedIsTrusted
onSelect={(e, selection) => { onIdentifiersFilterChange(selection) }}
onClearSelection={identifiersFilter != "all" && (() => { onIdentifiersFilterChange("all") })}
Copy link
Contributor

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.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! Frankly this looks great to me now, definitively an improvement over using the deprecated component.

#21175 (comment) still mentions some potential bug fixes, but I think these aren't regressions, but follow-ups?

@mvollmer
Copy link
Member Author

#21175 (comment) still mentions some potential bug fixes, but I think these aren't regressions, but follow-ups?

Yes.

@mvollmer mvollmer merged commit e57b414 into cockpit-project:main Oct 31, 2024
87 checks passed
@mvollmer mvollmer removed the request for review from garrett October 31, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants