Skip to content

Commit 430be25

Browse files
committed
user: Show highlighted custom profile fields first
New at feature level 146, part of the upcoming Zulip Server 6.0. Fixes: #5363
1 parent c35b883 commit 430be25

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/api/modelTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export type CustomProfileField = {|
8181
* it's a string, one serializing a JSON object.
8282
*/
8383
+field_data: string,
84+
+display_in_profile_summary?: true,
8485
|};
8586

8687
export type ImageEmojiType = $ReadOnly<{|

src/users/__tests__/userSelectors-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@ describe('getCustomProfileFieldsForUser', () => {
247247
]);
248248
});
249249

250+
test('put highlighted fields first', () => {
251+
expect(
252+
getCustomProfileFieldsForUser(
253+
mkRealm([
254+
{ id: 1, name: 'name one', type: CustomProfileFieldType.ShortText },
255+
{
256+
id: 2,
257+
name: 'name two',
258+
type: CustomProfileFieldType.ShortText,
259+
},
260+
{
261+
id: 3,
262+
name: 'name three',
263+
type: CustomProfileFieldType.ShortText,
264+
display_in_profile_summary: true,
265+
},
266+
]),
267+
mkUser({
268+
'1': { value: 'value one' },
269+
'2': { value: 'value two' },
270+
'3': { value: 'value three' },
271+
}),
272+
),
273+
).toEqual([
274+
{ fieldId: 3, name: 'name three', value: { displayType: 'text', text: 'value three' } },
275+
{ fieldId: 1, name: 'name one', value: { displayType: 'text', text: 'value one' } },
276+
{ fieldId: 2, name: 'name two', value: { displayType: 'text', text: 'value two' } },
277+
]);
278+
});
279+
250280
test('omit unset fields', () => {
251281
expect(
252282
getCustomProfileFieldsForUser(

src/users/userSelectors.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,17 @@ export function getCustomProfileFieldsForUser(
285285
// the order they appear in the array (`custom_profile_fields` in the
286286
// API; our `realmFields` array here.) See chat thread:
287287
// https://chat.zulip.org/#narrow/stream/378-api-design/topic/custom.20profile.20fields/near/1382982
288+
//
289+
// We go on to put at the start of the list any fields that are marked for
290+
// displaying in the "profile summary". (Possibly they should be at the
291+
// start of the list in the first place, but make sure just in case.)
292+
const sortedRealmFields = [
293+
...realmFields.filter(f => f.display_in_profile_summary),
294+
...realmFields.filter(f => !f.display_in_profile_summary),
295+
];
296+
288297
const fields = [];
289-
for (const realmField of realmFields) {
298+
for (const realmField of sortedRealmFields) {
290299
const value = interpretCustomProfileField(
291300
realmDefaultExternalAccounts,
292301
realmField,

0 commit comments

Comments
 (0)