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

feat(entry-file): added file upload source #736

Merged
merged 7 commits into from
Sep 2, 2024

Conversation

egordidenko
Copy link
Contributor

@egordidenko egordidenko commented Aug 28, 2024

Description

Checklist

Summary by CodeRabbit

  • New Features

    • Added a new source property to enhance the upload entry information in the Uploader API.
    • Expanded the upload entry schema to include the source property for better tracking and categorization.
    • Introduced the source property in the FileItem class to capture additional file-related information during uploads.
    • Added a getList method in the UploaderBlock class for easier access to predefined source types.
    • Launched the EditorFilerobotImage class for managing image editing activities.
    • Updated the SourceBtn class to utilize a centralized approach for source types.
    • Enhanced the UrlSource class to refine URL upload handling.
    • Consolidated external upload sources into a new ExternalUploadSource constant for better organization.
    • Exported new entities UploadSource and ExternalUploadSource for enhanced module functionality.
    • Introduced support for processing object types in the build-ssr-stubs logic.
  • Bug Fixes

    • Updated conditions in the DropArea class to ensure correct enabling of local file uploads.
  • Documentation

    • Added deprecation notices for certain enums in the UploaderBlock class to guide developers towards preferred alternatives.
    • Improved type definitions by introducing the SourceTypes type and updating the OutputFileEntry structure.

@egordidenko egordidenko requested a review from nd0ut August 28, 2024 18:59
Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

The changes introduce a new property, source, across multiple components, enhancing the output and documentation with additional context about the origin of uploads. New methods and typedefs improve functionality and type-checking. The UploaderBlock class includes deprecation notices for certain enums, and the handling of source types has been updated throughout the codebase. A new conditional branch is added to handle object types in the build-ssr-stubs.js file.

Changes

File Path Change Summary
abstract/UploaderPublicApi.js Added source property to the output object, derived from uploadEntryData?.source.
abstract/uploadEntrySchema.js Updated documentation to include source as a String property in the upload entry schema.
blocks/FileItem/FileItem.js Introduced source property in the FileItem class, populated from entry.getValue('source').
abstract/UploaderBlock.js Added getList method to return sourceTypes, added deprecation notices for extSrcList and sourceTypes, and defined SourceTypes typedef.
blocks/DropArea/DropArea.js Updated isEnabled logic to check for UploadSource.LOCAL instead of UploaderBlock.sourceTypes.LOCAL.
blocks/EditorFilerobotImage/EditorFilerobotImage.js Introduced new class for managing image editing activities with lifecycle methods.
blocks/SourceBtn/SourceBtn.js Replaced UploaderBlock.sourceTypes with UploadSource for defining source types.
blocks/UrlSource/UrlSource.js Updated addFileFromUrl method to use UploadSource.URL instead of UploadSource.URL_TAB.
blocks/utils/UploadSource.js Added ExternalUploadSource and new properties URL and DRAW to UploadSource, and defined SourceTypes typedef.
index.js Exported new entities UploadSource and ExternalUploadSource from blocks/utils/UploadSource.js.
build-ssr-stubs.js Added handling for object types in stubbedExports, converting them to JSON strings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UploaderPublicApi
    participant FileItem

    User->>UploaderPublicApi: Initiate upload
    UploaderPublicApi->>FileItem: Create FileItem with entry
    FileItem->>entry: Retrieve source value
    FileItem-->>UploaderPublicApi: Return FileItem with source
    UploaderPublicApi-->>User: Upload result with source
Loading

Poem

🐇 In the meadow, a change did bloom,
A new source to dispel the gloom.
With every upload, a tale to tell,
Of where it came from, all is well!
Hopping with joy, we celebrate,
Data enriched, oh, isn’t it great? 🎉


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 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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

@egordidenko egordidenko force-pushed the feat/add-source-upload-file branch from ac4497d to 23ccf77 Compare August 28, 2024 19:00
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.

Caution

Inline review comments failed to post

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b410122 and ac4497d.

Files selected for processing (3)
  • abstract/UploaderPublicApi.js (1 hunks)
  • abstract/uploadEntrySchema.js (1 hunks)
  • blocks/FileItem/FileItem.js (1 hunks)
