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

chore: Updating plugin action name editor component to use ADS text component #36960

Merged
merged 9 commits into from
Oct 18, 2024

Conversation

ankitakinger
Copy link
Contributor

@ankitakinger ankitakinger commented Oct 18, 2024

Description

Updating plugin action name editor component to use ADS text component instead of EditableText from blueprint. Also, adding permission checks for editable tabs to not allow the name edits when the user doesn't have the permission.

Fixes #36793

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11402567877
Commit: 0b695e8
Cypress dashboard.
Tags: @tag.All
Spec:


Fri, 18 Oct 2024 12:36:26 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced conditional editing functionality in the FileTab component based on user permissions.
    • Enhanced the PluginActionNameEditor with real-time validation and improved user interaction.
    • Added user permissions information to entity items and selectors for better access control.
    • Integrated new functionality for saving entity names and managing editable tab permissions.
    • Expanded the EditorTabs component to include contextual entity information for each tab.
  • Bug Fixes

    • Simplified the ActionNameEditor by removing unnecessary feature flag checks.
  • Documentation

    • Updated interfaces and components to improve clarity and functionality.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes in this pull request introduce several enhancements across multiple components in the application. Key modifications include the addition of a new optional property isChangePermitted to manage editing permissions in the FileTab component, improved state management in the PluginActionNameEditor, and updates to the EditableTab and EditorTabs components to incorporate entity data. Various utility functions and selectors have been updated to support these changes, aiming to enhance interactivity and usability within the editor environment.

Changes

File Path Change Summary
app/client/src/IDE/Components/FileTab/FileTab.tsx Added optional property isChangePermitted to FileTabProps and modified handleDoubleClick logic.
app/client/src/PluginActionEditor/components/PluginActionNameEditor.tsx Introduced hooks for state management, added new functions for editing behavior, and replaced styled components.
app/client/src/ce/entities/IDE/constants.ts Added optional property userPermissions to EntityItem interface.
app/client/src/ce/entities/IDE/utils.ts Added new interfaces and functions for saving entity names and managing permissions.
app/client/src/ce/selectors/entitiesSelector.ts Introduced new interface and function for checking saving status, updated existing functions to include userPermissions.
app/client/src/components/editorComponents/ActionNameEditor.tsx Removed feature flag logic, simplifying the component.
app/client/src/pages/Editor/IDE/EditorTabs/EditableTab.tsx Updated EditableTabProps to include entity, modified logic for saving names and checking permissions.
app/client/src/pages/Editor/IDE/EditorTabs/index.tsx Added selector for entities and updated tab rendering logic to include entity prop.
app/client/src/utils/hooks/useNameEditor.ts Changed visibility of NameSaveActionParams interface to public.

Assessment against linked issues

Objective Addressed Explanation
Update the editable text component for Action names on action editor (#36793)

Possibly related PRs

Suggested labels

Enhancement, ok-to-test

Suggested reviewers

  • ayushpahwa
  • hetunandu

🎉 In the realm of code, where logic flows,
New features sprout, like a garden that grows.
With permissions in place, editing's a breeze,
Enhancing the tabs, bringing joy and ease!
So here's to the changes, both bold and bright,
Crafting a future that feels just right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai 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.

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.

@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Oct 18, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 18, 2024
@ankitakinger
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11398296521.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36960.
recreate: .

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 36, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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 (6)
app/client/src/ce/entities/IDE/constants.ts (1)

125-125: LGTM. Consider adding JSDoc comment.

The addition of userPermissions aligns well with the PR objectives. To improve maintainability, consider adding a JSDoc comment explaining the purpose and expected format of this property.

+  /** Array of permission strings associated with this entity. */
   userPermissions?: string[];
app/client/src/components/editorComponents/ActionNameEditor.tsx (1)

86-86: LGTM. Consider adding a comment for clarity.

The change to set iconSize to a static value of "md" aligns with the PR objective and simplifies the component. Good job on removing the feature flag dependency.

Consider adding a brief comment explaining why "md" was chosen as the default size, for future maintainability:

-              iconSize={"md"}
+              iconSize={"md"} // Default medium size for consistency across the app
app/client/src/IDE/Components/FileTab/FileTab.tsx (1)

94-95: LGTM with a minor suggestion: Consider improving readability.

The logic correctly implements the new permission check. However, consider using an if-else statement for improved readability:

const handleDoubleClick = () => {
  if (editorConfig && isChangePermitted) {
    handleEnterEditMode();
  }
};

This approach might be easier to understand and maintain, especially if more conditions are added in the future.

app/client/src/pages/Editor/IDE/EditorTabs/index.tsx (2)

126-145: LGTM: Enhanced EditableTab with entity prop.

The changes correctly integrate the new entity prop into the EditableTab component, providing more context as per the PR objectives.

Consider optimizing the entity lookup by using a Map for O(1) access:

const entityMap = new Map(entities.map(entity => [entity.key, entity]));
// ...
const entity = entityMap.get(tab.key);

This could improve performance, especially with a large number of entities.


130-143: LGTM: EditableTab updated with entity prop.

The addition of the entity prop to EditableTab is consistent with the earlier changes and aligns with the PR objectives.

Consider adding a comment or updating the component's documentation to describe the purpose and expected shape of the entity prop for future maintainability.

app/client/src/ce/selectors/entitiesSelector.ts (1)

1707-1718: Function implementation is correct, but consider adding error handling.

The getIsSavingEntityName function correctly checks for API and JS object name saving states. However, it might be beneficial to add error handling for unexpected segment values.

Consider adding a default case to handle unexpected segment values:

export const getIsSavingEntityName = (
  state: AppState,
  { id, segment }: IsSavingEntityNameParams,
) => {
  let isSavingEntityName = getIsSavingForApiName(state, id);

  if (EditorEntityTab.JS === segment) {
    isSavingEntityName = getIsSavingForJSObjectName(state, id);
  }

+  // Handle unexpected segment values
+  if (![EditorEntityTab.API, EditorEntityTab.JS].includes(segment)) {
+    console.warn(`Unexpected segment value: ${segment}`);
+  }

  return isSavingEntityName;
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between faed301 and 6127f4e.

📒 Files selected for processing (9)
  • app/client/src/IDE/Components/FileTab/FileTab.tsx (3 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionNameEditor.tsx (2 hunks)
  • app/client/src/ce/entities/IDE/constants.ts (1 hunks)
  • app/client/src/ce/entities/IDE/utils.ts (2 hunks)
  • app/client/src/ce/selectors/entitiesSelector.ts (4 hunks)
  • app/client/src/components/editorComponents/ActionNameEditor.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorTabs/EditableTab.tsx (2 hunks)
  • app/client/src/pages/Editor/IDE/EditorTabs/index.tsx (2 hunks)
  • app/client/src/utils/hooks/useNameEditor.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (27)
app/client/src/utils/hooks/useNameEditor.ts (1)

14-17: LGTM. Verify usage in other files.

The export of NameSaveActionParams looks good. It aligns with the PR objectives and doesn't introduce any issues.

Let's check if this interface is now being imported elsewhere:

✅ Verification successful

The previous command used an unsupported file type. Retrying with correct file extensions.


Export of NameSaveActionParams is verified and utilized in other files.

  • Imported in app/client/src/ce/entities/IDE/utils.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for imports of NameSaveActionParams in other files

rg --type typescript "import.*NameSaveActionParams.*from.*useNameEditor" -g '!app/client/src/utils/hooks/useNameEditor.ts'

Length of output: 159


Script:

#!/bin/bash
# Description: Check for imports of NameSaveActionParams in other files

rg "import.*NameSaveActionParams.*from.*useNameEditor" -g '*.ts' -g '*.tsx' -g '!app/client/src/utils/hooks/useNameEditor.ts'

Length of output: 238

app/client/src/IDE/Components/FileTab/FileTab.tsx (2)

16-16: LGTM: New prop for permission control.

The addition of isChangePermitted aligns with the PR objective and is correctly typed.


36-36: LGTM: Sensible default for new permission prop.

Setting isChangePermitted to false by default is a safe choice and maintains backward compatibility.

app/client/src/pages/Editor/IDE/EditorTabs/index.tsx (1)

38-38: LGTM: New selector added correctly.

The addition of the entities selector using useSelector with shallowEqual is a good practice. It aligns with the PR objectives and should help prevent unnecessary re-renders.

app/client/src/ce/selectors/entitiesSelector.ts (2)

1701-1705: New interface looks good.

The IsSavingEntityNameParams interface is well-defined and includes all necessary properties for its purpose.


1657-1657: Good addition of user permissions.

The inclusion of userPermissions in the getQuerySegmentItems and getJSSegmentItems functions is a positive change. It enhances the security model by allowing for more granular access control.

Also applies to: 1672-1672

app/client/src/pages/Editor/IDE/EditorTabs/EditableTab.tsx (5)

21-21: Adding optional 'entity' prop enhances component flexibility

Including entity?: EntityItem in EditableTabProps allows the component to handle entity-specific logic when necessary.


28-32: Feature flag integration for 'license_gac_enabled' is appropriate

Utilizing useFeatureFlag with FEATURE_FLAG.license_gac_enabled and checking permissions with getEditableTabPermissions ensures that feature-specific behavior is correctly managed based on the user's permissions and the application's license.


37-37: Passing 'entity' to 'saveEntityName' aligns with updated action requirements

Including entity in the saveEntityName parameters provides the necessary context for the name-saving action, accommodating any entity-specific logic required during the save operation.


41-41: Selector update ensures accurate loading state

Adding entity to the getIsSavingEntityName selector call allows for precise tracking of the loading state associated with the specific entity being edited.


63-63: Verify that 'FileTab' component accepts 'isChangePermitted' prop

Ensure that the FileTab component is designed to handle the isChangePermitted prop to control the editability of the tab based on user permissions.

Run the following script to confirm that FileTab accepts the isChangePermitted prop:

✅ Verification successful

'FileTab' Component Correctly Accepts 'isChangePermitted' Prop

The FileTab component accepts the isChangePermitted prop and uses it to control the editability of the tab based on user permissions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if 'FileTab' component accepts 'isChangePermitted' prop.

# Search for 'isChangePermitted' in 'FileTab' component files
rg --type javascript --type typescript 'isChangePermitted' -A 5 -B 5 -g '*FileTab*'

Length of output: 118


Script:

#!/bin/bash
# Description: Re-verify if 'FileTab' component accepts 'isChangePermitted' prop with corrected file types.

# Search for 'isChangePermitted' in 'FileTab' component files
rg --type js --type ts 'isChangePermitted' -A 5 -B 5 -g '*FileTab*'

Length of output: 2453

app/client/src/ce/entities/IDE/utils.ts (2)

67-75: Ensure proper handling when entity is undefined

In getEditableTabPermissions, when entity is undefined, entity?.userPermissions || [] results in an empty array being passed to getHasManageActionPermission. Please verify that passing an empty permissions array is appropriate and that getHasManageActionPermission handles this scenario correctly.

Consider reviewing the implementation of getHasManageActionPermission to ensure it handles empty permission arrays as expected.


51-60: Verify that saveEntityName handles all segments correctly

The function saveEntityName defaults to using saveActionName when the segment is not EditorEntityTab.JS. Please ensure that saveActionName is appropriate for all other segments. Consider explicitly handling other segments if different actions are required.

To confirm all segments are handled correctly, you can run the following script:

app/client/src/PluginActionEditor/components/PluginActionNameEditor.tsx (14)

1-16: Imports are correctly organized

All necessary modules are imported appropriately.


29-51: Styled components are properly defined

The NameWrapper, IconContainer, and Text styled components are well-structured.


62-75: State and hooks are initialized correctly

The component's state variables and hooks are appropriately set up.


77-82: Editing state is managed effectively

The useBoolean hook efficiently controls the editing state.


89-90: Current title computation is accurate

The logic for determining currentTitle handles different states correctly.


94-112: Key events are handled appropriately

The handleKeyUp function processes 'Enter' and 'Escape' keys effectively.


115-119: Title changes are updated correctly

The handleTitleChange function normalizes and updates the title as expected.


121-124: Edit mode initiation is correct

Entering edit mode is handled properly in handleEnterEditMode.


126-127: Permission checks are implemented

Double-click functionality respects user permissions.


128-141: Input properties are optimized

Using useMemo for inputProps enhances performance.


143-160: Focus out event is handled properly

The useEventListener for 'focusout' manages title saving on focus loss.


162-169: Title synchronization is maintained

The useEffect hook keeps editableTitle in sync with title.


171-182: Input focus is correctly managed

Focusing the input when editing ensures a smooth user experience.


185-199: Rendering components appropriately

The JSX structure correctly displays all UI elements with proper conditional rendering.

Copy link

Deploy-Preview-URL: https://ce-36960.dp.appsmith.com

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 36, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

1 similar comment
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 36, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/IDE/Components/FileTab/FileTab.test.tsx (1)

Add tests for isChangePermitted prop to ensure proper functionality.

  • The new isChangePermitted prop is not currently covered by any tests in FileTab.test.tsx.
🔗 Analysis chain

Line range hint 1-238: Verify test coverage for new prop.

The new isChangePermitted prop may require additional test cases to ensure proper functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for test coverage of isChangePermitted prop

# Test: Search for tests related to isChangePermitted
rg --type typescript 'test.*isChangePermitted' app/client/src/IDE/Components/FileTab

Length of output: 121


Script:

#!/bin/bash
# Description: Retry searching for tests related to isChangePermitted using the correct file type

# Test: Search for tests related to isChangePermitted in TypeScript React files
rg --type typescriptreact 'isChangePermitted' app/client/src/IDE/Components/FileTab

Length of output: 123


Script:

#!/bin/bash
# Description: Search for tests related to isChangePermitted using file extension patterns

# Test: Search for isChangePermitted in .ts and .tsx files
rg 'isChangePermitted' app/client/src/IDE/Components/FileTab --glob '*.ts' --glob '*.tsx'

Length of output: 448


Script:

#!/bin/bash
# Description: Search for test cases and assertions related to isChangePermitted

# Test: Look for expect statements or test scenarios involving isChangePermitted
rg 'expect.*isChangePermitted' app/client/src/IDE/Components/FileTab/FileTab.test.tsx

Length of output: 87

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6127f4e and 91a7487.

📒 Files selected for processing (1)
  • app/client/src/IDE/Components/FileTab/FileTab.test.tsx (1 hunks)
🧰 Additional context used

@ankitakinger ankitakinger added the ok-to-test Required label for CI label Oct 18, 2024
@ankitakinger ankitakinger removed the ok-to-test Required label for CI label Oct 18, 2024
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/ce/entities/IDE/utils.ts (1)

67-75: LGTM with a minor suggestion for clarity.

The function looks good. Consider destructuring userPermissions for improved readability:

export const getEditableTabPermissions = ({
  entity,
  isFeatureEnabled,
}: EditableTabPermissions) => {
  const { userPermissions = [] } = entity || {};
  return getHasManageActionPermission(isFeatureEnabled, userPermissions);
};

This change makes it clearer that we're using an empty array as a fallback when entity or userPermissions is undefined.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 91a7487 and 0b695e8.

📒 Files selected for processing (1)
  • app/client/src/ce/entities/IDE/utils.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
app/client/src/ce/entities/IDE/utils.ts (3)

10-13: LGTM: New imports are relevant and correctly added.


15-22: LGTM: SaveEntityName interface is well-structured.

The interface provides a clear contract for saving entity names.


62-65: LGTM: EditableTabPermissions interface is well-defined.

app/client/src/ce/entities/IDE/utils.ts Show resolved Hide resolved
@ankitakinger ankitakinger added the ok-to-test Required label for CI label Oct 18, 2024
@ankitakinger ankitakinger merged commit 9a315ea into release Oct 18, 2024
88 checks passed
@ankitakinger ankitakinger deleted the chore/update-editable-action-name branch October 18, 2024 13:37
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
…omponent (appsmithorg#36960)

## Description

Updating plugin action name editor component to use ADS text component
instead of EditableText from blueprint. Also, adding permission checks
for editable tabs to not allow the name edits when the user doesn't have
the permission.

Fixes [appsmithorg#36793](appsmithorg#36793)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11402567877>
> Commit: 0b695e8
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11402567877&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 18 Oct 2024 12:36:26 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced conditional editing functionality in the FileTab component
based on user permissions.
- Enhanced the PluginActionNameEditor with real-time validation and
improved user interaction.
- Added user permissions information to entity items and selectors for
better access control.
- Integrated new functionality for saving entity names and managing
editable tab permissions.
- Expanded the EditorTabs component to include contextual entity
information for each tab.

- **Bug Fixes**
- Simplified the ActionNameEditor by removing unnecessary feature flag
checks.

- **Documentation**
- Updated interfaces and components to improve clarity and
functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Update the editable text component for Action names on action editor
3 participants