-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add rich tooltips for plugin trees and VSX extensions #10108
Changes from 2 commits
2fed721
faa1ed7
8384a8f
b6f58b8
377e5c5
aab37ea
cf8e2fe
199cc76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Arm and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
.theia-tooltip { | ||
color: var(--theia-list-hoverForeground) !important; | ||
background: var(--theia-list-hoverBackground) !important; | ||
border: 1px solid !important; | ||
border-color: var(--theia-list-hoverForeground) !important; | ||
thegecko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/* Hide tooltip arrow */ | ||
.theia-tooltip::before, | ||
.theia-tooltip::after { | ||
border: none !important; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||
/******************************************************************************** | ||||||
* Copyright (C) 2021 Arm and others. | ||||||
* | ||||||
* This program and the accompanying materials are made available under the | ||||||
* terms of the Eclipse Public License v. 2.0 which is available at | ||||||
* http://www.eclipse.org/legal/epl-2.0. | ||||||
* | ||||||
* This Source Code may also be made available under the following Secondary | ||||||
* Licenses when the conditions for such availability set forth in the Eclipse | ||||||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||||||
* with the GNU Classpath Exception which is available at | ||||||
* https://www.gnu.org/software/classpath/license.html. | ||||||
* | ||||||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||||||
********************************************************************************/ | ||||||
|
||||||
import { injectable, inject, optional } from 'inversify'; | ||||||
import * as React from 'react'; | ||||||
import ReactTooltip from 'react-tooltip'; | ||||||
import { ReactRenderer, RendererHost } from './widgets/react-renderer'; | ||||||
import { v4 } from 'uuid'; | ||||||
|
||||||
export const TooltipService = Symbol('TooltipService'); | ||||||
|
||||||
export interface TooltipService { | ||||||
attachTo(host: HTMLElement): void; | ||||||
tooltipId: string; | ||||||
update(): void; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Attributes to be added to an HTML element to enable | ||||||
* rich HTML tooltip rendering | ||||||
*/ | ||||||
export interface TooltipAttributes { | ||||||
/** | ||||||
* HTML to render in the tooltip. | ||||||
*/ | ||||||
'data-tip': string; | ||||||
/** | ||||||
* The ID of the tooltip renderer. Should be TOOLTIP_ID. | ||||||
*/ | ||||||
'data-for': string; | ||||||
} | ||||||
|
||||||
@injectable() | ||||||
export class TooltipServiceImpl extends ReactRenderer implements TooltipService { | ||||||
public readonly tooltipId: string; | ||||||
protected rendered = false; | ||||||
|
||||||
constructor( | ||||||
@inject(RendererHost) @optional() host?: RendererHost | ||||||
) { | ||||||
super(host); | ||||||
this.tooltipId = v4(); | ||||||
} | ||||||
|
||||||
public attachTo(host: HTMLElement): void { | ||||||
host.appendChild(this.host); | ||||||
} | ||||||
|
||||||
public update(): void { | ||||||
if (!this.rendered) { | ||||||
this.render(); | ||||||
this.rendered = true; | ||||||
} | ||||||
|
||||||
ReactTooltip.rebuild(); | ||||||
} | ||||||
|
||||||
protected doRender(): React.ReactNode { | ||||||
return <ReactTooltip id={this.tooltipId} className='theia-tooltip' html={true} delayShow={1000} />; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use some type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at the props and didn't find much we'd want to expose. I'd also suggest the popup delay is kept consistent across the product There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The delay in the vsx-registry felt a bit long, any reason you chose 1 second?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I timed the vscode popup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Vince here. It seems like the delay is indeed a bit long (depending on which OS you're using). See this setting in the vscode codebase which controlls the delay of the tooltip popup. I'd be in favor of adding a similar setting to the preferences in here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, I'm on a mac hence the longer delay experienced! |
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as markdownit from 'markdown-it'; | ||
import * as React from '@theia/core/shared/react'; | ||
import * as DOMPurify from '@theia/core/shared/dompurify'; | ||
import { injectable, inject } from '@theia/core/shared/inversify'; | ||
|
@@ -28,7 +29,7 @@ import { Endpoint } from '@theia/core/lib/browser/endpoint'; | |
import { VSXEnvironment } from '../common/vsx-environment'; | ||
import { VSXExtensionsSearchModel } from './vsx-extensions-search-model'; | ||
import { MenuPath } from '@theia/core/lib/common'; | ||
import { codicon, ContextMenuRenderer } from '@theia/core/lib/browser'; | ||
import { codicon, ContextMenuRenderer, TooltipService } from '@theia/core/lib/browser'; | ||
import { VSXExtensionNamespaceAccess, VSXUser } from '@theia/ovsx-client/lib/ovsx-types'; | ||
|
||
export const EXTENSIONS_CONTEXT_MENU: MenuPath = ['extensions_context_menu']; | ||
|
@@ -112,6 +113,9 @@ export class VSXExtension implements VSXExtensionData, TreeElement { | |
@inject(VSXExtensionsSearchModel) | ||
readonly search: VSXExtensionsSearchModel; | ||
|
||
@inject(TooltipService) | ||
readonly tooltipService: TooltipService; | ||
|
||
protected readonly data: Partial<VSXExtensionData> = {}; | ||
|
||
get uri(): URI { | ||
|
@@ -244,6 +248,29 @@ export class VSXExtension implements VSXExtensionData, TreeElement { | |
return this.getData('publishedBy'); | ||
} | ||
|
||
get tooltipId(): string { | ||
return this.tooltipService.tooltipId; | ||
} | ||
|
||
get tooltip(): string { | ||
const details = this.getData('readme') || this.description; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thegecko I believe it might be too much information to use the
vsx-tooltip.mp4There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readme removed |
||
let md = `__${this.displayName}__ ${this.version}\n\n${details}\n_____\n\nPublisher: ${this.publisher}`; | ||
|
||
if (this.license) { | ||
md += ` \rLicense: ${this.license}`; | ||
} | ||
|
||
if (this.downloadCount) { | ||
md += ` \rDownload count: ${downloadCompactFormatter.format(this.downloadCount)}`; | ||
} | ||
|
||
if (this.averageRating) { | ||
md += ` \rAverage Rating: ${this.averageRating.toFixed(1)}`; | ||
} | ||
|
||
return markdownit().render(md); | ||
} | ||
|
||
protected _busy = 0; | ||
get busy(): boolean { | ||
return !!this._busy; | ||
|
@@ -316,7 +343,9 @@ export class VSXExtension implements VSXExtensionData, TreeElement { | |
} | ||
|
||
render(): React.ReactNode { | ||
return <VSXExtensionComponent extension={this} />; | ||
const node = <VSXExtensionComponent extension={this} />; | ||
this.tooltipService.update(); | ||
return node; | ||
} | ||
} | ||
|
||
|
@@ -379,8 +408,9 @@ const downloadCompactFormatter = new Intl.NumberFormat(undefined, { notation: 'c | |
|
||
export class VSXExtensionComponent extends AbstractVSXExtensionComponent { | ||
render(): React.ReactNode { | ||
const { iconUrl, publisher, displayName, description, version, downloadCount, averageRating } = this.props.extension; | ||
return <div className='theia-vsx-extension'> | ||
const { iconUrl, publisher, displayName, description, version, downloadCount, averageRating, tooltipId, tooltip } = this.props.extension; | ||
|
||
return <div className='theia-vsx-extension' data-for={tooltipId} data-tip={tooltip}> | ||
{iconUrl ? | ||
<img className='theia-vsx-extension-icon' src={iconUrl} /> : | ||
<div className='theia-vsx-extension-icon placeholder' />} | ||
|
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.
@thegecko should the changes be added to a separate commit, I believe they are overall unrelated to the pull-request.
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.
Removed