Skip to content

feat: workspace home preference model#6300

Merged
sriramveeraghanta merged 5 commits intopreviewfrom
feat-home-preferences
Jan 3, 2025
Merged

feat: workspace home preference model#6300
sriramveeraghanta merged 5 commits intopreviewfrom
feat-home-preferences

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented Jan 2, 2025

Description

Created model and migration for storing home preferences.

Type of Change

  • Feature (non-breaking change which adds functionality)

Summary by CodeRabbit

  • New Features

    • Introduced Workspace Home Preference functionality with configurable widget settings
    • Added predefined widget key options for workspace home
  • Database Changes

    • Modified Page and Sticky models to allow more flexible name field configurations
    • Added unique constraints for workspace home preferences
  • Improvements

    • Enhanced workspace user experience with customizable home widget settings

@pablohashescobar pablohashescobar added ⚙️backend 🔄migrations Contains Migration changes labels Jan 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

This pull request introduces a new WorkspaceHomePreference model to manage user-specific home preferences within workspaces. The migration adds fields like sort_order, config, and key, along with unique constraints. Additionally, the changes modify the name field in both Page and Sticky models, converting them to TextField with more flexible constraints. These modifications enhance the data model's flexibility for storing workspace-related user preferences and text-based attributes.

Changes

File Change Summary
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py - Added WorkspaceHomePreference model migration
- Added sort_order field
- Added unique constraints
- Modified Page.name to TextField
- Modified Sticky.name to TextField(null=True, blank=True)
apiserver/plane/db/models/workspace.py - Added WorkspaceHomePreference class
- Added HomeWidgetKeys enumeration
- Defined fields: workspace, user, key, is_enabled, config, sort_order
- Added __str__ method
apiserver/plane/db/models/page.py - Changed name field from CharField to TextField
apiserver/plane/db/models/sticky.py - Modified name field to TextField(null=True, blank=True)

Sequence Diagram

sequenceDiagram
    participant User
    participant Workspace
    participant WorkspaceHomePreference
    
    User->>Workspace: Select Workspace
    Workspace->>WorkspaceHomePreference: Retrieve User Preferences
    WorkspaceHomePreference-->>Workspace: Return Configured Widgets
    Workspace->>User: Display Personalized Home View
Loading

Possibly Related PRs

Suggested Reviewers

  • pablohashescobar
  • sriramveeraghanta

Poem

🐰 Widgets dance, preferences sing,
A workspace home with sorting's wing
Flexible fields, no limits tight
Data flows with pure delight!
CodeRabbit's magic takes its flight 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (4)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (2)

38-45: Redundant constraints and unique_together:
You’re defining both a partial UniqueConstraint and a unique_together that also includes deleted_at. Although this is a valid approach, it might be worth confirming that this duplication is necessary. Typically, many teams prefer a single partial index with the condition to handle the uniqueness while ignoring deleted records.

🧰 Tools
🪛 Ruff (0.8.2)

40-40: Line too long (221 > 88)

(E501)


19-29: Line length violations reported by Ruff (E501).
Be mindful that some lines exceed the recommended maximum length of 88 characters (as flagged by Ruff). While these style warnings don’t affect functionality, consider line-wrapping or reformatting to maintain consistent code style.

Also applies to: 40-40

🧰 Tools
🪛 Ruff (0.8.2)

19-19: Line too long (99 > 88)

(E501)


20-20: Line too long (101 > 88)

(E501)


21-21: Line too long (103 > 88)

(E501)


22-22: Line too long (140 > 88)

(E501)


26-26: Line too long (200 > 88)

(E501)


27-27: Line too long (206 > 88)

(E501)


28-28: Line too long (166 > 88)

(E501)


29-29: Line too long (161 > 88)

(E501)

apiserver/plane/db/models/workspace.py (2)

369-377: Confirm overlap between unique constraints and the partial constraint.
As in the migration file, consider if you really need both unique_together with deleted_at and a partial constraint ignoring deleted_at. One partial unique constraint might suffice.


347-384: Line length violations (E501).
Some lines within this segment slightly exceed the style guidelines on max line length. If you wish to maintain compliance with Ruff or PEP 8, consider splitting longer lines or using multiline formatting for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a555df2 and c144cc6.

📒 Files selected for processing (2)
  • apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1 hunks)
  • apiserver/plane/db/models/workspace.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py

19-19: Line too long (99 > 88)

(E501)


20-20: Line too long (101 > 88)

(E501)


21-21: Line too long (103 > 88)

(E501)


22-22: Line too long (140 > 88)

(E501)


26-26: Line too long (200 > 88)

(E501)


27-27: Line too long (206 > 88)

(E501)


28-28: Line too long (166 > 88)

(E501)


29-29: Line too long (161 > 88)

(E501)


40-40: Line too long (221 > 88)

(E501)

🔇 Additional comments (3)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1)

16-37: Migration logic is correct and aligns with Django best practices.
The creation of the WorkspaceHomePreference model with well-defined fields, timestamps, and soft-deletion support is consistent. Adding a partial unique constraint with deleted_at__isnull=True helps enforce uniqueness only for active records, which is highly recommended to preserve historical data.

🧰 Tools
🪛 Ruff (0.8.2)

19-19: Line too long (99 > 88)

(E501)


20-20: Line too long (101 > 88)

(E501)


21-21: Line too long (103 > 88)

(E501)


22-22: Line too long (140 > 88)

(E501)


26-26: Line too long (200 > 88)

(E501)


27-27: Line too long (206 > 88)

(E501)


28-28: Line too long (166 > 88)

(E501)


29-29: Line too long (161 > 88)

