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

NUX: Prevent duplicate DotTips from appearing #8642

Merged
merged 1 commit into from
Aug 8, 2018
Merged

Conversation

noisysocks
Copy link
Member

Description

Fixes #8285.

When there are multiple instances of DotTip that reference the same tip identifier, only show the first instance that was mounted.

I've done this by introducing the concept of "registration". When a <DotTip id="foo"> instance mounts, it registers itself as being associated with the "foo" tip. When it unmounts, the registration is removed. Only the first instance to have registered itself for any given tip will be made visible.

How has this been tested?

  1. If it isn't already, uncheck the "Show Tips" option.
  2. Add a column block.
  3. Check the "Show Tips" option—only one tip should appear on the screen.

Screenshots

nux

When there are multiple instances of `DotTip` that reference the same
tip identifier, only show the first instance that was mounted.
@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended [Package] NUX labels Aug 7, 2018
@noisysocks noisysocks added this to the 3.5 milestone Aug 7, 2018
@noisysocks noisysocks requested review from talldan and aduth August 7, 2018 04:50
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Looks good - I added a few comments, but they're optional changes apart from the typo.

Let me know if I misunderstood the code.

@@ -13,6 +13,43 @@ export function triggerGuide( tipIds ) {
};
}

/**
* Returns an action object that, when dispathed, associates an instance of the
Copy link
Contributor

Choose a reason for hiding this comment

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

minor typo here - dispathed -> dispatched

case 'REGISTER_TIP_INSTANCE':
return {
...state,
[ action.tipId ]: union( state[ action.tipId ] || [], [ action.instanceId ] ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Found this quite a hard line to read initially. I wonder if this would be more succinct? I think they do the same thing.

uniq( [ ...state[ action.tipId ], action.instanceId ] )

Copy link
Member Author

@noisysocks noisysocks Aug 9, 2018

Choose a reason for hiding this comment

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

We need to handle the case where state[ action.tipId ] is undefined.

uniq( [ ...state[ action.tipId ] || [], action.instanceId ] )

Maybe I'll just use a temporary variable.

const existingInstanceIds = state[ action.tipId ] || [];
uniq( [ ...existingInstanceIds, action.instanceId ] )

return false;
}

if ( instanceId ) {
const [ firstInstanceId ] = state.tipInstanceIds[ tipId ] || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Was wondering - if we only use the first instance Id, do the others need to be stored in tipInstanceIds? Potentially the value of tipInstanceIds[ tipId ] could just be the instance Id of the first instance of that tip, instead of an array of all the tips. Maybe renamed to tipActiveInstanceId or something

There might be another use case that I'm missing, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that it doesn't handle the case where the first/active instance is unmounted because of e.g. a block removal. When this happens, the tip should move to the next available instance. You actually encounter this in the reproduction steps for the bug above, because the first/active DotTip is unmounted when you insert the Columns block.

It's a pretty bizarre use-case, I'll admit. Hoping that we can make this all unnecessary either through #8050 or by otherwise iterating on these tips. Tammie and I have been working through some ideas on what to do with NUX...

@gziolo gziolo merged commit 09dc71c into master Aug 8, 2018
@gziolo gziolo deleted the fix/duplicate-tips branch August 8, 2018 11:27
@gziolo
Copy link
Member

gziolo commented Aug 8, 2018

We want to do 3.5 release today. I merged this PR. @noisysocks please open follow up and address the comments. At least the typo one 😄

@noisysocks
Copy link
Member Author

Thanks @talldan and @gziolo!

I may end up reverting this in favour of #8050 which would make it all unnecessary.

noisysocks added a commit that referenced this pull request Aug 22, 2018
noisysocks added a commit that referenced this pull request Aug 24, 2018
* Revert "NUX: Prevent duplicate DotTips from appearing (#8642)"

This reverts commit 09dc71c.

* NUX: Move first tip to the toolbar

Move the first tip to the toolbar so that post content isn't covered,
and adjust DotTip so that it can correctly position itself below the
inserter button.

* s/id/tipId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants