From 33d06af6c25c331f40eb5894432e9a846e51b996 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 21 Feb 2023 17:48:57 +0530 Subject: [PATCH] user_profile: Deduplicate code for showing custom profile fields. This commit deduplicates template code for showing custom profile fields in user info popover and full profile modal by extracting it in a new file and then using that template file to render the fields in user info popover and full profile modal. This commit does not change the design or behavior and they are same as before. --- static/styles/popovers.css | 4 +++ .../templates/user_custom_profile_fields.hbs | 31 +++++++++++++++++++ .../templates/user_info_popover_content.hbs | 24 +------------- static/templates/user_profile_modal.hbs | 21 +------------ 4 files changed, 37 insertions(+), 43 deletions(-) create mode 100644 static/templates/user_custom_profile_fields.hbs diff --git a/static/styles/popovers.css b/static/styles/popovers.css index a8d73c0b49..cad2a33c1c 100644 --- a/static/styles/popovers.css +++ b/static/styles/popovers.css @@ -383,6 +383,10 @@ ul { #profile-tab { margin: 1px 5px 0; + + li.custom_user_field { + display: block; + } } .top { diff --git a/static/templates/user_custom_profile_fields.hbs b/static/templates/user_custom_profile_fields.hbs new file mode 100644 index 0000000000..051351bd91 --- /dev/null +++ b/static/templates/user_custom_profile_fields.hbs @@ -0,0 +1,31 @@ +{{#each profile_fields}} +
  • + {{#unless ../for_user_info_popover}} +
    {{this.name}}
    + {{/unless}} + {{#if this.is_link}} + + {{else if this.is_external_account}} + + {{else if this.is_user_field}} +
    + +
    + {{else}} + {{#if this.rendered_value}} + + {{else}} + + {{/if}} + {{/if}} +
  • +{{/each}} diff --git a/static/templates/user_info_popover_content.hbs b/static/templates/user_info_popover_content.hbs index 52b2f53368..99b4bc9ecc 100644 --- a/static/templates/user_info_popover_content.hbs +++ b/static/templates/user_info_popover_content.hbs @@ -50,29 +50,7 @@
  • {{ user_type }}
  • {{/if}} {{!-- Display selected custom profile fields in this popover. --}} - {{#each display_profile_fields}} -
  • - {{#if this.is_link}} - {{this.value}} - {{else if this.is_external_account}} - - {{#if (eq this.subtype "github") }} - - {{else if (eq this.subtype "twitter") }} - - {{/if}} - {{this.value}} - - {{else}} - {{#if this.rendered_value}} - {{rendered_markdown this.rendered_value}} - {{else}} - {{this.value}} - {{/if}} - {{/if}} -
  • - {{/each}} - + {{> user_custom_profile_fields profile_fields=display_profile_fields for_user_info_popover=true}}
  • {{#tr}}Joined {date_joined}{{/tr}}
  • diff --git a/static/templates/user_profile_modal.hbs b/static/templates/user_profile_modal.hbs index f98b3b3432..08e27b1d51 100644 --- a/static/templates/user_profile_modal.hbs +++ b/static/templates/user_profile_modal.hbs @@ -81,26 +81,7 @@ {{/if}} {{else}} - {{#each profile_data}} -
    -
    {{this.name}}
    - {{#if this.is_user_field}} -
    - -
    - {{else if this.is_link}} - {{this.value}} - {{else if this.is_external_account}} - {{this.value}} - {{else}} - {{#if this.rendered_value}} -
    {{rendered_markdown this.rendered_value}}
    - {{else}} -
    {{this.value}}
    - {{/if}} - {{/if}} -
    - {{/each}} + {{> user_custom_profile_fields profile_fields=profile_data}} {{/if}}