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 link in record details isn't deleted by default #9840

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

Conversation

Lucifer4255
Copy link
Contributor

Gives a fix for #9780 . I have added handleDelete inside the submit function and created a state to manage the empty placeholder
Screencast from 2025-01-24 01-45-22.webm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds functionality to handle empty link deletion in record details, ensuring that empty links are properly removed when a user clears the input field.

  • Added isClearingInput state in MultiItemFieldInput.tsx to track input clearing status
  • Modified handleSubmitInput to trigger item deletion when input is cleared
  • Improved empty string validation using turnIntoEmptyStringIfWhitespacesOnly utility
  • Integrated with existing link field components to maintain consistent behavior

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 86 to 87
if (value === '' && itemToEditIndex !== null) {
setIsClearingInput(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: comparing with !== null here is incorrect since itemToEditIndex is a number. Should use !== -1 to match initialization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 138 to 147
if (isClearingInput && itemToEditIndex !== null) {
handleDeleteItem(itemToEditIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: same issue here with !== null comparison for itemToEditIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@etiennejouan etiennejouan left a comment

Choose a reason for hiding this comment

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

Hi @Lucifer4255, thank you for your PR.

Your solution is not handling case where input is empty string (without update).

I would handle empty string input in handleSubmitInput method.

  • If inputValue is empty string AND isAddingNewItem, it should early return
  • If inputValue is empty string AND !isAddingNewItem, it should delete updated item and early return

Copy link
Contributor

@etiennejouan etiennejouan left a comment

Choose a reason for hiding this comment

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

@Lucifer4255 thank you for your update, added few comments.

@@ -69,6 +69,7 @@ export const MultiItemFieldInput = <T,>({

useScopedHotkeys(Key.Escape, handleDropdownClose, hotkeyScope);

const [isClearingInput, setIsClearingInput] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this state. Empty input case is handled at submit.

Comment on lines +146 to +149
if (isClearingInput && itemToEditIndex !== -1) {
handleDeleteItem(itemToEditIndex);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, you can delete these lines. no need to handle empty item deletion since they're not created anymore thanks to logic above.

Comment on lines +86 to +91
if (value === '' && itemToEditIndex !== -1) {
setIsClearingInput(true);
} else {
setIsClearingInput(false);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

same here, you can remove these lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants