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

[WEB-2677] chore: draft issue issue type #5836

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Oct 15, 2024

Changes:
This PR includes issue type implementation for draft issues.

Reference:
[WEB-2677]

Summary by CodeRabbit

  • New Features

    • Introduced a new draft feature for issues, allowing users to create and manage draft issues.
    • Added an option to indicate whether an issue is a draft during creation or updates.
  • Bug Fixes

    • Improved form submission logic to ensure accurate data handling based on the issue's draft status.
  • Documentation

    • Updated type definitions to include the new isDraft property for better clarity and usability.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in this pull request introduce a new optional property isDraft across multiple components and types related to issue management. This property, defined as a boolean, is incorporated into the TIssueAdditionalPropertiesProps, TCreateUpdatePropertyValuesProps, and various component methods, allowing the system to distinguish between draft and non-draft issues. Additionally, modifications to function signatures and payload handling ensure that the draft status is appropriately managed during issue creation and updates.

Changes

File Path Change Summary
web/ce/components/issues/issue-modal/additional-properties.tsx Added optional property isDraft?: boolean to TIssueAdditionalPropertiesProps.
web/core/components/issues/issue-modal/base.tsx Updated CreateUpdateIssueModalBase methods to include isDraft parameter in issue handling.
web/core/components/issues/issue-modal/context/issue-modal.tsx Introduced optional property isDraft?: boolean to TCreateUpdatePropertyValuesProps.
web/core/components/issues/issue-modal/draft-issue-layout.tsx Modified DraftIssueLayout to include isDraft in handleCreateDraftIssue function.
web/core/components/issues/issue-modal/form.tsx Adjusted IssueFormRoot to manage isDraft in form submission and state handling.

Possibly related PRs

Suggested labels

🌟improvement

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham

Poem

🐰 In the meadow where ideas sprout,
A draft of change, we sing about.
With isDraft now, our issues gleam,
Creating pathways, a coder's dream!
Hops of joy in every line,
For every draft, a chance to shine! 🌼


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

🧹 Outside diff range and nitpick comments (1)
web/core/components/issues/issue-modal/base.tsx (1)

Line range hint 289-290: LGTM: Improved form submission handling

The changes in handleFormSubmit enhance the robustness of the form submission process:

  1. Making is_draft_issue a required parameter ensures explicit specification of the draft status.
  2. Removing sourceIssueId from the payload prevents sending unnecessary data.

These modifications align well with the PR objectives and improve the overall code quality.

Consider using object destructuring for cleaner code:

const { sourceIssueId, ...payloadWithoutSource } = payload;

This approach would create a new object payloadWithoutSource without the sourceIssueId property, making the removal more explicit and potentially easier to understand.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ff090ec and 432457d.

📒 Files selected for processing (5)
  • web/ce/components/issues/issue-modal/additional-properties.tsx (1 hunks)
  • web/core/components/issues/issue-modal/base.tsx (2 hunks)
  • web/core/components/issues/issue-modal/context/issue-modal.tsx (1 hunks)
  • web/core/components/issues/issue-modal/draft-issue-layout.tsx (1 hunks)
  • web/core/components/issues/issue-modal/form.tsx (5 hunks)
🧰 Additional context used
🔇 Additional comments (9)
web/ce/components/issues/issue-modal/additional-properties.tsx (2)

6-6: LGTM: Addition of isDraft property

The addition of the optional isDraft property to TIssueAdditionalPropertiesProps is appropriate and aligns with the PR objective of implementing a new issue type for draft issues. The boolean type is suitable for this flag, and making it optional ensures backward compatibility.


9-9: Verify the empty implementation of IssueAdditionalProperties

The IssueAdditionalProperties component is currently not utilizing any of the props defined in TIssueAdditionalPropertiesProps, including the newly added isDraft. Please confirm if this is intentional and if there are plans to implement this component in the future.

If this is a placeholder for future implementation, consider adding a TODO comment to make it clear for other developers. For example:

// TODO: Implement additional properties for issues, including draft status
export const IssueAdditionalProperties: React.FC<TIssueAdditionalPropertiesProps> = () => <></>;
web/core/components/issues/issue-modal/context/issue-modal.tsx (2)

25-25: LGTM: New isDraft property added to TCreateUpdatePropertyValuesProps

The addition of the optional isDraft property to the TCreateUpdatePropertyValuesProps type is consistent with the PR objectives of implementing a new issue type for draft issues. This change allows for the distinction between draft and non-draft issues during creation and updates.

However, to ensure consistency across the codebase:

✅ Verification successful

**** The isDraft property has been successfully added to TCreateUpdatePropertyValuesProps and is consistently used across the codebase. No additional updates are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the `isDraft` property is used consistently in other relevant types and functions.

# Test 1: Search for other occurrences of TCreateUpdatePropertyValuesProps
echo "Searching for other occurrences of TCreateUpdatePropertyValuesProps:"
rg --type typescript "TCreateUpdatePropertyValuesProps"

# Test 2: Search for uses of handleCreateUpdatePropertyValues to ensure they're updated if necessary
echo "Searching for uses of handleCreateUpdatePropertyValues:"
rg --type typescript "handleCreateUpdatePropertyValues"

# Test 3: Search for other types or interfaces that might need the isDraft property
echo "Searching for other types or interfaces that might need the isDraft property:"
rg --type typescript "type.*\{" -A 10 | rg "issue|Issue"

Length of output: 708


Script:

#!/bin/bash
# Description: Check if the `isDraft` property is used consistently in other relevant types and functions.

# Test 1: Search for other occurrences of TCreateUpdatePropertyValuesProps in TypeScript files
echo "Searching for other occurrences of TCreateUpdatePropertyValuesProps:"
rg -t ts -t tsx "TCreateUpdatePropertyValuesProps"

# Test 2: Search for uses of handleCreateUpdatePropertyValues to ensure they're updated if necessary
echo "Searching for uses of handleCreateUpdatePropertyValues:"
rg -t ts -t tsx "handleCreateUpdatePropertyValues"

# Test 3: Search for other types or interfaces that might need the isDraft property
echo "Searching for other types or interfaces that might need the isDraft property:"
rg -t ts -t tsx "type\s+\w+\s+\{" -A 10 | rg "issue|Issue"

Length of output: 679


Script:

#!/bin/bash
# Description: Check if the `isDraft` property is used consistently in other relevant types and functions.

# Test 1: Search for other occurrences of TCreateUpdatePropertyValuesProps in .ts and .tsx files
echo "Searching for other occurrences of TCreateUpdatePropertyValuesProps:"
rg "TCreateUpdatePropertyValuesProps" -g "*.ts" -g "*.tsx"

# Test 2: Search for uses of handleCreateUpdatePropertyValues to ensure they're updated if necessary
echo "Searching for uses of handleCreateUpdatePropertyValues:"
rg "handleCreateUpdatePropertyValues" -g "*.ts" -g "*.tsx"

# Test 3: Search for other types or interfaces that might need the isDraft property in .ts and .tsx files
echo "Searching for other types or interfaces that might need the isDraft property:"
rg "type\s+\w+\s+\{" -A 10 -g "*.ts" -g "*.tsx" | rg "issue|Issue"

Length of output: 1817


Line range hint 32-39: Verify implementation of handleCreateUpdatePropertyValues

The TIssueModalContext type includes a handleCreateUpdatePropertyValues function that uses the updated TCreateUpdatePropertyValuesProps type. Ensure that the implementation of this function (which is likely in another file) correctly handles the new isDraft property.

web/core/components/issues/issue-modal/draft-issue-layout.tsx (1)

145-145: LGTM with suggestions for improvement

The addition of isDraft: true to the handleCreateUpdatePropertyValues function call is appropriate for identifying the issue as a draft. However, there are a couple of points to consider:

  1. The isDraft prop is defined in the DraftIssueProps interface but not used in the component's parameters. For consistency, consider updating the component definition to include this prop:
export const DraftIssueLayout: React.FC<DraftIssueProps> = observer((props) => {
  const {
    // ... other props
    isDraft,
    // ... remaining props
  } = props;
  // ... rest of the component
});
  1. Ensure that the handleCreateUpdatePropertyValues function in the parent component or context correctly handles the isDraft property. You may want to verify its implementation to confirm that it processes this flag appropriately.

To verify the handling of the isDraft property, you can run the following script:

This script will help you locate the implementation of handleCreateUpdatePropertyValues and check if it properly handles the isDraft property.

web/core/components/issues/issue-modal/base.tsx (3)

207-207: LGTM: Proper handling of draft status in property values

The addition of the isDraft parameter to handleCreateUpdatePropertyValues ensures that the draft status is correctly handled when creating or updating issue property values. This change aligns well with the PR objective of implementing a new issue type for draft issues.


261-261: LGTM: Consistent handling of draft status in issue updates

The addition of the isDraft parameter to handleCreateUpdatePropertyValues in the handleUpdateIssue method ensures consistency in handling the draft status when updating issues. This change maintains alignment with the PR objective and the previous modification in handleCreateIssue.


Line range hint 1-368: Overall assessment: Changes are well-implemented and align with PR objectives

The modifications in this file consistently implement the handling of draft issues across different methods (handleCreateIssue, handleUpdateIssue, and handleFormSubmit). These changes align well with the PR objective of introducing a new issue type for draft issues.

Key improvements:

  1. Consistent addition of isDraft parameter in relevant method calls.
  2. Explicit requirement of is_draft_issue parameter in handleFormSubmit.
  3. Removal of unnecessary sourceIssueId from the payload during form submission.