Additional comments not posted (7)
abstract/UploaderPublicApi.js (5)

Line range hint 28-32: LGTM!

The addition of the source property is consistent with the new feature.


Line range hint 39-43: LGTM!

The addition of the source property is consistent with the new feature.


Line range hint 50-55: LGTM!

The addition of the source property is consistent with the new feature.


Line range hint 62-69: LGTM!

The addition of the source property is consistent with the new feature.


243-243: LGTM!

The addition of the source property is consistent with the new feature.

blocks/FileItem/FileItem.js (2)

Line range hint 178-178: LGTM!

The addition of the source property is consistent with the new feature.


395-395: LGTM!

The addition of the source property is consistent with the new feature.

Comments failed to post (1)
abstract/uploadEntrySchema.js (1)

30-30: Change default value of source to null.

The default value of false for a string property is unusual and might cause confusion. Consider changing the default value to null for consistency with other nullable string properties.

 source: {
   type: String,
-  value: false,
+  value: null,
   nullable: true,
 },
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.

 source: {
   type: String,
   value: null,
   nullable: true,
 },

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ac4497d and 23ccf77.

Files selected for processing (3)
  • abstract/UploaderPublicApi.js (1 hunks)
  • abstract/uploadEntrySchema.js (1 hunks)
  • blocks/FileItem/FileItem.js (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • abstract/UploaderPublicApi.js
  • abstract/uploadEntrySchema.js
  • blocks/FileItem/FileItem.js

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 23ccf77 and 75ad4de.

Files selected for processing (2)
  • abstract/UploaderBlock.js (2 hunks)
  • abstract/UploaderPublicApi.js (2 hunks)
Additional comments not posted (4)
abstract/UploaderPublicApi.js (2)

243-243: LGTM!

The addition of the source property to the outputItem object enhances the output by providing additional context about the origin of the upload. The use of optional chaining ensures safe access to the source property of uploadEntryData.


333-336: LGTM!

The addition of the getSourceTypes method to the UploaderPublicApi class is a useful enhancement. It provides a read-only view of the source types, allowing consumers of the API to access this information without the ability to modify it directly. The method retrieves the source types from the context using this._ctx.getList(), ensuring consistency with the internal state.

abstract/UploaderBlock.js (2)

422-425: LGTM!

The new getList() method provides a clean way to access the predefined source types from an instance of the UploaderBlock class. The method name is clear and descriptive of its purpose.


452-452: LGTM!

The new SourceTypes typedef provides a clean way to reuse the type of the sourceTypes property in other parts of the code. The typedef is correctly defined using JSDoc syntax and the name is clear and descriptive of its purpose.

blocks/FileItem/FileItem.js Outdated Show resolved Hide resolved
abstract/UploaderBlock.js Outdated Show resolved Hide resolved
abstract/UploaderPublicApi.js Outdated Show resolved Hide resolved
@egordidenko egordidenko force-pushed the feat/add-source-upload-file branch from ff6647a to e13e3b8 Compare September 2, 2024 14:20
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.

Caution

Inline review comments failed to post

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75ad4de and ff6647a.

Files selected for processing (7)
  • abstract/UploaderBlock.js (2 hunks)
  • abstract/UploaderPublicApi.js (1 hunks)
  • blocks/DropArea/DropArea.js (1 hunks)
  • blocks/EditorFilerobotImage/EditorFilerobotImage.js (1 hunks)
  • blocks/SourceBtn/SourceBtn.js (3 hunks)
  • blocks/UrlSource/UrlSource.js (1 hunks)
  • blocks/utils/UploadSource.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • abstract/UploaderBlock.js
Additional context used
GitHub Check: build
blocks/EditorFilerobotImage/EditorFilerobotImage.js

[warning] 1-1:
'uploadFile' is defined but never used


[warning] 4-4:
'FilerobotImageEditor' is defined but never used


[warning] 38-38:
'file' is assigned a value but never used


[warning] 39-39:
'cdnUrl' is assigned a value but never used

Additional comments not posted (13)
blocks/utils/UploadSource.js (4)

2-14: LGTM!

The new constant ExternalUploadSource is implemented correctly. It consolidates various external upload sources into a single, immutable object, which allows for better organization and management of these options. The constant name is clear and follows the naming convention. Freezing the object using Object.freeze() is a good practice to prevent accidental modifications.


22-24: LGTM!

The changes to the UploadSource constant are implemented correctly. The new properties URL and DRAW expand the available upload sources, enhancing the functionality. Spreading the ExternalUploadSource into the UploadSource effectively merges the external sources into the existing upload options, allowing users to access both local and external upload sources seamlessly through a unified interface.


27-27: LGTM!

The new typedef SourceTypes is implemented correctly. It provides better type-checking and documentation for developers using this module, ensuring clarity in the expected structure of upload sources.


1-1: LGTM!

Adding the TypeScript directive // @ts-check at the beginning of the file is a good practice. It enables type-checking for JavaScript files, helping catch type-related errors and improving code quality.

blocks/EditorFilerobotImage/EditorFilerobotImage.js (1)

6-10: LGTM!

The rest of the code looks good and follows a standard pattern for defining a custom block.

Also applies to: 11-17, 19-28, 30-37, 46-50, 53-53

blocks/UrlSource/UrlSource.js (1)

16-16: LGTM!

The code change is approved. The modification to the source parameter passed to the addFileFromUrl method aligns with the PR objective of refining the source categorization for uploaded files. It simplifies the source types and maintains consistency with the naming convention.

blocks/SourceBtn/SourceBtn.js (5)

4-4: LGTM!

The code changes are approved.


41-41: LGTM!

The code changes are approved.


48-48: LGTM!

The code changes are approved.


53-53: LGTM!

The code changes are approved.


69-69: LGTM!

The code changes are approved.

blocks/DropArea/DropArea.js (1)

154-154: LGTM! The code change is approved.

The modification updates the condition for setting this.$.isEnabled to check for the presence of UploadSource.LOCAL in the sourceList configuration array, instead of UploaderBlock.sourceTypes.LOCAL. This change suggests a refactoring or reorganization of how source types are defined or accessed.

The behavior of the drop area in relation to local file uploads is now determined by the presence of UploadSource.LOCAL in the sourceList configuration. The visibility of the drop area is still controlled by the isEnabled property or the presence of a default slot, preserving the overall control flow.

The change appears to be consistent with the usage of UploadSource in other parts of the file, such as in the onItems callback.

abstract/UploaderPublicApi.js (1)

243-243: LGTM!

The code changes are approved.

The following existing comment is still applicable:

nd0ut: We need to add this property to the OutputFileEntry type

Please update the corresponding type definition.

Comments failed to post (2)
blocks/EditorFilerobotImage/EditorFilerobotImage.js (2)

1-1: Remove unused imports.

The following imports are unused and should be removed:

  • uploadFile from @uploadcare/upload-client
  • FilerobotImageEditor

Apply this diff to remove the unused imports:

-import { uploadFile } from '@uploadcare/upload-client';
 import { ActivityBlock } from '../../abstract/ActivityBlock.js';
 import { UploaderBlock } from '../../abstract/UploaderBlock.js';
-import FilerobotImageEditor from 'filerobot-image-editor';

Also applies to: 4-4

Tools
GitHub Check: build

[warning] 1-1:
'uploadFile' is defined but never used


38-39: Remove unused variables and unnecessary assignment.

The following variables are unused and should be removed:

  • file
  • cdnUrl

Also, the assignment of null to instance seems unnecessary and should be removed.

Apply this diff to remove the unused variables and the unnecessary assignment:

-    const file = this._entry.getValue('file');
-    const cdnUrl = this._entry.getValue('cdnUrl');
-
-    const instance = null;
-
-    this._instance = instance;

Also applies to: 41-43

Tools
GitHub Check: build

[warning] 38-38:
'file' is assigned a value but never used


[warning] 39-39:
'cdnUrl' is assigned a value but never used

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ff6647a and e13e3b8.

Files selected for processing (7)
  • abstract/UploaderBlock.js (2 hunks)
  • abstract/UploaderPublicApi.js (1 hunks)
  • blocks/DropArea/DropArea.js (1 hunks)
  • blocks/SourceBtn/SourceBtn.js (3 hunks)
  • blocks/UrlSource/UrlSource.js (1 hunks)
  • blocks/utils/UploadSource.js (1 hunks)
  • index.js (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • abstract/UploaderBlock.js
  • abstract/UploaderPublicApi.js
  • blocks/DropArea/DropArea.js
  • blocks/SourceBtn/SourceBtn.js
  • blocks/utils/UploadSource.js
Additional comments not posted (2)
blocks/UrlSource/UrlSource.js (1)

16-16: LGTM!

The code change simplifies the source identifier for uploaded files from URLs by updating the source parameter passed to the addFileFromUrl method from UploadSource.URL_TAB to UploadSource.URL. This change aligns with the AI-generated summary and is unlikely to have any unintended consequences.

index.js (1)

47-47: LGTM!

The export statement is syntactically correct and consistent with the AI-generated summary. It enhances the module's functionality by making UploadSource and ExternalUploadSource available for import in other parts of the application, potentially allowing for new features or integrations related to file uploads. The change doesn't alter any existing functionality but expands the module's interface. It also doesn't introduce any new dependencies or potential issues.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e13e3b8 and f928e6a.

Files selected for processing (4)
  • abstract/UploaderBlock.js (2 hunks)
  • blocks/FileItem/FileItem.js (1 hunks)
  • blocks/utils/UploadSource.js (1 hunks)
  • types/exported.d.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • blocks/FileItem/FileItem.js
Files skipped from review as they are similar to previous changes (2)
  • abstract/UploaderBlock.js
  • blocks/utils/UploadSource.js
Additional comments not posted (2)
types/exported.d.ts (2)

8-8: LGTM!

The code changes are approved.


173-173: Verify the usage of the source property in the codebase.

The code changes are approved, but ensure that the source property is being set and accessed correctly throughout the codebase.

Run the following script to verify the usage of the source property:

Verification successful

The source property is correctly integrated and used throughout the codebase.

The verification confirms that the source property is accessed and assigned in multiple files, indicating its proper integration and usage. No issues were found with its implementation.

  • Accessed in: abstract/UploaderPublicApi.js, blocks/FileItem/FileItem.js, etc.
  • Assigned in: abstract/UploaderPublicApi.js, blocks/UrlSource/UrlSource.js, etc.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `source` property in the codebase.

# Test 1: Search for the property access. Expect: At least one occurrence.
rg --type typescript $'\\.(source)[^\\w]'

# Test 2: Search for the property assignment. Expect: At least one occurrence.
rg --type typescript $'source:\\s*\\w+'

Length of output: 149


Script:

#!/bin/bash
# Description: Verify the usage of the `source` property in the codebase.

# Test 1: Search for the property access. Expect: At least one occurrence.
rg '\.(source)[^\w]'

# Test 2: Search for the property assignment. Expect: At least one occurrence.
rg 'source:\s*\w+'

Length of output: 2168

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f928e6a and 990b561.

Files selected for processing (1)
  • build-ssr-stubs.js (1 hunks)
Additional comments not posted (1)
build-ssr-stubs.js (1)

75-76: LGTM!

The code changes are approved. The new conditional branch correctly handles the case when value is of type 'object' by converting it to a JSON string using JSON.stringify(value). This enhancement is consistent with the existing code structure and style, and no potential issues or edge cases are identified.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 990b561 and 9e5024a.

Files selected for processing (1)
  • types/exported.d.ts (2 hunks)
Additional comments not posted (2)
types/exported.d.ts (2)

24-24: LGTM!

The code change is approved.


172-172: LGTM!

The code change is approved.

@egordidenko egordidenko requested a review from nd0ut September 2, 2024 15:21
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e5024a and ba9e7f6.

Files selected for processing (2)
  • types/exported.d.ts (2 hunks)
  • types/test/uc-upload-ctx-provider.test-d.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • types/exported.d.ts
Additional comments not posted (2)
types/test/uc-upload-ctx-provider.test-d.tsx (2)

14-14: LGTM!

The code changes are approved.


100-100: LGTM!

The code changes are approved.

@egordidenko egordidenko merged commit 6fe5bcd into main Sep 2, 2024
1 check passed
@egordidenko egordidenko deleted the feat/add-source-upload-file branch September 2, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants