Skip to content
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(api): parse Team Member data from Google Doc #676

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

lmontero18
Copy link
Contributor

@lmontero18 lmontero18 commented Jan 21, 2025

ETA: January 29
resolves: https://github.com/holdex/marketing/issues/97
test: http://holdex-venture-studio-git-feat-parsing-data-holdex-accelerator.vercel.app/

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for parsing and rendering a team members section in content.
    • Enhanced document conversion process to extract team member details.
  • Improvements

    • Updated About page template with improved navigation and layout.
    • Refined breadcrumb navigation for better user experience.

The changes introduce a new capability to handle team member information across the application's content parsing and rendering systems.

@lmontero18 lmontero18 self-assigned this Jan 21, 2025
Copy link

vercel bot commented Jan 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
holdex-venture-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:29pm

@lmontero18 lmontero18 marked this pull request as draft January 21, 2025 22:31
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

This pull request introduces a new TeamMembersBlock type and associated parsing functionality for handling team member information across different components of the application. The changes span multiple files, including the body parser, about page template, and Google conversion API route. The implementation enables the extraction, parsing, and rendering of team member data, with a focus on supporting the display of team photos and information on the about page.

Changes

File Change Summary
src/lib/components/BodyParser/blocks.ts Added TeamMembersBlock type definition, parseTeamMembers function, and updated htmlParser configuration
src/routes/(pages)/about/template.pug Updated page structure with navigation crumbs and dynamic h1 id attribute
src/routes/api/google-conversion/+server.ts Added parseTeamMembersSection function, updated type imports, and modified convertToHoldexJson to handle team members

Assessment against linked issues

