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

[NAE-1907] - Prompt user before leaving/reloading site when data does not need to be saved #208

Open
wants to merge 6 commits into
base: release/6.4.0
Choose a base branch
from

Conversation

camperko
Copy link
Member

@camperko camperko commented Jul 7, 2023

Description

  • prompt user with dialog when leaving/reloading site and focus is still in input of field (text/number/i18n)
  • if user decide to stay on site, blur input field so data is saved

Implements NAE-1907

Dependencies

No new dependencies were introduced.

Third party dependencies

No new dependencies were introduced.

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

This was tested manually

Test Configuration

<Please describe configuration for tests to run if applicable, like program parameters, host OS, VM configuration etc. You can use >

Name Tested on
OS Linux Mint 21
Runtime Node 18.12.1
Dependency Manager npm 8.19.2
Framework version Angular 13.3.1
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @RudeBoyxX @tuplle
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

…ot need to be saved

- prompt user with dialog when leaving/reloading site and focus is still in input of field (text/number/i18n)
- if user decide to stay on site, blur input field so data is saved
@pull-request-quantifier-deprecated

This PR has 118 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +90 -28
Percentile : 43.6%

Total files changed: 20

Change summary by file extension:
.ts : +69 -20
.html : +21 -8

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@camperko camperko changed the title Nae 1907 - Prompt user before leaving/reloading site when data does not need to be saved [NAE-1907] - Prompt user before leaving/reloading site when data does not need to be saved Jul 7, 2023
@camperko camperko self-assigned this Jul 7, 2023
@camperko camperko added improvement New feature or request new feature labels Jul 7, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

43.3% 43.3% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@@ -8,7 +8,9 @@
[placeholder]="numberField.placeholder"
[required]="numberField.behavior.required"
(focusout)="onFocusOut($event)"
(focusin)="onFocusIn()">
(focusin)="onFocusIn()"
Copy link
Contributor

Choose a reason for hiding this comment

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

working correctly ? because there are assigned two different functions two times, isn't it better to assigned it like (focusin)="onFocusIn();numberField.setFocus()" ?

Copy link
Member

Choose a reason for hiding this comment

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

Consider to use dedicated function for multiple functions call on output event.

@@ -62,6 +62,8 @@ export class EasymdeWrapperComponent implements OnDestroy, AfterViewInit, Contro
this._easyMDE = new EasyMDE(this.options);
this._easyMDE.value(this.textAreaField.value);
this._easyMDE.codemirror.on('change', this._onChange);
this._easyMDE.codemirror.on('focus', () => this.textAreaField.setFocus());
this._easyMDE.codemirror.on('blur', () => this.textAreaField.unsetFocus());
Copy link
Contributor

Choose a reason for hiding this comment

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

it was tested ? is it working ?

@@ -8,7 +8,9 @@
[placeholder]="numberField.placeholder"
[required]="numberField.behavior.required"
(focusout)="onFocusOut($event)"
(focusin)="onFocusIn()">
(focusin)="onFocusIn()"
Copy link
Member

Choose a reason for hiding this comment

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

Consider to use dedicated function for multiple functions call on output event.

@@ -50,7 +50,8 @@
[placeholder]="textI18nField.placeholder ? textI18nField.placeholder : ''"
[required]="textI18nField.behavior.required"
[(ngModel)]="currentValue[selectedLanguage]"
(blur)="setSelectedValue()">
(focusout)="setSelectedValue(); textI18nField.unsetFocus()"
Copy link
Member

Choose a reason for hiding this comment

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

Consider to use dedicated function for multiple functions call on output event.

# Conflicts:
#	projects/nae-example-app/src/app/app.module.ts
#	projects/netgrif-components-core/src/lib/data-fields/models/abstract-data-field.ts
#	projects/netgrif-components-core/src/lib/data-fields/text-field/textarea-field/abstract-textarea-field.component.ts
#	projects/netgrif-components/src/lib/data-fields/number-field/number-currency-field/number-currency-field.component.html
#	projects/netgrif-components/src/lib/data-fields/number-field/number-default-field/number-default-field.component.html
#	projects/netgrif-components/src/lib/data-fields/text-field/html-textarea-field/html-textarea-field.component.html
#	projects/netgrif-components/src/lib/data-fields/text-field/simple-text-field/simple-text-field.component.html
#	projects/netgrif-components/src/lib/data-fields/text-field/text-field.component.ts
#	projects/netgrif-components/src/lib/data-fields/text-field/textarea-field/textarea-field.component.html
- updated to 6.4.0

constructor(@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<T>) {
constructor(@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<T>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

as far as I know, setting default value for an @Optional injector does not work as desired.
null is a falsy value, so it still works as intended.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if there is no such injection token provided, it will be considered as null, which will indicate falsy value, but I think, the default value is used because of without that it would be needed to add the @Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean to constructors of every subclass of AbstractBaseDataFieldComponent

@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>) {
super(dataFieldPortalData);
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the default value (even if it doesn't work) should be provided only at the class that introduces the dependency (AbstractBaseDataFieldComponent in this case)

Copy link
Member

Choose a reason for hiding this comment

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

Corrected.

constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null) {
super(informAboutInvalidData);
constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>) {
super(languageIconsService, _translateService, dataFieldPortalData);
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

}

protected constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) protected _informAboutInvalidData: boolean | null,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) protected _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value doesn't work

@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextAreaField>) {
super(_translate, dataFieldPortalData);
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextAreaField>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>) {
super(_translate, dataFieldPortalData);
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

textFieldComponentEnum = TextFieldComponentEnum;

constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) saveDataInform: boolean | null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

@@ -7,11 +7,14 @@
#textArea
[placeholder]="dataField.placeholder"
[required]="dataField.behavior.required"
[formControl]="formControlRef"
[(ngModel)]="dataField.value"
Copy link
Contributor

Choose a reason for hiding this comment

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

why? A lot of functionality (e.g. enabling/disabling) depends on the FormControl as far as I know.

I notice the hidden <input> on line 17. Does it work, when for example disabling the hidden field?

Copy link
Member

Choose a reason for hiding this comment

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

@camperko I think you can answer this.

@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextAreaField>) {
super(_translate, _ngZone, dataFieldPortalData);
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextAreaField>,
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean | null = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

default value in inheritance chain

- updated according to PR
Copy link

sonarcloud bot commented May 22, 2024

Copy link

sonarcloud bot commented Sep 16, 2024

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.

5 participants