Skip to content

Commit 6399184

Browse files
ergunshDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[PatchWidget] Use PopoverHelper for rendering info tooltip
This is a workaround until b/409965560 is fixed Bug: 405913892 Change-Id: I5d9335f90c12845639ee8e189cee29daabee9f56 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6450698 Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Ergün Erdoğmuş <ergunsh@chromium.org>
1 parent 56932f7 commit 6399184

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

front_end/panels/ai_assistance/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ devtools_module("ai_assistance") {
4747
"../../third_party/marked:bundle",
4848
"../../ui/components/markdown_view:bundle",
4949
"../../ui/components/spinners:bundle",
50-
"../../ui/components/tooltips:bundle",
5150
"../../ui/legacy:bundle",
5251
"../../ui/lit:bundle",
5352
]

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import '../../ui/legacy/legacy.js';
77
import '../../ui/components/markdown_view/markdown_view.js';
88
import '../../ui/components/spinners/spinners.js';
9-
import '../../ui/components/tooltips/tooltips.js';
109

1110
import * as Common from '../../core/common/common.js';
1211
import * as Host from '../../core/host/host.js';
@@ -211,6 +210,7 @@ export class PatchWidget extends UI.Widget.Widget {
211210
#automaticFileSystem =
212211
Persistence.AutomaticFileSystemManager.AutomaticFileSystemManager.instance().automaticFileSystem;
213212
#applyToDisconnectedAutomaticWorkspace = false;
213+
#popoverHelper: UI.PopoverHelper.PopoverHelper|null = null;
214214

215215
constructor(element?: HTMLElement, view?: View, opts?: {
216216
aidaClient: Host.AidaClient.AidaClient,
@@ -388,19 +388,6 @@ export class PatchWidget extends UI.Widget.Widget {
388388
.variant=${Buttons.Button.Variant.ICON}
389389
.title=${input.applyToWorkspaceTooltipText}
390390
></devtools-button>
391-
<devtools-tooltip variant="rich" id="info-tooltip" ${Directives.ref(output.tooltipRef)}>
392-
<div class="info-tooltip-container">
393-
${input.applyToWorkspaceTooltipText}
394-
<button
395-
class="link tooltip-link"
396-
role="link"
397-
jslog=${VisualLogging.link('open-ai-settings').track({
398-
click: true,
399-
})}
400-
@click=${input.onLearnMoreTooltipClick}
401-
>${lockedString(UIStringsNotTranslate.learnMore)}</button>
402-
</div>
403-
</devtools-tooltip>
404391
</div>
405392
</div>`;
406393
}
@@ -426,6 +413,56 @@ export class PatchWidget extends UI.Widget.Widget {
426413

427414
render(template, target, {host: target});
428415
});
416+
// We're using PopoverHelper as a workaround instead of using <devtools-tooltip>. See the bug for more details.
417+
// TODO: Update here when b/409965560 is fixed.
418+
this.#popoverHelper = new UI.PopoverHelper.PopoverHelper(this.contentElement, event => {
419+
// There are two ways this event is received for showing a popover case:
420+
// * The latest element on the composed path is `<devtools-button>`
421+
// * The 2nd element on the composed path is `<devtools-button>` (the last element is the `<button>` inside it.)
422+
const hoveredNode = event.composedPath()[0];
423+
const maybeDevToolsButton = event.composedPath()[2];
424+
425+
const popoverShownNode = hoveredNode instanceof HTMLElement && hoveredNode.getAttribute('aria-details') === 'info-tooltip' ? hoveredNode
426+
: maybeDevToolsButton instanceof HTMLElement && maybeDevToolsButton.getAttribute('aria-details') === 'info-tooltip' ? maybeDevToolsButton
427+
: null;
428+
if (!popoverShownNode) {
429+
return null;
430+
}
431+
return {
432+
box: popoverShownNode.boxInWindow(),
433+
show: async (popover: UI.GlassPane.GlassPane) => {
434+
// clang-format off
435+
render(html`
436+
<style>
437+
.info-tooltip-container {
438+
max-width: var(--sys-size-28);
439+
padding: var(--sys-size-4) var(--sys-size-5);
440+
441+
.tooltip-link {
442+
display: block;
443+
margin-top: var(--sys-size-4);
444+
color: var(--sys-color-primary);
445+
padding-left: 0;
446+
}
447+
}
448+
</style>
449+
<div class="info-tooltip-container">
450+
${UIStringsNotTranslate.applyToWorkspaceTooltip}
451+
<button
452+
class="link tooltip-link"
453+
role="link"
454+
jslog=${VisualLogging.link('open-ai-settings').track({
455+
click: true,
456+
})}
457+
@click=${this.#onLearnMoreTooltipClick}
458+
>${lockedString(UIStringsNotTranslate.learnMore)}</button>
459+
</div>`, popover.contentElement, {host: this});
460+
// clang-forat on
461+
return true;
462+
},
463+
};
464+
}, 'patch-widget.info-tooltip');
465+
this.#popoverHelper.setTimeout(0);
429466
// clang-format on
430467
this.requestUpdate();
431468
}

front_end/panels/ai_assistance/components/chatView.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,6 @@ main {
887887
}
888888
}
889889

890-
.info-tooltip-container {
891-
max-width: var(--sys-size-28);
892-
893-
.tooltip-link {
894-
display: block;
895-
margin-top: var(--sys-size-4);
896-
color: var(--sys-color-primary);
897-
}
898-
}
899-
900890
.loading-text-container {
901891
margin-right: var(--sys-size-3);
902892
display: flex;

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,7 @@ export const knownContextValues = new Set([
26412641
'patch-widget.discard',
26422642
'patch-widget.save-all',
26432643
'patch-widget.save-to-workspace',
2644+
'patch-widget.info-tooltip',
26442645
'path',
26452646
'pattern',
26462647
'pause',

0 commit comments

Comments
 (0)