Skip to content

Change order and selections of annotation tools new property, annotationToolsIds #532

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

HimonRana
Copy link
Contributor

@HimonRana HimonRana commented Apr 11, 2025

It is possible to provide own list of annotation tools and have in any order by using the property annotationToolsIds.
Extra fix is persisting the defaultToolId when selecting another tab and back persist the tool selection.

Summary by CodeRabbit

  • New Features
    • Introduced a configurable option that lets users customize which annotation tools appear and in what order. If left empty, all available tools are shown.
    • Enhanced the logic for selecting tools when switching tabs for a more tailored user experience.
  • Documentation
    • Updated the documentation to explain the new annotation tools configuration and its impact on tool display.

…so persisting the selection of defaultToolId
Copy link

coderabbitai bot commented Apr 11, 2025

Walkthrough

This update introduces a new configuration property, annotationToolsIds, across documentation, configuration files, type definitions, and runtime logic. It modifies how the editor assigns annotation tools during tab selection and tool rendering. Key functions in the actions and components now reference the provided tool identifier, enabling more flexible tool selection per tab. The ToolsBar component conditionally renders annotation tools based on this configuration. New defaults and initialization code ensure the editor can be configured to show either a specific set of annotation tools or all available ones when no explicit list is provided.

Changes

File(s) Change Summary
README.md Added a new annotationToolsIds section describing the array of tool IDs available since version 4.0.0 with default values.
packages/react-filerobot-image-editor/src/actions/selectTab.js Updated selectTab to assign toolId from payload.toolId instead of defaulting to the first tool of the tab.
packages/react-filerobot-image-editor/src/actions/selectTool.js Reformatted selectTool function without changing logic or behavior.
packages/react-filerobot-image-editor/src/components/Tabs/index.jsx Added toolId from store, computed annotateToolIdKey to determine tool index, and included toolId in selectTab dispatch payload.
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx Updated ToolsBar to use annotationToolsIds from config; conditionally render annotation tools based on this array or default to all; introduced helper functions for visibility and rendering; updated dependencies for memoization.
packages/react-filerobot-image-editor/src/context/defaultConfig.js Added annotationToolsIds property initialized as an empty array in default config.
packages/react-filerobot-image-editor/src/index.d.ts Added optional annotationToolsIds property to FilerobotImageEditorConfig interface.
public/demo-config.js Added annotationToolsIds property initialized as an empty array in demo config.
public/init.js Imported TOOLS alongside TABS; defined selectedAnnotationTools array with annotation tool IDs; added annotationToolsIds to plugin config using this array.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant T as Tabs Component
    participant A as selectTab Action
    participant S as Store
    U->>T: Selects a new tab with payload {tabId, toolId}
    T->>T: Computes annotateToolIdKey based on selected tab and current toolId
    T->>A: Dispatches selectTab with payload including toolId
    A->>S: Updates state with TABS_TOOLS[tabId][toolId]
    S-->>A: Returns updated state
    A-->>T: Completes update and triggers re-render
Loading
sequenceDiagram
    participant U as User
    participant I as init.js
    participant FE as FilerobotImageEditor
    U->>I: Launches editor initialization
    I->>I: Defines selectedAnnotationTools constant
    I->>FE: Initializes editor with config (includes annotationToolsIds)
    FE-->>U: Renders editor with annotation tools configured
Loading

Poem

In a field of code, I hop with glee,
New tools gleam in arrays for me.
With every log and dispatch call,
My hops make changes big and small.
I select, I annotate, I proudly roam,
A rabbit coding happily in its digital home. 🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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

@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: 3

🔭 Outside diff range comments (1)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (1)

104-104: 💡 Verification agent

🧩 Analysis chain

Verify toolId usage against currentToolId

On line 104, you're checking if TABS_TOOLS[currentTabId] includes currentToolId, but in the subsequent lines 105-107, you're using toolId instead of currentToolId. This inconsistency could lead to bugs.


🏁 Script executed:

#!/bin/bash
# Check for usage pattern of toolId vs currentToolId
grep -n "toolId" --include="*.jsx" --include="*.js" packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx

Length of output: 471


Inconsistent tool identifier: Align usage of currentToolId and toolId

The current implementation checks whether TABS_TOOLS[currentTabId] includes currentToolId on line 104, but then accesses tool properties via toolId in lines 105–107 (and elsewhere). This discrepancy risks bugs due to potential mismatches between the two variables. Please verify which identifier should be the single source of truth. For example:

  • If currentToolId is intended to be the primary identifier, update lines 105–107 (and any related logic) to consistently use currentToolId.
  • If toolId (e.g., as derived on line 28) is the correct identifier, then adjust the check on line 104 to use toolId instead.

Ensuring consistency here will help prevent unintended behavior in the tool selection logic.

🧹 Nitpick comments (9)
README.md (1)

438-450: Documentation for annotationToolsIds is clear and follows project conventions

The documentation follows the established format and clearly explains the purpose and behavior of the new property. It provides useful information about the default tools available.

However, the code block is missing a language specifier, which would improve syntax highlighting.

-```
+```javascript
 ['Text', 'Image', 'Rect', 'Ellipse', 'Polygon', 'Pen', 'Line', 'Arrow']

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

448-448: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>
<details>
<summary>packages/react-filerobot-image-editor/src/actions/selectTab.js (1)</summary><blockquote>

`18-18`: **Minor formatting issue**

There's a linting error related to indentation on this line. The closing curly brace should be properly indented.

```diff
-};
+  };
🧰 Tools
🪛 ESLint

[error] 18-18: Insert ······

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/Tabs/index.jsx (3)

11-11: Fix import order

The import for TABS_TOOLS should be moved before the local imports to follow consistent import ordering.

/** Internal Dependencies */
import { useStore } from 'hooks';
import { SELECT_TAB } from 'actions';
+import { TABS_TOOLS } from 'components/tools/tools.constants';
import TabItem from './TabItem';
import { AVAILABLE_TABS } from './Tabs.constants';
-import { TABS_TOOLS } from 'components/tools/tools.constants';
🧰 Tools
🪛 ESLint

[error] 11-11: components/tools/tools.constants import should occur before import of ./TabItem

(import/order)


25-26: Implementation of tool persistence across tab selection

This logic determines which tool should be selected when switching tabs, supporting the PR objective to persist the defaultToolId when switching between tabs.

However, the code formatting should be improved:

-    const annotateToolIdKey = defaultTabId === newTabId ? TABS_TOOLS.Annotate.indexOf(toolId) : 0;
+    const annotateToolIdKey = defaultTabId === newTabId 
+      ? TABS_TOOLS.Annotate.indexOf(toolId) 
+      : 0;
🧰 Tools
🪛 ESLint

[error] 25-25: Insert ⏎·····

(prettier/prettier)


31-31: Missing trailing comma

Add a trailing comma for consistency with the code style:

        tabId: newTabId,
-        toolId: annotateToolIdKey
+        toolId: annotateToolIdKey,
      },
🧰 Tools
🪛 ESLint

[error] 31-31: Insert ,

(prettier/prettier)

packages/react-filerobot-image-editor/src/actions/selectTool.js (1)

12-12: Add missing semicolon

The function is missing a semicolon at the end:

-}
+};
🧰 Tools
🪛 ESLint

[error] 12-12: Insert ;

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (3)

44-46: Remove console.log statements from production code

Debug logging should not be committed to production code. It clutters the console and may expose implementation details.

  const items = useMemo(() => {
-   console.log({TABS_IDS, TABS_TOOLS: TABS_TOOLS.Annotate, tabTools});
    const shouldShowTool = (id) =>
🧰 Tools
🪛 ESLint

[error] 45-45: Replace TABS_IDS,·TABS_TOOLS:·TABS_TOOLS.Annotate,·tabTools with ·TABS_IDS,·TABS_TOOLS:·TABS_TOOLS.Annotate,·tabTools·

(prettier/prettier)


49-61: Use optional chaining for better error handling

The static analysis suggests using optional chaining on line 51 to make the code more robust against potential null/undefined values.

  const renderItem = (id) => {
    const { Item, hideFn } = TOOLS_ITEMS[id];
-   if (!Item || (hideFn && hideFn({ useCloudimage }))) return null;
+   if (!Item || (hideFn?.({ useCloudimage }))) return null;

    return (
      <Item
        key={id}
        selectTool={selectTool}
        t={t}
        isSelected={currentToolId === id}
      />
    );
  };
🧰 Tools
🪛 Biome (1.9.4)

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 ESLint

[error] 52-52: Delete ··

(prettier/prettier)


82-83: Format dependency array correctly

Per the linting error, the dependency array needs proper formatting for readability.

-  }, [currentTabId, tabTools, annotationToolsIds, currentToolId, useCloudimage]);
+  }, [
+    currentTabId,
+    tabTools,
+    annotationToolsIds,
+    currentToolId,
+    useCloudimage,
+  ]);
🧰 Tools
🪛 ESLint

[error] 83-83: Replace currentTabId,·tabTools,·annotationToolsIds,·currentToolId,·useCloudimage with ⏎····currentTabId,⏎····tabTools,⏎····annotationToolsIds,⏎····currentToolId,⏎····useCloudimage,⏎··

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d198dd and 2097527.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • README.md (1 hunks)
  • packages/react-filerobot-image-editor/src/actions/selectTab.js (1 hunks)
  • packages/react-filerobot-image-editor/src/actions/selectTool.js (1 hunks)
  • packages/react-filerobot-image-editor/src/components/Tabs/index.jsx (1 hunks)
  • packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (3 hunks)
  • packages/react-filerobot-image-editor/src/context/defaultConfig.js (1 hunks)
  • packages/react-filerobot-image-editor/src/index.d.ts (1 hunks)
  • public/demo-config.js (1 hunks)
  • public/init.js (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
public/init.js (2)
public/demo-config.js (1)
  • FilerobotImageEditor (11-11)
packages/react-filerobot-image-editor/src/index.d.ts (1)
  • TOOLS (366-366)
packages/react-filerobot-image-editor/src/components/Tabs/index.jsx (11)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (1)
  • useStore (17-25)
packages/react-filerobot-image-editor/src/components/tools/Watermark/WatermarksGallery.jsx (1)
  • useStore (17-17)
packages/react-filerobot-image-editor/src/components/App/index.jsx (1)
  • useStore (43-53)
packages/react-filerobot-image-editor/src/components/MainCanvas/CanvasNode.jsx (1)
  • useStore (35-46)
packages/react-filerobot-image-editor/src/components/Topbar/ResetButton.jsx (1)
  • useStore (12-12)
packages/react-filerobot-image-editor/src/components/Topbar/UndoButton.jsx (1)
  • useStore (12-12)
packages/react-filerobot-image-editor/src/components/Topbar/RedoButton.jsx (1)
  • useStore (12-12)
packages/react-filerobot-image-editor/src/components/NodeControls/index.jsx (1)
  • useStore (16-16)
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (1)
  • useStore (40-43)
packages/react-filerobot-image-editor/src/actions/selectTab.js (1)
  • selectTab (6-18)
packages/react-filerobot-image-editor/src/components/tools/tools.constants.js (2)
  • TABS_TOOLS (122-149)
  • TABS_TOOLS (122-149)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (4)
packages/react-filerobot-image-editor/src/components/tools/tools.constants.js (2)
  • TABS_TOOLS (122-149)
  • TABS_TOOLS (122-149)
packages/react-filerobot-image-editor/src/actions/selectTool.js (1)
  • selectTool (3-12)
packages/react-filerobot-image-editor/src/components/Tabs/index.jsx (1)
  • currentTabId (22-22)
packages/react-filerobot-image-editor/src/utils/constants.js (2)
  • TABS_IDS (13-20)
  • TABS_IDS (13-20)
🪛 ESLint
packages/react-filerobot-image-editor/src/actions/selectTab.js

[error] 18-18: Insert ······

(prettier/prettier)

packages/react-filerobot-image-editor/src/actions/selectTool.js

[error] 4-4: Replace payload,·state with ·payload,·state·

(prettier/prettier)


[error] 12-12: Insert ;

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/Tabs/index.jsx

[error] 11-11: components/tools/tools.constants import should occur before import of ./TabItem

(import/order)


[error] 25-25: Insert ⏎·····

(prettier/prettier)


[error] 31-31: Insert ,

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx

[error] 7-7: Replace ·TABS_TOOLS,·TOOLS_ITEMS,·AVAILABLE_ANNOTATIONS_TOOLS· with ⏎··TABS_TOOLS,⏎··TOOLS_ITEMS,⏎··AVAILABLE_ANNOTATIONS_TOOLS,⏎

(prettier/prettier)


[error] 7-7: AVAILABLE_ANNOTATIONS_TOOLS not found in 'components/tools/tools.constants'

(import/named)


[error] 45-45: Replace TABS_IDS,·TABS_TOOLS:·TABS_TOOLS.Annotate,·tabTools with ·TABS_IDS,·TABS_TOOLS:·TABS_TOOLS.Annotate,·tabTools·

(prettier/prettier)


[error] 48-48: Delete ··

(prettier/prettier)


[error] 52-52: Delete ··

(prettier/prettier)


[error] 65-65: Delete ··

(prettier/prettier)


[error] 72-72: Replace orderedToolIds with ·orderedToolIds·

(prettier/prettier)


[error] 76-76: Delete ··

(prettier/prettier)


[error] 81-81: Delete ··

(prettier/prettier)


[error] 83-83: Replace currentTabId,·tabTools,·annotationToolsIds,·currentToolId,·useCloudimage with ⏎····currentTabId,⏎····tabTools,⏎····annotationToolsIds,⏎····currentToolId,⏎····useCloudimage,⏎··

(prettier/prettier)

🪛 markdownlint-cli2 (0.17.2)
README.md

448-448: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 Biome (1.9.4)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (9)
packages/react-filerobot-image-editor/src/context/defaultConfig.js (1)

95-95: Well-structured addition of the new annotationToolsIds property

The new property is properly added and initialized as an empty array, consistent with the similar tabsIds property above it. This enables users to provide a custom list of annotation tools and arrange them in any desired order.

packages/react-filerobot-image-editor/src/index.d.ts (1)

295-295: Type definition correctly added for annotationToolsIds

The TypeScript type is appropriately defined as an optional property accepting either an array of available tools or an empty array. This matches the implementation in defaultConfig.js and provides proper type checking for this new feature.

packages/react-filerobot-image-editor/src/actions/selectTab.js (1)

12-12: Improved tab selection logic to maintain tool selection

The change enhances the tab selection functionality by utilizing the tool ID from the payload rather than always defaulting to the first tool. This ensures that the defaultToolId is persisted when a user changes tabs and then returns to a previous tab, improving the overall user experience.

public/demo-config.js (1)

354-354: Adds a new configuration property for customizing annotation tools order

This new property annotationToolsIds aligns with the PR objective of allowing users to provide a custom list of annotation tools in their preferred order. It's commented out by default, which makes it a non-intrusive addition to the existing configuration.

packages/react-filerobot-image-editor/src/components/Tabs/index.jsx (1)

17-17: Added toolId to handle persistent tool selection

Adding the toolId to the destructured properties from useStore enables tracking the currently selected tool, which is necessary for the new feature that persists tool selection across tab changes.

public/init.js (3)

30-30: Added TOOLS import to support annotation tools customization

This change imports the TOOLS constant needed for defining the custom list of annotation tools.


53-62: Definition of default annotation tools

This new constant defines a complete set of annotation tools that will be used as the default configuration. This implementation correctly supports the PR objective of allowing custom ordering of annotation tools.

The array includes all the annotation tools that were previously shown by default, ensuring backward compatibility while adding configurability.


77-77: Applied annotation tools configuration

The new annotationToolsIds property is added to the plugin configuration, utilizing the predefined list of tools. This enables the feature described in the PR objectives, allowing users to provide a custom list of annotation tools and arrange them in their desired order.

packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (1)

24-24: LGTM! Config properly updated

The addition of annotationToolsIds to the config destructuring aligns with the PR objective to support custom ordering of annotation tools.

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

🧹 Nitpick comments (2)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (2)

7-7: Adhere to Prettier formatting for import statement.
The static analysis hints mention inserting spacing around braces for consistency with Prettier rules.

- import { TABS_TOOLS, TOOLS_ITEMS} from 'components/tools/tools.constants';
+ import { TABS_TOOLS, TOOLS_ITEMS } from 'components/tools/tools.constants';
🧰 Tools
🪛 ESLint

[error] 7-7: Insert ·

(prettier/prettier)


63-72: Consider simplifying the tool reordering for clarity and performance.
The current mapping logic is somewhat complex and can be O(n²). It also silently discards unknown tool IDs via .filter(Boolean). If you want to maintain a custom order with minimal overhead, consider a more direct approach:

- const annotateToolIds = annotationToolsIds.length
-   ? annotationToolsIds
-       .map((_, index) =>
-         TABS_TOOLS.Annotate.find(id => annotationToolsIds.indexOf(id) === index),
-       )
-       .filter(Boolean)
-   : TABS_TOOLS.Annotate;

+ // Prefer a simpler approach:
+ let annotateToolIds;
+ if (annotationToolsIds.length > 0) {
+   // Keep valid user-specified IDs in order
+   annotateToolIds = annotationToolsIds.filter(id =>
+     TABS_TOOLS.Annotate.includes(id)
+   );
+   // Append remaining defaults that were not included in annotationToolsIds
+   TABS_TOOLS.Annotate.forEach((id) => {
+     if (!annotateToolIds.includes(id)) {
+       annotateToolIds.push(id);
+     }
+   });
+ } else {
+   annotateToolIds = [...TABS_TOOLS.Annotate];
+ }
🧰 Tools
🪛 ESLint

[error] 65-65: Replace ?·annotationToolsIds.map((_,·index)·=>·TABS_TOOLS.Annotate.find(id·=>·annotationToolsIds.indexOf(id)·===·index)) with ··?·annotationToolsIds⏎············.map((_,·index)·=>⏎··············TABS_TOOLS.Annotate.find(⏎················(id)·=>·annotationToolsIds.indexOf(id)·===·index,⏎··············),⏎············)⏎············

(prettier/prettier)


[error] 66-66: Insert ··

(prettier/prettier)


[error] 70-70: Delete ··

(prettier/prettier)


[error] 72-72: Replace currentTabId,·tabTools,·annotationToolsIds,·currentToolId,·useCloudimage with ⏎····currentTabId,⏎····tabTools,⏎····annotationToolsIds,⏎····currentToolId,⏎····useCloudimage,⏎··

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2097527 and 27af247.

📒 Files selected for processing (2)
  • packages/react-filerobot-image-editor/src/actions/selectTool.js (1 hunks)
  • packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react-filerobot-image-editor/src/actions/selectTool.js (2)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (1)
  • selectTool (35-42)
packages/react-filerobot-image-editor/src/actions/updateState.js (1)
  • payload (7-10)
🪛 ESLint
packages/react-filerobot-image-editor/src/actions/selectTool.js

[error] 4-10: Expected an assignment or function call and instead saw an expression.

(no-unused-expressions)


[error] 5-5: Insert ··

(prettier/prettier)


[error] 6-6: Insert ··

(prettier/prettier)


[error] 7-7: Insert ··

(prettier/prettier)


[error] 8-8: Replace ······ with ········

(prettier/prettier)


[error] 9-9: Insert ··

(prettier/prettier)


[error] 10-10: Insert ··

(prettier/prettier)


[error] 11-11: Insert ;

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx

[error] 7-7: Insert ·

(prettier/prettier)


[error] 49-49: Delete ··

(prettier/prettier)


[error] 52-52: Delete ··

(prettier/prettier)


[error] 65-65: Replace ?·annotationToolsIds.map((_,·index)·=>·TABS_TOOLS.Annotate.find(id·=>·annotationToolsIds.indexOf(id)·===·index)) with ··?·annotationToolsIds⏎············.map((_,·index)·=>⏎··············TABS_TOOLS.Annotate.find(⏎················(id)·=>·annotationToolsIds.indexOf(id)·===·index,⏎··············),⏎············)⏎············

(prettier/prettier)


[error] 66-66: Insert ··

(prettier/prettier)


[error] 70-70: Delete ··

(prettier/prettier)


[error] 72-72: Replace currentTabId,·tabTools,·annotationToolsIds,·currentToolId,·useCloudimage with ⏎····currentTabId,⏎····tabTools,⏎····annotationToolsIds,⏎····currentToolId,⏎····useCloudimage,⏎··

(prettier/prettier)

🔇 Additional comments (2)
packages/react-filerobot-image-editor/src/components/ToolsBar/index.jsx (2)

24-24: New annotationToolsIds property looks good.
This new configuration prop aligns well with the feature requirements for customizing annotation tools.


45-48: Visibility check logic is clear.
The isToolVisible method is straightforward and effectively hides tools if hideFn is set.

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

🧹 Nitpick comments (1)
packages/react-filerobot-image-editor/src/actions/selectTool.js (1)

3-10: Logic is correct; consider fixing indentation for style compliance.

The function is concise, correct, and follows reducer best practices. Only minor indentation issues remain, as flagged by static analysis tools. Fixing these will improve code consistency and satisfy Prettier/ESLint.

Apply this diff to fix indentation:

-const selectTool = (state, payload) =>
-  state.toolId === payload.toolId
-  ? state
-  : {
-      ...state,
-      toolId: payload.toolId,
-      selectionsIds: payload.keepSelections ? state.selectionsIds : [],
-    };
+const selectTool = (state, payload) =>
+  state.toolId === payload.toolId
+    ? state
+    : {
+        ...state,
+        toolId: payload.toolId,
+        selectionsIds: payload.keepSelections ? state.selectionsIds : [],
+      };
🧰 Tools
🪛 ESLint

[error] 5-5: Insert ··

(prettier/prettier)


[error] 6-6: Insert ··

(prettier/prettier)


[error] 7-7: Replace ······ with ········

(prettier/prettier)


[error] 8-8: Insert ··

(prettier/prettier)


[error] 9-9: Insert ··

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 27af247 and c61cebc.

📒 Files selected for processing (1)
  • packages/react-filerobot-image-editor/src/actions/selectTool.js (1 hunks)
🧰 Additional context used
🪛 ESLint
packages/react-filerobot-image-editor/src/actions/selectTool.js

[error] 5-5: Insert ··

(prettier/prettier)


[error] 6-6: Insert ··

(prettier/prettier)


[error] 7-7: Replace ······ with ········

(prettier/prettier)


[error] 8-8: Insert ··

(prettier/prettier)


[error] 9-9: Insert ··

(prettier/prettier)


[error] 10-11: Replace };⏎ with ··};

(prettier/prettier)

Comment on lines +5 to +11
? state
: {
...state,
toolId: payload.toolId,
selectionsIds: payload.keepSelections ? state.selectionsIds : [],
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's revert this back and keep the spaces as they are for a better formatting

dispatch,
config: { defaultTabId, tabsIds, useCloudimage },
} = useStore();

const currentTabId = tabId || defaultTabId;

const selectTab = useCallback((newTabId) => {
const annotateToolIdKey = defaultTabId === newTabId ? TABS_TOOLS.Annotate.indexOf(toolId) : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do u need to pass the index and reuse the index from the tab_tools constant as long as the toolId is going to be exact the same as the toolId needed? it's more performant to use the id directly and drop searching for the id by the key every time and only make a verification that uses the constants.TABS_IDS and add a fallback for the first item of the array in the reducer.

Comment on lines +63 to +67
if (currentTabId === TABS_IDS.ANNOTATE) {
const annotateToolIds = annotationToolsIds.length
? annotationToolsIds.map((_, index) => TABS_TOOLS.Annotate.find(id => annotationToolsIds.indexOf(id) === index)).filter(Boolean)
: TABS_TOOLS.Annotate;

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will need to be changed if u applied the last comment of using the toolId instead of the tool key/index

@@ -292,6 +292,7 @@ export interface FilerobotImageEditorConfig {
};
// TABS_IDS
tabsIds?: availableTabs[] | [];
annotationToolsIds?: availableTools[] | [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this will be only for annotation tab I think we need to limit this with the annotation tools as long as u are using TAB_TOOLS

@@ -9,12 +9,12 @@ const selectTab = (state, payload) =>
: {
...state,
tabId: payload.tabId,
toolId: TABS_TOOLS[payload.tabId][0],
toolId: TABS_TOOLS[payload.tabId][payload.toolId],
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use the toolId directly instead of the tool index as this is possible to be changed anytime + have the fallback for the first item of the array in-case the toolId isn't found

@AhmeeedMostafa
Copy link
Collaborator

@HimonRana FYI - this will be possible in the new major version of the editor as it will be more customized by providing the functionality through the context and you could reuse it with whatever UI (but this will take time to be released)

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