-
Notifications
You must be signed in to change notification settings - Fork 1k
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
When mocking a cell, set the id value as a String or Number based on the type of primary key #4778
When mocking a cell, set the id value as a String or Number based on the type of primary key #4778
Conversation
✅ Deploy Preview for redwoodjs-docs canceled. 🔨 Explore the source changes: 32560a1 🔍 Inspect the deploy log: https://app.netlify.com/sites/redwoodjs-docs/deploys/6235bebd2bd3c1000891bceb |
@dthyresson Unfortunately this is going to be a problem in the cell component where we use the id as a unique key (see export const Success = ({ userExamples }: CellSuccessProps<UserExamplesQuery>) => {
return (
<ul>
{userExamples.map((item) => {
return <li key={item.id}>{JSON.stringify(item)}</li>
})}
</ul>
)
} |
packages/cli/src/commands/generate/cell/templates/mock.js.template
Outdated
Show resolved
Hide resolved
packages/cli/src/commands/generate/cell/templates/mockList.js.template
Outdated
Show resolved
Hide resolved
Co-authored-by: Tobbe Lundberg <[email protected]>
Co-authored-by: Tobbe Lundberg <[email protected]>
@Tobbe I have updated the generator to include multiple mocked values. And now there are tests that actually check the mock files for both numeric and string values. |
Fixes #4531
Prior to this PR, a cell mocked valid was always number: 42 (or 42, 43,44 in lists).
But, this could be problematic if your model id was a String (like uuid or cuids).
This PR detects if the
idType
is a String and uses a string value -- otherwise numeric.Note the value is "42" or 42.
In the list to keep the template simple, the ids are 3 of the same value ... that is they do not increment. This avoided more template vars to pass or logic.
For example:
or
or