Skip to content

samsaffron/codex/convert filter tips to use dmenu #33876

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SamSaffron
Copy link
Member

  • feat: use DMenu for filter tips
  • remove trigger


this.selectedIndex = -1;

next(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

schedule("afterRender", ...) for operations on the DOM


updateValue(value) {
this.newQueryString = value;
this.args.updateQueryString(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be something like onChange, what we do with the new value is implementation detail of the parent component

@inputElement={{this.inputElement}}
/>

<DMenu
Copy link
Contributor

Choose a reason for hiding this comment

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

try using @identifier

} else {
data.last_seen_users = true;
}
const response = await ajax("/u/search/users.json", { data });
Copy link
Contributor

Choose a reason for hiding this comment

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

we try catch tags, but not this one

Comment on lines 604 to +605
{{didInsert this.storeInputElement}}
{{didInsert this.setupEventListeners}}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably use {{on "focus" ...}} and others, to remove a lot of code

Comment on lines +541 to +543
this.updateValue(updatedValue);
this.searchResults = [];
this.updateResults(updatedValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

We update the queryString twice in 3 lines here. It's a code smell for me. Having this kind of duplicated setters makes it hard to understand the flow

Comment on lines +360 to +371
if (this.searchTimer) {
cancel(this.searchTimer);
}
this.searchTimer = discourseDebounce(
this,
this._performPlaceholderSearch,
filterName,
valueText,
tip,
prefix,
300
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not debounced. Cancelling a debounce handler before calling it, defeats the purpose of it.

}

hideTipsIfNeeded() {
this.handleBlurTimer = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that is necessary

Comment on lines +195 to +197
if (this.handleBlurTimer) {
cancel(this.handleBlurTimer);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

cancel will not generate an error on undefined values, so you don't need the if here

searchTimer = null;
handleBlurTimer = null;

@tracked _selectedIndex = -1;
Copy link
Contributor

@jjaffeux jjaffeux Jul 28, 2025

Choose a reason for hiding this comment

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

I think we should stop using these _xxxx. How is _selectedIndex� more private that handleBlurTimer for example?

});

if (tip?.type) {
this.activeFilter = filterName;
Copy link
Contributor

@jjaffeux jjaffeux Jul 28, 2025

Choose a reason for hiding this comment

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

should maybe just be a boolean, we never do anything of the actual filter name.

if (this.selectedIndex >= 0) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

was it necessary?

}

@action
handleKeyDownTips(event) {
Copy link
Contributor

@jjaffeux jjaffeux Jul 28, 2025

Choose a reason for hiding this comment

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

That's probably a bigger refactor, and debatable, but having the listeners on the list seems better. You should be able to do exactly the same behavior with this technique.

Comment on lines +321 to +322
const aStartsWith = aName.startsWith(lastWord);
const bStartsWith = bName.startsWith(lastWord);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is case sensitive, not sure this is what you want here

@martin-brennan
Copy link
Contributor

@jjaffeux I will cover all the review items here

}));
}

/* selecting an item ------------------------------------------------------- */
Copy link
Contributor

Choose a reason for hiding this comment

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

we can probably remove this comment

@contentClass="filter-navigation__tips-dropdown"
>
<:content>
{{#if (and this.showTips this.currentItems.length)}}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just clear currentItems when we hideTips?

Comment on lines +68 to +70
get currentItems() {
return this.filteredTips;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use filteredTips directly here, I don't think currentItems is a better name

@@ -81,6 +124,462 @@ export default class DiscoveryFilterNavigation extends Component {
this._allowEnterSubmit = !value;
}

@action
setupEventListeners() {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can have the element here setupEventListeners(element) so you don't need the check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants