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

refactor(schematics):entity schematics should update the state to plural #1596

Merged
merged 11 commits into from
Mar 12, 2019
Merged

refactor(schematics):entity schematics should update the state to plural #1596

merged 11 commits into from
Mar 12, 2019

Conversation

santoshyadavdev
Copy link
Contributor

@santoshyadavdev santoshyadavdev commented Mar 3, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

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

What is the current behavior?

currently the state variable is singular updating the same to plural
Closes #1412

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@coveralls
Copy link

coveralls commented Mar 3, 2019

Coverage Status

Coverage increased (+0.02%) to 89.529% when pulling 2ceba07 on santoshyadav198613:refactor(schematics)-Entity-schematics-should-update-the-state-with-a-plural-instead-of-a-singular into 5cb9a46 on ngrx:master.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 3, 2019

Preview docs changes for 46c246b at https://previews.ngrx.io/pr1596-46c246b/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 3, 2019

Preview docs changes for dbde8bc at https://previews.ngrx.io/pr1596-dbde8bc/

@santoshyadavdev
Copy link
Contributor Author

@brandonroberts ,

Need help here don't know why CI is getting failed for e2e testing.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 3, 2019

Preview docs changes for 2ceba07 at https://previews.ngrx.io/pr1596-2ceba07/

@timdeschryver
Copy link
Member

@santoshyadav198613 , the failing e2e test isn't related to your change.
I will take a look at it.

@timdeschryver
Copy link
Member

The problem is that we are caching the cypress installation in the wrong build step.
This should be solved when #1593 gets merged.

Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

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

This should be isolated to @ngrx/entity for now. And it needs some tests for common scenarios.

@santoshyadavdev
Copy link
Contributor Author

d it needs some tests for common scenarios.

But this code is part of common function inside schematics-core , can you guide me how should we handle it?

@brandonroberts
Copy link
Member

You create a test for a generated schematic and check that the output is what you expect. For example, your test would use the entity schematic to generate a user collection. The schematic should generate a property named users, with the associated files.

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.

Should we use the pluralize method at this point?
Because I'm a bit afraid this would lead to inconsistencies, for example, while scaffolding the effects we append the name with an s.

@santoshyadavdev
Copy link
Contributor Author

Should we use the pluralize method at this point?
Because I'm a bit afraid this would lead to inconsistencies, for example, while scaffolding the effects we append the name with an s.

Ok let me check it.

@santoshyadavdev
Copy link
Contributor Author

You create a test for a generated schematic and check that the output is what you expect. For example, your test would use the entity schematic to generate a user collection. The schematic should generate a property named users, with the associated files.

ok will update and let you know.

…or(schematics)-Entity-schematics-should-update-the-state-with-a-plural-instead-of-a-singular
@santoshyadavdev
Copy link
Contributor Author

You create a test for a generated schematic and check that the output is what you expect. For example, your test would use the entity schematic to generate a user collection. The schematic should generate a property named users, with the associated files.

Hi @brandonroberts ,

Added a test case for the scenario this is what i have done.
Added one store and entity and then verified if state variable is plural or not same for reducers.

@santoshyadavdev
Copy link
Contributor Author

@brandonroberts and @timdeschryver let me know about the usage of plural function should i remove it.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 5, 2019

Preview docs changes for ca25fe4 at https://previews.ngrx.io/pr1596-ca25fe4/

@santoshyadavdev
Copy link
Contributor Author

Hi @brandonroberts ,
Can you verify again, wrote the test case as per our discussion.

@brandonroberts
Copy link
Member

@santoshyadav198613 we don't want to modify existing behavior for other areas. Instead, add an options object to the ngrx-utils methods as the second argument that's set to { pluralize: false }. For entity schematics, pass { pluralize: true }and use it whether to callpluralizeor justcamelize` inside those functions.

@timdeschryver
Copy link
Member

I'm a bit hesitant to add pluralize (for now) because this would lead to inconsistencies, e.g. city would be pluralized to cities, and in the other schematics to citys.

What about keeping this PR scoped to making the entities pluralized (adding an s), and to create a separate issue to pluralize all the schematics via this function?

@brandonroberts
Copy link
Member

@timdeschryver yes, scoping this to entities is what I had in mind also.

@santoshyadavdev
Copy link
Contributor Author

@santoshyadav198613 we don't want to modify existing behavior for other areas. Instead, add an options object to the ngrx-utils methods as the second argument that's set to { pluralize: false }. For entity schematics, pass { pluralize: true }and use it whether to callpluralizeor justcamelize` inside those functions.

Thanks @brandonroberts ,
Will make the changes.

…or(schematics)-Entity-schematics-should-update-the-state-with-a-plural-instead-of-a-singular
@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 8, 2019

Preview docs changes for ed6655d at https://previews.ngrx.io/pr1596-ed6655d/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 8, 2019

Preview docs changes for 1510211 at https://previews.ngrx.io/pr1596-1510211/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 8, 2019

Preview docs changes for 757d04e at https://previews.ngrx.io/pr1596-757d04e/

@santoshyadavdev
Copy link
Contributor Author

Hi @brandonroberts and @timdeschryver ,
Done with the changes as per discussion, test cases are also added/modified.
The change is restricted to entity only, also appending only 's', keeping pluralize let me know if i should remove it.

modules/schematics/src/entity/index.spec.ts Outdated Show resolved Hide resolved
modules/schematics-core/utility/ngrx-utils.ts Outdated Show resolved Hide resolved
modules/schematics/src/entity/schema.json Outdated Show resolved Hide resolved
modules/schematics/src/entity/schema.ts Outdated Show resolved Hide resolved
@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 9, 2019

Preview docs changes for 0b4a3a2 at https://previews.ngrx.io/pr1596-0b4a3a2/

Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

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

Pretty close. Few more changes

@@ -90,11 +90,13 @@ export function addReducerToStateInterface(
return new NoopChange();
}

let state = stringUtils.camelize(options.name);
Copy link
Member

@brandonroberts brandonroberts Mar 9, 2019

Choose a reason for hiding this comment

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

Suggested change
let state = stringUtils.camelize(options.name);
const state = options.plural ? stringUtils.pluralize(options.name) : stringUtils.camelize(options.name);

Let's use the pluralize method instead of tacking on an s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'innerHTML'.pluralize() // 'InnerHTMLs'
'action_name'.pluralize() // 'actionNames'
'css-class-name'.pluralize() // 'cssClassNames'
'regex'.capitalize() // 'regexes'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'regex'.capitalize() // 'regexes'
'regex'.pluralize() // 'regexes'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'action_name'.pluralize() // 'actionNames'
'css-class-name'.pluralize() // 'cssClassNames'
'regex'.capitalize() // 'regexes'
'user'.capitalize() // 'users'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'user'.capitalize() // 'users'
'user'.pluralize() // 'users'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -110,6 +110,25 @@ export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.substr(1);
}

/**
Returns the Pluralize form of a string
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Returns the Pluralize form of a string
Returns the plural form of a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 10, 2019

Preview docs changes for 4eb91da at https://previews.ngrx.io/pr1596-4eb91da/

@santoshyadavdev
Copy link
Contributor Author

Hi @brandonroberts @timdeschryver ,
All changes are done please review.

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

@brandonroberts brandonroberts merged commit 1e49530 into ngrx:master Mar 12, 2019
tja4472 pushed a commit to tja4472/platform that referenced this pull request Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entity schematics should update the state with a plural instead of a singular
5 participants