Objective Addressed Explanation
Display team photos in /about page [#97]

Possibly related PRs

Suggested reviewers

  • zolotokrylin
  • matthewvogas
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@matthewvogas
Copy link
Contributor

@lmontero18 pls use correct naming of pr, instead backend use api, read our guidelines

Copy link
Contributor

@georgeciubotaru georgeciubotaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmontero18 basically that is the first part of the work, you need the second part where you will parse the API and generate such block defined now.

eg. https://github.com/holdex/holdex-venture-studio/pull/537/files#diff-281da5440e8b15fc8657ba9ec28a570ed1c72916bb929ca8c6874ca81321dbdeR95

@lmontero18 lmontero18 changed the title feat(backend): implement Google Doc parser for team member data feat(api): implement Google Doc parser for team member data Jan 22, 2025
@lmontero18
Copy link
Contributor Author

log: working on the parser for team members block

@lmontero18 lmontero18 marked this pull request as ready for review January 23, 2025 21:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
src/lib/components/BodyParser/blocks.ts (1)

124-135: Consider adding validation constraints to the type.

The TeamMembersBlock type looks good, but consider adding constraints for required fields:

  • Maximum length for text fields (name, role, description)
  • URL validation for image and link fields
src/routes/api/google-conversion/+server.ts (1)

94-122: Simplify nested conditionals in table content handling.

The nested conditionals make the code harder to read and maintain. Consider extracting the content type detection into a separate function.

+function detectContentType(tableContent: any[]) {
+  const types = {
+    teamMembers: parseTeamMembersSection(tableContent),
+    cta: parseCTASection(tableContent),
+    testimonial: parseTestimonialSection(tableContent),
+  };
+
+  return Object.entries(types).find(([_, content]) => !_.isEmpty(content));
+}

-const teamMembers = parseTeamMembersSection(tableContent);
-const cta: CTAElement = parseCTASection(tableContent);
-const testimonial: TestimonialElement = parseTestimonialSection(tableContent);

-if (!_.isEmpty(teamMembers)) {
-  newContent.push({
-    type: 'teamMembers',
-    data: teamMembers,
-  });
-  if (!_.isEmpty(testimonial)) {
-    newContent.push({
-      type: 'testimonial',
-      data: testimonial,
-    });
-  } else if (!_.isEmpty(cta)) {
-    newContent.push({
-      type: 'cta',
-      data: cta,
-    });
-  } else {
-    newContent.push({
-      type: 'table',
-      data: {
-        content: tableContent,
-      },
-    });
-  }
-}

+const contentType = detectContentType(tableContent);
+if (contentType) {
+  const [type, data] = contentType;
+  newContent.push({ type, data });
+} else {
+  newContent.push({
+    type: 'table',
+    data: { content: tableContent },
+  });
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4389fcc and 9faf16c.

📒 Files selected for processing (3)
  • src/lib/components/BodyParser/blocks.ts (3 hunks)
  • src/routes/(pages)/about/template.pug (2 hunks)
  • src/routes/api/google-conversion/+server.ts (5 hunks)
🔇 Additional comments (1)
src/routes/(pages)/about/template.pug (1)

Line range hint 3-12: LGTM! Clean template structure.

The template follows good practices with proper navigation hierarchy and semantic HTML structure.

src/lib/components/BodyParser/blocks.ts Show resolved Hide resolved
src/routes/api/google-conversion/+server.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@georgeciubotaru georgeciubotaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@zolotokrylin zolotokrylin changed the title feat(api): implement Google Doc parser for team member data feat(api): parse Team Member data from Google Doc Jan 24, 2025
@lmontero18
Copy link
Contributor Author

log: working on the suggestions

@lmontero18 lmontero18 marked this pull request as draft January 24, 2025 20:07
@matthewvogas
Copy link
Contributor

@lmontero18 pls update the ETA

@lmontero18 lmontero18 marked this pull request as ready for review January 27, 2025 17:55
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

♻️ Duplicate comments (1)
src/routes/api/google-conversion/+server.ts (1)

221-264: ⚠️ Potential issue

Enhance error handling and data validation.

The current implementation lacks proper error handling and data validation. Consider implementing the following improvements:

Apply this diff to improve the implementation:

 function parseTeamMembersSection(content: any[]): TeamMembersBlock | null {
+  try {
     const teamMembersBlock: TeamMembersBlock = {
       type: 'teamMember',
       data: {
         members: [],
       },
     };
 
     if (content.length >= 5 && (content[0] as any[]).length === 2) {
       const contentHead = content[0];
 
       if (
         contentHead[0][0]?.type === 'paragraph' &&
         contentHead[0][0]?.data?.text === 'type' &&
         contentHead[1][0]?.type === 'paragraph' &&
         contentHead[1][0]?.data?.text === 'teamMember'
       ) {
         content.forEach(([[first], [second]], i) => {
           if (first === undefined || first.type !== 'paragraph') return;
 
           const rowData: Record<string, string> = {};
           if (second && second.type === 'paragraph') {
             rowData[first.data.text] = second.data.text;
           }
 
-          if (rowData.name && rowData.role) {
+          // Validate required fields
+          if (!rowData.name?.trim() || !rowData.role?.trim()) {
+            console.warn(`Skipping member at row ${i}: missing required fields`);
+            return;
+          }
+
           teamMembersBlock.data.members.push({
-            name: rowData.name || '',
-            role: rowData.role || '',
-            description: rowData.description || '',
+            name: rowData.name.trim(),
+            role: rowData.role.trim(),
+            description: (rowData.description || '').trim(),
             image: rowData.image || '',
-            link: rowData.link || undefined,
+            link: rowData.link?.trim() || undefined,
           });
-          }
         });
 
         if (teamMembersBlock.data.members.length > 0) {
           return teamMembersBlock;
         }
       }
     }
 
     return null;
+  } catch (error) {
+    console.error('Error parsing team members section:', error);
+    return null;
+  }
 }
🧹 Nitpick comments (1)
src/routes/api/google-conversion/+server.ts (1)

107-129: Simplify the nested conditional structure.

The current implementation has deeply nested if-else statements that make the code hard to maintain. Consider refactoring to a more flat structure using early returns or a switch-case pattern.

-        if (!_.isEmpty(teamMembers)) {
-          newContent.push({
-            type: 'teamMember',
-            data: teamMembers,
-          });
-          if (!_.isEmpty(testimonial)) {
-            newContent.push({
-              type: 'testimonial',
-              data: testimonial,
-            });
-          } else if (!_.isEmpty(cta)) {
-            newContent.push({
-              type: 'cta',
-              data: cta,
-            });
-          } else {
-            newContent.push({
-              type: 'table',
-              data: {
-                content: tableContent,
-              },
-            });
-          }
-        }
+        // Process special blocks in order of priority
+        if (!_.isEmpty(teamMembers)) {
+          newContent.push({ type: 'teamMember', data: teamMembers });
+          return;
+        }
+        
+        if (!_.isEmpty(testimonial)) {
+          newContent.push({ type: 'testimonial', data: testimonial });
+          return;
+        }
+        
+        if (!_.isEmpty(cta)) {
+          newContent.push({ type: 'cta', data: cta });
+          return;
+        }
+        
+        // Default to table if no special blocks are found
+        newContent.push({
+          type: 'table',
+          data: { content: tableContent }
+        });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf781f7 and eb14371.

📒 Files selected for processing (1)
  • src/routes/api/google-conversion/+server.ts (8 hunks)
🔇 Additional comments (1)
src/routes/api/google-conversion/+server.ts (1)

Line range hint 1-671: Verify type consistency and integration.

Please verify:

  1. The TeamMembersBlock type matches the schema used in the frontend components
  2. The changes don't affect existing document conversion functionality

Run the following script to verify type consistency:

✅ Verification successful

Types and integration are consistent

The TeamMembersBlock type is properly defined and consistently used across the codebase. The conversion logic maintains data integrity and doesn't affect existing document conversion functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent type usage across the codebase

# Check TeamMembersBlock type usage
echo "Checking TeamMembersBlock type usage:"
rg -A 5 "TeamMembersBlock"

# Check team member block rendering
echo "Checking team member block rendering:"
rg -A 5 "type: 'teamMember'"

Length of output: 3088

🧰 Tools
🪛 Biome (1.9.4)

[error] 268-268: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@lmontero18
Copy link
Contributor Author

@matthewvogas you can also check, It'll help!

Copy link
Contributor

@matthewvogas matthewvogas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove allways PR Inits comments

src/routes/(pages)/about/template.pug Outdated Show resolved Hide resolved
Copy link
Contributor

@georgeciubotaru georgeciubotaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmontero18 based on the https://holdex-venture-studio-git-feat-parsing-data-holdex-accelerator.vercel.app/api/google-conversion POST request I made I cannot see the teamMember object using the JSON I provided. please double check.

Also provide in 1 comment the files for @matthewvogas to also test that

@lmontero18 lmontero18 marked this pull request as draft January 28, 2025 19:26
@lmontero18
Copy link
Contributor Author

log: working on the changes

@matthewvogas
Copy link
Contributor

@lmontero18 pls update the eta based in your locatio - add CR time or utc -6 to know about the ETA withou doubts

Copy link
Contributor

@georgeciubotaru georgeciubotaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmontero18 let's wrap it up quickly, as too much time takes

@lmontero18 lmontero18 marked this pull request as draft January 30, 2025 20:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/routes/api/google-conversion/+server.ts (2)

Line range hint 104-128: Enhance validation and error handling for table content processing.

While the integration works, consider improving the validation:

  1. Add explicit type checking before parsing
  2. Consider logging parsing errors for debugging
  3. Use more specific empty checks instead of _.isEmpty
-        const teamMembers = parseTeamMembersSection(tableContent);
-        const cta: CTAElement = parseCTASection(tableContent);
-        const testimonial: TestimonialElement = parseTestimonialSection(tableContent);
-
-        if (!_.isEmpty(teamMembers)) {
+        try {
+          const teamMembers = parseTeamMembersSection(tableContent);
+          const cta: CTAElement = parseCTASection(tableContent);
+          const testimonial: TestimonialElement = parseTestimonialSection(tableContent);
+
+          if (teamMembers && teamMembers.length > 0) {
             newContent.push(teamMembers);
-        } else if (!_.isEmpty(testimonial)) {
+          } else if (testimonial && Object.keys(testimonial).length > 0) {
             newContent.push({
               type: 'testimonial',
               data: testimonial,
             });
-        } else if (!_.isEmpty(cta)) {
+          } else if (cta && Object.keys(cta).length > 0) {
             newContent.push({
               type: 'cta',
               data: cta,
             });
           } else {
             newContent.push({
               type: 'table',
               data: {
                 content: tableContent,
               },
             });
           }
+        } catch (error) {
+          console.error('Error processing table content:', error);
+          newContent.push({
+            type: 'table',
+            data: {
+              content: tableContent,
+            },
+          });
+        }

447-447: Improve type safety in parseParagraphElement function.

The wrappingTable parameter could benefit from better typing to make its purpose clearer.

 const parseParagraphElement = (
   document: Schema$Document,
   tag: string,
   parentContent: (Parsed$Paragraph | Parsed$ParagraphElement)[],
   element: Schema$ParagraphElement,
-  wrappingTable: boolean | undefined = undefined
+  options: {
+    wrappingTable?: boolean;
+    isCtaLink?: boolean;
+  } = {}
 ) => {
   // ... rest of the function
   getText(element, {
     isHeader: tag !== 'p',
-    isCtaLink: wrappingTable,
+    isCtaLink: options.wrappingTable,
   })
 };

Also applies to: 627-629

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d07a03c and 45d75bb.

📒 Files selected for processing (1)
  • src/routes/api/google-conversion/+server.ts (9 hunks)
🔇 Additional comments (2)
src/routes/api/google-conversion/+server.ts (2)

19-29: LGTM! Clean import organization.

The imports are well-structured and correctly separated between types and components.


Line range hint 1-671: Verify edge cases in the document conversion process.

Please ensure the following scenarios are tested:

  1. Google Doc with mixed content (team members, testimonials, and CTAs)
  2. Empty or malformed table structures
  3. Missing or invalid field values

Run this script to analyze the conversion process:

✅ Verification successful

Document conversion process handles edge cases appropriately

The code implements robust error handling through:

  • Extensive null checks and optional chaining
  • Validation of required fields before processing
  • Graceful handling of missing or malformed data
  • Type-safe conversions with proper fallbacks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze the document conversion process for edge cases

# Test 1: Search for error handling patterns
echo "Checking error handling patterns..."
rg -n 'try|catch|throw|error|warn' src/routes/api/google-conversion/

# Test 2: Search for type validations
echo "Checking type validations..."
rg -n 'typeof|instanceof|Array.isArray' src/routes/api/google-conversion/

# Test 3: Search for null checks
echo "Checking null checks..."
rg -n '\?\.|===?\s*(null|undefined)|isEmpty' src/routes/api/google-conversion/

Length of output: 5530

🧰 Tools
🪛 Biome (1.9.4)

[error] 268-268: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/routes/api/google-conversion/+server.ts Show resolved Hide resolved
Copy link

pr-time-tracker bot commented Jan 30, 2025

@georgeciubotaru
@matthewvogas
⚠️⚠️⚠️
You must submit the time spent on this PR.
⚠️⚠️⚠️

@lmontero18
Copy link
Contributor Author

@georgeciubotaru could you please review? thanks!

Copy link

@georgeciubotaru
@matthewvogas
⚠️⚠️⚠️
You must submit the time spent on this PR.
⚠️⚠️⚠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants