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

docs(data): add document about how customize a entityCollection level property of ngrx-data #1921

Merged

Conversation

JiaLiPassion
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[x] Documentation content changes
[ ] Other... Please describe:

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Add documentation about how to customize a EntityCollection level property. Such as in my use case, I want to add paging information in EntityCollection level, but current document can only add an additional property in initialization, there is no document about who to get the property from backend.

@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch 3 times, most recently from 452be79 to 428e48a Compare June 5, 2019 23:25
@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 5, 2019

Preview docs changes for 428e48a at https://previews.ngrx.io/pr1921-428e48a/

@brandonroberts
Copy link
Member

Thanks for the PR @JiaLiPassion! Something is being formatted incorrectly in the preview starting at bullet 3 that throws off the rest of the sections.

@JiaLiPassion
Copy link
Contributor Author

JiaLiPassion commented Jun 6, 2019

@brandonroberts, thanks, I fixed it, please review.

@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 428e48a to 1776114 Compare June 6, 2019 04:21
@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 6, 2019

Preview docs changes for 1776114 at https://previews.ngrx.io/pr1921-1776114/

@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 1776114 to 1149354 Compare June 6, 2019 13:33
@JiaLiPassion
Copy link
Contributor Author

@timdeschryver, thanks for the review, I have updated the doc!

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 6, 2019

Preview docs changes for 1149354 at https://previews.ngrx.io/pr1921-1149354/

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

I went over it one more time and found some small improvements.
Besides these, LGTM and I learned something new 👍

projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 1149354 to db7d7c6 Compare June 10, 2019 13:21
@JiaLiPassion
Copy link
Contributor Author

@timdeschryver, thank you for the detailed review, I updated the doc!

@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from db7d7c6 to 6a20c14 Compare June 10, 2019 13:24
@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 10, 2019

Preview docs changes for db7d7c6 at https://previews.ngrx.io/pr1921-db7d7c6/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 10, 2019

Preview docs changes for 6a20c14 at https://previews.ngrx.io/pr1921-6a20c14/

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

LGTM, I think the typos are fixed.
Not very familiar with ngrx/data, an extra pair of eyes would be helpful here 🙂

@wesleygrimes wesleygrimes self-requested a review June 10, 2019 16:57
Copy link
Contributor

@wesleygrimes wesleygrimes left a comment

Choose a reason for hiding this comment

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

Just a few more changes

@JiaLiPassion
Copy link
Contributor Author

@wesleygrimes, thanks, sorry, I didn't see the changes you requested, could you check it?

Copy link
Contributor

@wesleygrimes wesleygrimes left a comment

Choose a reason for hiding this comment

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

Jia,

Nice work. Here are my suggestions.

Thanks,
Wes

projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
@wesleygrimes
Copy link
Contributor

@wesleygrimes, thanks, sorry, I didn't see the changes you requested, could you check it?

Sorry about that, they should be there now.

@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 6a20c14 to 2ce1807 Compare June 10, 2019 17:24
@JiaLiPassion
Copy link
Contributor Author

@wesleygrimes, thanks for the review, I have updated the doc.

Copy link
Contributor

@wesleygrimes wesleygrimes left a comment

Choose a reason for hiding this comment

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

Need spacing between Step and Step Number. For some reason, GitHub would not let me suggest fix on Step3 but that should be fixed as well.

Thanks!
Wes

projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 2ce1807 to f9325e4 Compare June 10, 2019 17:27
@JiaLiPassion
Copy link
Contributor Author

@wesleygrimes, sure, thanks, I have fixed those 3 Steps.

Copy link
Contributor

@wesleygrimes wesleygrimes left a comment

Choose a reason for hiding this comment

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

One more round of changes, Thanks Jia!

projects/ngrx.io/content/guide/data/entity-metadata.md Outdated Show resolved Hide resolved
@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from f9325e4 to 11d52a1 Compare June 10, 2019 17:37
@JiaLiPassion JiaLiPassion force-pushed the customize-additional-property-doc branch from 11d52a1 to db19d4e Compare June 10, 2019 17:38
@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 10, 2019

Preview docs changes for f9325e4 at https://previews.ngrx.io/pr1921-f9325e4/

@wesleygrimes
Copy link
Contributor

LGTM

@JiaLiPassion
Copy link
Contributor Author

@wesleygrimes, thanks, I will use Grammarly.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 10, 2019

Preview docs changes for db19d4e at https://previews.ngrx.io/pr1921-db19d4e/

@AdditionAddict
Copy link
Contributor

AdditionAddict commented Mar 5, 2020

@JiaLiPassion I think this needs an update to step 1.

The default QUERY_MANY_SUCCESS reducer is expecting action.payload.data to be an array of entities but the QUERY_MANY action action.payload.data will be whatever the api returns.

Say it returns

interface QueryManyAPIResponse {
total: number,
entities: T[]
}

You can add a property total to the action payload but action.payload.data needs to be the entities if you want the default reducer for a query many success to work.

@Injectable()
export class AdditionalPersistenceResultHandler  extends DefaultPersistenceResultHandler {

    handleSuccess(originalAction: EntityAction): (data: any) => Action {
        const actionHandler = super.handleSuccess(originalAction);

        return function(data: any) {
            /** Default success action */
            const successAction = actionHandler.call(this, data);

            /** Change payload for query many */
            if (successAction && data && data.total) {
                (successAction as any).payload.total = data.total;
            }
            if (successAction && data && data.entities) {
                (successAction as any).payload.data = data.entities;
            }

            return action;
        };
    }
}

Also AdditionalPropertyPersistenceResultHandler changes its name to AdditionalPersistenceResultHandler in step 3. I suggest updating step 1 to AdditionalPersistenceResultHandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants