Skip to content

Commit

Permalink
[lens] update LensEmbeddable.getSavedVis to return LensSavedObjectAtt…
Browse files Browse the repository at this point in the history
…ributes (#177064)

Blocking #176869

While working on #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>
  • Loading branch information
nreese and kibanamachine authored Feb 20, 2024
1 parent 4d96654 commit 82d7244
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 82d7244

Please sign in to comment.