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: Add a useTagEditor hook to control the diffing of tags #2733

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

taheramr
Copy link
Member

Description

Related links, issue #, if available: n/a

How has this been tested?

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.

Project coverage is 95.91%. Comparing base (093fdc0) to head (90a7313).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/tag-editor/hooks/use-tag-editor.tsx 0.00% 17 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2733      +/-   ##
==========================================
+ Coverage   95.90%   95.91%   +0.01%     
==========================================
  Files         748      750       +2     
  Lines       20732    20915     +183     
  Branches     7059     7123      +64     
==========================================
+ Hits        19882    20061     +179     
- Misses        794      798       +4     
  Partials       56       56              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


useEffect(() => {
if (initialTags.length === 0) {
console.warn('Warning: initialTags is empty.');
Copy link
Member

Choose a reason for hiding this comment

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

We have an internal util (warnOnce) for this, to keep warnings from repeating every render or messing up console output in production.

useEffect(() => {
if (initialTags !== initialTagsRef.current) {
console.warn('Warning: initialTags has changed in the useTagEditor hook. The internal state will be reset.');
initialTagsRef.current = initialTags;
Copy link
Member

Choose a reason for hiding this comment

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

This feels dangerous. A state variable just for a dev warning is good enough. I don't think we need to reset the internal state if this happens.

initialTags.some(({ key, value }) => tag.key === key && tag.existing && tag.value !== value)
);

const onChange = useCallback((event: NonCancelableCustomEvent<TagEditorProps.ChangeDetail>) => {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this function to be stable? Otherwise, useCallback here is probably just useless.

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