Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { faker } from '@faker-js/faker';
import { createEmptyLensState } from '../helper';
import { makeEmbeddableServices, getLensRuntimeStateMock } from '../mocks';
import { LensRuntimeState } from '../types';
Expand Down Expand Up @@ -55,5 +56,15 @@ describe('Dashboard services API', () => {
// * references should be at root level
expect(references).toEqual(attributes.references);
});

it('should remove the searchSessionId from the serializedState', async () => {
const attributes = createAttributesWithReferences();
const api = setupIntegrationsApi({
attributes,
searchSessionId: faker.string.uuid(),
});
const { rawState } = api.serializeState();
expect('searchSessionId' in rawState).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ import {
getLanguageDisplayName,
isOfAggregateQueryType,
} from '@kbn/es-query';
import { noop } from 'lodash';
import { noop, omit } from 'lodash';
import type { HasSerializableState } from '@kbn/presentation-publishing';
import { SavedObjectReference } from '@kbn/core/types';
import { emptySerializer, isTextBasedLanguage } from '../helper';
import type { GetStateType, LensEmbeddableStartServices } from '../types';
import type { GetStateType, LensEmbeddableStartServices, LensRuntimeState } from '../types';
import type { IntegrationCallbacks } from '../types';

function cleanupSerializedState({
rawState,
references,
}: {
rawState: LensRuntimeState;
references: SavedObjectReference[];
}) {
const cleanedState = omit(rawState, 'searchSessionId');
return {
rawState: cleanedState,
references,
};
}

export function initializeIntegrations(
getLatestState: GetStateType,
{ attributeService }: LensEmbeddableStartServices
Expand Down Expand Up @@ -43,7 +58,9 @@ export function initializeIntegrations(
*/
serializeState: () => {
const currentState = getLatestState();
const cleanedState = attributeService.extractReferences(currentState);
const cleanedState = cleanupSerializedState(
attributeService.extractReferences(currentState)
);
if (cleanedState.rawState.savedObjectId) {
return { ...cleanedState, rawState: { ...cleanedState.rawState, attributes: undefined } };
}
Expand Down