Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty space is clickable when user edits app name or organisatio… #36882

Conversation

Sai6347
Copy link

@Sai6347 Sai6347 commented Oct 15, 2024

Bug issue

Description:
In the home page when the user clicks the edit(pencil) icon to edit the application or organization name, edit icon is hiding and if we click on empty space where the edit icon is initially placed, we are able to save the name. Now i have implemented Save(Tick) and Cancel(Cross) icons, if we click on Save icon it will save or click on Cancel icon to cancel the editing.
Initially, any changes to the edited data would automatically save and display the updated application name when the user clicked anywhere. However, I have modified the functionality so that the name only changes when the user explicitly clicks the "Save" (tick) icon. Otherwise, the old name will remain displayed.

Screenshots

Before the fix:
Screenshot from 2024-10-15 16-32-34

After the fix:
Screenshot from 2024-10-15 16-32-41
Screenshot from 2024-10-15 16-41-39

Summary by CodeRabbit

  • New Features
    • Enhanced interactivity in the EditableTextSubComponent with clear cancel and confirm actions.
  • Improvements
    • Streamlined state management in the ApplicationCard component for better performance and reduced unnecessary re-renders.
  • Bug Fixes
    • Updated conditions for application name updates to ensure accurate tracking based on user actions.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in this pull request enhance the EditableTextSubComponent by introducing a new state variable to track cancellation of edits, updating the confirmation and cancellation handling functions, and modifying rendering logic for better interactivity. Additionally, the ApplicationCard component has been simplified by converting a state variable to a constant, removing real-time change tracking, and adjusting the update conditions based on the application name.

Changes

File Path Change Summary
app/client/packages/design-system/ads-old/src/... - Added state variable isCancelled to track editing cancellation.
- Introduced onCancel function to reset state and update saving status.
- Updated onConfirm to set lastValidValue and value.
- Modified rendering logic to conditionally display cancel and confirm icons.
app/client/src/pages/Applications/ApplicationCard.tsx - Changed lastUpdatedValue from a state variable to a constant.
- Removed onTextChanged event handler for EditableText.
- Updated handleMenuOnClose to check conditions before updating the application name.

Possibly related PRs

Suggested labels

Bug, Enhancement, High, Production, Needs Triaging, IDE Product, ok-to-test

Suggested reviewers

  • ankitakinger
  • ApekshaBhosale
  • hetunandu

🎉 In the realm of code, where changes unfold,
EditableText shines, with stories retold.
Cancel and confirm, now clear as the day,
With logic enhanced, in a seamless ballet.
ApplicationCard too, finds a simpler way,
In the world of components, bright colors 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>, 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.

@Sai6347
Copy link
Author

Sai6347 commented Oct 15, 2024

Hi @riteshkew, As per our discussion i made changes, can you please review it and let me know if any changes required.

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

🧹 Outside diff range and nitpick comments (3)
app/client/src/pages/Applications/ApplicationCard.tsx (3)

Line range hint 290-305: Let's turn our attention to the handleMenuOnClose function, class.

We've made some adjustments to how we update the application name. Now, we only update if lastUpdatedValue is not empty and the name has actually changed.

Consider the following points for our discussion:

  1. How does this change affect the user experience when editing the application name?
  2. Are we ensuring that all valid name changes are captured and saved?
  3. Could we improve error handling or user feedback in this function?

Remember, clear and intuitive user interactions are key to a good learning experience. Let's make sure our changes support this goal.


Line range hint 290-305: Class, let's examine an important change in our component's behavior.

We've removed the onTextChanged event handler for the EditableText component. This means we're no longer tracking changes to the application name in real-time.

Let's consider the following questions:

  1. How does this affect the user's ability to see their changes as they type?
  2. Are we still providing adequate feedback to the user about the status of their edits?
  3. Could this change lead to any confusion or frustration for users who expect immediate feedback?

Remember, in our classroom of code, we always strive for clarity and responsiveness. Let's discuss if this change aligns with those principles or if we need to revisit our approach.


Line range hint 1-605: Class, let's summarize our review of the ApplicationCard component.

We've observed several significant changes:

  1. The simplification of lastUpdatedValue state management.
  2. Modifications to the handleMenuOnClose function.
  3. Removal of real-time tracking for application name changes.

For our next steps, I suggest:

  1. Conducting thorough user testing to ensure these changes don't negatively impact the user experience.
  2. Reviewing our error handling and user feedback mechanisms in light of these changes.
  3. Considering if we need to add any additional safeguards or confirmations for name changes.

Remember, every line of code is an opportunity to learn and improve. Let's take these insights and use them to make our application even better in our next iteration.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3032adc and cb04f62.

📒 Files selected for processing (2)
  • app/client/packages/design-system/ads-old/src/EditableTextSubComponent/index.tsx (5 hunks)
  • app/client/src/pages/Applications/ApplicationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome
app/client/packages/design-system/ads-old/src/EditableTextSubComponent/index.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
app/client/packages/design-system/ads-old/src/EditableTextSubComponent/index.tsx (2)

141-141: Good addition of state variable isCancelled

Introducing const [isCancelled, setIsCancelled] = useState<boolean>(false); is a thoughtful approach to manage the cancellation state in the component.


191-192: Ensure state updates are in sync

Updating setLastValidValue(finalVal); and setValue(finalVal); upon confirmation is a good approach to keep your component's state consistent.

