Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lens] Calculate existence of fields in datasource #44422

Merged
merged 10 commits into from
Sep 3, 2019
3 changes: 2 additions & 1 deletion src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function stubbedLogstashFields() {
['area', 'geo_shape', true, true ],
['hashed', 'murmur3', false, true ],
['geo.coordinates', 'geo_point', true, true ],
['extension', 'keyword', true, true ],
['extension', 'text', true, true],
['extension.keyword', 'keyword', true, true, {}, 'extension', 'multi' ],
['machine.os', 'text', true, true ],
['machine.os.raw', 'keyword', true, true, {}, 'machine.os', 'multi' ],
['geo.src', 'keyword', true, true ],
Expand Down
21 changes: 19 additions & 2 deletions x-pack/legacy/plugins/lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/

import * as Joi from 'joi';
import { Server } from 'hapi';
import { resolve } from 'path';
import { LegacyPluginInitializer } from 'src/legacy/types';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { CoreSetup } from 'src/core/server';
import mappings from './mappings.json';
import { PLUGIN_ID, getEditPath } from './common';
import { lensServerPlugin } from './server';

const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';

Expand Down Expand Up @@ -49,7 +51,9 @@ export const lens: LegacyPluginInitializer = kibana => {
}).default();
},

init(server: Server) {
async init(server: Server) {
const kbnServer = (server as unknown) as KbnServer;

server.plugins.xpack_main.registerFeature({
id: PLUGIN_ID,
name: NOT_INTERNATIONALIZED_PRODUCT_NAME,
Expand Down Expand Up @@ -77,6 +81,19 @@ export const lens: LegacyPluginInitializer = kibana => {
},
},
});

// Set up with the new platform plugin lifecycle API.
const plugin = lensServerPlugin();
await plugin.setup(({
http: {
...kbnServer.newPlatform.setup.core.http,
createRouter: () => kbnServer.newPlatform.setup.core.http.createRouter('/api/lens'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but I wonder if this /api/lens path should be in a const in our common folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Updated here and one other place.

},
} as unknown) as CoreSetup);

server.events.on('stop', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The async / await is unnecessary: server.events.on('stop', () => plugin.stop()); You can probably just do server.events.on('stop', plugin.stop);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I'm going to make it all synchronous. I was going back and forth on this while developing because I think we will eventually want async here once we are fully on the new platform.

await plugin.stop();
});
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
import React, { useMemo, memo, useContext, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiPopover, EuiButtonIcon, EuiContextMenuPanel, EuiContextMenuItem } from '@elastic/eui';
import { Query } from 'src/plugins/data/common';
import { DatasourceDataPanelProps, Datasource } from '../../../public';
import { NativeRenderer } from '../../native_renderer';
import { Action } from './state_management';
import { DragContext } from '../../drag_drop';
import { StateSetter } from '../../types';
import { StateSetter, FramePublicAPI } from '../../types';

interface DataPanelWrapperProps {
datasourceState: unknown;
datasourceMap: Record<string, Datasource>;
activeDatasource: string | null;
datasourceIsLoading: boolean;
dispatch: (action: Action) => void;
query: Query;
dateRange: FramePublicAPI['dateRange'];
}

export const DataPanelWrapper = memo((props: DataPanelWrapperProps) => {
Expand All @@ -37,6 +40,8 @@ export const DataPanelWrapper = memo((props: DataPanelWrapperProps) => {
dragDropContext: useContext(DragContext),
state: props.datasourceState,
setState: setDatasourceState,
query: props.query,
dateRange: props.dateRange,
};

const [showDatasourceSwitcher, setDatasourceSwitcher] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export function EditorFrame(props: EditorFrameProps) {
: true
}
dispatch={dispatch}
query={props.query}
dateRange={props.dateRange}
/>
}
configPanel={
Expand Down
Loading