-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(contentful-apps): Team member - Editor app #16127
Conversation
WalkthroughThe pull request introduces significant updates to the Contentful application components, including the addition of the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16127 +/- ##
==========================================
- Coverage 36.96% 36.77% -0.19%
==========================================
Files 6779 6775 -4
Lines 139879 139565 -314
Branches 39778 39636 -142
==========================================
- Hits 51700 51321 -379
- Misses 88179 88244 +65
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 120 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (4)
apps/contentful-apps/components/editors/ContentfulField.tsx (2)
8-15
: LGTM! Consider adding JSDoc comments for better documentation.The introduction of the
ContentfulFieldProps
interface significantly improves type safety and code clarity. The use ofkeyof
for thefieldID
property is particularly good, ensuring that only valid keys fromlocaleToFieldMapping
can be used.Consider adding JSDoc comments to the interface properties for better documentation. For example:
export interface ContentfulFieldProps { /** The Contentful SDK instance */ sdk: EditorExtensionSDK; /** Mapping of locales to field APIs */ localeToFieldMapping: Record<string, ReturnType<typeof mapLocalesToFieldApis>>; // ... (add comments for other properties) }
17-17
: LGTM! Consider using arrow function syntax for consistency.The update to use
ContentfulFieldProps
for the component's props improves type safety and code clarity. The component follows React best practices and appears to be compatible with Next.js.For consistency with modern React practices and to align with the arrow function syntax used elsewhere in the file, consider updating the component definition to:
export const ContentfulField: React.FC<ContentfulFieldProps> = (props) => { // ... (rest of the component implementation) }This change also explicitly declares the return type of the component as a React Functional Component.
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx (2)
100-102
: Safely Access Nested Fields with Optional ChainingAccessing nested fields like
fields.title[sdk.locales.default]
without checking for their existence might lead to runtime errors if any part of the chain isundefined
ornull
.Consider using optional chaining and providing a fallback value:
- return sortAlpha(sdk.locales.default)( - a.fields.title, - b.fields.title, - ) + return sortAlpha(sdk.locales.default)( + a.fields.title?.[sdk.locales.default] ?? '', + b.fields.title?.[sdk.locales.default] ?? '', + ) ... - {tagGroup.fields.title[sdk.locales.default]} + {tagGroup.fields.title?.[sdk.locales.default] ?? 'Untitled'} ... - {tag.fields.title[sdk.locales.default]} + {tag.fields.title?.[sdk.locales.default] ?? 'Untitled'}Also applies to: 143-144, 177-178
50-189
: Specify Return Type for Functional ComponentFor better type safety and clarity, explicitly specify the return type of the
TeamMemberFilterTagsField
component.Add the return type annotation:
export const TeamMemberFilterTagsField = ({ sdk, }: TeamMemberFilterTagsField) + : JSX.Element => {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (8)
- apps/contentful-apps/components/editors/ContentfulField.tsx (1 hunks)
- apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (1 hunks)
- apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx (1 hunks)
- apps/contentful-apps/components/editors/lists/GenericListEditor/GenericListEditor.tsx (2 hunks)
- apps/contentful-apps/components/editors/lists/GenericListItemEditor/GenericListItemEditor.tsx (2 hunks)
- apps/contentful-apps/pages/editors/generic-list-editor.ts (1 hunks)
- apps/contentful-apps/pages/editors/generic-list-item-editor.ts (1 hunks)
- apps/contentful-apps/pages/editors/team-member-editor.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
- apps/contentful-apps/components/editors/lists/GenericListEditor/GenericListEditor.tsx
- apps/contentful-apps/pages/editors/generic-list-editor.ts
- apps/contentful-apps/pages/editors/generic-list-item-editor.ts
- apps/contentful-apps/pages/editors/team-member-editor.ts
🧰 Additional context used
📓 Path-based instructions (4)
apps/contentful-apps/components/editors/ContentfulField.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
apps/contentful-apps/components/editors/lists/GenericListItemEditor/GenericListItemEditor.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (3)
apps/contentful-apps/components/editors/lists/GenericListItemEditor/GenericListItemEditor.tsx (2)
29-31
: LGTM. Import path change is consistent.The update to the dynamic import path for
ContentfulField
is consistent with the previous import path change. This modification maintains the correct relative path after the apparent directory structure change.The use of dynamic import here is a good practice, especially for components that rely on browser-specific APIs, adhering to Next.js best practices for optimizing client-side rendering when necessary.
Line range hint
1-85
: Overall, the code demonstrates good adherence to Next.js and React best practices.The
GenericListItemEditor
component is well-structured and follows Next.js conventions. Key observations:
- Effective use of TypeScript for type safety, particularly with the Contentful SDK.
- Proper implementation of React hooks like
useMemo
for performance optimization.- Good use of dynamic imports to handle client-side rendering for components with browser-specific dependencies.
- Consistent and clear component structure with appropriate use of Contentful SDK and custom utilities.
The recent changes to import paths are consistent and reflect a modification in the directory structure without affecting the overall functionality or best practices.
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (1)
87-93
: Conditionally enforce the 'image' field requirement based onteamList
variantPer the PR objectives, the 'image' field should be marked as required only for the 'card' variant of the
teamList
. Currently, the 'image' field is always rendered and may not have conditional validation enforcing its required status.Consider implementing conditional validation or rendering for the 'image' field based on the
teamList
variant:{teamList?.fields?.variant?.[sdk.locales.default] === 'card' ? ( <ContentfulField displayName="Image" fieldID="image" localeToFieldMapping={localeToFieldMapping} sdk={sdk} widgetId="assetLinkEditor" isRequired /> ) : ( <ContentfulField displayName="Image" fieldID="image" localeToFieldMapping={localeToFieldMapping} sdk={sdk} widgetId="assetLinkEditor" /> )}This conditionally enforces the
isRequired
prop when the variant is 'card'.Would you like assistance in implementing this conditional logic?
apps/contentful-apps/components/editors/lists/GenericListItemEditor/GenericListItemEditor.tsx
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx
Outdated
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberFilterTagsField.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
libs/cms/src/lib/models/teamMember.model.ts (2)
37-38
: LGTM! Consider adding a comment for clarity.The change to make the
image
property nullable aligns with the PR objective and maintains good TypeScript practices. This allows for more flexibility in handling team member data across different variants.Consider adding a brief comment explaining why the
image
property is nullable, e.g.:// Image is nullable to accommodate different Team List variants @CacheField(() => Image, { nullable: true }) image!: Image | nullThis would improve code readability and make the intent clearer for future developers.
92-92
: LGTM! Consider using optional chaining for consistency.The update to the
image
assignment in themapTeamMember
function correctly handles the case when no image is provided, aligning with the PR objectives and the changes made to theTeamMember
class.For consistency with the
imageOnSelect
assignment on the next line, consider using optional chaining:image: fields.mynd ? mapImage(fields.mynd) : null, imageOnSelect: fields.imageOnSelect ? mapImage(fields.imageOnSelect) : null,This makes the code more uniform and easier to read.
libs/island-ui/contentful/src/lib/TeamList/TeamList.tsx (1)
Line range hint
1-238
: Consider further modularization for improved reusabilityWhile the file adheres well to the coding guidelines for the
libs
directory, consider the following suggestion to enhance modularity and reusability:The
TeamMemberImageUrlProvider
component could potentially be extracted into a separate file. This would:
- Improve the overall structure of the codebase.
- Enhance reusability by making it easier to import this component in other parts of the application if needed.
- Potentially improve tree-shaking by allowing unused components to be more easily identified.
Would you like me to provide a code snippet demonstrating how to extract this component?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- libs/cms/src/lib/models/teamMember.model.ts (2 hunks)
- libs/island-ui/contentful/src/lib/TeamList/TeamList.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/cms/src/lib/models/teamMember.model.ts (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/island-ui/contentful/src/lib/TeamList/TeamList.tsx (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (2)
libs/cms/src/lib/models/teamMember.model.ts (1)
Line range hint
1-102
: Verify alignment with PR objectivesThe changes implemented in this file partially address the PR objectives by making the
image
field nullable. However, the objectives also mentioned hiding email, free text, and phone fields when the Team List variant is set to "card". These changes are not reflected in the current modifications.Please confirm if these additional changes are intended to be implemented in a different file or if they should be addressed here. If they should be implemented in this file, consider updating the
TeamMember
class andmapTeamMember
function to accommodate the variant-specific field visibility.To verify the implementation of these changes elsewhere in the codebase, you can run the following script:
This will help identify if the variant-specific behavior is implemented in other parts of the codebase.
libs/island-ui/contentful/src/lib/TeamList/TeamList.tsx (1)
162-175
: Improved conditional rendering for image columnThe changes improve the
TeamMemberAccordionList
component by conditionally rendering the image column only whenmember.image?.url
exists. This enhancement:
- Prevents the creation of empty image slots in the UI.
- Aligns with React best practices for conditional rendering.
- Potentially improves performance by reducing unnecessary DOM elements.
The modification maintains the component's reusability and adheres to the coding guidelines for the
libs
directory.
Datadog ReportAll test runs ✅ 11 Total Test Services: 0 Failed, 10 Passed Test ServicesThis report shows up to 10 services
🔻 Code Coverage Decreases vs Default Branch (1)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (4)
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx (4)
1-18
: LGTM: Imports and dynamic import are well-structuredThe imports are appropriate for the component's functionality, and the dynamic import of
ContentfulField
is a good practice to avoid SSR issues withwindow
andnavigator
objects.
61-63
: Verify variant check against PR objectivesThe current code checks for an 'accordion' variant, but the PR objectives mention a "card" variant. Ensure that this logic aligns with the intended functionality:
- const teamListIsAccordionVariant = - teamList?.fields?.variant?.[sdk.locales.default] === 'accordion' + const teamListIsCardVariant = + teamList?.fields?.variant?.[sdk.locales.default] === 'card'Please confirm if this change is necessary or if the PR objectives need to be updated.
20-35
:⚠️ Potential issueEnsure consistent field names for the 'image' field
In
createLocaleToFieldMapping
, the field is created withcreateField('mynd', sdk)
, but later in the component, it's referred to as 'image'. This discrepancy may lead to issues where the field does not display or function as expected.To resolve this, ensure that the field names are consistent:
- mynd: createField('mynd', sdk), + image: createField('image', sdk),
47-59
: 🛠️ Refactor suggestionOptimize
useEffect
dependenciesThe
useEffect
hook depends oncma.entry
andsdk.entry
, which may cause unnecessary re-runs. Consider optimizing the dependency array:useEffect(() => { const fetchTeamList = async () => { // Fetch logic } fetchTeamList() - }, [cma.entry, sdk.entry]) + }, [sdk.entry.getSys().id])This ensures the effect only re-runs when the entry ID changes, potentially improving performance.
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx
Show resolved
Hide resolved
apps/contentful-apps/components/editors/TeamMemberEditor/TeamMemberEditor.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui code LGTM
Team member - Editor app
What
Screenshots / Gifs
Card variant
Accordion variant
Screen.Recording.2024-10-02.at.10.13.20.mov
Before
Ignore the red underline, I had document.designMode = "on" in the browser
After
Ignore the red underline, I had document.designMode = "on" in the browser
Checklist:
Summary by CodeRabbit
TeamMemberEditor
component for editing team member information.TeamMemberFilterTagsField
component for managing filter tags associated with team members.image
property in theTeamMember
class to allow for nullable types.TeamList
component to conditionally display images based on availability.TeamMemberEditor
as the primary entity for its module.