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

Reduce code duplication in bug reporting, team response and tester response views #1024

Open
jamesyeap opened this issue Oct 22, 2022 · 6 comments

Comments

@jamesyeap
Copy link
Contributor

jamesyeap commented Oct 22, 2022

As suggested by @gycgabriel, we can reduce the duplication in the code that checks if a user has made any changes to the issue or response while in edit mode.

Context

This feature was introduced in the following PRs:

This was done to ensure that the when the user leaves edit mode, the cancel edit warning dialog box (that warns the user that some changes made will be discarded) is only shown if he/she has actually made any changes to the issue or response.

Where the code duplication is

The method to detect changes openCancelDialogIfModified is currently declared in 4 separate components (shown below):

openCancelDialogIfModified(): void {
const issueTitleInitialValue = this.issue.title || '';
if (this.issueTitleForm.get('title').value !== issueTitleInitialValue) {
// if the title has been edited, request user to confirm the cancellation
this.openCancelDialog();
} else {
// if no changes have been made, simply cancel edit mode without getting confirmation
this.cancelEditMode();
}
}

openCancelDialogIfModified(): void {
const issueDescriptionInitialValue = this.issue.description || '';
if (this.issueDescriptionForm.get('description').value !== issueDescriptionInitialValue) {
// if the description has been edited, request user to confirm the cancellation
this.openCancelDialog();
} else {
// if no changes have been made, simply cancel edit mode without getting confirmation
this.cancelEditMode();
}
}

openCancelDialogIfModified(): void {
const issueTeamResponseInitialValue = this.issue.teamResponse || '';
if (this.responseForm.get('description').value !== issueTeamResponseInitialValue) {
// if the response has been edited, request user to confirm the cancellation
this.openCancelDialog();
} else {
// if no changes have been made, simply cancel edit mode without getting confirmation
this.cancelEditMode();
}
}

openCancelDialogIfModified(): void {
const reasonForDisagreementIsModified = this.issue.testerResponses
.filter((t: TesterResponse, index: number) => this.isResponseDisagreed(index))
.map((t: TesterResponse, index: number) => {
const currentValue = this.getTesterResponseText(index);
const initialValue = t.reasonForDisagreement || '';
return currentValue !== initialValue;
})
.reduce((a, b) => a || b, false);
const disagreementIsModified = this.issue.testerResponses
.map((t: TesterResponse, index: number) => {
const currentValue = this.isResponseDisagreed(index);
const initialValue = t.isDisagree();
return currentValue !== initialValue;
})
.reduce((a, b) => a || b, false);
const isModified = reasonForDisagreementIsModified || disagreementIsModified;
if (isModified) {
// if the disagreement decision and/or reason for disagreement of any response has been edited,
// request user to confirm the cancellation
this.openCancelDialog();
} else {
// if no changes have been made, simply cancel edit mode without getting confirmation
this.cancelEditMode();
}
}

What can be done

There is an opportunity to reduce code duplication, possibly by moving this function into a service.

@jamesyeap jamesyeap changed the title Reduce code duplication in issue components title and description Reduce code duplication in bug reporting, team response and tester response views Oct 22, 2022
@RyanCheungJF
Copy link
Contributor

Hi! Could I possibly work on this?

@gycgabriel
Copy link
Contributor

Hello! Yes please go ahead

@cheehongw
Copy link
Contributor

Sorry for all spam above 😓, just realized @RyanCheungJF may still be working on this.

@vigneshsankariyer1234567890
Copy link
Contributor

@cheehongw are you working on this?

@cheehongw
Copy link
Contributor

@vigneshsankariyer1234567890 nope

@vigneshsankariyer1234567890
Copy link
Contributor

Can we close this issue? I see that there is already a PR that has been merged

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

Successfully merging a pull request may close this issue.

5 participants