Skip to content

Commit ea429a4

Browse files
committed
refactor: 💡 move embeddable data-title setting to render-compl
1 parent ea8d585 commit ea429a4

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

‎src/plugins/embeddable/public/lib/embeddables/embeddable.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { cloneDeep, isEqual } from 'lodash';
2121
import * as Rx from 'rxjs';
22+
import { distinctUntilChanged, map } from 'rxjs/operators';
2223
import { RenderCompleteDispatcher } from '../../../../kibana_utils/public';
2324
import { Adapters, ViewMode } from '../types';
2425
import { IContainer } from '../containers';
@@ -80,6 +81,15 @@ export abstract class Embeddable<
8081
this.onResetInput(newInput);
8182
});
8283
}
84+
85+
this.getOutput$()
86+
.pipe(
87+
map(({ title }) => title || ''),
88+
distinctUntilChanged()
89+
)
90+
.subscribe((title) => {
91+
this.renderComplete.setTitle(title);
92+
});
8393
}
8494

8595
public getIsContainer(): this is IContainer {
@@ -108,8 +118,8 @@ export abstract class Embeddable<
108118
return this.input;
109119
}
110120

111-
public getTitle() {
112-
return this.output.title;
121+
public getTitle(): string {
122+
return this.output.title || '';
113123
}
114124

115125
/**
@@ -138,8 +148,7 @@ export abstract class Embeddable<
138148

139149
public render(el: HTMLElement): void {
140150
this.renderComplete.setEl(el);
141-
142-
el.setAttribute('data-title', this.output.title || '');
151+
this.renderComplete.setTitle(this.output.title || '');
143152

144153
if (this.destroyed) {
145154
throw new Error('Embeddable has been destroyed');

‎src/plugins/kibana_utils/public/render_complete/render_complete_dispatcher.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,9 @@ export class RenderCompleteDispatcher {
7575
this.el.setAttribute('data-render-complete', 'false');
7676
this.el.setAttribute('data-rendering-count', String(this.count));
7777
}
78+
79+
public setTitle(title: string) {
80+
if (!this.el) return;
81+
this.el.setAttribute('data-title', title);
82+
}
7883
}

‎src/plugins/visualizations/public/embeddable/visualize_embeddable.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
8484
private timefilter: TimefilterContract;
8585
private timeRange?: TimeRange;
8686
private query?: Query;
87-
private title?: string;
8887
private filters?: Filter[];
8988
private visCustomizations?: Pick<VisualizeInput, 'vis' | 'table'>;
9089
private subscriptions: Subscription[] = [];
@@ -157,7 +156,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
157156
if (!adapters) return;
158157

159158
return this.deps.start().plugins.inspector.open(adapters, {
160-
title: this.getTitle() || this.title || '',
159+
title: this.getTitle(),
161160
});
162161
};
163162

@@ -221,16 +220,6 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
221220
this.updateOutput({ title: this.vis.title });
222221
}
223222

224-
// Keep title depending on the output Embeddable to decouple the
225-
// visual appearance of the title and the actual title content (useful in Dashboard)
226-
if (this.output.title !== this.title) {
227-
this.title = this.output.title;
228-
229-
if (this.domNode) {
230-
this.domNode.setAttribute('data-title', this.title || '');
231-
}
232-
}
233-
234223
if (this.vis.description && this.domNode) {
235224
this.domNode.setAttribute('data-description', this.vis.description);
236225
}

0 commit comments

Comments
 (0)