[lens] update LensEmbeddable.getSavedVis to return LensSavedObjectAttributes (#177064)

Blocking https://github.com/elastic/kibana/pull/176869

While working on https://github.com/elastic/kibana/pull/176869, I
discovered there is a type mismatch between `LensEmbeddable.getSavedVis`
internal implementation and consumers of `LensEmbeddable.getSavedVis`
results.

LensEmbeddable.getSavedVis returns `Readonly<Document | undefined>`.
LensEmbeddable.getSavedVis consumers are typing the response as
`LensSavedObjectAttributes`.

This PR updates `LensEmbeddable.getSavedVis` to return
`Readonly<LensSavedObjectAttributes | undefined>` since that is how its
being used.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2024-02-20 11:21:09 -07:00 committed by GitHub
parent 4d96654756
commit 82d7244582
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View file

@ -1591,8 +1591,19 @@ export class Embeddable
return this.savedVis?.state.query;
}
public getSavedVis(): Readonly<Document | undefined> {
return this.savedVis;
public getSavedVis(): Readonly<LensSavedObjectAttributes | undefined> {
if (!this.savedVis) {
return;
}
// Why are 'type' and 'savedObjectId' keys being removed?
// Prior to removing them,
// this method returned 'Readonly<Document | undefined>' while consumers typed the results as 'LensSavedObjectAttributes'.
// Removing 'type' and 'savedObjectId' keys to align method results with consumer typing.
const savedVis = { ...this.savedVis };
delete savedVis.type;
delete savedVis.savedObjectId;
return savedVis;
}
destroy() {

View file

@ -6,10 +6,10 @@
*/
import { type HasType, apiIsOfType } from '@kbn/presentation-publishing';
import { Document } from '../../persistence';
import { LensSavedObjectAttributes } from '../embeddable';
export type HasLensConfig = HasType<'lens'> & {
getSavedVis: () => Readonly<Document | undefined>;
getSavedVis: () => Readonly<LensSavedObjectAttributes | undefined>;
};
export const apiHasLensConfig = (api: unknown): api is HasLensConfig => {