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

fix: improvements for project types. #5857

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

prateekshourya29
Copy link
Collaborator

@prateekshourya29 prateekshourya29 commented Oct 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced project dropdown functionality with updated project type handling.
    • Improved sidebar project list with user permission checks for actions.
  • Bug Fixes

    • Resolved issues related to project type inconsistencies across components and services.
  • Documentation

    • Updated method signatures and types to reflect changes in project type definitions.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces a significant update across several components and services, transitioning from using the IProject type to the TProject type. This change includes updates to prop types, variable types, method signatures, and import statements to ensure consistency in type usage. Additionally, user permission checks have been added to enhance functionality in the SidebarProjectsList component.

Changes

File Path Change Summary
web/core/components/dropdowns/project.tsx - Updated renderCondition prop type from IProject to TProject.
- Imported TProject from @/plane-web/types.
web/core/components/workspace/sidebar/projects-list.tsx - Updated joinedProjectsList type from IProject[] to TProject[].
- Updated handleOnProjectDrop to use TProject.
- Added imports for user permissions and TProject.
web/core/services/project/project.service.ts - Replaced IProject with TProject in method signatures for createProject, getProjects, getProject, and updateProject.
- Updated return types from Promise<IProject> to Promise<TProject>.
web/core/store/project/project.store.ts - Updated import path for TProject from @/plane-web/types/projects/projects to @/plane-web/types/projects.
web/helpers/project.helper.ts - Replaced IProject with TProject in multiple function signatures.
- Adjusted imports to include TProject and removed IProject.

Possibly related PRs

Suggested reviewers

  • SatishGandham
  • pushya22

🐰 In the meadow, we hop with glee,
Types have changed, as you can see!
From IProject to TProject, we cheer,
With clearer paths, our code is dear!
Permissions checked, all is bright,
Hooray for updates, oh what a sight! 🌼


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

🧹 Outside diff range and nitpick comments (7)
web/core/services/project/project.service.ts (3)

18-18: LGTM: Method signature updated correctly.

The createProject method signature has been updated to use Partial<TProject> as input and Promise<TProject> as output, which is consistent with the transition from IProject to TProject. This change maintains type safety and reflects the asynchronous nature of the operation.

Consider adding a JSDoc comment to describe the method's purpose and parameters for better documentation:

/**
 * Creates a new project in the specified workspace.
 * @param workspaceSlug - The slug of the workspace where the project will be created.
 * @param data - Partial project data for creation.
 * @returns A promise that resolves to the created project.
 */
async createProject(workspaceSlug: string, data: Partial<TProject>): Promise<TProject>

54-54: LGTM: Method signature updated correctly.

The updateProject method signature has been updated to use Partial<TProject> as input and Promise<TProject> as output, which is consistent with the transition from IProject to TProject. This change maintains type safety and reflects the asynchronous nature of the operation.

Consider adding a JSDoc comment to describe the method's purpose and parameters for better documentation:

/**
 * Updates an existing project in the specified workspace.
 * @param workspaceSlug - The slug of the workspace containing the project.
 * @param projectId - The ID of the project to update.
 * @param data - Partial project data for update.
 * @returns A promise that resolves to the updated project.
 */
async updateProject(workspaceSlug: string, projectId: string, data: Partial<TProject>): Promise<TProject>

Line range hint 1-165: Summary: Successful transition from IProject to TProject

The changes in this file consistently update the ProjectService class to use the TProject type instead of IProject. This transition improves type consistency across the project service and aligns with the broader changes in the PR.

Key points:

  1. Import statements have been updated correctly.
  2. Method signatures for createProject, getProjects, getProject, and updateProject have been updated to use TProject.
  3. The use of Partial<TProject> in input parameters allows for flexible project creation and updates.

These changes enhance type safety and maintain the existing functionality of the ProjectService class. The transition appears to be complete and correct for this file.

Consider adding JSDoc comments to the updated methods for improved documentation and developer experience.

web/helpers/project.helper.ts (1)

Line range hint 1-116: Overall assessment: Successful type transition with improved consistency.

The changes in this file successfully transition from IProject to TProject type, improving type consistency across the project. The logic of the functions remains unchanged, which is appropriate for this type of refactoring. The addition of EUserPermissions enum usage also enhances code readability and maintainability.

To ensure a smooth transition:

  1. Verify that all occurrences of IProject have been replaced with TProject throughout the codebase.
  2. Update any documentation or comments that may still reference IProject.
  3. Run comprehensive tests to catch any type-related issues that may have been introduced.

Consider creating a migration guide or updating the project's documentation to reflect this type change, especially if IProject was part of a public API.

web/core/components/workspace/sidebar/projects-list.tsx (3)

21-24: LGTM! Consider grouping related imports.

The addition of EUserPermissions, EUserPermissionsLevel, and TProject imports aligns with the PR objectives. These changes support the transition from IProject to TProject and enhance permission checks.

Consider grouping related imports together for better readability. For example:

import { EUserPermissions, EUserPermissionsLevel } from "@/plane-web/constants/user-permissions";
import { TProject } from "@/plane-web/types";

Line range hint 39-43: LGTM! Consider adding a comment for clarity.

The addition of isAuthorizedUser enhances permission control, aligning with the PR objectives. This constant is used to conditionally render UI elements, improving security and user experience.

Consider adding a brief comment explaining the purpose of isAuthorizedUser:

// Check if the user has admin or member permissions at the workspace level
const isAuthorizedUser = allowPermissions(
  [EUserPermissions.ADMIN, EUserPermissions.MEMBER],
  EUserPermissionsLevel.WORKSPACE
);

Line range hint 71-77: LGTM! Consider using type assertion for improved type safety.

The transition from IProject[] to TProject[] for joinedProjectsList is correctly implemented, aligning with the PR objectives.

For improved type safety, consider using a type assertion when pushing project details:

const joinedProjectsList: TProject[] = [];
joinedProjects.map((projectId) => {
  const projectDetails = getProjectById(projectId);
  if (projectDetails) joinedProjectsList.push(projectDetails as TProject);
});

This ensures that projectDetails is explicitly treated as TProject when added to the list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9530884 and 9cddaae.

📒 Files selected for processing (5)
  • web/core/components/dropdowns/project.tsx (2 hunks)
  • web/core/components/workspace/sidebar/projects-list.tsx (2 hunks)
  • web/core/services/project/project.service.ts (2 hunks)
  • web/core/store/project/project.store.ts (1 hunks)
  • web/helpers/project.helper.ts (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/core/store/project/project.store.ts
🧰 Additional context used
🔇 Additional comments (13)
web/core/services/project/project.service.ts (3)

8-9: LGTM: Import statement updated correctly.

The import statement has been updated to use TProject from @/plane-web/types, which is consistent with the transition from IProject to TProject throughout the file. This change supports better type consistency and maintainability.


38-38: LGTM: Return type updated correctly.

The getProjects method signature has been updated to return Promise<TProject[]>, which is consistent with the transition from IProject to TProject. This change maintains type safety for the array of projects returned by the method.


46-46: LGTM: Return type updated correctly.

The getProject method signature has been updated to return Promise<TProject>, which is consistent with the transition from IProject to TProject. This change maintains type safety for the single project returned by the method.

web/helpers/project.helper.ts (5)

3-3: LGTM: Import statements updated to reflect type changes.

The import statements have been correctly updated to accommodate the transition from IProject to TProject. The addition of EUserPermissions import suggests new functionality related to user permissions, which aligns with the PR objectives.

Also applies to: 7-7, 10-10


23-23: LGTM: Parameter type updated for consistency.

The parameter type for joinedProjects has been correctly updated from IProject[] to TProject[], maintaining consistency with the new type system.


54-54: LGTM: Function updated with improved type safety and readability.

The shouldRenderProject function has been successfully updated to use TProject type. Additionally, the use of EUserPermissions.MEMBER enum instead of a hardcoded value improves code readability and maintainability.

Also applies to: 57-57, 58-58


62-62: LGTM: Function signature updated for type consistency.

The shouldFilterProject function has been correctly updated to use the TProject type, maintaining consistency with the new type system while preserving the existing logic.

Also applies to: 68-68


99-99: LGTM: Function updated for type consistency. Verify usage across the codebase.

The orderProjects function has been correctly updated to use TProject[] for parameter and return types, maintaining consistency with the new type system.

To ensure that this change doesn't introduce any issues elsewhere in the codebase, please run the following verification script:

Also applies to: 101-101, 103-103, 104-104

web/core/components/dropdowns/project.tsx (4)

15-16: LGTM: Import statement for TProject added correctly.

The import statement for TProject from @/plane-web/types has been added correctly. This change aligns with the transition from IProject to TProject type.


Line range hint 1-238: Summary: TProject integration looks good, final verification recommended.

The changes to integrate TProject instead of IProject in the ProjectDropdown component look good. The import statement and prop type have been updated correctly. To ensure a smooth transition, please:

  1. Verify that all usages of renderCondition within the component are compatible with TProject.
  2. Confirm that getProjectById and all usages of projectDetails are compatible with TProject.
  3. Run a final type-check and build process to catch any potential type-related issues.

These steps will help ensure that the refactoring from IProject to TProject is complete and consistent throughout the component and its dependencies.


30-30: LGTM: Prop type updated to use TProject.

The renderCondition prop type has been correctly updated to use TProject instead of IProject. This change is consistent with the new import statement.

To ensure consistency, please verify that all usages of renderCondition within the component are compatible with the TProject type. Run the following script to check for any remaining references to IProject:


Line range hint 1-238: Verify compatibility of getProjectById and projectDetails with TProject.

While the prop type has been updated to use TProject, it's important to ensure that getProjectById from the useProject hook and all usages of projectDetails throughout the component are compatible with the TProject type.

Please run the following script to check the type definition of getProjectById and verify its compatibility with TProject:

If any incompatibilities are found, please update the relevant parts of the component to ensure full compatibility with TProject.

web/core/components/workspace/sidebar/projects-list.tsx (1)

Line range hint 1-324: Overall, the changes look good and align with the PR objectives.

The transition from IProject to TProject, addition of user permission checks, and related import changes have been implemented correctly. The suggestions provided are minor and aimed at improving code clarity and type safety.

Great job on maintaining consistency throughout the file while implementing these changes!

@SatishGandham SatishGandham merged commit 46302f4 into preview Oct 18, 2024
14 of 15 checks passed
@SatishGandham SatishGandham deleted the fix/project-types branch October 18, 2024 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants