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

Add ability to rename projects #306

Merged
merged 4 commits into from
Jan 9, 2025
Merged

Conversation

nidhi-wa
Copy link
Contributor

@nidhi-wa nidhi-wa commented Jan 5, 2025

Description:

This PR introduces the ability to rename existing projects via a new PUT route (/projects/[projectId]) and updates the frontend to allow users to rename projects through the UI.
Currently, projects cannot be renamed after creation. This feature will allow users to update project names easily.

Changes Made

  1. Implemented a PUT Route for Renaming Projects:
  • - Route: /api/projects/[projectId]
  • - Functionality: Updates the project name in the database using Drizzle ORM.
  • - Logic: The request body must include the new name. If the project is not found or the name is missing, appropriate
    error responses are returned.
  1. Allows users to rename a project from the UI.

  2. Refactored DELETE Route:
    Removed redundant authentication lines, as they are now handled by middleware.

#300


Important

Adds functionality to rename projects via a new API route and UI component, and refactors DELETE route authentication.

  • API:
    • Adds PUT route in route.ts to rename projects using Drizzle ORM.
    • Handles missing name and project not found errors with appropriate responses.
  • UI:
    • Adds RenameProject component in rename-project.tsx for renaming projects via a dialog.
    • Integrates RenameProject into settings.tsx.
  • Misc:
    • Refactors DELETE route in route.ts to remove redundant authentication.

This description was created by Ellipsis for 757f01a. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 757f01a in 40 seconds

More details
  • Looked at 197 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. frontend/app/api/projects/[projectId]/route.ts:11
  • Draft comment:
    Consider adding validation for the name field to ensure it meets any necessary criteria (e.g., length, character restrictions) before proceeding with the update.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    While input validation is generally good practice, we don't have enough context about the project's requirements or the schema constraints. The validation rules would be arbitrary without knowing the actual requirements. The current null check provides basic validation, and database-level constraints would catch any serious issues.
    The comment suggests a reasonable security/validation practice. Not having proper input validation could lead to data quality issues.
    Without seeing the schema or requirements, suggesting specific validation would be speculative. The database schema likely already has constraints, and we shouldn't duplicate them without good reason.
    Delete the comment as it's speculative without context and could lead to arbitrary validation rules that may conflict with actual requirements or existing database constraints.
2. frontend/components/settings/rename-project.tsx:33
  • Draft comment:
    Consider adding a try-catch block around the fetch call to handle network errors gracefully.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment has merit since network errors would leave the UI in a bad state with perpetual loading. However, the code already has basic error handling. The improvement would be incremental rather than fixing a serious bug. The current error handling may be sufficient for the app's needs.
    I may be underestimating the importance of handling network errors properly. An uncaught error could cause other issues in the app.
    While network error handling is important, the existing error handling catches most cases and logs errors. The UI impact is limited since the dialog can be closed and reopened.
    The comment suggests a valid improvement but isn't critical enough to warrant keeping, given the existing error handling and limited impact of network errors in this context.

Workflow ID: wflow_OJmil0CHFtDVI3s4


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

window.location.reload();
} else {
// Handle error (e.g., show toast or error message)
console.error('Failed to rename project');
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider providing user feedback for errors, such as displaying a toast notification or an error message, instead of just logging to the console.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


export async function DELETE(
export async function PUT(
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you delete DELETE endpoint? Also, we prefer to use POST instead of PUT for updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I should not have to delete DELETE endpoint. Can you suggest me how to handle DELETE endpoint in absence of auth related lines since auth related lines are redundant? Should I directly perform the delete operation in the database?

I will convert PUT to POST in next commit.

Copy link
Member

Choose a reason for hiding this comment

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

just remove the auth-related lines in the route handler itself. This is already handled in middleware.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After removing auth-related lines in the route its just stop working. May be DELETE route rely on requiring apiKey or user session . if something I missing here please guide me .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve reverted the DELETE endpoint as per your feedback. Additionally, I’ve converted the previous PUT method to POST for updates.

Copy link
Member

Choose a reason for hiding this comment

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

I'll checkout to your repo/branch later this week to try and reproduce the auth-related issue. If I manage to get things working, I'll merge the rest, thanks

title: 'Project Renamed',
description: `Project renamed successfully!.`,
});
window.location.reload();
Copy link
Member

Choose a reason for hiding this comment

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

can we change this to router.refresh()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course! I can make that change to use router.refresh()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +51 to +52
});
router.refresh();
Copy link
Member

Choose a reason for hiding this comment

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

you should probably do setIsRenameDialogOpen(false) here. Now the dialog does not close on successful rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@dinmukhamedm dinmukhamedm left a comment

Choose a reason for hiding this comment

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

LGTM

@dinmukhamedm dinmukhamedm merged commit 29f2ba6 into lmnr-ai:dev Jan 9, 2025
1 check passed
@nidhi-wa
Copy link
Contributor Author

nidhi-wa commented Jan 9, 2025

Thank you for reviewing and merging my PR! I appreciate your time and feedback.

dinmukhamedm added a commit that referenced this pull request Jan 10, 2025
* Merge pull request #311 from lmnr-ai/fix/dashboard-tooltip

fix double conversion date in chart tooltip too

* Collapsable trace tree (#312)

* Add ability to rename projects (#306)

* Add ability to rename projects

* Added user feedback notifiaction and convert PUT to POST

* change to router.refresh

* add close dialog after rename

* Custom-formatter (#305)

---------

Co-authored-by: skull8888888 <skull8888888@gmail.com>
Co-authored-by: Nidhi Singh <120259299+nidhi-wa@users.noreply.github.com>
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