[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} value={undefined}
onChange={(e) => switchChartPreset(Number(e.target.value))} onChange={(e) => switchChartPreset(Number(e.target.value))}
aria-label="Load from a preset" aria-label="Load from a preset"
prepend={'Load preset'}
/> />
</EuiFlexItem> </EuiFlexItem>
<EuiFlexItem grow={false}> <EuiFlexItem grow={false}>

View file

@ -91,9 +91,11 @@ export class EmbeddedLensExamplePlugin
id: 'third_party_lens_vis_example', id: 'third_party_lens_vis_example',
title: 'Third party Lens vis example', title: 'Third party Lens vis example',
navLinkStatus: AppNavLinkStatus.hidden, navLinkStatus: AppNavLinkStatus.hidden,
mount: (params) => { mount: ({ history }) => {
(async () => { (async () => {
const [, { lens: lensStart, dataViews }] = await core.getStartServices(); 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(); const defaultDataView = await dataViews.getDefault();
lensStart.navigateToPrefilledEditor({ lensStart.navigateToPrefilledEditor({
id: '', id: '',
@ -103,6 +105,10 @@ export class EmbeddedLensExamplePlugin
}, },
attributes: getLensAttributes(defaultDataView!), attributes: getLensAttributes(defaultDataView!),
}); });
} else {
// if it's a "back" navigation, go to developer examples
coreStart.application.navigateToApp('developerExamples');
}
})(); })();
return () => {}; return () => {};
}, },

View file

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