Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

popovers: Display custom profile fields in user profile popover.

yogesh sirsatcd71fdea6081
diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js
index 1cfad261c23..a2ad3312a4f 100644
--- a/frontend_tests/node_tests/popovers.js
+++ b/frontend_tests/node_tests/popovers.js
@@ -178,6 +178,7 @@ test_ui("sender_hover", ({override, mock_template}) => {
can_manage_user: false,
can_send_private_message: true,
can_unmute: false,
+ display_profile_fields: [],
user_full_name: "Alice Smith",
user_email: "[email protected]",
user_id: 42,
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 3f2dacb46ff..462ae398619 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -50,6 +50,7 @@ import * as settings_users from "./settings_users";
import * as stream_popover from "./stream_popover";
import * as ui_report from "./ui_report";
import * as user_groups from "./user_groups";
+import * as user_profile from "./user_profile";
import * as user_status from "./user_status";
import * as user_status_ui from "./user_status_ui";
import * as util from "./util";
@@ -219,6 +220,12 @@ function render_user_info_popover(
const dateFormat = new Intl.DateTimeFormat("default", {dateStyle: "long"});
date_joined = dateFormat.format(parseISO(user.date_joined));
}
+ // Filtering out only those profile fields that can be display in the popover and are not empty.
+ const dateFormat = new Intl.DateTimeFormat("default", {dateStyle: "long"});
+ const field_types = page_params.custom_profile_field_types;
+ const display_profile_fields = page_params.custom_profile_fields
+ .map((f) => user_profile.get_custom_profile_field_data(user, f, field_types, dateFormat))
+ .filter((f) => f.display_in_profile_summary && f.value !== undefined && f.value !== null);
const args = {
can_revoke_away,
@@ -231,6 +238,7 @@ function render_user_info_popover(
page_params.realm_private_message_policy !==
settings_config.private_message_policy_values.disabled.code,
can_unmute: muting_allowed && is_muted,
+ display_profile_fields,
has_message_context,
is_active,
is_bot: user.is_bot,
diff --git a/static/js/user_profile.js b/static/js/user_profile.js
index cbd840e0114..4864e20f7e7 100644
--- a/static/js/user_profile.js
+++ b/static/js/user_profile.js
@@ -109,7 +109,7 @@ function render_user_group_list(groups, user) {
});
}
-function get_custom_profile_field_data(user, field, field_types, dateFormat) {
+export function get_custom_profile_field_data(user, field, field_types, dateFormat) {
const field_value = people.get_custom_profile_data(user.user_id, field.id);
const field_type = field.type;
const profile_field = {};
@@ -125,6 +125,7 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {
profile_field.is_link = field_type === field_types.URL.id;
profile_field.is_external_account = field_type === field_types.EXTERNAL_ACCOUNT.id;
profile_field.type = field_type;
+ profile_field.display_in_profile_summary = field.display_in_profile_summary;
switch (field_type) {
case field_types.DATE.id:
@@ -148,6 +149,7 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {
case field_types.EXTERNAL_ACCOUNT.id:
profile_field.value = field_value.value;
profile_field.field_data = JSON.parse(field.field_data);
+ profile_field.subtype = profile_field.field_data.subtype;
profile_field.link = settings_profile_fields.get_external_account_link(profile_field);
break;
default:
diff --git a/static/styles/popovers.css b/static/styles/popovers.css
index 171049a52f8..62e336ca025 100644
--- a/static/styles/popovers.css
+++ b/static/styles/popovers.css
@@ -36,6 +36,23 @@
text-align: center;
}
+.popover_info .custom_user_field {
+ text-overflow: ellipsis;
+ overflow: hidden;
+
+ a i {
+ /* Hack: This overrides the 3px margin-right for all <i> elements in
+ this component. Ideally, that other logic would restrict
+ the behavior elements with the right CSS class, and we'd
+ delete this. */
+ margin-right: 0;
+ }
+
+ a:hover {
+ text-decoration: none;
+ }
+}
+
.sp-container {
z-index: 106;
}
diff --git a/static/templates/user_info_popover_content.hbs b/static/templates/user_info_popover_content.hbs
index 8615e054465..885cfcd459f 100644
--- a/static/templates/user_info_popover_content.hbs
+++ b/static/templates/user_info_popover_content.hbs
@@ -43,6 +43,29 @@
{{else}}
<li>{{ user_type }}</li>
{{/if}}
+ {{!-- Display selected custom profile fields in this popover. --}}
+ {{#each display_profile_fields}}
+ <li data-type="{{this.type}}" class="field-section custom_user_field tippy-zulip-tooltip" data-tippy-content="{{this.name}}" data-field-id="{{this.id}}">
+ {{#if this.is_link}}
+ <a tabindex="0" href="{{this.value}}" target="_blank" rel="noopener noreferrer" class="value">{{this.value}}</a>
+ {{else if this.is_external_account}}
+ <a tabindex="0" href="{{this.link}}" target="_blank" rel="noopener noreferrer" class="value">
+ {{#if (eq this.subtype "github") }}
+ <i class="fa fa-github" aria-hidden="true"></i>
+ {{else if (eq this.subtype "twitter") }}
+ <i class="fa fa-twitter" aria-hidden="true"></i>
+ {{/if}}
+ {{this.value}}
+ </a>
+ {{else}}
+ {{#if this.rendered_value}}
+ <span class="value rendered_markdown">{{rendered_markdown this.rendered_value}}</span>
+ {{else}}
+ <span class="value">{{this.value}}</span>
+ {{/if}}
+ {{/if}}
+ </li>
+ {{/each}}
{{#if user_time}}
<li class="hidden-for-spectators">{{ user_time }} {{#tr}}Local time{{/tr}}</li>