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 modify document titles #342

Merged

Conversation

hugosandsjo
Copy link
Contributor

@hugosandsjo hugosandsjo commented Sep 10, 2024

What this PR does / why we need it:

Created the logic to update the document title after its created since it would create a better user experience. A title could be misspelled or the content and the needs of that document could change over time.

Which issue(s) this PR fixes:

Fixes #143

Special notes for your reviewer:

I am currently studying web development at YRGO in Gothenburg, Sweden, and this contribution is part of an open-source assignment for my coursework. Working on this issue has been an enjoyable and educational experience, and I appreciate the opportunity to contribute to this project.

I welcome any feedback you may have.

Additionally, I want to mention that although I was not initially assigned to this issue, I communicated with the original assignees in the comments, and they confirmed it was fine for me to proceed with the work.

Does this PR introduce a user-facing change?:


Created an input field in DocumentHeader.tsx where the user can submit the changes to the documents title.

Additional documentation:

Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new endpoint to update document titles within a workspace.
    • Added functionality for users to dynamically edit and update document titles in the UI.
    • Implemented a new mutation hook for handling document title updates.
  • Bug Fixes

    • Enhanced validation for document title updates to ensure non-empty strings.
  • Documentation

    • Improved API documentation for the new title update functionality.
  • Chores

    • Restructured component code for better readability and maintainability.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

The pull request introduces functionality for updating document titles in a NestJS application. It includes the creation of a Data Transfer Object (DTO) for title updates, a new PUT endpoint in the controller, and a corresponding service method. Frontend components are enhanced to manage document titles interactively. Additionally, a new mutation hook is added to facilitate the title update process.

Changes

Files Change Summary
backend/src/workspace-documents/dto/update-document-title.dto.ts Added UpdateDocumentTitleDto class with validation for document title updates.
backend/src/workspace-documents/workspace-documents.controller.ts Added a PUT endpoint for updating document titles, including necessary decorators and logic.
backend/src/workspace-documents/workspace-documents.service.ts Introduced updateTitle method for updating document titles in the service layer.
frontend/src/components/headers/DocumentHeader.tsx Enhanced document header for dynamic title management with state and event handlers.
frontend/src/hooks/api/types/document.d.ts Added UpdateDocumentRequest class to encapsulate title update requests.
frontend/src/hooks/api/workspaceDocument.ts Introduced useUpdateDocumentTitleMutation hook for handling title updates in the frontend.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Database

    User->>Frontend: Update Document Title
    Frontend->>Backend: PUT /workspace/:workspaceId/document/:documentId/title
    Backend->>Database: Find Document
    Database-->>Backend: Document Found
    Backend->>Database: Update Document Title
    Database-->>Backend: Title Updated
    Backend-->>Frontend: Success Response
    Frontend-->>User: Title Updated Successfully
Loading

Assessment against linked issues

