kibana/packages/presentation/presentation_containers/interfaces/serialized_state.ts
Devon Thomson 7e19cc5660
[Embeddables Rebuild] Clone panels with runtime state (#186052)
Makes the clone operation use runtime state rather than serialized state.
2024-06-20 10:18:42 -04:00

43 lines
1.7 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { Reference } from '@kbn/content-management-utils';
import { MaybePromise } from '@kbn/utility-types';
/**
* A package containing the serialized Embeddable state, with references extracted. When saving Embeddables using any
* strategy, this is the format that should be used.
*/
export interface SerializedPanelState<RawStateType extends object = object> {
references?: Reference[];
rawState: RawStateType;
}
export interface HasSerializableState<State extends object = object> {
/**
* Serializes all state into a format that can be saved into
* some external store. The opposite of `deserialize` in the {@link ReactEmbeddableFactory}
*/
serializeState: () => MaybePromise<SerializedPanelState<State>>;
}
export const apiHasSerializableState = (api: unknown | null): api is HasSerializableState => {
return Boolean((api as HasSerializableState)?.serializeState);
};
export interface HasSnapshottableState<RuntimeState extends object = object> {
/**
* Serializes all runtime state exactly as it appears. This can be used
* to rehydrate a component's state without needing to serialize then deserialize it.
*/
snapshotRuntimeState: () => RuntimeState;
}
export const apiHasSnapshottableState = (api: unknown | null): api is HasSnapshottableState => {
return Boolean((api as HasSnapshottableState)?.snapshotRuntimeState);
};