(E501)

apiserver/plane/db/models/workspace.py (2)

347-367: Appropriate usage of TextChoices and JSONField.
Defining HomeWidgetKeys as a TextChoices enum is a clean way to maintain clarity for different widget keys. Using a JSONField for config is flexible for storing additional preference data. This approach is consistent with Django recommendations.


383-384: Clear and concise __str__ method.
Your string representation is straightforward, which can be helpful for debugging logs and the Django admin.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c144cc6 and 5f64396.

📒 Files selected for processing (2)
  • apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1 hunks)
  • apiserver/plane/db/models/page.py (1 hunks)
🔇 Additional comments (3)
apiserver/plane/db/models/page.py (1)

23-23: Use caution when changing field types from CharField to TextField.
If there's any logic or validation relying on the max_length property, you should ensure it still behaves as intended. Additionally, consider potential performance implications for indexes in larger fields if you plan to query the name field frequently.

Would you like to inspect other references or constraints on the name field across the codebase?

apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (2)

16-92: New model addition looks good, but confirm usage aligns with requirements.
The WorkspaceHomePreference model and fields appear appropriate for storing user preferences. Ensure that the logic for reading and writing these preferences is integrated well, and that any sensitive data handled in the config JSONField is managed securely.


93-104: Check indexing and overlaps in unique constraints.
You’ve added a unique constraint with a condition on deleted_at and also declared unique_together with ("workspace", "user", "key", "deleted_at"). Verify the interaction between these constraints to avoid conflicts or unexpected database errors.

Do you want me to generate a shell script to look for references to the WorkspaceHomePreference table creation or usage to confirm no potential overlap issues with these constraints?

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

🧹 Nitpick comments (3)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (3)

46-48: Consider adding choices for the key field

The key field appears to store preference types but lacks constraints on possible values. Consider adding choices to ensure data consistency.

-"key", models.CharField(max_length=255)),
+"key", models.CharField(
+    max_length=255,
+    choices=[
+        ('dashboard', 'Dashboard'),
+        ('issues', 'Issues'),
+        # Add other valid preference keys
+    ]
+)),

48-48: Add validation for the config JSONField

The config field uses a default empty dict but lacks schema validation. Consider adding JSON schema validation to ensure the stored configuration is valid.

-"config", models.JSONField(default=dict)),
+"config", models.JSONField(
+    default=dict,
+    validators=[validate_config_schema]  # Add a validator function
+)),

110-114: Consider index for sort_order field

Since the sort_order field will likely be used for ordering queries, consider adding a database index to improve query performance.

-    field=models.PositiveIntegerField(default=65535),
+    field=models.PositiveIntegerField(default=65535, db_index=True),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f64396 and d74fa1b.

📒 Files selected for processing (3)
  • apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1 hunks)
  • apiserver/plane/db/migrations/0090_workspacehomepreference_sort_order.py (1 hunks)
  • apiserver/plane/db/models/workspace.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apiserver/plane/db/models/workspace.py
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/db/migrations/0090_workspacehomepreference_sort_order.py

3-3: django.db.models imported but unused

Remove unused import: django.db.models

(F401)

🔇 Additional comments (1)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1)

105-109: Verify data migration for Page.name field

Changing from CharField to TextField might require data migration if there's existing data with specific formatting or if the old field had a max_length constraint.

Let's verify the existing data constraints:

#!/bin/bash
# Check for existing Page model definition and any max_length constraints
ast-grep --pattern 'class Page($$_):
  $$$
  name = models.CharField($$$)
  $$$'

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

🧹 Nitpick comments (1)
apiserver/plane/db/models/sticky.py (1)

10-10: Handle null=True responsibly.

Allowing null=True on a TextField means name could be None in Python. Ensure that any references or string operations on self.name handle None without raising exceptions. If you intended to allow an empty string but not a None value, use blank=True without null=True.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d74fa1b and e1b9d51.

📒 Files selected for processing (2)
  • apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (1 hunks)
  • apiserver/plane/db/models/sticky.py (1 hunks)
🔇 Additional comments (4)
apiserver/plane/db/migrations/0089_workspacehomepreference_and_more.py (4)

16-92: Validate the growing JSON structure in config.

Since config defaults to an unbounded dictionary, confirm that you have sufficient validation and size checks in place to avoid inadvertently storing huge or malformed payloads that could degrade performance.


93-104: Examine potential redundancy in existing uniqueness constraints.

You have both a conditional UniqueConstraint (line 93) and a unique_together (line 101) on the same fields. This might be redundant, as previously noted. Consider removing one of them to keep your model constraints simpler and avoid confusion.


105-109: Confirm the migration from CharField to TextField.

Switching from CharField to TextField relaxes any length constraints. If the old schema enforced strict length limits, verify that no existing data or future usage relies on a maximum length.


110-114: Consistently manage nullable fields for Sticky.

Mirrors the change in sticky.py: the name field is now nullable. Double-check any logic or templates that depend on name being always present to handle None values gracefully.

@sriramveeraghanta
Copy link
Member

@pablohashescobar revert back page.py changes and regenerate the migration file.

@sriramveeraghanta
Copy link
Member

@pablohashescobar revert back page.py changes and regenerate the migration file.

Not required.

@sriramveeraghanta sriramveeraghanta merged commit e4f9d02 into preview Jan 3, 2025
10 of 11 checks passed
@sriramveeraghanta sriramveeraghanta deleted the feat-home-preferences branch January 3, 2025 14:54
@coderabbitai coderabbitai bot mentioned this pull request Jan 13, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️backend 🔄migrations Contains Migration changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants