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

GO-3788 Create FileObject on DnD file to other space #1420

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

KirillSto
Copy link
Member

https://linear.app/anytype/issue/GO-3788/dnd-file-blocks-between-spaces

If file block is Dragged-n-Dropped from object of one space to object in other space, file object in target space should be created

@KirillSto KirillSto requested review from deff7 and fat-fellow July 25, 2024 14:45
@KirillSto KirillSto self-assigned this Jul 25, 2024
Copy link

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent changes significantly enhance file management in the block editor, particularly through the basic struct. The introduction of a file object service improves handling of file-related operations during block duplication, enhancing error management and encapsulation. Updated tests ensure greater flexibility and accuracy in managing file interactions across various contexts.

Changes

Files Change Summary
core/block/editor/basic/basic.go, basic_test.go, Enhanced basic struct with a new file object service for improved file management. Constructor and method signatures updated.
core/block/editor/basic/extract_objects_test.go Test cases modified to accommodate new parameters for the NewBasic function, enhancing test coverage for file handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dashboard
    participant Basic
    participant FileService

    User ->> Dashboard: Initialize with NewBasic
    Dashboard ->> Basic: Create new instance
    Basic ->> FileService: Initialize file operations
    Basic ->> User: Ready for file operations
    User ->> Basic: Duplicate block
    Basic ->> FileService: Process file block
    FileService -->> Basic: Return new file details
    Basic -->> User: Block duplicated successfully
Loading

🐇 "In the land of code, where changes abound,
A hop and a skip, new features are found.
With files in our grasp, we leap and we bound,
In the world of smart blocks, joy knows no bound!
So let’s celebrate this festive array,
With code and a wink, let’s frolic and play!" 🌟


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

@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, codebase verification and nitpick comments (2)
core/block/editor/widget.go (1)

33-33: Issues found with the added nil parameter in basic.NewBasic.

The fileObjectService parameter is used directly in method calls without any nil checks, which will cause runtime errors if nil is passed. This needs to be addressed to ensure the stability of the code.

  • core/block/editor/basic/basic.go
    • processFileBlock method: fileObjectService.GetFileIdFromObject
    • Another method: fileObjectService.CreateFromImport
Analysis chain

Verify the impact of the added parameter in basic.NewBasic.

The added nil parameter in basic.NewBasic might introduce new functionality or configuration. Ensure that this change does not break existing functionality and check for its impact on the rest of the codebase.


Verify the usage of fileObjectService in NewBasic.

The added nil parameter corresponds to the fileObjectService parameter in NewBasic. Ensure that this parameter being nil does not break existing functionality.


Verify the usage of fileObjectService in basic struct.

Ensure that the fileObjectService being nil does not cause runtime errors by checking its usage within the basic struct.


Verify nil checks for fileObjectService in basic struct.

Ensure that there are nil checks before using fileObjectService to prevent runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and impact of the added parameter in `basic.NewBasic`.

# Test: Search for the `NewBasic` function definition and its usage. Expect: Ensure the new parameter is handled correctly.
rg --type go -A 5 $'func NewBasic'

Length of output: 414


Script:

#!/bin/bash
# Description: Verify the usage of `fileObjectService` within the `NewBasic` function.

# Test: Search for the usage of `fileObjectService` within the `NewBasic` function.
rg --type go -A 20 'func NewBasic' core/block/editor/basic/basic.go

Length of output: 581


Script:

#!/bin/bash
# Description: Verify the usage of `fileObjectService` within the `basic` struct.

# Test: Search for the usage of `fileObjectService` within the `basic` struct.
rg --type go 'fileObjectService' core/block/editor/basic/basic.go

Length of output: 319


Script:

#!/bin/bash
# Description: Verify nil checks for `fileObjectService` within the `basic` struct.

# Test: Search for the context around the usage of `fileObjectService` to check for nil checks.
rg --type go -A 5 -B 5 'fileObjectService.GetFileIdFromObject' core/block/editor/basic/basic.go
rg --type go -A 5 -B 5 'fileObjectService.CreateFromImport' core/block/editor/basic/basic.go

Length of output: 796

core/block/editor/profile.go (1)

43-43: Update function calls to match the new signature

The following files contain calls to basic.NewBasic that do not match the new signature. Please update these calls to include the f.fileObjectService parameter:

  • core/block/editor/participant_test.go
  • core/block/editor/participant.go
  • core/block/editor/widget.go
  • core/block/editor/dashboard.go
Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all calls to basic.NewBasic match the new signature.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `basic.NewBasic` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'basic.NewBasic'

