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

[Improvement] Create task and assign another team member #3353

Conversation

CREDO23
Copy link
Contributor

@CREDO23 CREDO23 commented Nov 20, 2024

Description

Fix #3130

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Current screenshots

Loom

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced task management with the ability to assign team members to tasks.
    • Introduced a multi-select component for selecting task assignees.
    • Added warning messages for task estimation and planning in the estimation modal.
    • New action to copy task links directly from the Kanban card menu.
  • Improvements

    • Streamlined task creation process with consistent naming conventions.
    • Refined logic for task estimation and planning feedback.
    • Improved user feedback during asynchronous operations.
  • Bug Fixes

    • Improved error handling and loading states for task operations.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes encompass modifications to several files, primarily focusing on enhancing task management functionalities. Key updates include the introduction of a taskAssignees state in the useTaskInput hook, allowing for the assignment of team members during task creation. The createTask function signatures across various components have been updated to reflect this addition, with taskName renamed to title. Additionally, the API functions have been streamlined by removing unnecessary parameters. Overall, these changes aim to improve the task creation process and user experience.

Changes

File Path Change Summary
.vscode/settings.json Minor formatting adjustments; no settings added or removed.
apps/web/app/hooks/features/useTaskInput.ts Added taskAssignees state; updated handleTaskCreation to include members and rename taskName to title.
apps/web/app/hooks/features/useTeamTasks.ts Renamed taskName to title and added members parameter to createTask.
apps/web/app/services/client/api/tasks.ts Updated createTeamTaskAPI to remove user parameter; minor formatting adjustments.
apps/web/components/pages/kanban/menu-kanban-card.tsx Renamed taskName to title; made TeamMembersSelect an exported function; added clipboard copy functionality.
apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx Renamed taskName to title in SearchTaskInput; added warnings for task estimation.
apps/web/lib/features/task/task-input.tsx Added AssigneesSelect component; updated task creation logic to include assignees.

Assessment against linked issues

Objective Addressed Explanation
Allow assignment of a task to another team member during creation (3130)

Possibly related PRs

Suggested reviewers

  • Cedric921

Poem

🐇 In the meadow, tasks do bloom,
With team members, there's more room.
Assignments made with just a click,
A joyful hop, the changes stick!
Let's create and share with glee,
Together, tasks are done, you see! 🌼


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.

@CREDO23 CREDO23 changed the title 3130 improvement create task assign another team member on create new task [Improvement] Create task and assign another team member Nov 20, 2024
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: 3

🧹 Outside diff range and nitpick comments (8)
apps/web/app/hooks/features/useTaskInput.ts (1)

155-167: Consider adding assignee validation

While the members array construction is logically sound, consider adding validation for:

  1. Duplicate member IDs in the array
  2. Maximum number of assignees allowed

Example implementation:

members: [
  ...(autoAssignTaskAuth && user?.employee.id ? [{id: user?.employee.id}] : []),
+ // Filter out duplicates and limit to MAX_ASSIGNEES
+ ...Array.from(new Set([...taskAssignees.current.map(a => a.id)]))
+   .slice(0, MAX_ASSIGNEES)
+   .map(id => ({id}))
]
apps/web/app/services/client/api/tasks.ts (2)

Line range hint 110-139: Add input validation and error handling.

Several improvements could enhance the robustness of this function:

  1. Input validation for required fields
  2. Error handling for API calls
  3. Cookie validation before use
  4. Input sanitization for user-provided content

Consider applying these improvements:

 export async function createTeamTaskAPI(body: Partial<ICreateTask> & { title: string }) {
   if (GAUZY_API_BASE_SERVER_URL.value) {
     const organizationId = getOrganizationIdCookie();
     const teamId = getActiveTeamIdCookie();
     const tenantId = getTenantIdCookie();
     const projectId = getActiveProjectIdCookie();
+    // Validate required cookies
+    if (!organizationId || !teamId || !tenantId || !projectId) {
+      throw new Error('Missing required organization context');
+    }
+
     const title = body.title.trim() || '';
+    // Validate title after trim
+    if (!title) {
+      throw new Error('Task title is required');
+    }

     const datas: ICreateTask = {
       description: '',
       teams: [
         {
           id: teamId
         }
       ],
       tags: [],
       organizationId,
       tenantId,
       projectId,
       estimate: 0,
       ...body,
       title // this must be called after ...body
     };

-    await post('/tasks', datas, { tenantId });
-    return getTeamTasksAPI(organizationId, tenantId, projectId, teamId);
+    try {
+      await post('/tasks', datas, { tenantId });
+      return getTeamTasksAPI(organizationId, tenantId, projectId, teamId);
+    } catch (error) {
+      // Log error for monitoring
+      console.error('Failed to create task:', error);
+      throw error;
+    }
   }

   return api.post<PaginationResponse<ITeamTask>>('/tasks/team', body);
 }

Line range hint 110-139: Consider standardizing the return type.

The function returns different response types based on GAUZY_API_BASE_SERVER_URL. This could lead to inconsistent handling in the consuming code.

Consider standardizing the return type to Promise<PaginationResponse<ITeamTask>> for both code paths:

 if (GAUZY_API_BASE_SERVER_URL.value) {
   // ... existing code ...
   await post('/tasks', datas, { tenantId });
-  return getTeamTasksAPI(organizationId, tenantId, projectId, teamId);
+  const response = await getTeamTasksAPI(organizationId, tenantId, projectId, teamId);
+  return response;
 }

-return api.post<PaginationResponse<ITeamTask>>('/tasks/team', body);
+const response = await api.post<PaginationResponse<ITeamTask>>('/tasks/team', body);
+return response;
apps/web/components/pages/kanban/menu-kanban-card.tsx (2)

204-204: LGTM! Well-structured component export.

The export of TeamMembersSelect component is a good architectural decision that promotes reusability. The implementation aligns well with the PR objective of improving task assignment functionality.

Consider creating a dedicated components directory for shared team-related components if more components become reusable in the future.


Line range hint 62-63: Track TODOs in issue tracker.

Several menu items have TODO comments with unimplemented functionality:

  • Estimate task
  • Change parent
  • Change relations
  • Set as next
  • Move to

Would you like me to create GitHub issues to track these TODOs? This will help ensure these features are properly implemented in future iterations.

Also applies to: 108-110, 115-117, 122-124, 129-131

apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (1)

594-594: Implement issue type selection to replace hardcoded 'Bug' value

The current implementation hardcodes all new tasks as 'Bug' type, which limits task categorization. This should be replaced with a proper issue type selection mechanism.

Would you like me to help implement the issue type selection feature? I can:

  1. Add an issue type dropdown component
  2. Integrate it with the task creation form
  3. Update the createTask payload to use the selected issue type
apps/web/lib/features/task/task-input.tsx (2)

829-830: Use strict equality operator '===' instead of '=='.

For type safety and to avoid unexpected type coercion, it's recommended to use '===' when comparing values in JavaScript/TypeScript.

Apply this diff:

- const authMember = useMemo(() => teamMembers.find(member => member.employee.user?.id == user?.id), [teamMembers, user?.id])
+ const authMember = useMemo(() => teamMembers.find(member => member.employee.user?.id === user?.id), [teamMembers, user?.id])

838-838: Update label to 'ASSIGNEES' for clarity in multi-select component.

Since users can select multiple assignees, updating the label to 'ASSIGNEES' will provide better context.

Apply this diff:

- <span>{t('common.ASSIGNEE')}</span>
+ <span>{t('common.ASSIGNEES')}</span>

Ensure that the corresponding translation key exists in your localization files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bc63849 and d9218d8.

📒 Files selected for processing (7)
  • .vscode/settings.json (1 hunks)
  • apps/web/app/hooks/features/useTaskInput.ts (3 hunks)
  • apps/web/app/hooks/features/useTeamTasks.ts (3 hunks)
  • apps/web/app/services/client/api/tasks.ts (1 hunks)
  • apps/web/components/pages/kanban/menu-kanban-card.tsx (2 hunks)
  • apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (1 hunks)
  • apps/web/lib/features/task/task-input.tsx (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
🔇 Additional comments (8)
apps/web/app/hooks/features/useTaskInput.ts (3)

67-67: LGTM: Well-typed state for task assignees

The taskAssignees ref is appropriately typed and initialized for storing assignee IDs.


241-241: LGTM: Consistent exposure of task assignees state

The taskAssignees ref is properly exposed in the hook's return value, maintaining consistency with other task-related refs and enabling the new assignment functionality.


Line range hint 67-241: Verify integration with AssigneesSelect component

The hook changes look good and support the new task assignment functionality. Let's verify the integration with the UI components.

✅ Verification successful

Integration between useTaskInput hook and AssigneesSelect component is properly implemented

The verification confirms that the integration is correctly implemented:

  • The taskAssignees ref is properly defined in useTaskInput hook
  • The AssigneesSelect component is correctly implemented in task-input.tsx and receives the required props
  • The integration flow works as expected:
    • Hook maintains assignees state via taskAssignees ref
    • Component receives and updates the assignees through the ref
    • Task creation includes assignees in the payload
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration between useTaskInput hook and AssigneesSelect component

# Check for AssigneesSelect component usage
echo "Checking for AssigneesSelect component usage..."
rg -l "AssigneesSelect.*taskAssignees"

# Check for taskAssignees usage in components
echo "Checking for taskAssignees usage in components..."
rg "useTaskInput.*taskAssignees"

Length of output: 331


Script:

#!/bin/bash
# Let's examine the task-input.tsx file to verify the integration
echo "Checking task-input.tsx content..."
cat "apps/web/lib/features/task/task-input.tsx"

# Let's also check for any AssigneesSelect component definition
echo -e "\nChecking for AssigneesSelect component definition..."
rg -l "AssigneesSelect"

# Let's look for any other files that might be using taskAssignees
echo -e "\nChecking for other taskAssignees usages..."
rg "taskAssignees" -A 3 -B 3

Length of output: 31189

apps/web/app/services/client/api/tasks.ts (2)

110-110: LGTM! Function signature simplified.

The removal of the user parameter aligns with the PR objective of allowing task assignment to other team members during creation.


Line range hint 110-139: Verify the impact of these changes on task assignment.

The removal of the user parameter suggests that task assignment is now handled differently. Let's verify this change doesn't break existing functionality.

✅ Verification successful

Task assignment is handled through team association, no issues found

Based on the code analysis:

  • Tasks are now created with team association (teams: [{ id: teamId }]) rather than individual user assignment
  • Task members are managed through the team membership as shown in the components (task?.members)
  • The UI components properly handle task assignees display and member management
  • The removal of the user parameter is consistent with this team-based approach
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the task creation and assignment flow

# Check for any references to the old createTeamTaskAPI signature
echo "Checking for old function signature usage..."
rg -l "createTeamTaskAPI.*user.*\)" 

# Check for task assignment handling in related components
echo "Checking task assignment handling..."
rg -l "taskAssignees|members.*task"

# Check for any potential breaking changes in test files
echo "Checking test files..."
fd -e test.ts -e spec.ts | xargs rg "createTeamTaskAPI"

Length of output: 1425


Script:

#!/bin/bash
# Let's analyze the task creation and assignment implementation

# Check the implementation details of task creation
echo "Checking task creation implementation..."
ast-grep --pattern 'export async function createTeamTaskAPI($$$)'

# Check for task assignees handling in the tasks API
echo "Checking task assignees handling..."
rg -A 5 "taskAssignees|assignedTo" apps/web/app/services/client/api/tasks.ts

# Check for task member assignment in related components
echo "Checking task member assignment in components..."
rg -A 5 "members.*task|assignees.*task" apps/web/lib/features/task/

Length of output: 2953


Script:

#!/bin/bash
# Let's check how tasks are updated and how members are assigned

# Check for task update endpoints and member assignment
echo "Checking task update implementations..."
rg -A 10 "updateTask|assignTask|addMember.*task" apps/web/app/services/client/api/tasks.ts

# Check the task interface to understand member structure
echo "Checking task interface definition..."
ast-grep --pattern 'interface ITask {
  $$$
}'

# Look for task member assignment mutations
echo "Checking task member assignment mutations..."
rg -A 5 "mutation.*task.*member|mutation.*assign.*task" apps/web/app/services/

Length of output: 1178

apps/web/app/hooks/features/useTeamTasks.ts (2)

Line range hint 292-312: LGTM! Function signature changes align with requirements.

The changes to the createTask function signature effectively support task assignment to other team members while improving naming consistency:

  • Renamed taskName to title for better consistency
  • Added members parameter to support team member assignment
  • Made projectId optional for flexibility

Line range hint 315-329: Verify API endpoint handling of members parameter.

The implementation correctly includes the members array in the API call. However, let's verify that the API endpoint properly handles the new parameter.

✅ Verification successful

Let me gather more information about the API endpoint and type definitions.


Based on the gathered information, I can now generate the final response:

API endpoint is properly configured to handle members parameter

The implementation is correct as:

  • The ICreateTask interface in apps/web/app/interfaces/ITask.ts properly defines the members field as members?: { id: string;[x: string]: any }[]
  • The createTeamTaskAPI function accepts a Partial<ICreateTask> parameter, which includes the members field
  • The type definition matches the usage in the code under review
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the API endpoint is prepared to handle the members parameter

# Search for API endpoint definition
rg -A 5 "createTeamTaskAPI|POST.*tasks" --type ts

# Search for related type definitions and interfaces
ast-grep --pattern 'interface $interface {
  $$$
  members?: { id: string }[];
  $$$
}'

Length of output: 1688


Script:

#!/bin/bash
# Search for ICreateTask interface definition and related types
ast-grep --pattern 'interface ICreateTask {
  $$$
}'

# Search for API implementation details
rg -A 10 "createTeamTaskAPI" --type ts --no-filename

Length of output: 5018

apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (1)

594-594: LGTM: Property rename aligns with API contract

The change from taskName to title in the task creation payload aligns with the API contract changes mentioned in the summary.

Let's verify the consistency of this property name change across the codebase:

✅ Verification successful

Property rename is consistent with API contract

The verification confirms that the change from taskName to title is correct. The createTask implementation in useTeamTasks.ts shows that the task creation payload uses title as the property name, and there are no remaining instances of taskName being used in task creation contexts. The change aligns with the existing API contract.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of taskName to ensure complete migration
# Expect: No instances of taskName in task creation/update operations

# Search for taskName in task-related operations
rg "taskName.*task.*create" -A 5 -B 5

# Search for title in task creation to confirm new usage
rg "title.*task.*create" -A 5 -B 5

Length of output: 1769


Script:

#!/bin/bash
# Let's search for taskName and title usage in task-related files more broadly
# First, find task-related files
fd -e ts -e tsx task

# Then search for taskName property in these files
rg "taskName.*:" --type ts --type tsx -A 2 -B 2

# Also search for title property in task contexts
rg "title.*:" --type ts --type tsx -A 2 -B 2

# Search for task creation/update mutations or API calls
ast-grep --pattern 'const createTask = $$$'
ast-grep --pattern 'mutation CreateTask($$$) { $$ }'

Length of output: 16386

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.

[Improvement] Create Task | Assign another team member on create new task
2 participants