Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7040354
[Lens] move references to server
nickofthyme Oct 14, 2025
5e0138b
Merge branch 'main' into lens-server-refs
nickofthyme Oct 19, 2025
c1f0633
chore: cleanup transforms, handle dynamic actions, stub out api confi…
nickofthyme Oct 21, 2025
61822ed
Merge branch 'main' into lens-server-refs
nickofthyme Oct 21, 2025
c91a92f
fix type errors
nickofthyme Oct 22, 2025
b72c7e6
Merge branch 'main' into lens-server-refs
nickofthyme Oct 22, 2025
642db89
Merge branch 'main' into lens-server-refs
dej611 Oct 23, 2025
da71217
Merge remote-tracking branch 'upstream/main' into lens-server-refs
dej611 Oct 24, 2025
3f21b73
:label: first type pass
dej611 Oct 24, 2025
d7aa151
:label: More types fixed
dej611 Oct 24, 2025
c023bcc
:wrench: Flag package for treeshake
dej611 Oct 24, 2025
7319d75
:white_check_mark: Align test to lack of references
dej611 Oct 24, 2025
19a76e7
chore: remove `schema` on transform definition
nickofthyme Oct 28, 2025
5c507da
chore: move `LensParentApi` types to `@kbn/lens-common`
nickofthyme Oct 28, 2025
3385eb1
chore: revert code cleanup
nickofthyme Oct 28, 2025
de8412e
Merge branch 'main' into lens-server-refs
nickofthyme Oct 28, 2025
4ad0c86
fix: lens api integration tests
nickofthyme Oct 28, 2025
8b2a35e
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Oct 28, 2025
e8fc9db
fix add panel from library
nickofthyme Oct 28, 2025
7e65eee
Merge branch 'main' into lens-server-refs
nickofthyme Oct 28, 2025
7ee482f
Merge remote-tracking branch 'origin/lens-server-refs' into lens-serv…
nickofthyme Oct 28, 2025
05215fe
fix: background session issue
nickofthyme Oct 29, 2025
7b2483a
Merge branch 'main' into lens-server-refs
nickofthyme Oct 29, 2025
897b867
Merge branch 'main' into lens-server-refs
nickofthyme Oct 29, 2025
35c3697
Merge branch 'main' into lens-server-refs
nickofthyme Oct 30, 2025
b2b01af
chore: update cloud limits
nickofthyme Oct 30, 2025
46b7b69
Merge remote-tracking branch 'origin/lens-server-refs' into lens-serv…
nickofthyme Oct 30, 2025
c364724
Merge branch 'main' into lens-server-refs
nickofthyme Oct 30, 2025
46ecfb3
Merge branch 'main' into lens-server-refs
dej611 Oct 30, 2025
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
64 changes: 53 additions & 11 deletions src/platform/packages/shared/kbn-lens-common/embeddable/types.ts
Comment thread
nickofthyme marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { BehaviorSubject } from 'rxjs';

import type { HasSerializedChildState } from '@kbn/presentation-containers';
import type {
AggregateQuery,
ExecutionContextSearch,
Expand Down Expand Up @@ -44,6 +47,7 @@ import type {
PublishingSubject,
SerializedTitles,
ViewMode,
useSearchApi,
} from '@kbn/presentation-publishing';
import type { Action } from '@kbn/ui-actions-plugin/public';
import type {
Expand Down Expand Up @@ -126,9 +130,9 @@ export interface PreventableEvent {
preventDefault(): void;
}

interface LensByValue {
// by-value
attributes?: Simplify<LensSavedObjectAttributes>;
export interface LensByValueBase {
savedObjectId?: string; // really should be never but creates type issues
attributes?: LensSavedObjectAttributes;
}

export interface LensOverrides {
Expand All @@ -150,20 +154,22 @@ export interface LensOverrides {
/**
* Lens embeddable props broken down by type
*/

export interface LensByReference {
// by-reference
interface LensByReferenceBase {
savedObjectId?: string;
attributes?: never;
}

interface ContentManagementProps {
sharingSavedObjectProps?: SharingSavedObjectProps;
managed?: boolean;
}

export type LensPropsVariants = (LensByValue & LensByReference) & {
interface LensWithReferences {
/**
* @deprecated use `state.attributes.references`
*/
references?: Reference[];
};
}

export interface ViewInDiscoverCallbacks extends LensApiProps {
canViewUnderlyingData$: PublishingSubject<boolean>;
Expand Down Expand Up @@ -259,16 +265,29 @@ interface LensRequestHandlersProps {
* * Panel settings
* * other props from the embeddable
*/
export type LensSerializedState = Simplify<
LensPropsVariants &
LensOverrides &
type LensSerializedSharedState = Simplify<
LensOverrides &
LensWithReferences &
LensUnifiedSearchContext &
LensPanelProps &
SerializedTitles &
Omit<LensSharedProps, 'noPadding'> &
Partial<DynamicActionsSerializedState> & { isNewPanel?: boolean }
>;

export type LensByValueSerializedState = Simplify<LensSerializedSharedState & LensByValueBase>;
export type LensByRefSerializedState = Simplify<LensSerializedSharedState & LensByReferenceBase>;

/**
* Combined properties of serialized state stored on dashboard panel
*
* Includes:
* - Lens document state (for by-value)
* - Panel settings
* - other props from the embeddable
*/
export type LensSerializedState = LensByRefSerializedState | LensByValueSerializedState;

/**
* Custom props exposed on the Lens exported component
*/
Expand Down Expand Up @@ -516,3 +535,26 @@ export interface ESQLVariablesCompatibleDashboardApi {
controlGroupApi$: PublishingSubject<Partial<CanAddNewPanel> | undefined>;
children$: PublishingSubject<{ [key: string]: unknown }>;
}

type SearchApi = ReturnType<typeof useSearchApi>;

interface GeneralLensApi {
searchSessionId$: BehaviorSubject<string | undefined>;
disabledActionIds$: BehaviorSubject<string[] | undefined>;
setDisabledActionIds: (ids: string[] | undefined) => void;
viewMode$: BehaviorSubject<ViewMode | undefined>;
settings: {
syncColors$: BehaviorSubject<boolean>;
syncCursor$: BehaviorSubject<boolean>;
syncTooltips$: BehaviorSubject<boolean>;
};
forceDSL?: boolean;
esqlVariables$: BehaviorSubject<ESQLControlVariable[] | undefined>;
hideTitle$: BehaviorSubject<boolean | undefined>;
reload$: BehaviorSubject<void>;
}

export type LensParentApi = SearchApi &
LensRuntimeState &
GeneralLensApi &
HasSerializedChildState<LensSerializedState>;
6 changes: 4 additions & 2 deletions src/platform/packages/shared/kbn-lens-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ export type {
DocumentToExpressionReturnType,
PreventableEvent,
LensOverrides,
LensByReference,
LensPropsVariants,
LensByValueSerializedState,
LensByRefSerializedState,
ViewInDiscoverCallbacks,
IntegrationCallbacks,
LensPublicCallbacks,
Expand All @@ -268,6 +268,7 @@ export type {
LensHasEditPanel,
LensInspectorAdapters,
LensApi,
LensParentApi,
LensInternalApi,
ExpressionWrapperProps,
GetStateType,
Expand All @@ -276,6 +277,7 @@ export type {
TypedLensSerializedState,
LensEmbeddableOutput,
ESQLVariablesCompatibleDashboardApi,
LensByValueBase,
} from './embeddable/types';
export type {
LensAppLocatorParams,
Expand Down
14 changes: 1 addition & 13 deletions src/platform/packages/shared/kbn-lens-common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ import type { InspectorOptions } from '@kbn/inspector-plugin/public';
import type { OnSaveProps } from '@kbn/saved-objects-plugin/public';
import type { NavigateToLensContext } from './convert_to_lens_types';
import type { LensAppLocator, MainHistoryLocationState } from './locator_types';
import type {
LensRuntimeState,
LensSavedObjectAttributes,
StructuredDatasourceStates,
} from './embeddable/types';
import type { LensSavedObjectAttributes, StructuredDatasourceStates } from './embeddable/types';
import type {
DimensionLink,
LensConfiguration,
Expand Down Expand Up @@ -144,14 +140,6 @@ export interface LensAttributesService {
savedObjectId?: string
) => Promise<string>;
checkForDuplicateTitle: (props: CheckDuplicateTitleProps) => Promise<{ isDuplicate: boolean }>;
injectReferences: (
runtimeState: LensRuntimeState,
references: Reference[] | undefined
) => LensRuntimeState;
extractReferences: (runtimeState: LensRuntimeState) => {
rawState: LensRuntimeState;
references: Reference[];
};
}

export interface LensAppServices extends StartServices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0",
"homepage": "https://docs.elastic.dev/kibana-dev-docs/lens/config-builder"
"homepage": "https://docs.elastic.dev/kibana-dev-docs/lens/config-builder",
"sideEffects": false
}
12 changes: 7 additions & 5 deletions x-pack/platform/plugins/shared/cases/server/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
import { flatMap, uniqWith, xorWith } from 'lodash';
import type { LensServerPluginSetup } from '@kbn/lens-plugin/server';
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
import type { LensEmbeddableStateWithType } from '@kbn/lens-plugin/server/embeddable/types';
import type {
ActionsAttachmentPayload,
AlertAttachmentPayload,
Expand Down Expand Up @@ -402,15 +403,16 @@ export const extractLensReferencesFromCommentString = (
lensEmbeddableFactory: LensServerPluginSetup['lensEmbeddableFactory'],
comment: string
): SavedObjectReference[] => {
const extract = lensEmbeddableFactory()?.extract;
const extract = lensEmbeddableFactory().extract;

if (extract) {
const parsedComment = parseCommentString(comment);
const lensVisualizations = getLensVisualizations(parsedComment.children);
const flattenRefs = flatMap(
lensVisualizations,
(lensObject) => extract(lensObject)?.references ?? []
);
const flattenRefs = flatMap(lensVisualizations, (vis) => {
// TODO: Improve these types
const lensVis = vis as unknown as LensEmbeddableStateWithType;
return extract(lensVis).references;
Comment on lines +412 to +414
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types here are complaining because vis.attributes are Record<string, unknown>.

});

const uniqRefs = uniqWith(
flattenRefs,
Expand Down

This file was deleted.

42 changes: 42 additions & 0 deletions x-pack/platform/plugins/shared/lens/common/references/index.ts
Comment thread
nickofthyme marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { cloneDeep, uniqBy } from 'lodash';

import type { Reference } from '@kbn/content-management-utils';

import type { LensSerializedState } from '../../public';

export const injectLensReferences = (
state: LensSerializedState,
references: Reference[] = []
): LensSerializedState => {
const clonedState = cloneDeep(state);

if (clonedState.savedObjectId || !clonedState.attributes) {
return clonedState;
}

// TODO: find a way to cull erroneous dashboard references
const combinedReferences = uniqBy([...references, ...clonedState.attributes.references], 'name');

clonedState.attributes.references = combinedReferences;

return clonedState;
};

export const extractLensReferences = (
state: LensSerializedState
): {
state: LensSerializedState;
references: Reference[];
} => {
return {
state,
references: state.attributes?.references ?? state.references ?? [],
};
};

This file was deleted.

19 changes: 18 additions & 1 deletion x-pack/platform/plugins/shared/lens/common/transforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@
* 2.0.
*/

export { ConfigBuilderStub } from './config_builder_stub';
import type { EnhancementsRegistry } from '@kbn/embeddable-plugin/common/enhancements/registry';

import type { LensTransforms } from './types';
import { getTransformIn } from './transform_in';
import { getTransformOut } from './transform_out';

export interface LensTransformDependencies {
transformEnhancementsIn?: EnhancementsRegistry['transformIn'];
transformEnhancementsOut?: EnhancementsRegistry['transformOut'];
}

export function getLensTransforms(deps: LensTransformDependencies): LensTransforms {
return {
transformIn: getTransformIn(deps),
transformOut: getTransformOut(deps),
transformOutInjectsReferences: true,
};
}
Loading