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: add virtual as expected & avoid overriding with default #8832

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

mertmit
Copy link
Member

@mertmit mertmit commented Jun 22, 2024

Change Summary

  • Add virtual as expected & avoid overriding with default

Change type

  • fix: (bug fix for the user, not a fix to a build script)

Copy link
Contributor

coderabbitai bot commented Jun 22, 2024

Walkthrough

Walkthrough

The changes introduced involve adding a new virtual property to the Column class, modifying the initialization of the same property in the LinkToAnotherRecordColumn class, and removing an unused import from the columns.service.ts file. These updates enhance the functionality by accommodating virtual column attributes and cleaning up redundant code.

Changes

File Summary of Changes
packages/nocodb/src/models/Column.ts Added virtual property to the Column class.
packages/nocodb/src/models/LinkToAnotherRecordColumn.ts Modified virtual property initialization in LinkToAnotherRecordColumn class to use object spreading in the constructor.
packages/nocodb/src/services/columns.service.ts Removed the SourceRestriction import.

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 Configration 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 (8)
packages/nocodb/src/models/LinkToAnotherRecordColumn.ts (3)

33-33: Add documentation for the virtual property.

The addition of the virtual property is aligned with the PR's objective to manage overrides effectively. It would be beneficial to add a comment describing its purpose and usage to aid future developers.


Line range hint 57-63: Refactor to simplify assignment expressions.

The current method of assigning values within return statements is flagged as a potential source of confusion. Consider separating the assignments from the return statements to enhance clarity.

- return (this.childColumn = await Column.get(context, { colId: this.fk_child_column_id }, ncMeta));
+ this.childColumn = await Column.get(context, { colId: this.fk_child_column_id }, ncMeta);
+ return this.childColumn;

Apply similar changes to the other methods flagged by static analysis.

Also applies to: 70-76, 83-89, 95-101, 107-113, 119-125


Line range hint 155-155: Correct the use of this in static context.

The use of this in the static method insert is incorrect and can lead to runtime errors. Replace this with the class name LinkToAnotherRecordColumn.

- return this.read(context, data.fk_column_id, ncMeta);
+ return LinkToAnotherRecordColumn.read(context, data.fk_column_id, ncMeta);
packages/nocodb/src/models/Column.ts (3)

Line range hint 1190-1191: Use optional chaining for better null safety.

The code can be improved by using optional chaining to safely access properties on objects that might be null or undefined.

- if (column.column_order && column.column_order.order && column.column_order.view_id) {
+ if (column.column_order?.order && column.column_order?.view_id) {

Line range hint 1531-1531: Remove assignment within expression.

The current implementation of using assignments within expressions can lead to confusion and unintended side effects. Refactor to separate the assignment from the expression.

- const updatedColumn = await (this.get(context, { colId }, ncMeta));
+ const updatedColumn = await Column.get(context, { colId }, ncMeta);

Line range hint 998-1000: Remove unnecessary block statement.

The standalone block statement found in the code serves no purpose and can be safely removed to simplify the code structure.

- {
-   // Code block
- }
packages/nocodb/src/services/columns.service.ts (2)

Line range hint 2326-2335: Prevent unintended fallthrough in switch-case.

The case handling UITypes.DateTime and UITypes.Date is falling through to the default case. This may lead to unintended behavior if not explicitly intended.

+ break;

Line range hint 2337-2351: Prevent unintended fallthrough in switch-case.

Similar to the previous comment, the case for UITypes.DateTime is falling through to the default case. This could lead to unintended updates or deletions if not managed correctly.

+ break;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6946620 and b07faae.

Files selected for processing (3)
  • packages/nocodb/src/models/Column.ts (1 hunks)
  • packages/nocodb/src/models/LinkToAnotherRecordColumn.ts (2 hunks)
  • packages/nocodb/src/services/columns.service.ts (1 hunks)
Additional context used
Biome
packages/nocodb/src/models/LinkToAnotherRecordColumn.ts

[error] 57-63: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 70-76: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 83-89: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 95-101: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 107-113: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 119-125: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 155-155: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.

packages/nocodb/src/models/Column.ts

[error] 198-198: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 206-206: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 670-670: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 1190-1191: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 1222-1222: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 1531-1531: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 998-1000: This block statement doesn't serve any purpose and can be safely removed. (lint/complexity/noUselessLoneBlockStatements)

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

packages/nocodb/src/services/columns.service.ts

[error] 912-914: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 1135-1137: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 1272-1274: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 1380-1382: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 1453-1455: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 2369-2371: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 2326-2335: This case is falling through to the next case. (lint/suspicious/noFallthroughSwitchClause)

Add a break or return statement to the end of this case to prevent fallthrough.


[error] 2337-2351: This case is falling through to the next case. (lint/suspicious/noFallthroughSwitchClause)

Add a break or return statement to the end of this case to prevent fallthrough.


[error] 2544-2546: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 2697-2699: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Additional comments not posted (3)
packages/nocodb/src/models/LinkToAnotherRecordColumn.ts (1)

48-48: Initialize virtual property correctly in constructor.

The initialization of virtual using false as a default value directly in the constructor is a good practice to ensure it has a predictable initial state.

packages/nocodb/src/models/Column.ts (1)

154-154: Ensure the virtual property is handled correctly during insertion.

The addition of the virtual property in the insert method is correctly implemented. It ensures that this property is considered during the creation of new column entries.

packages/nocodb/src/services/columns.service.ts (1)

Line range hint 912-914: Remove unnecessary else clauses.

Several else clauses in the code are redundant because all preceding branches of the if-else chain contain break, continue, return, or throw statements. Removing these will improve the readability of the code.
[REFACTOR_SUGGESTion]

- else {
-   ...
- }

Also applies to: 1135-1137, 1272-1274, 1380-1382, 1453-1455, 2369-2371, 2544-2546, 2697-2699

Copy link
Contributor

github-actions bot commented Jun 22, 2024

Uffizzi Preview deployment-53374 was deleted.

@dstala dstala requested a review from pranavxc June 24, 2024 08:46
@mertmit mertmit merged commit de3c72f into develop Jun 24, 2024
23 checks passed
@mertmit mertmit deleted the nc-fix/virtual-rel branch June 24, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants