Skip to content

Conversation

@tkow
Copy link

@tkow tkow commented Jan 18, 2022

Closes #7054

Add previous data argument transform method. My tests added is redundant because previousData always is passed and asserted in every tests but, it's noting worth to keep description about expecting behavior, ready for this behavior is modified (however if you don't need it, I'll remove them).

# The Create and Edit Views

`<Resource>` maps URLs to components - it takes care of *routing*. When you set a component as the `create` prop for a Resource, react-admin renders that component when users go to the `/[resource]/create` URL. When you set a component as the `edit` prop for a resource, react-admin renders that component when users go to the `/[resource]/:id` URL.
`<Resource>` maps URLs to components - it takes care of *routing*. When you set a component as the `create` prop for a Resource, react-admin renders that component when users go to the `/[resource]/create` URL. When you set a component as the `edit` prop for a resource, react-admin renders that component when users go to the `/[resource]/:id` URL.
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a lot of unrelated and unnecessary changes here due to your markdown formatter probably. Can you please revert them?

Copy link
Author

Choose a reason for hiding this comment

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

Sure. Maybe my editor or prettier convert trailing space, I'll fix it asap.

Comment on lines 544 to 546
**Tip**: `<Edit>`'s transform prop can recieve below variables from second argument.

| field | Description |
| -------------- | ------------------------------------------------------------------------------------------ |
| `previousData` | Previous data fetched or last updated on `dataProvider.update` |

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
**Tip**: `<Edit>`'s transform prop can recieve below variables from second argument.
| field | Description |
| -------------- | ------------------------------------------------------------------------------------------ |
| `previousData` | Previous data fetched or last updated on `dataProvider.update` |
**Tip**: `<Edit>`'s transform prop function also get the `previousData` in its second argument:

Comment on lines 2313 to 2317
**Tip**: `<SaveButton>`'s transform prop inside `<Edit>` can recieve below variables from second argument.

| field | Description |
| -------------- | ------------------------------------------------------------------------------------------ |
| `previousData` | Previous data fetched or last updated on `dataProvider.update` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
**Tip**: `<SaveButton>`'s transform prop inside `<Edit>` can recieve below variables from second argument.
| field | Description |
| -------------- | ------------------------------------------------------------------------------------------ |
| `previousData` | Previous data fetched or last updated on `dataProvider.update` |
**Tip**: `<Edit>`'s transform prop function also get the `previousData` in its second argument:

@tkow tkow marked this pull request as ready for review January 18, 2022 09:21
@tkow tkow force-pushed the feat/7054-previous-data-on-transform branch from 7b68bda to 500b47b Compare January 18, 2022 09:21
@vercel vercel bot temporarily deployed to Preview – react-admin January 18, 2022 09:21 Inactive
@tkow tkow force-pushed the feat/7054-previous-data-on-transform branch from 500b47b to ff3c330 Compare January 18, 2022 09:22
@vercel vercel bot temporarily deployed to Preview – react-admin January 18, 2022 09:24 Inactive
@tkow
Copy link
Author

tkow commented Jan 18, 2022

@djhi
Now, I revised them, and please review again when you have time.

Vercel – react-admin-storybook's deploy is failed. Is that no problem?

@tkow
Copy link
Author

tkow commented Jan 22, 2022

@djhi I'm sorry, but I couldn't find why Vercel - react-admin-storybook deployment has failed because I have no idea to know that without vercel logs. It can be build in my local environment.
Could you help me when you have time?

Promise.resolve(
transformFromSave
? transformFromSave(data)
? transformFromSave(data, {
Copy link
Member

Choose a reason for hiding this comment

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

check the linter warning for missing dependency

Copy link
Author

Choose a reason for hiding this comment

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

Thank you I've not noticed. It's green now.


```jsx
export const UserEdit = (props) => {
const transform = (data, { previousData }) => ({
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer that the transform function signature be (data, previousData)

Copy link
Author

@tkow tkow Jan 24, 2022

Choose a reason for hiding this comment

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

@fzaninotto

Sorry, but I'd prefer my way, because it rarely breaks user code when we need to add more optionalData compared to push it to the tail of arguments though the change may be seldom.
Increasing arguments have risks when we want to add new argument, intermediate arguments can't change order without breaking change and even if they are not used in some cases, we may need to assign undefined like, (data, undefined, someEditControllerParameter) when we call or when we set no used variables' specification like, (data, _, someEditControllerParameter) as event hander.

Argument addition as option is better way for me if the argument is really optional value. In this case, users can ignore previousData so, it's optional value.
But, I can't say that previousData must be optional form because I haven't found the case we need more additional parameter in the future. My point is opposite to YAGNI, and previousData may be just enough parameter in all edit controller context parameters to satisfy user demands. So, I'll fix that if you still want to do nonetheless you have read this comment.

@fzaninotto
Copy link
Member

The react-admin-storybook deployment randomly fails, don't worry about It. I redeployed it manually.

@fzaninotto
Copy link
Member

we'll wait for #7087 to be merged to merge this one, as I prefer that you rebase your small PR rather than asking @djhi to rebase his mega-jumbo-huge-not-so-small PR.

@tkow
Copy link
Author

tkow commented Jan 26, 2022

I rebased my commits to remove no diff against next branch merged commits and fixing reviewed commits.

@fzaninotto fzaninotto merged commit e057be1 into marmelab:next Jan 27, 2022
@fzaninotto
Copy link
Member

Thanks!

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