Skip to content

Commit ebb63e3

Browse files
authored
Switch to using full name (#1621)
1 parent 763024e commit ebb63e3

File tree

9 files changed

+32
-74
lines changed

9 files changed

+32
-74
lines changed

frontends/api/src/generated/v0/api.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,12 +1597,6 @@ export interface PatchedChannelWriteRequest {
15971597
* @interface PatchedProfileRequest
15981598
*/
15991599
export interface PatchedProfileRequest {
1600-
/**
1601-
*
1602-
* @type {string}
1603-
* @memberof PatchedProfileRequest
1604-
*/
1605-
name?: string | null
16061600
/**
16071601
*
16081602
* @type {string}
@@ -1928,11 +1922,11 @@ export interface PreferencesSearch {
19281922
*/
19291923
export interface Profile {
19301924
/**
1931-
*
1925+
* Get the user\'s name
19321926
* @type {string}
19331927
* @memberof Profile
19341928
*/
1935-
name?: string | null
1929+
name: string
19361930
/**
19371931
*
19381932
* @type {string}
@@ -2054,12 +2048,6 @@ export interface Profile {
20542048
* @interface ProfileRequest
20552049
*/
20562050
export interface ProfileRequest {
2057-
/**
2058-
*
2059-
* @type {string}
2060-
* @memberof ProfileRequest
2061-
*/
2062-
name?: string | null
20632051
/**
20642052
*
20652053
* @type {string}

frontends/mit-learn/src/page-components/Header/Header.test.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ describe("UserMenu", () => {
3131
return screen.findByRole("menu")
3232
}
3333

34-
test.each([
35-
{ first_name: "", last_name: "" },
36-
{ first_name: null, last_name: null },
37-
])(
34+
test.each([{}, { profile: null }, { profile: {} }])(
3835
"Trigger button shows UserIcon for authenticated users w/o initials",
3936
async (userSettings) => {
4037
setMockResponse.get(urls.userMe.get(), userSettings)
@@ -46,29 +43,13 @@ describe("UserMenu", () => {
4643
},
4744
)
4845

49-
test.each([
50-
{
51-
userSettings: { first_name: "Alice", last_name: "Bee" },
52-
expectedName: "Alice Bee",
53-
},
54-
{
55-
userSettings: { first_name: "Alice", last_name: "" },
56-
expectedName: "Alice",
57-
},
58-
{
59-
userSettings: { first_name: "", last_name: "Bee" },
60-
expectedName: "Bee",
61-
},
62-
])(
63-
"Trigger button shows name if available",
64-
async ({ userSettings, expectedName }) => {
65-
setMockResponse.get(urls.userMe.get(), userSettings)
46+
test("Trigger button shows name if available", async () => {
47+
setMockResponse.get(urls.userMe.get(), { profile: { name: "Alice Bee" } })
6648

67-
renderWithProviders(<Header />)
68-
const trigger = await screen.findByRole("button", { name: "User Menu" })
69-
expect(trigger.textContent).toBe(expectedName)
70-
},
71-
)
49+
renderWithProviders(<Header />)
50+
const trigger = await screen.findByRole("button", { name: "User Menu" })
51+
expect(trigger.textContent).toBe("Alice Bee")
52+
})
7253

7354
test("Unauthenticated users see the Sign Up / Login link", async () => {
7455
const isAuthenticated = false

frontends/mit-learn/src/page-components/Header/UserMenu.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,7 @@ const UserNameContainer = styled.span(({ theme }) => ({
7070
}))
7171

7272
const UserName: React.FC<{ user: User | undefined }> = ({ user }) => {
73-
const first = user?.first_name ?? ""
74-
const last = user?.last_name ?? ""
75-
return (
76-
<UserNameContainer>
77-
{first}
78-
{first && last ? " " : ""}
79-
{last}
80-
</UserNameContainer>
81-
)
73+
return <UserNameContainer>{user?.profile?.name ?? ""}</UserNameContainer>
8274
}
8375

8476
const UserMenuChevron: React.FC<{ open: boolean }> = ({ open }) => {

frontends/mit-learn/src/pages/DashboardPage/Dashboard.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,20 @@ describe("DashboardPage", () => {
210210
setupAPIs()
211211
setMockResponse.get(urls.userMe.get(), {
212212
[Permissions.Authenticated]: true,
213-
first_name: "User",
214-
last_name: "Info",
213+
first_name: "Joe",
214+
last_name: "Smith",
215+
profile: {
216+
name: "Jane Smith",
217+
},
215218
})
216219

217220
renderWithProviders(<DashboardPage />)
218221
await waitFor(() => {
219222
/**
220-
* There should be two instances of "User Info" text,
223+
* There should be two instances of "Jane Smith" text,
221224
* one in the header and one in the main content
222225
*/
223-
const userInfoText = screen.getByText("User Info")
226+
const userInfoText = screen.getByText("Jane Smith")
224227
expect(userInfoText).toBeInTheDocument()
225228
})
226229
})

frontends/mit-learn/src/pages/DashboardPage/DashboardPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const DashboardPage: React.FC = () => {
330330
{isLoadingUser ? (
331331
<Skeleton variant="text" width={128} height={32} />
332332
) : (
333-
<UserNameText>{`${user?.first_name} ${user?.last_name}`}</UserNameText>
333+
<UserNameText>{`${user?.profile?.name}`}</UserNameText>
334334
)}
335335
</UserNameContainer>
336336
</ProfilePhotoContainer>

frontends/mit-learn/src/pages/DashboardPage/ProfileEditForm.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,10 @@ const ProfileEditForm: React.FC<Props> = ({ profile }) => {
103103
<FormContainer>
104104
<NameRow>
105105
<TextField
106-
label="First Name"
107-
name="first_name"
106+
label="Full Name"
107+
name="full_name"
108108
fullWidth
109-
value={user?.first_name}
110-
disabled
111-
/>
112-
<TextField
113-
label="Last Name"
114-
fullWidth
115-
name="last_name"
116-
value={user?.last_name}
109+
value={user?.profile?.name}
117110
disabled
118111
/>
119112
</NameRow>

openapi/specs/v0.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,9 +1893,6 @@ components:
18931893
type: object
18941894
description: Serializer for Profile
18951895
properties:
1896-
name:
1897-
type: string
1898-
nullable: true
18991896
image:
19001897
type: string
19011898
nullable: true
@@ -2096,7 +2093,8 @@ components:
20962093
properties:
20972094
name:
20982095
type: string
2099-
nullable: true
2096+
description: Get the user's name
2097+
readOnly: true
21002098
image:
21012099
type: string
21022100
nullable: true
@@ -2179,6 +2177,7 @@ components:
21792177
- image_file
21802178
- image_medium_file
21812179
- image_small_file
2180+
- name
21822181
- placename
21832182
- preference_search_filters
21842183
- profile_image_medium
@@ -2188,9 +2187,6 @@ components:
21882187
type: object
21892188
description: Serializer for Profile
21902189
properties:
2191-
name:
2192-
type: string
2193-
nullable: true
21942190
image:
21952191
type: string
21962192
nullable: true

profiles/serializers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class PreferencesSearchSerializer(serializers.Serializer):
8181
class ProfileSerializer(serializers.ModelSerializer):
8282
"""Serializer for Profile"""
8383

84+
name = serializers.SerializerMethodField(read_only=True)
8485
email_optin = serializers.BooleanField(write_only=True, required=False)
8586
toc_optin = serializers.BooleanField(write_only=True, required=False)
8687
username = serializers.SerializerMethodField(read_only=True)
@@ -90,6 +91,12 @@ class ProfileSerializer(serializers.ModelSerializer):
9091
topic_interests = TopicInterestsField(default=list)
9192
preference_search_filters = serializers.SerializerMethodField(read_only=True)
9293

94+
def get_name(self, obj) -> str:
95+
"""Get the user's name"""
96+
return obj.name or " ".join(
97+
filter(lambda name: name, [obj.user.first_name, obj.user.last_name])
98+
)
99+
93100
def get_username(self, obj) -> str:
94101
"""Custom getter for the username""" # noqa: D401
95102
return str(obj.user.username)

profiles/serializers_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def test_serialize_create_user(db, mocker):
5050
Test creating a user
5151
"""
5252
profile = {
53-
"name": "name",
5453
"email_optin": True,
5554
"toc_optin": True,
5655
"bio": "bio",
@@ -67,6 +66,7 @@ def test_serialize_create_user(db, mocker):
6766

6867
profile.update(
6968
{
69+
"name": "",
7070
"image": None,
7171
"image_small": None,
7272
"image_medium": None,
@@ -100,7 +100,6 @@ def test_serialize_create_user(db, mocker):
100100
@pytest.mark.parametrize(
101101
("key", "value"),
102102
[
103-
("name", "name_value"),
104103
("email_optin", True),
105104
("email_optin", False),
106105
("bio", "bio_value"),
@@ -191,7 +190,6 @@ def test_location_validation(user, data, is_valid):
191190
@pytest.mark.parametrize(
192191
("key", "value"),
193192
[
194-
("name", "name_value"),
195193
("bio", "bio_value"),
196194
("headline", "headline_value"),
197195
("location", {"value": "Hobbiton, The Shire, Middle-Earth"}),

0 commit comments

Comments
 (0)