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

Change slug usage to encoded text #261

Merged
merged 6 commits into from
Aug 2, 2024

Conversation

minai621
Copy link
Contributor

@minai621 minai621 commented Jul 30, 2024

What this PR does / why we need it:
This PR changes the method of handling text from using slugs to using encoded text. The previous slug generation method did not support all languages and returned empty strings when special characters like emojis were included. By switching to encoded text, we ensure compatibility with any type of text input.

Which issue(s) this PR fixes:

Fixes #209

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

The method for handling workspace names has been changed from slug generation to encoded text to support all languages and special characters.

Additional documentation:


Checklist:

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

Summary by CodeRabbit

  • New Features

    • Enhanced validation for nickname and title fields in the creation modal, requiring a minimum of 2 characters.
  • Bug Fixes

    • Improved handling of special characters in workspace and user nicknames by replacing the slugify function with encodeURIComponent, ensuring more accurate conflict detection and URL safety.
  • Refactor

    • Cleaned up import statements across various services for better organization and clarity.

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

Recent changes in the project enhance name handling and conflict detection in backend services, significantly improving support for non-English characters. The slugify package has been replaced with encodeURIComponent, allowing for better encoding of names and workspace slugs. Additionally, frontend validation has been strengthened to ensure that nicknames and titles meet minimum length requirements, facilitating smoother workspace creation.

Changes

File Change Summary
backend/package.json Removed slugify from dependencies; retained rxjs.
backend/src/check/check.service.ts Replaced slugify with encodeURIComponent in the checkNameConflict method to enhance name conflict detection.
backend/src/users/users.service.ts Updated nickname processing to use encodeURIComponent instead of slugify, improving handling of special characters.
backend/src/workspaces/workspaces.controller.ts Modified findOneBySlug to use encodeURIComponent(workspaceSlug) for better slug encoding.
backend/src/workspaces/workspaces.service.ts Changed workspace slug generation from slugify to encodeURIComponent(title), affecting how workspace identifiers are created.
frontend/src/components/modals/CreateModal.tsx Enhanced validation logic for nickname and title fields, requiring a minimum length of 2 characters for successful submission.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CreateModal
    participant UsersService
    participant WorkspacesService

    User->>CreateModal: Submit Workspace
    CreateModal->>UsersService: Validate Nickname & Title
    UsersService-->>CreateModal: Validation Result
    CreateModal->>WorkspacesService: Create Workspace
    WorkspacesService-->>CreateModal: Workspace Created
    CreateModal->>User: Display Success Message
Loading

Assessment against linked issues

