-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: issue #113 author field population
- Loading branch information
Showing
11 changed files
with
133 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* | ||
* Avatar | ||
* | ||
*/ | ||
|
||
// @ts-nocheck | ||
|
||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { isObject } from "lodash"; | ||
import { Avatar, Initials } from "@strapi/design-system/Avatar"; | ||
import { renderInitials } from "../../utils"; | ||
|
||
const UserAvatar = ({ | ||
avatar, | ||
name, | ||
}) => { | ||
if (avatar) { | ||
let image = avatar; | ||
if (isObject(avatar)) { | ||
image = avatar?.formats?.thumbnail.url || avatar.url | ||
} | ||
return <Avatar src={image} alt={name} /> | ||
} | ||
return <Initials>{renderInitials(name)}</Initials> | ||
}; | ||
|
||
UserAvatar.propTypes = { | ||
avatar: PropTypes.oneOfType(PropTypes.string, PropTypes.object).isRequired, | ||
name: PropTypes.string, | ||
}; | ||
|
||
export default UserAvatar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,9 +393,15 @@ describe("Test Comments service functions utils", () => { | |
content: "IKL", | ||
threadOf: 2, | ||
related, | ||
authorId: 1, | ||
authorName: "Joe Doe", | ||
authorEmail: "[email protected]", | ||
authorUser: { | ||
id: 1, | ||
username: "Joe Doe", | ||
email: "[email protected]", | ||
avatar: { | ||
id: 1, | ||
url: 'http://example.com' | ||
} | ||
} | ||
}, | ||
]; | ||
const relatedEntity = { id: 1, title: "Test", uid: collection }; | ||
|
@@ -435,6 +441,23 @@ describe("Test Comments service functions utils", () => { | |
expect(Object.keys(filterOutUndefined(result.data[3]))).toHaveLength(6); | ||
}); | ||
|
||
test("Should return structure with populated avatar field", async () => { | ||
const result = await getPluginService<IServiceCommon>( | ||
"common" | ||
).findAllFlat({ | ||
query: { related }, | ||
populate: { | ||
authorUser: { | ||
populate: { avatar: true }, | ||
}, | ||
} | ||
}, relatedEntity); | ||
expect(result).toHaveProperty("data"); | ||
expect(result).not.toHaveProperty("meta"); | ||
expect(result.data.length).toBe(4); | ||
expect(result).toHaveProperty(["data", 3, "author", "avatar", "url"], db[3].authorUser.avatar.url); | ||
}); | ||
|
||
test("Should return structure with pagination", async () => { | ||
const result = await getPluginService<IServiceCommon>( | ||
"common" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters