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

chore(dotcms-ui): Fix error with autocomplete #30249 #30269

Merged
merged 13 commits into from
Oct 7, 2024

Conversation

nicobytes
Copy link
Contributor

@nicobytes nicobytes commented Oct 5, 2024

Parent Issue

#30249

Proposed Changes

  • Change singal approach

The problem

This computed signal caused the error:

$filteredSuggestions = computed(() => {
    const classes = this.$classes();
    const query = this.$query();

    if (!query) {
        return classes;
    }

    return classes.filter((item) => item.includes(query));
});

filterClasses({ query }: AutoCompleteCompleteEvent): void {
    this.$query.set(query);
}

The signals functionality in PrimeNg doesn't works very well. In the previous signal, $filteredSuggestions doesn't trigger a change if the classes or query are the same as the current state. This is desirable. However, PrimeNg waits for a change in the suggestions input after the completeMethod is called to turn off the loading. This is why the loading indicator remains active but never deactivates.

To address this, we manually forced a change in $filteredSuggestions and used [...filteredClasses] to create a new array.

filterClasses({ query }: AutoCompleteCompleteEvent): void {
      const classes = this.$classes();
      const filteredClasses = query ? classes.filter((item) => item.includes(query)) : classes;
      this.$filteredSuggestions.set([...filteredClasses]);
  }

Checklist

  • Tests
  • Translations
  • Security Implications Contemplated (add notes if applicable)

Screenshots

2024-10-07.10-03-18.mp4

This PR fixes: #30249

@nicobytes nicobytes linked an issue Oct 5, 2024 that may be closed by this pull request
@nicobytes nicobytes added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit 3f8e75b Oct 7, 2024
20 checks passed
@nicobytes nicobytes deleted the 30249-autocomplete-doesnt-work-properly branch October 7, 2024 19:57
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.

Autocomplete doesn't work properly
3 participants