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

Amplify Studio - Data Manager Autocomplete field doesn't load all searchable data #1079

Open
4 tasks done
loe-lobo opened this issue Dec 25, 2023 · 2 comments
Open
4 tasks done
Labels
bug An issue which has been identified as a bug cms An issue identified as a cms bug/feature studio-ui An issue that needs to be tracked by Studio Console team

Comments

@loe-lobo
Copy link

loe-lobo commented Dec 25, 2023

Before opening, please confirm:

App Id

d1thx85qzidq63

Region

sa-east-1

Environment name

dev

Figma File Version (if applicable)

No response

Amplify CLI Version

12.10.0

If applicable, what version of Node.js are you using?

v18.17.1

What operating system are you using?

Mac

Browser type?

Google Chrome

Describe the bug

Autocomplete field isn't loading all the data from DynamoDB (AppSync API).

When searching for BB the result box should show 23 results, but it only shows 1. I can see that the first query executed has a NextToken populated, but the UI isn't looping through the results to load all matching items from DB.

Expected behavior

When searching for an Item on Autocomplete in Data Manager, I would expect to get all results that match the filter.

Reproduction steps

  1. Create the following schema
type Portfolio @model
  @auth(
    rules: [
      { allow: private, provider: [iam] }
    ]
  ) {
  id: ID!
  name: String!
  tickers: [PortfolioTicker] @hasMany(indexName: "byPortfolio", fields: ["id"])
}

type PortfolioTicker @model
  @auth(
    rules: [
      { allow: private, provider: iam }
    ]
  ) {
  portfolioId: ID! @primaryKey(sortKeyFields: ["symbol"]) @index(name: "byPortfolio")
  portfolio: Portfolio @belongsTo(fields: ["portfolioId"])
  symbol: String! @index(name: "byTicker")
  ticker: Ticker @belongsTo(fields: ["symbol"])
  entryDate: AWSDateTime!
}

type Ticker @model
  @auth(
    rules: [
      { allow: private, provider: iam }
    ]
  ) {
  symbol: String! @primaryKey
  name: String
  portfolioTickers: [PortfolioTicker] @hasMany(indexName: "byTicker", fields: ["symbol"])
}
  1. Populate Ticker with more than 50 items (you can retrieve a list of Tickers here: Tickers; the stocks property will give you enough to start.
  2. Open Amplify Studio and go to Data Manager
  3. Create a new Portfolio without adding any Tickers
  4. Change the type to PortfolioTicker
  5. Click on Create new PortfolioTicker
  6. Search for BB on the ticker autocomplete field.

The expected result should contain many instances of tickers with BB, but it doesn't show them all.

Project Identifier

8893b0f513340872ef0f1d36b5e0b90a

Additional information

No response

@loe-lobo loe-lobo added the pending-triage An issue that is pending triage label Dec 25, 2023
@loe-lobo
Copy link
Author

loe-lobo commented Jan 4, 2024

I believe I've found the culprit, if Amplify Studio uses the autogenerated Autocomplete from Amplify-UI.
This is the code generated by Amplify-UI (Figma-to-code) for a autocomplete field:

  const fetchTickerRecords = async (value) => {
    setTickerLoading(true);
    const newOptions = [];
    let newNext = "";
    while (newOptions.length < autocompleteLength && newNext != null) {
      const variables = {
        limit: autocompleteLength * 5,
        filter: {
          or: [{ name: { contains: value } }, { symbol: { contains: value } }],
        },
      };
      if (newNext) {
        variables["nextToken"] = newNext;
      }
      const result = (
        await client.graphql({
          query: listTickers.replaceAll("__typename", ""),
          variables,
        })
      )?.data?.listTickers?.items;
      var loaded = result.filter(
        (item) => !tickerIdSet.has(getIDValue.ticker?.(item))
      );
      newOptions.push(...loaded);
      newNext = result.nextToken;
    }
    setTickerRecords(newOptions.slice(0, autocompleteLength));
    setTickerLoading(false);
  };

The problem here is that
result.nextToken doesn't exist. The nextToken property is outside of the items list.

@ykethan
Copy link
Member

ykethan commented Feb 1, 2024

I was able to reproduce the issue, marking as bug.

@ykethan ykethan added bug An issue which has been identified as a bug cms An issue identified as a cms bug/feature studio-ui An issue that needs to be tracked by Studio Console team and removed pending-triage An issue that is pending triage labels Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue which has been identified as a bug cms An issue identified as a cms bug/feature studio-ui An issue that needs to be tracked by Studio Console team
Projects
None yet
Development

No branches or pull requests

2 participants