@@ -117,7 +117,7 @@ export function ApplicationCard(props: ApplicationCardProps) {
const [isDeleting, setIsDeleting] = useState(false);
const [isForkApplicationModalopen, setForkApplicationModalOpen] =
useState(false);
const [lastUpdatedValue, setLastUpdatedValue] = useState("");
const lastUpdatedValue = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Class, let's examine this change in our state management.

The lastUpdatedValue has been transformed from a reactive state variable to a constant empty string. This simplification might affect how we handle updates to the application name.

Please consider the following:

  1. How will this impact real-time tracking of changes to the application name?
  2. Are there any other parts of the component that relied on lastUpdatedValue being reactive?

Let's discuss the reasoning behind this change and ensure it aligns with our learning objectives for this component.

@@ -70,6 +70,7 @@ const TextContainer = styled.div<{
}>`
display: flex;
align-items: center;
// justify-content: space-evenly;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider removing commented-out code

Dear student, it's generally a good practice to remove any commented-out code like // justify-content: space-evenly; unless it's needed for future reference. This helps keep the codebase clean and maintainable.

Comment on lines +231 to +238
const onCancel = useCallback(() => {
onBlur && onBlur(lastValidValue);
setIsEditing(false);
setIsInvalid(false);
setSavingState(SavingState.NOT_STARTED);
setValue(lastValidValue);
setIsCancelled(true);
}, [lastValidValue, onBlur]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify function calls with optional chaining

In your onCancel function, you can simplify the conditional invocation of onBlur by using optional chaining. This makes the code cleaner and more readable.

Here's how you can apply this change:

-          onBlur && onBlur(lastValidValue);
+          onBlur?.(lastValidValue);
📝 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.

Suggested change
const onCancel = useCallback(() => {
onBlur && onBlur(lastValidValue);
setIsEditing(false);
setIsInvalid(false);
setSavingState(SavingState.NOT_STARTED);
setValue(lastValidValue);
setIsCancelled(true);
}, [lastValidValue, onBlur]);
const onCancel = useCallback(() => {
onBlur?.(lastValidValue);
setIsEditing(false);
setIsInvalid(false);
setSavingState(SavingState.NOT_STARTED);
setValue(lastValidValue);
setIsCancelled(true);
}, [lastValidValue, onBlur]);
🧰 Tools
🪛 Biome

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +240 to +245
useEffect(() => {
if (isCancelled) {
setValue(lastValidValue);
}
}, [isCancelled, lastValidValue]);

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review the necessity of useEffect for isCancelled

I notice that you're setting setValue(lastValidValue); both in the onCancel function and within a useEffect that watches isCancelled. This might be redundant. Let's consider simplifying the state management by removing the isCancelled state and the accompanying useEffect.

You can modify your code as follows:

- const [isCancelled, setIsCancelled] = useState<boolean>(false);

  // ...

  const onCancel = useCallback(() => {
-   onBlur && onBlur(lastValidValue);
+   onBlur?.(lastValidValue);
    setIsEditing(false);
    setIsInvalid(false);
    setSavingState(SavingState.NOT_STARTED);
    setValue(lastValidValue);
-   setIsCancelled(true);
  }, [lastValidValue, onBlur]);

- useEffect(() => {
-   if (isCancelled) {
-     setValue(lastValidValue);
-   }
- }, [isCancelled, lastValidValue]);
📝 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.

Suggested change
useEffect(() => {
if (isCancelled) {
setValue(lastValidValue);
}
}, [isCancelled, lastValidValue]);
const onCancel = useCallback(() => {
onBlur?.(lastValidValue);
setIsEditing(false);
setIsInvalid(false);
setSavingState(SavingState.NOT_STARTED);
setValue(lastValidValue);
}, [lastValidValue, onBlur]);

Comment on lines +278 to +305
{value && !props.hideEditIcon && isEditing ? (
<>
<span
className="pl-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onConfirm(value);
}}
>
<Icon className="cursor-pointer" name="check-line" size="md" />
</span>
<span
className="px-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onCancel();
}}
>
<Icon
className="cursor-pointer"
name="close-circle-line"
size="md"
/>
</span>
</>
) : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use semantic HTML elements for interactive controls

When creating interactive elements, it's important to use semantic HTML tags. Replacing <span> with <button> enhances accessibility and ensures that users can interact with your component using the keyboard.

Here's how you can update your code:

-                  <span
+                  <button
                     className="pl-1"
                     onClick={(e) => {
                       e.preventDefault();
                       e.stopPropagation();
                       onConfirm(value);
                     }}
                   >
                     <Icon className="cursor-pointer" name="check-line" size="md" />
-                  </span>
+                  </button>
-                  <span
+                  <button
                     className="px-1"
                     onClick={(e) => {
                       e.preventDefault();
                       e.stopPropagation();
                       onCancel();
                     }}
                   >
                     <Icon
                       className="cursor-pointer"
                       name="close-circle-line"
                       size="md"
                     />
-                  </span>
+                  </button>
📝 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.

Suggested change
{value && !props.hideEditIcon && isEditing ? (
<>
<span
className="pl-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onConfirm(value);
}}
>
<Icon className="cursor-pointer" name="check-line" size="md" />
</span>
<span
className="px-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onCancel();
}}
>
<Icon
className="cursor-pointer"
name="close-circle-line"
size="md"
/>
</span>
</>
) : null}
{value && !props.hideEditIcon && isEditing ? (
<>
<button
className="pl-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onConfirm(value);
}}
>
<Icon className="cursor-pointer" name="check-line" size="md" />
</button>
<button
className="px-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onCancel();
}}
>
<Icon
className="cursor-pointer"
name="close-circle-line"
size="md"
/>
</button>
</>
) : null}

@ankitakinger
Copy link
Contributor

@Sai6347 The following things doesn't seem to work correct after these changes:

  1. The name is not getting saved if I press enter on the keyboard. This used to work in the current implementation.
  2. Even if I click the cross icon, the update name API is getting called, which shouldn't be the case.
  3. The name editor inside an application isn't working:
image 4. Even the widget name editor on the property pane isn't working: image

@ankitakinger
Copy link
Contributor

@Sai6347
I had a discussion with the team as I was concerned with a new UI/UX getting introduced with this fix. After the discussion, we unfortunately came to a conclusion that we won’t be able to proceed with your changes at this time to avoid introducing further design inconsistencies with different components.

We are currently working to bring consistency across all components used in the product, and we’ll inform you once those components are ready for use.

Thank you for your efforts, and please feel free to contribute to other issues in the meantime.

@Sai6347
Copy link
Author

Sai6347 commented Oct 21, 2024

@ankitakinger
Thanks for your time to review, will work on the other issues

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