Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

feat(app): add dynamic translation to agent detail form #311

Conversation

Karvel
Copy link
Contributor

@Karvel Karvel commented Apr 6, 2021

Changes

  • Trigger call to set-translate route using event emitters instead of state.
  • Add form title translations for "Set Translation".
  • Add form action translations for "Set Translation".
  • Update AgentDetailComponent to handle the set-translation route:
    • Add a isSetTranslation boolean.
    • Use isSetTranslation to disable form controls.
    • Use isSetTranslation to update form title and submit method.
  • Update the dynamic form title to consume translation parameters, if available.
  • Wire up the set-translation/:id/:languageCode route.
  • Initialize CreateAgentResolver with default language dynamic content.

Purpose

The webapp should be able to load a form where a user can set translations for records with dynamic content. This form should disable the non-dynamic fields. It should load the selected language values when available. It should state the selected language in the form title to improve the UX.

setTranslation() does not yet send a request payload to the AgentService.

Approach

This branch puts the responsibility of setting up the dynamic content in the component that creates the form, in this case, AgentDetailComponent, rather than DynamicFormComponent. The only change to DynamicFormComponent was to translate formTitleParams when it is available.

Pre-Testing TODOs

  1. Add the shims for the Agent list & details views.

Testing Steps

If you are not a member of this project, skip this step

  1. Login (as at least an editor).
  2. Go to the Agents view.
  3. Click on "Add Agent" & confirm that the form is built properly.
  4. Go back to the list view & "Update" a record.
  5. Confirm that the form is built properly.
  6. Choose a table row and click on the set translation button.
  7. Choose and click on a language in the popover.
  8. Confirm that a form view is loaded that has "Set Translation for Spanish" (if Spanish was selected) title.
  9. Confirm that all of the form fields that do not require translated text in the translation form are disabled.
  10. Confirm that only the "Description" field is enabled & has the required error message under the input wherever applicable (if the value is blank).
  11. While in the "Set Translation" view, verify that the route looks like http://localhost:4200/content/set-translation/1/es-ES & that changing the language code to one that isn't supported by the application returns the user to the Agent list view.
  12. For each of the above forms, verify that the title, labels, error messages, button are all displayed in the language selected at the top navigation. Change the language selection & verify that the forms react appropriately.

Closes #310.

@Karvel Karvel added this to the Translation - Sprint #5 milestone Apr 6, 2021
@pratimasakinala pratimasakinala force-pushed the 310-ebg-add-dynamic-translation-to-agent-detail-form branch from ff36faa to b0ef512 Compare April 6, 2021 21:32
…y `setTranslation` under the dynamicForm.action & adds translation for its value in all of the JSON files. Uses this new property to set the form submit button text when setting translation on an agent
…get()` if the fieldConfig is not for dynamicContent translation fields. Otherwise uses `group.control` to get the value of fields that requires translation
@pratimasakinala pratimasakinala marked this pull request as ready for review April 7, 2021 13:56
@pratimasakinala pratimasakinala requested review from a team, vinsonf and AramayisO and removed request for a team April 7, 2021 13:56
@pratimasakinala pratimasakinala requested review from a team and removed request for a team April 7, 2021 13:56
@@ -31,7 +31,9 @@ export class FormInputComponent implements OnInit {
}

public get formControl(): AbstractControl {
return this.group.get(this.config.name);
return this.config.name.split('.').length > 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a better way to implement this? I wasn't able to get the formControl using group.get when the config.name was a nested property type string like "dynamicContent.description"

signUp: string = 'dynamicForm.title.signUp';
updateAgency: string = 'dynamicForm.title.updateAgency';
updateAgent: string = 'dynamicForm.title.updateAgent';
updateProfile: string = 'dynamicForm.title.updateProfile';
updateUser: string = 'dynamicForm.title.activateAccount';
updateUser: string = 'dynamicForm.title.updateUser';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

@pratimasakinala pratimasakinala added feature New feature or change that directly affects users refactor Code changes underneath the hood; no difference in user experience labels Apr 7, 2021
@@ -54,19 +69,24 @@ export class AgentDetailSmartComponent implements OnInit {
}

public updateOrCreateAgent(): void {
return this.agent.id ? this.updateAgent() : this.createAgent();
if (this.isSetTranslation) {
this.setTranslation();
Copy link
Contributor

Choose a reason for hiding this comment

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

This function seems to just call this.buildPayload(), could we just call that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That functionality isn't in yet. The method is essentially noop right now. We decided to handle the mapping of the data into the payload in a separate branch so we could merge this while the API catches up.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Karvel Got it, thank you!

@pratimasakinala pratimasakinala self-assigned this Apr 7, 2021
Copy link
Contributor

@mwallert mwallert left a comment

Choose a reason for hiding this comment

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

Changes look good to me, I think @pratimasakinala has better implementation context

Copy link
Collaborator

@pratimasakinala pratimasakinala left a comment

Choose a reason for hiding this comment

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

Everything's working great! NIce job!

@pratimasakinala pratimasakinala merged commit f26e384 into ps-locale-translation Apr 8, 2021
@pratimasakinala pratimasakinala deleted the 310-ebg-add-dynamic-translation-to-agent-detail-form branch April 8, 2021 13:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature or change that directly affects users refactor Code changes underneath the hood; no difference in user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants