From 553409c1ca161e058e0f7776033aee021229e9f4 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Thu, 10 Oct 2024 15:45:49 +0530 Subject: [PATCH] settings_profile_fields: Move computations out of ListWidget code. This commit moves the code to compute the profile field order and the number of fields shown is user card, out of the list_widget functions just to maintain the code readability and keeping code easy to understand. --- web/src/settings_profile_fields.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/src/settings_profile_fields.ts b/web/src/settings_profile_fields.ts index c2b5b6fa47..93964679a9 100644 --- a/web/src/settings_profile_fields.ts +++ b/web/src/settings_profile_fields.ts @@ -670,10 +670,19 @@ export function do_populate_profile_fields(profile_fields_data: CustomProfileFie let display_in_profile_summary_fields_count = 0; + for (const profile_field of profile_fields_data) { + order.push(profile_field.id); + + // Keeping counts of all display_in_profile_summary profile fields, + // to keep track of whether the limit has been reached. + if (profile_field.display_in_profile_summary) { + display_in_profile_summary_fields_count += 1; + } + } + ListWidget.create($profile_fields_table, profile_fields_data, { name: "settings_profile_fields_list", get_item(profile_field) { - order.push(profile_field.id); return profile_field; }, modifier_html(profile_field) { @@ -688,12 +697,6 @@ export function do_populate_profile_fields(profile_fields_data: CustomProfileFie const display_in_profile_summary = profile_field.display_in_profile_summary === true; const required = profile_field.required; - // Keeping counts of all display_in_profile_summary profile fields, to keep track of - // whether the limit has been reached. - if (display_in_profile_summary) { - display_in_profile_summary_fields_count += 1; - } - return render_admin_profile_field_list({ profile_field: { id: profile_field.id,