[Lens] Fix rotating number example (#134234)

* fix rotating number example

* fix nav

* add label
This commit is contained in:
Joe Reuter 2022-06-13 18:41:46 +02:00 committed by GitHub
parent c1915ea61d
commit b5583eb5ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 14 deletions

View file

@ -669,6 +669,7 @@ export const App = (props: {
value={undefined}
onChange={(e) => switchChartPreset(Number(e.target.value))}
aria-label="Load from a preset"
prepend={'Load preset'}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>

View file

@ -91,18 +91,24 @@ export class EmbeddedLensExamplePlugin
id: 'third_party_lens_vis_example',
title: 'Third party Lens vis example',
navLinkStatus: AppNavLinkStatus.hidden,
mount: (params) => {
mount: ({ history }) => {
(async () => {
const [, { lens: lensStart, dataViews }] = await core.getStartServices();
const defaultDataView = await dataViews.getDefault();
lensStart.navigateToPrefilledEditor({
id: '',
timeRange: {
from: 'now-5d',
to: 'now',
},
attributes: getLensAttributes(defaultDataView!),
});
const [coreStart, { lens: lensStart, dataViews }] = await core.getStartServices();
// if it's a regular navigation, redirect to Lens
if (history.action === 'PUSH') {
const defaultDataView = await dataViews.getDefault();
lensStart.navigateToPrefilledEditor({
id: '',
timeRange: {
from: 'now-5d',
to: 'now',
},
attributes: getLensAttributes(defaultDataView!),
});
} else {
// if it's a "back" navigation, go to developer examples
coreStart.application.navigateToApp('developerExamples');
}
})();
return () => {};
},

View file

@ -16,7 +16,10 @@ import { layerTypes } from '@kbn/lens-plugin/public';
import type { RotatingNumberState } from '../common/types';
import { DEFAULT_COLOR } from '../common/constants';
const toExpression = (state: RotatingNumberState): Ast | null => {
const toExpression = (
state: RotatingNumberState,
datasourceExpressionsByLayers?: Record<string, Ast>
): Ast | null => {
if (!state.accessor) {
return null;
}
@ -24,6 +27,7 @@ const toExpression = (state: RotatingNumberState): Ast | null => {
return {
type: 'expression',
chain: [
...Object.values(datasourceExpressionsByLayers || {})[0].chain,
{
type: 'function',
function: 'rotating_number',
@ -149,8 +153,10 @@ export const getRotatingNumberVisualization = ({
}
},
toExpression: (state) => toExpression(state),
toPreviewExpression: (state) => toExpression(state),
toExpression: (state, _layers, _attributes, datasourceExpression) =>
toExpression(state, datasourceExpression),
toPreviewExpression: (state, _layers, datasourceExpression) =>
toExpression(state, datasourceExpression),
setDimension({ prevState, columnId }) {
return { ...prevState, accessor: columnId };