Closed jacob-ai-bot[bot] closed 2 days ago
Hello human! 👋
This PR was created by JACoB to address the issue Add 'Research' Tab to Code Visualizer to Display Project-Level Research Items
Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.
If you identify code that needs to be changed, please reject the PR with a specific reason. Be as detailed as possible in your comments. JACoB will take these comments, make changes to the code and push up changes. Please note that this process will take a few minutes.
Once the code looks good, approve the PR and merge the code.
Summary:
Description
Enhance the Code Visualizer by adding a new 'Research' tab to the top navigation bar, alongside the existing 'Folder' and 'Architecture' tabs.
When a user clicks on the 'Research' tab:
Backend:
todo
router.todoId
is0
.issueId
is0
.projectId
matches the current project.Frontend:
Research
component from the To-Do details section./src/app/dashboard/[org]/[repo]/todos/components/Research.tsx
and/src/app/dashboard/[org]/[repo]/todos/components/TodoDetails.tsx
for implementation details."Research items are being generated. Please check again in a few minutes."
Expected Outcome
Research
component.Plan:
Step 1: Edit
/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseVisualizer.tsx
Task: Add 'Research' tab to CodebaseVisualizer navigation bar and handle 'research' view mode
Instructions: In the file '/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseVisualizer.tsx', modify the 'viewMode' state to include 'research' as an additional option. Update the type definition for 'viewMode' to '"folder" | "taxonomy" | "research"'. Add a new button labeled 'Research' in the navigation bar alongside the existing 'Folder' and 'Architecture' tabs. The button should have similar styling and functionality as the existing tabs, and should call 'handleViewModeChange("research")' when clicked.
Implement the logic to handle the 'research' view mode in the component. When 'viewMode' is 'research', do not render the 'Tree' component. Instead, fetch the project-level research items using the TRPC client to call the 'getProjectResearch' endpoint (to be created in another step). Use the 'projectId' prop passed to the component to make the request. Manage loading and error states appropriately.
If research items are available, render them using the existing 'Research' component imported from '/src/app/dashboard/[org]/[repo]/todos/components/Research'. Map over the research items and render each one using the 'Research' component. Add the 'max-w-5xl' class and center the research content on the page. Start with the research items collapsed by default. Use the same meadow gradient background as seen in the 'TodoDetails' component.
If no research items are available, display a friendly message: 'Research items are being generated. Please check again in a few minutes.'
Ensure that the component is correctly importing all required dependencies and that 'use client' is declared at the top of the file.
Exit Criteria: The 'Research' tab is added to the navigation bar. Clicking the 'Research' tab displays project-level research items using the existing 'Research' component, styled consistently with the 'TodoDetails' component. If no research items are available, a friendly message is displayed. The component handles the 'research' view mode correctly.
Step 2: Edit
/src/app/dashboard/[org]/[repo]/code-visualizer/Codebase.tsx
Task: Update Codebase.tsx to fetch project ID and pass it to CodebaseVisualizer
Instructions: In the file '/src/app/dashboard/[org]/[repo]/code-visualizer/Codebase.tsx', modify the component to fetch the project ID based on the 'org' and 'repo' parameters. Import 'api.projects.getByOrgRepo' from the TRPC client. Use 'api.projects.getByOrgRepo.useQuery' with 'org' and 'repo' to fetch the project data.
Handle loading and error states appropriately. If the project data is still loading or not available, display a loading indicator or appropriate message. Once the project data is available, extract the 'id' from the project data (e.g., 'const projectId = projectData.id') and pass it as a prop to the 'CodebaseVisualizer' component.
Ensure that the 'CodebaseVisualizer' component receives the 'projectId' prop and can use it to fetch research items.
Exit Criteria: 'Codebase.tsx' fetches the project ID based on 'org' and 'repo', handles loading and error states, and passes the 'projectId' to 'CodebaseVisualizer' as a prop.
Step 3: Edit
/src/server/api/routers/todos.ts
Task: Add 'getProjectResearch' endpoint to 'todo' router in TRPC
Instructions: In the file '/src/server/api/routers/todos.ts', add a new procedure to the 'todoRouter' TRPC router named 'getProjectResearch'. Import the 'z' object from 'zod' for input validation, and import the 'getOrCreateResearchForProject' function from the research agent file.
The 'getProjectResearch' procedure should accept an input object containing 'projectId' (number). Validate the input using 'z.object({ projectId: z.number() })'. Implement the procedure to:
Ensure proper error handling and input validation in the procedure.
Exit Criteria: The 'getProjectResearch' endpoint is available in the 'todo' TRPC router. It correctly fetches project-level research items and initiates their generation if none are available. The endpoint handles input validation and errors appropriately.