Length of output: 3046

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d5efef1 and 959da83.

Files selected for processing (14)
  • core/block/editor/basic/basic.go (5 hunks)
  • core/block/editor/basic/basic_test.go (25 hunks)
  • core/block/editor/basic/details_test.go (1 hunks)
  • core/block/editor/basic/extract_objects_test.go (3 hunks)
  • core/block/editor/dashboard.go (1 hunks)
  • core/block/editor/files.go (1 hunks)
  • core/block/editor/page.go (1 hunks)
  • core/block/editor/participant.go (1 hunks)
  • core/block/editor/participant_test.go (1 hunks)
  • core/block/editor/profile.go (1 hunks)
  • core/block/editor/widget.go (1 hunks)
  • core/block/editor/workspaces.go (1 hunks)
  • space/internal/components/migration/readonlyfixer/relationsfixer.go (2 hunks)
  • space/internal/components/migration/systemobjectreviser/systemobjectreviser.go (3 hunks)
Additional comments not posted (33)
core/block/editor/files.go (1)

28-28: Verify the impact of the added parameter in basic.NewBasic.

The added f.fileObjectService parameter in basic.NewBasic might introduce new functionality or configuration. Ensure that this change does not break existing functionality and check for its impact on the rest of the codebase.

space/internal/components/migration/readonlyfixer/relationsfixer.go (2)

62-64: Verify the usage of the detailsSettable interface in the Run method.

The Run method now uses the detailsSettable interface. Ensure that this change does not break existing functionality and check for its impact on the rest of the codebase.

Verification successful

The usage of the detailsSettable interface in the Run method has been verified successfully.

The Run method in relationsfixer.go correctly utilizes the detailsSettable interface, and the SetDetails method is implemented and used as expected. No issues were found with this implementation.

  • space/internal/components/migration/readonlyfixer/relationsfixer.go
  • space/internal/components/migration/systemobjectreviser/systemobjectreviser.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and impact of the `detailsSettable` interface in the `Run` method.

# Test: Search for the `Run` method definition and its usage. Expect: Ensure the `detailsSettable` interface is used correctly.
rg --type go -A 5 $'func (Migration) Run'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify the definition and usage of the `Run` method in the `Migration` struct and the `detailsSettable` interface.

# Search for the definition of the `Migration` struct.
rg --type go 'type Migration struct'

# Search for the `Run` method within the `Migration` struct.
rg --type go 'func (m Migration) Run'

# Search for all usages of the `detailsSettable` interface.
rg --type go 'detailsSettable'

Length of output: 809


Script:

#!/bin/bash
# Description: Verify the definition and usage of the `Run` method in the `Migration` struct and the implementation of the `detailsSettable` interface.

# Search for all methods in the files where `Migration` is defined.
rg --type go 'func ' space/internal/components/migration/systemobjectreviser/systemobjectreviser.go
rg --type go 'func ' space/internal/components/migration/readonlyfixer/relationsfixer.go
rg --type go 'func ' core/block/migration/migrations.go

# Search for the implementation of the `detailsSettable` interface.
rg --type go 'SetDetails' space/internal/components/migration/systemobjectreviser/systemobjectreviser.go
rg --type go 'SetDetails' space/internal/components/migration/readonlyfixer/relationsfixer.go

Length of output: 1978


20-22: Verify the implementation of the detailsSettable interface.

The detailsSettable interface defines a method SetDetails. Ensure that this interface is correctly implemented by the relevant smartblocks.

core/block/editor/dashboard.go (1)

36-36: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all calls to basic.NewBasic match the new signature.

Verification successful

All calls to basic.NewBasic match the new signature.

The function usage is consistent across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `basic.NewBasic` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'basic.NewBasic'

Length of output: 3046

core/block/editor/basic/details_test.go (1)

35-35: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all calls to basic.NewBasic match the new signature.

Verification successful

Function usage verified.

The basic.NewBasic function is consistently used across the codebase with the new signature. Variations in the last parameter (nil or f.fileObjectService) are intentional and valid.

  • core/block/editor/participant.go
  • core/block/editor/page.go
  • core/block/editor/participant_test.go
  • core/block/editor/widget.go
  • core/block/editor/workspaces.go
  • core/block/editor/files.go
  • core/block/editor/dashboard.go
  • core/block/editor/profile.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `basic.NewBasic` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'basic.NewBasic'

Length of output: 3046

core/block/editor/participant.go (1)

34-34: Verify the correctness of the new parameter.

The addition of the nil parameter in the basic.NewBasic call suggests an enhancement in the function's capability. Ensure that this change is correctly handled in the NewBasic function and that nil is the appropriate value for this parameter.

core/block/editor/workspaces.go (1)

38-38: Verify the correctness of the new parameter.

The addition of the f.fileObjectService parameter in the basic.NewBasic call suggests an enhancement in the function's capability. Ensure that this change is correctly handled in the NewBasic function and that f.fileObjectService is the appropriate value for this parameter.

core/block/editor/participant_test.go (1)

138-138: Verify the correctness of the new parameter.

The addition of the nil parameter in the basic.NewBasic call suggests an enhancement in the function's capability. Ensure that this change is correctly handled in the NewBasic function and that nil is the appropriate value for this parameter.

space/internal/components/migration/systemobjectreviser/systemobjectreviser.go (2)

25-27: LGTM!

The detailsSettable interface is well-defined and aligns with the summary. No issues detected.


106-108: LGTM!

The type assertion logic has been correctly updated to use the new detailsSettable interface. This enhances modularity and decouples the code from the basic package.

core/block/editor/page.go (1)

61-61: LGTM!

The additional parameter f.fileObjectService enhances the functionality of AllOperations by incorporating file-related operations. This change is consistent with the summary provided.

core/block/editor/basic/extract_objects_test.go (3)

293-293: LGTM!

The additional parameter nil is consistent with the changes in the NewBasic function. The core logic of the test cases remains unchanged.


348-348: LGTM!

The additional parameter nil is consistent with the changes in the NewBasic function. The core logic of the test cases remains unchanged.


381-381: LGTM!

The additional parameter nil is consistent with the changes in the NewBasic function. The core logic of the test cases remains unchanged.

core/block/editor/basic/basic.go (5)

120-122: LGTM!

The addition of fileObjectService to the basic struct is correctly implemented.


156-156: LGTM!

The changes to the Duplicate method are correctly implemented.


Line range hint 176-205: LGTM!

The changes to the copyBlocks method are correctly implemented.


209-226: LGTM!

The new method processFileBlock is correctly implemented.


107-113: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to NewBasic match the new signature.

core/block/editor/basic/basic_test.go (14)

46-46: LGTM!

The changes to the TestBasic_Create function are correctly implemented.

Also applies to: 60-60, 81-81


88-105: LGTM!

The changes to the TestBasic_Duplicate function are correctly implemented. The new test cases enhance the test coverage.

Also applies to: 107-195


207-207: LGTM!

The changes to the TestBasic_Unlink function are correctly implemented.

Also applies to: 221-221


238-238: LGTM!

The changes to the TestBasic_Move function are correctly implemented.

Also applies to: 252-252, 301-301, 317-317, 337-337, 351-351


371-371: LGTM!

The changes to the TestBasic_MoveToAnotherObject function are correctly implemented.


406-406: LGTM!

The changes to the TestBasic_Replace function are correctly implemented.


416-416: LGTM!

The changes to the TestBasic_SetFields function are correctly implemented.


435-435: LGTM!

The changes to the TestBasic_Update function are correctly implemented.


449-449: LGTM!

The changes to the TestBasic_SetDivStyle function are correctly implemented.


460-460: LGTM!

The changes to the TestBasic_PasteBlocks function are correctly implemented.


487-487: LGTM!

The changes to the TestBasic_SetRelationKey function are correctly implemented.

Also applies to: 509-509, 518-518


534-534: LGTM!

The changes to the TestBasic_FeaturedRelationAdd function are correctly implemented.


550-550: LGTM!

The changes to the TestBasic_FeaturedRelationRemove function are correctly implemented.


587-587: LGTM!

The changes to the TestBasic_ReplaceLink function are correctly implemented.

Copy link

New Coverage 47.4% of statements
Patch Coverage 47.1% of changed statements (16/34)

Coverage provided by /~https://github.com/seriousben/go-patch-cover-action

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 959da83 and ff0042b.

Files selected for processing (3)
  • core/block/editor/basic/basic.go (5 hunks)
  • core/block/editor/basic/basic_test.go (34 hunks)
  • core/block/editor/basic/extract_objects_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • core/block/editor/basic/basic.go
  • core/block/editor/basic/basic_test.go
  • core/block/editor/basic/extract_objects_test.go

@KirillSto KirillSto merged commit 000f61a into main Jul 29, 2024
5 checks passed
@KirillSto KirillSto deleted the go-3788-cross-spce-file-dnd branch July 29, 2024 20:57
@github-actions github-actions bot locked and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants