-
Notifications
You must be signed in to change notification settings - Fork 8
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
T352298: Add custom tooltip #111
Merged
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0239564
Add initial tooltip.js
medied 2e50f7a
Initial computeTooltipPosition
medied 9f475a2
Use Popover component
medied 4e44ddd
Naming update
medied e24f898
Address warnings
medied da477e3
Move useEffect logic to a method for consistency
medied 2c8c1f4
Use property to store tooltip count
medied 089406b
Remove className
medied 1c64954
Add guard to prevent displaying tooltip if toolbar is closed
medied cf59256
Address php linter
medied c9c1363
Proprogate property
medied 03f74a5
Color popover arrow and add offset
medied 5f28125
Rewrite endpoints set up as a function for consistency
medied a66986f
Address linter
medied 62b3868
Increment property via window object
medied f8f3546
Merge branch 'T352298-tooltip-property' into T352298-tooltip
medied 995ab80
Use camelCasing and improve readability
medied 51680af
Concentrate all tooltip logic inside CustomTooltip for better code hy…
medied 8e8b8bc
Disable selector-class-pattern globally
medied f83aa6d
Track whether the tooltip has been displayed for the full 5 secs
medied 20ed74b
Address linter
medied afa3625
Clear timeouts if user clicks on W before the tooltip diplays
medied 1661af8
Address linter
medied 0e297c4
Add comments for php properties
medied File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Popover } from '@wordpress/components'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
export const CustomTooltip = ( { | ||
anchorRef, | ||
setDisplayCustomTooltip, | ||
} ) => { | ||
useEffect( () => { | ||
// Wait 5 seconds and then hide the tooltip | ||
setTimeout( () => { | ||
setDisplayCustomTooltip( false ); | ||
}, 5000 ); | ||
} ); | ||
|
||
return ( | ||
<div> | ||
<Popover | ||
anchor={ anchorRef.current } | ||
placement={ 'top' } | ||
noArrow={ false } | ||
> | ||
<div className="wikipediapreview-edit-inline-tooltip"> | ||
<p className="wikipediapreview-edit-inline-tooltip-text">{ __( 'Add Wikipedia Preview' ) }</p> | ||
</div> | ||
</Popover> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opting for
localStorage
here to save this count state,useState
wouldn't work here as it gets reset on page reload. Yet the specification asks to re-display tooltip at least a second time:Hence
customTooltipDisplayedLimit
which can be increased to 2 (or whatever limit). However this is what I would like to discuss with Sudhanshu, details of this UX, what should we look for here to decide whether to display tooltip again? For example, we could look into whether there are already previews in the post: if no previews added, display again; otherwise we could infer the user learned to add the preview as there are present already.Also
localStorage
gets reset on a fresh/new browser session, which makes us run into the risk of the tooltip being annoying. Perhaps another reason to check whether previews are added already.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is showing up for editors within the admin interface, we can use a property for storage. Like we did for the review banner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, here's one implementation: 2c8c1f4, do you think there's a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm exploring with a propagated property here but looks like the global var only gets updated on page reload so it may not work for what we need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct me if I miss the context here, this need to be documented well and easy to confuse if we revisit this logic again in few months/years later.
This can handled by localStorage, so it checks through the current session
full duration for 5 seconds, then we set post the incrementDisplayedCount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's propagated from php to js on page load. After that, you have to update it yourself on the js side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, updating directly on JS side by incrementing directly via
window
(and withoutuseState
): 62b3868There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea this is part of the UX I would like to clarify with Sudhanshu, specially the other point:
I think we just need to first make sure we're on the same page of what a 'session' is in this case, and also just agree on when exactly we should display tooltip again. Let's circle back to this later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just realise there is a sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage in browser, if we are dealing with session maybe this is what we can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right I came across that method too, but it's not really suited as we need the storage to be more permanent. From the docs:
What we need is to be able to display the tooltip with the full 5 seconds duration, and then we don't show again.