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

RelationField auto-fetch/auto-fill options results in duplicate values for initially empty lists #2138

Open
HussainTaj-arbisoft opened this issue Apr 3, 2024 · 0 comments
Labels
bug Something isn't working product:ocw

Comments

@HussainTaj-arbisoft
Copy link
Contributor

HussainTaj-arbisoft commented Apr 3, 2024

Please view the following view to see what the issue is about.

Screen.Recording.2024-04-03.at.4.30.19.PM.mov

Please see this RC course for an example.

When does this occur?

This issue appears when a multi-select list already contains the top results (as returned by the API). Since selected items are not a part of the options list, they are removed from the options, and an empty list is generated. An empty list triggers a fetch until the options list is sufficiently populated or until the API says it has no more data.

What is the likely cause?

The following might be the source of the issue.

const response = await fetchOptions(inputValue, true, options.length)

The third parameter to fetchOptions is an offset forwarded to the API request. I believe options to be visible options only. Combined with FEATURE_SORTABLE_SELECT_HIDE_SELECTED=true it causes the duplicate options problem.

Expected Behavior

The options list does not show duplicates.

Current Behavior

The options list shows duplicates.

Steps to Reproduce

The environment must have the following variables

FEATURE_SELECT_FIELD_INFINITE_SCROLL=true
FEATURE_SORTABLE_SELECT_HIDE_SELECTED=true
  1. Create a course with at least 21 resources.
  2. Create a menu and add the top 8 resources to it.
  3. Edit the first resource and open the select field to observe the issue.

Possible Solution

I believe we'll have to separately track the running offset. The loadOptions function has a third argument called additional which we can utilize to track the running offset. Docs.

async (inputValue: string, options: Option[]) => {

@HussainTaj-arbisoft HussainTaj-arbisoft added bug Something isn't working product:ocw labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working product:ocw
Projects
None yet
Development

No branches or pull requests

1 participant