Objective Addressed Explanation
Allow users to modify document titles (#143)
Ensure integrity of document title modifications (#143)

🐇 In the meadow where the documents play,
A title change brightens the day.
With a hop and a click, it’s easy to see,
How titles can dance, oh so joyfully!
Let’s celebrate this change, hooray! 🎉


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2fb4d0e and 9b61681.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (3)
  • backend/src/workspace-documents/workspace-documents.controller.ts (3 hunks)
  • backend/src/workspace-documents/workspace-documents.service.ts (1 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • backend/src/workspace-documents/workspace-documents.controller.ts
  • backend/src/workspace-documents/workspace-documents.service.ts
Additional comments not posted (6)
frontend/src/components/headers/DocumentHeader.tsx (6)

14-16: LGTM!

The new imports are necessary for the added functionality and look good.


29-32: LGTM!

The new imports are necessary for the added functionality and look good.


39-51: LGTM!

The new state variable, constants, and function are necessary for the added functionality and look good.


68-71: LGTM!

The new function is necessary for the added functionality and looks good.


73-82: LGTM!

The new validation rules are necessary for the added functionality and look good.


123-161: LGTM!

The new components and conditional rendering logic are necessary for the added functionality and look good.


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 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.

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Also, please resolve the merge conflict. A conflict occurred because another PR was merged. Feel free to ask if you're unsure how to proceed.

frontend/src/components/editor/Editor.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
@hugosandsjo
Copy link
Contributor Author

Thanks a lot for the feedback. Il look into it as soon as possible

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0a8c326 and 2fb4d0e.

Files selected for processing (6)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (0 hunks)
  • backend/src/workspace-documents/workspace-documents.controller.ts (3 hunks)
  • backend/src/workspace-documents/workspace-documents.service.ts (1 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (4 hunks)
  • frontend/src/hooks/api/workspaceDocument.ts (2 hunks)
Files not reviewed due to no reviewable changes (1)
  • backend/docker/docker-compose-full.yml
Files skipped from review as they are similar to previous changes (2)
  • backend/src/workspace-documents/workspace-documents.service.ts
  • frontend/src/hooks/api/workspaceDocument.ts
Additional context used
Gitleaks
backend/.env.development

8-9: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (7)
backend/src/workspace-documents/workspace-documents.controller.ts (1)

41-70: LGTM!

The new PUT endpoint for updating document titles is well-implemented and follows best practices. The code segment includes:

  • Appropriate endpoint route and method name
  • Clear and concise API documentation decorators
  • Correctly typed and named method parameters
  • Invocation of the service function with the appropriate parameters
  • Consistent response handling with the @ApiOkResponse decorator

The implementation enhances the functionality of the WorkspaceDocumentsController without introducing any apparent issues or inconsistencies.

frontend/src/components/headers/DocumentHeader.tsx (6)

14-16: LGTM!

The imports for Button, FormControl, and Typography components from @mui/material are necessary for the newly added UI components in the file.


18-18: LGTM!

The imports for useEffect and useState hooks from react are necessary for the newly added state management and side effects in the component.


29-32: LGTM!

The imports for FormContainer and TextFieldElement components from react-hook-form-mui, selectDocument and setDocumentData from ../../store/documentSlice, useUpdateDocumentTitleMutation from ../../hooks/api/workspaceDocument, and UpdateDocumentRequest from ../../hooks/api/types/document are necessary for the newly added form handling, state management, and API calls in the component.


39-51: LGTM!

The changes introduce necessary state management for the document store and the focus state of the title input field. The useUpdateDocumentTitleMutation hook is used to get the function for updating the document title, and the isEditingDisabled variable is used to disable editing when the user has a read-only share role. The handleFocus function is used to update the focus state when the title input field is focused. The code changes look good.


68-97: LGTM!

The handleDocumentTitleChange function updates the document title in the Redux store when the input field value changes, and the handleUpdateDocumentTitle function calls the updateDocumentTitle mutation to update the document title on the server and resets the focus state. The validationRules object defines the necessary validation rules for the document title input field. The code changes look good.


137-176: LGTM!

The changes introduce a new UI for displaying and updating the document title. If editing is disabled, a Typography component is rendered with the document title. If editing is enabled, a form is rendered with a TextFieldElement for the document title input field and a submit button. The form is implemented using the react-hook-form-mui library for form handling and validation, and the TextFieldElement component is configured with various props for validation, event handling, and UI customization. The submit button is conditionally rendered based on the focus state of the input field. The code changes look good.

backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
@hugosandsjo
Copy link
Contributor Author

I've addressed the comments you provided and look forward to your feedback.

Copy link
Contributor Author

@hugosandsjo hugosandsjo left a comment

Choose a reason for hiding this comment

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

Updated changes from review

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@devleejb devleejb merged commit 5913e92 into yorkie-team:main Sep 21, 2024
3 checks passed
minai621 pushed a commit that referenced this pull request Nov 5, 2024
* updating the document title works

* now fetches current document and displays its name as well

* feedback on submit updated

* removed codes

* fixed feedback

* fixed credentials

* update on feedback
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add functionality to modify document titles
2 participants