Objective Addressed Explanation
Handle non-English characters in workspace slugs (#[209])
Ensure slug creation process handles special characters (#[209])
Improve user input validation for workspace creation (#[209])

Poem

🐰 In a garden where the bytes do play,
A rabbit hops to save the day!
With encodeURIComponent, oh what a sight,
Non-English names can now take flight!
Validation sings, no more strife,
Creating workspaces, a joyous life! 🌷


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e184d24 and 7f6b281.

Files ignored due to path filters (1)
  • backend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (6)
  • backend/package.json (1 hunks)
  • backend/src/check/check.service.ts (2 hunks)
  • backend/src/users/users.service.ts (3 hunks)
  • backend/src/workspaces/workspaces.controller.ts (3 hunks)
  • backend/src/workspaces/workspaces.service.ts (2 hunks)
  • frontend/src/components/modals/CreateModal.tsx (5 hunks)
Files skipped from review due to trivial changes (1)
  • backend/package.json
Additional comments not posted (9)
backend/src/users/users.service.ts (2)

97-97: LGTM! Verify the usage of encodedText in the codebase.

The change from slugify to encodeURIComponent ensures proper encoding of special characters.

However, ensure that all occurrences of encodedText are correctly used in database operations.

Verification successful

LGTM!

The change from slugify to encodeURIComponent ensures proper encoding of special characters. The encodedText variable is correctly used in various database operations.

  • Lines involving encodedText:
    • slug: encodedText
    • OR: [{ nickname: name }, { nickname: encodedText }]
    • OR: [{ title: name }, { title: encodedText }]
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of `encodedText` in the codebase.

# Test: Search for the variable usage. Expect: Proper usage in database operations.
rg --type typescript -A 5 $'encodedText'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify all occurrences of `encodedText` in the codebase.

# Find all TypeScript files and search for the variable usage. Expect: Proper usage in database operations.
fd --type f --extension ts --exec rg 'encodedText' {}

Length of output: 287


106-106: LGTM! Verify the workspace creation logic.

The change ensures that workspace slugs are correctly encoded using encodedText.

However, ensure that the workspace creation logic handles the encoded text properly.

Verification successful

Verified: The slug is correctly assigned encodedText in the backend/src/users/users.service.ts file, ensuring proper handling of the encoded text in the workspace creation logic.

  • backend/src/users/users.service.ts: slug: encodedText
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the workspace creation logic for handling `encodedText`.

# Test: Search for the workspace creation logic. Expect: Proper handling of `encodedText`.
rg --type typescript -A 5 $'this.prismaService.workspace.create'

Length of output: 98


Script:

#!/bin/bash
# Description: Verify the workspace creation logic for handling `encodedText`.

# Test: Search for the workspace creation logic. Expect: Proper handling of `encodedText`.
rg --type ts -A 5 $'this.prismaService.workspace.create'

Length of output: 818


Script:

#!/bin/bash
# Description: Verify the `slug` assignment in `backend/src/users/users.service.ts`.

# Test: Search for `slug` assignment in `backend/src/users/users.service.ts`. Expect: Proper handling of `encodedText`.
rg --type ts -A 5 'slug' backend/src/users/users.service.ts

Length of output: 447

backend/src/check/check.service.ts (1)

18-18: LGTM! Verify the usage of encodedText in the conflict checking logic.

The change from slugify to encodeURIComponent ensures proper encoding of special characters.

However, ensure that all occurrences of encodedText are correctly used in the conflict checking logic.

Verification successful

LGTM! Verify the usage of encodedText in the conflict checking logic.

The change from slugify to encodeURIComponent ensures proper encoding of special characters.

  • backend/src/check/check.service.ts:
    • Line 18: const encodedText = encodeURIComponent(name);
    • Line 21: OR: [{ nickname: name }, { nickname: encodedText }];
    • Line 26: OR: [{ title: name }, { title: encodedText }];

The occurrences of encodedText are correctly used in the conflict checking logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of `encodedText` in the conflict checking logic.

# Test: Search for the variable usage. Expect: Proper usage in conflict checking logic.
rg --type typescript -A 5 $'encodedText'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify all occurrences of `encodedText` in the conflict checking logic.

# Test: Search for the variable usage. Expect: Proper usage in conflict checking logic.
rg --type ts -A 5 $'encodedText'

Length of output: 1681

frontend/src/components/modals/CreateModal.tsx (4)

111-111: LGTM! Verify the button's disabled property logic.

The change ensures that the button is disabled if either errorMessage is present or the nickname length is less than 2.

However, ensure that the button's disabled property logic is consistent across the component.

Verification successful

The button's disabled property logic is consistent.

The disabled property is correctly set based on the presence of errorMessage or if the nickname length is less than 2. This ensures that the button is disabled under the intended conditions.

  • Verified that the logic is centralized and consistent within the CreateModal.tsx file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the button's `disabled` property logic in the component.

# Test: Search for button's `disabled` property logic. Expect: Consistent handling of `disabled` property.
rg --type tsx -A 5 $'disabled'

Length of output: 57


Script:

#!/bin/bash
# Description: Verify the button's `disabled` property logic in the CreateModal.tsx component.

# Test: Search for button's `disabled` property logic in the CreateModal.tsx file. Expect: Consistent handling of `disabled` property.
rg 'disabled' frontend/src/components/modals/CreateModal.tsx -A 5

Length of output: 209


56-59: LGTM! Verify the title length logic.

The change ensures that the title must have at least 2 characters before proceeding.

However, ensure that the title length logic is consistent across the component.

Verification successful

Verification Successful: Title length logic is consistent.

The title length check is only present in the CreateModal.tsx file, ensuring that the logic is not duplicated or inconsistent elsewhere in the codebase.

  • frontend/src/components/modals/CreateModal.tsx: if (data.title.length >= 2) { ... }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the title length logic in the component.

# Test: Search for title length logic. Expect: Consistent title length handling.
rg --type tsx -A 5 $'title.length'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the title length logic in the component.

# Test: Search for title length logic. Expect: Consistent title length handling.
rg --type ts -A 5 $'title.length'

Length of output: 404


Line range hint 61-63: LGTM! Verify the nickname state logic.

The change ensures that the nickname state is updated correctly.

However, ensure that the nickname state logic is consistent across the component.

Verification successful

Let's generate a new shell script to search for the setNickname function in the TypeScript component files without specifying the file type.


The nickname state logic is consistent.

The setNickname function is used appropriately to update the nickname state across various components, including CreateModal.tsx.

  • frontend/src/components/modals/CreateModal.tsx
  • frontend/src/components/modals/ChangeNicknameModal.tsx
  • frontend/src/pages/settings/profile/Index.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the nickname state logic in the component.

# Test: Search for nickname state logic. Expect: Consistent nickname state handling.
rg --type tsx -A 5 $'setNickname'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify the nickname state logic in the component.

# Test: Search for nickname state logic. Expect: Consistent nickname state handling.
rg 'setNickname' -A 5

Length of output: 3642


34-36: LGTM! Verify the error message logic.

The change ensures that the nickname must have at least 2 characters before proceeding.

However, ensure that the error message logic is consistent across the component.

Verification successful

Let's re-run the verification script by specifying the file extension directly to ensure we capture the error message logic.


To fully understand and verify the error message logic, we need to extract the complete useMemo hooks where errorMessage is being computed.


Verification Successful: Error Message Logic Consistent

The error message logic in CreateModal.tsx is consistent and correctly checks for both the nickname length and conflict conditions.

  • frontend/src/components/modals/CreateModal.tsx: The useMemo hook for errorMessage ensures that the nickname must be at least 2 characters long and checks for any conflicts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the error message logic in the component.

# Test: Search for error message logic. Expect: Consistent error message handling.
rg --type tsx -A 5 $'errorMessage'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the error message logic in the component.

# Find all .tsx files and search for errorMessage logic within those files.
fd -e tsx -x rg 'errorMessage' {}

Length of output: 628


Script:

#!/bin/bash
# Description: Extract the complete useMemo hooks for errorMessage computation.

# Search for useMemo hooks and include surrounding lines for context.
rg 'useMemo' -A 10 -B 2

Length of output: 31877

backend/src/workspaces/workspaces.service.ts (1)

33-33: LGTM! Verify the impact on URL routing and workspace identification.

The change to use encodeURIComponent for generating slugs enhances compatibility with special characters. Ensure that this change does not introduce any issues with URL routing or workspace identification.

backend/src/workspaces/workspaces.controller.ts (1)

71-71: LGTM! Verify the impact on URL routing and workspace identification.

The change to use encodeURIComponent for the workspaceSlug parameter enhances compatibility with special characters. Ensure that this change does not introduce any issues with URL routing or workspace identification.

@devleejb devleejb self-requested a review July 31, 2024 11:44
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.

And we have to add validation check in CreateWorkspaceDto and ChangeNicknameDto.

Validation Docs: https://docs.nestjs.com/techniques/validation

@@ -102,7 +108,7 @@ function CreateModal(props: CreateModalProps) {
type="submit"
variant="contained"
size="large"
disabled={Boolean(errorMessage)}
disabled={Boolean(errorMessage) || nickname.length < 2}
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant.
When nickname.length < 2, errorMessage already exists.

Copy link
Contributor Author

@minai621 minai621 Jul 31, 2024

Choose a reason for hiding this comment

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

Thanks. I think it's right to check that the error message exists.

@minai621
Copy link
Contributor Author

And we have to add validation check in CreateWorkspaceDto and ChangeNicknameDto.

Validation Docs: https://docs.nestjs.com/techniques/validation

Could you let me know which parts need validation?

@devleejb
Copy link
Member

And we have to add validation check in CreateWorkspaceDto and ChangeNicknameDto.
Validation Docs: https://docs.nestjs.com/techniques/validation

Could you let me know which parts need validation?

For workspace title and user nickname should be checked both frontend in backend.

For example, in CreateWorkspaceDto

@ApiProperty({ description: "Title of project to create", type: String, maxLength: 2 })
@MinLength(2)
title: string;

(It also should be applied to swagger.)

@minai621 minai621 requested a review from devleejb July 31, 2024 14:43
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7f6b281 and ec9774f.

Files selected for processing (3)
  • backend/src/users/dto/change-nickname.dto.ts (1 hunks)
  • backend/src/workspaces/dto/create-workspace.dto.ts (1 hunks)
  • frontend/src/components/modals/CreateModal.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/modals/CreateModal.tsx
Additional comments not posted (4)
backend/src/workspaces/dto/create-workspace.dto.ts (2)

2-2: LGTM! Import statement is necessary.

The MinLength decorator from the class-validator library is correctly imported to enforce the minimum length constraint.


5-6: LGTM! Enhanced validation and documentation for the title property.

The @ApiProperty decorator now includes the minLength attribute, and the @MinLength(2) decorator ensures the title has a minimum length of 2 characters.

backend/src/users/dto/change-nickname.dto.ts (2)

2-2: LGTM! Import statement is necessary.

The MinLength decorator from the class-validator library is correctly imported to enforce the minimum length constraint.


5-6: LGTM! Enhanced validation and documentation for the nickname property.

The @ApiProperty decorator now includes the minLength attribute, and the @MinLength(2) decorator ensures the nickname has a minimum length of 2 characters.

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 1d5e8e4 into yorkie-team:main Aug 2, 2024
3 checks passed
@devleejb devleejb added this to the v0.1.1 milestone Aug 3, 2024
@injae-kim
Copy link

Nice improvement @minai621! 👍👍

minai621 added a commit that referenced this pull request Nov 5, 2024
* Chore remove slugify

* Feat change slug to encoding text

* Feat decoded workspace_slug to encoding back

* Feat Add validate title length in CreateModal

* Refactor remove duplicated error check

* Feat update validation for nickname and title length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Unable to Access Workspace when Creating a Workspace with non-English Language
3 participants