These changes enhance the robustness and clarity of the issue creation and update processes. The code quality is good, with only a minor suggestion for improvement in the handleFormSubmit method.

web/core/components/issues/issue-modal/form.tsx (1)

364-364: Verify necessity of passing isDraft prop

Passing isDraft={isDraft} to the IssueAdditionalProperties component may be unnecessary if the component doesn't utilize this prop. Unused props can lead to confusion and maintenance overhead.

Please confirm whether IssueAdditionalProperties requires the isDraft prop. If not, consider removing it to simplify the component's API.

@@ -352,7 +352,7 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
className={cn(
"px-5",
activeAdditionalPropertiesLength <= 4 &&
"max-h-[25vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
"max-h-[25vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consistent handling of container overflow

Similar to the previous comment, using max-h-[25vh] may lead to inconsistent behavior across devices. Removing fixed heights promotes a more fluid layout.

Update the className to allow content-driven sizing:

- "max-h-[25vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
+ "overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"max-h-[25vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
"overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"

@@ -393,7 +394,7 @@
tabIndex={getIndex("create_more")}
role="button"
>
<ToggleSwitch value={isCreateMoreToggleEnabled} onChange={() => { }} size="sm" />
<ToggleSwitch value={isCreateMoreToggleEnabled} onChange={() => {}} size="sm" />
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Handle toggle state within ToggleSwitch component

Currently, the ToggleSwitch has an empty onChange handler, and the state change is managed by the parent <div>. This approach can lead to unexpected behavior and complicates the component interaction.

It's better practice to handle the toggle state within the onChange prop of the ToggleSwitch component. Update the code as follows:

<div className="inline-flex items-center gap-1.5 cursor-pointer">
- <ToggleSwitch value={isCreateMoreToggleEnabled} onChange={() => {}} size="sm" />
+ <ToggleSwitch
+   value={isCreateMoreToggleEnabled}
+   onChange={() => onCreateMoreToggleChange(!isCreateMoreToggleEnabled)}
+   size="sm"
+ />
  <span className="text-xs">Create more</span>
</div>

Additionally, you can remove the onClick, onKeyDown, tabIndex, and role attributes from the parent <div> since the interaction is now handled within ToggleSwitch. This improves accessibility and aligns with React best practices.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<ToggleSwitch value={isCreateMoreToggleEnabled} onChange={() => {}} size="sm" />
<ToggleSwitch
value={isCreateMoreToggleEnabled}
onChange={() => onCreateMoreToggleChange(!isCreateMoreToggleEnabled)}
size="sm"
/>

Comment on lines +198 to +203
...getChangedIssuefields(formData, dirtyFields as { [key: string]: boolean | undefined }),
project_id: getValues<"project_id">("project_id"),
id: data.id,
description_html: formData.description_html ?? "<p></p>",
type_id: getValues<"type_id">("type_id"),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Ensure consistent inclusion of is_draft in submitData

In the handleFormSubmit function, the submitData object may not always include the is_draft property, which could lead to inconsistencies when submitting draft issues. While you conditionally add is_draft later, it's clearer and safer to include it explicitly during the submitData construction.

Consider modifying the submitData to always include the is_draft property:

const submitData = !data?.id
  ? formData
  : {
      ...getChangedIssuefields(formData, dirtyFields as { [key: string]: boolean | undefined }),
      project_id: getValues<"project_id">("project_id"),
      id: data.id,
      description_html: formData.description_html ?? "<p></p>",
      type_id: getValues<"type_id">("type_id"),
+     is_draft: formData.is_draft,
    };

This ensures that the draft status is consistently handled during updates.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
...getChangedIssuefields(formData, dirtyFields as { [key: string]: boolean | undefined }),
project_id: getValues<"project_id">("project_id"),
id: data.id,
description_html: formData.description_html ?? "<p></p>",
type_id: getValues<"type_id">("type_id"),
};
...getChangedIssuefields(formData, dirtyFields as { [key: string]: boolean | undefined }),
project_id: getValues<"project_id">("project_id"),
id: data.id,
description_html: formData.description_html ?? "<p></p>",
type_id: getValues<"type_id">("type_id"),
is_draft: formData.is_draft,
};

@@ -323,7 +323,7 @@
className={cn(
"pb-4 space-y-3",
activeAdditionalPropertiesLength > 4 &&
"max-h-[45vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
"max-h-[45vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid hardcoded height values for better responsiveness

Using fixed heights like max-h-[45vh] can cause layout issues on different screen sizes. This might limit the component's flexibility and affect user experience on various devices.

Consider using dynamic sizing or responsive design utilities to enhance adaptability:

- "max-h-[45vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
+ "overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"

This change allows the container to adjust its height based on content and screen size.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"max-h-[45vh] overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"
"overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-sm"

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