Skip to content

Commit e676076

Browse files
Merge branch 'master' into fix/remove-imports-for-core-utils
2 parents 860c0a3 + 856a820 commit e676076

File tree

84 files changed

+4746
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4746
-1230
lines changed

x-pack/plugins/ingest_manager/common/types/models/epm.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ export interface RegistryVarsEntry {
205205
interface PackageAdditions {
206206
title: string;
207207
latestVersion: string;
208-
installedVersion?: string;
209208
assets: AssetsGroupedByServiceByType;
210209
}
211210

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/header.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ const Text = styled.span`
2929
type HeaderProps = PackageInfo & { iconType?: IconType };
3030

3131
export function Header(props: HeaderProps) {
32-
const { iconType, name, title, version, installedVersion, latestVersion } = props;
32+
const { iconType, name, title, version, latestVersion } = props;
33+
34+
let installedVersion;
35+
if ('savedObject' in props) {
36+
installedVersion = props.savedObject.attributes.version;
37+
}
3338
const hasWriteCapabilites = useCapabilities().write;
3439
const { toListView } = useLinks();
3540
const ADD_DATASOURCE_URI = useLink(`${EPM_PATH}/${name}-${version}/add-datasource`);

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export function Detail() {
3232
const packageInfo = response.data?.response;
3333
const title = packageInfo?.title;
3434
const name = packageInfo?.name;
35-
const installedVersion = packageInfo?.installedVersion;
35+
let installedVersion;
36+
if (packageInfo && 'savedObject' in packageInfo) {
37+
installedVersion = packageInfo.savedObject.attributes.version;
38+
}
3639
const status: InstallStatus = packageInfo?.status as any;
3740

3841
// track install status state

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/home/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,34 @@ export function EPMHomePage() {
6767
function InstalledPackages() {
6868
const { data: allPackages, isLoading: isLoadingPackages } = useGetPackages();
6969
const [selectedCategory, setSelectedCategory] = useState('');
70-
const packages =
71-
allPackages && allPackages.response && selectedCategory === ''
72-
? allPackages.response.filter(pkg => pkg.status === 'installed')
73-
: [];
7470

7571
const title = i18n.translate('xpack.ingestManager.epmList.installedTitle', {
7672
defaultMessage: 'Installed integrations',
7773
});
7874

75+
const allInstalledPackages =
76+
allPackages && allPackages.response
77+
? allPackages.response.filter(pkg => pkg.status === 'installed')
78+
: [];
79+
80+
const updatablePackages = allInstalledPackages.filter(
81+
item => 'savedObject' in item && item.version > item.savedObject.attributes.version
82+
);
83+
7984
const categories = [
8085
{
8186
id: '',
8287
title: i18n.translate('xpack.ingestManager.epmList.allFilterLinkText', {
8388
defaultMessage: 'All',
8489
}),
85-
count: packages.length,
90+
count: allInstalledPackages.length,
8691
},
8792
{
8893
id: 'updates_available',
8994
title: i18n.translate('xpack.ingestManager.epmList.updatesAvailableFilterLinkText', {
9095
defaultMessage: 'Updates available',
9196
}),
92-
count: 0, // TODO: Update with real count when available
97+
count: updatablePackages.length,
9398
},
9499
];
95100

@@ -106,7 +111,7 @@ function InstalledPackages() {
106111
isLoading={isLoadingPackages}
107112
controls={controls}
108113
title={title}
109-
list={packages}
114+
list={selectedCategory === 'updates_available' ? updatablePackages : allInstalledPackages}
110115
/>
111116
);
112117
}
@@ -134,7 +139,6 @@ function AvailablePackages() {
134139
},
135140
...(categoriesRes ? categoriesRes.response : []),
136141
];
137-
138142
const controls = categories ? (
139143
<CategoryFacets
140144
isLoading={isLoadingCategories}

x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ export {
9090
DetailViewPanelName,
9191
InstallStatus,
9292
InstallationStatus,
93+
Installable,
9394
} from '../../../../common';

x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export function createInstallableFrom<T>(
4343
? {
4444
...from,
4545
status: InstallationStatus.installed,
46-
installedVersion: savedObject.attributes.version,
4746
savedObject,
4847
}
4948
: {
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import React from 'react';
7+
8+
import { AppMountParameters, CoreSetup } from 'kibana/public';
9+
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';
10+
import { HashRouter, Route, RouteComponentProps, Switch } from 'react-router-dom';
11+
import { render, unmountComponentAtNode } from 'react-dom';
12+
13+
import rison from 'rison-node';
14+
import { DashboardConstants } from '../../../../../src/plugins/dashboard/public';
15+
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
16+
17+
import { LensReportManager, setReportManager, trackUiEvent } from '../lens_ui_telemetry';
18+
19+
import { App } from './app';
20+
import { EditorFrameStart } from '../types';
21+
import { addEmbeddableToDashboardUrl, getUrlVars, isRisonObject } from '../helpers';
22+
import { addHelpMenuToAppChrome } from '../help_menu_util';
23+
import { SavedObjectIndexStore } from '../persistence';
24+
import { LensPluginStartDependencies } from '../plugin';
25+
26+
export async function mountApp(
27+
core: CoreSetup<LensPluginStartDependencies, void>,
28+
params: AppMountParameters,
29+
createEditorFrame: EditorFrameStart['createInstance']
30+
) {
31+
const [coreStart, startDependencies] = await core.getStartServices();
32+
const { data: dataStart, navigation } = startDependencies;
33+
const savedObjectsClient = coreStart.savedObjects.client;
34+
addHelpMenuToAppChrome(coreStart.chrome, coreStart.docLinks);
35+
36+
const instance = await createEditorFrame();
37+
38+
setReportManager(
39+
new LensReportManager({
40+
storage: new Storage(localStorage),
41+
http: core.http,
42+
})
43+
);
44+
const updateUrlTime = (urlVars: Record<string, string>): void => {
45+
const decoded = rison.decode(urlVars._g);
46+
if (!isRisonObject(decoded)) {
47+
return;
48+
}
49+
// @ts-ignore
50+
decoded.time = dataStart.query.timefilter.timefilter.getTime();
51+
urlVars._g = rison.encode(decoded);
52+
};
53+
const redirectTo = (
54+
routeProps: RouteComponentProps<{ id?: string }>,
55+
addToDashboardMode: boolean,
56+
id?: string
57+
) => {
58+
if (!id) {
59+
routeProps.history.push('/lens');
60+
} else if (!addToDashboardMode) {
61+
routeProps.history.push(`/lens/edit/${id}`);
62+
} else if (addToDashboardMode && id) {
63+
routeProps.history.push(`/lens/edit/${id}`);
64+
const lastDashboardLink = coreStart.chrome.navLinks.get('kibana:dashboard');
65+
if (!lastDashboardLink || !lastDashboardLink.url) {
66+
throw new Error('Cannot get last dashboard url');
67+
}
68+
const urlVars = getUrlVars(lastDashboardLink.url);
69+
updateUrlTime(urlVars); // we need to pass in timerange in query params directly
70+
const dashboardUrl = addEmbeddableToDashboardUrl(lastDashboardLink.url, id, urlVars);
71+
window.history.pushState({}, '', dashboardUrl);
72+
}
73+
};
74+
75+
const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => {
76+
trackUiEvent('loaded');
77+
const addToDashboardMode =
78+
!!routeProps.location.search &&
79+
routeProps.location.search.includes(
80+
DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM
81+
);
82+
return (
83+
<App
84+
core={coreStart}
85+
data={dataStart}
86+
navigation={navigation}
87+
editorFrame={instance}
88+
storage={new Storage(localStorage)}
89+
docId={routeProps.match.params.id}
90+
docStorage={new SavedObjectIndexStore(savedObjectsClient)}
91+
redirectTo={id => redirectTo(routeProps, addToDashboardMode, id)}
92+
addToDashboardMode={addToDashboardMode}
93+
/>
94+
);
95+
};
96+
97+
function NotFound() {
98+
trackUiEvent('loaded_404');
99+
return <FormattedMessage id="xpack.lens.app404" defaultMessage="404 Not Found" />;
100+
}
101+
102+
render(
103+
<I18nProvider>
104+
<HashRouter>
105+
<Switch>
106+
<Route exact path="/lens/edit/:id" render={renderEditor} />
107+
<Route exact path="/lens" render={renderEditor} />
108+
<Route path="/lens" component={NotFound} />
109+
</Switch>
110+
</HashRouter>
111+
</I18nProvider>,
112+
params.element
113+
);
114+
return () => {
115+
instance.unmount();
116+
unmountComponentAtNode(params.element);
117+
};
118+
}

x-pack/plugins/lens/public/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*/
66

77
export { addEmbeddableToDashboardUrl, getUrlVars } from './url_helper';
8+
export { isRisonObject } from './is_rison_object';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { RisonObject, RisonValue } from 'rison-node';
8+
import { isObject } from 'lodash';
9+
10+
export const isRisonObject = (value: RisonValue): value is RisonObject => {
11+
return isObject(value);
12+
};
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { AppMountParameters, CoreSetup, CoreStart } from 'kibana/public';
8+
import { DataPublicPluginSetup, DataPublicPluginStart } from 'src/plugins/data/public';
9+
import { EmbeddableSetup, EmbeddableStart } from 'src/plugins/embeddable/public';
10+
import { ExpressionsSetup, ExpressionsStart } from 'src/plugins/expressions/public';
11+
import { VisualizationsSetup } from 'src/plugins/visualizations/public';
12+
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
13+
import { KibanaLegacySetup } from 'src/plugins/kibana_legacy/public';
14+
import { EditorFrameService } from './editor_frame_service';
15+
import { IndexPatternDatasource } from './indexpattern_datasource';
16+
import { XyVisualization } from './xy_visualization';
17+
import { MetricVisualization } from './metric_visualization';
18+
import { DatatableVisualization } from './datatable_visualization';
19+
import { stopReportManager } from './lens_ui_telemetry';
20+
21+
import { UiActionsStart } from '../../../../src/plugins/ui_actions/public';
22+
import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../common';
23+
import { EditorFrameStart } from './types';
24+
import { getLensAliasConfig } from './vis_type_alias';
25+
26+
import './index.scss';
27+
28+
export interface LensPluginSetupDependencies {
29+
kibanaLegacy: KibanaLegacySetup;
30+
expressions: ExpressionsSetup;
31+
data: DataPublicPluginSetup;
32+
embeddable?: EmbeddableSetup;
33+
visualizations: VisualizationsSetup;
34+
}
35+
36+
export interface LensPluginStartDependencies {
37+
data: DataPublicPluginStart;
38+
embeddable: EmbeddableStart;
39+
expressions: ExpressionsStart;
40+
navigation: NavigationPublicPluginStart;
41+
uiActions: UiActionsStart;
42+
}
43+
44+
export class LensPlugin {
45+
private datatableVisualization: DatatableVisualization;
46+
private editorFrameService: EditorFrameService;
47+
private createEditorFrame: EditorFrameStart['createInstance'] | null = null;
48+
private indexpatternDatasource: IndexPatternDatasource;
49+
private xyVisualization: XyVisualization;
50+
private metricVisualization: MetricVisualization;
51+
52+
constructor() {
53+
this.datatableVisualization = new DatatableVisualization();
54+
this.editorFrameService = new EditorFrameService();
55+
this.indexpatternDatasource = new IndexPatternDatasource();
56+
this.xyVisualization = new XyVisualization();
57+
this.metricVisualization = new MetricVisualization();
58+
}
59+
60+
setup(
61+
core: CoreSetup<LensPluginStartDependencies, void>,
62+
{ kibanaLegacy, expressions, data, embeddable, visualizations }: LensPluginSetupDependencies
63+
) {
64+
const editorFrameSetupInterface = this.editorFrameService.setup(core, {
65+
data,
66+
embeddable,
67+
expressions,
68+
});
69+
const dependencies = {
70+
expressions,
71+
data,
72+
editorFrame: editorFrameSetupInterface,
73+
formatFactory: core
74+
.getStartServices()
75+
.then(([_, { data: dataStart }]) => dataStart.fieldFormats.deserialize),
76+
};
77+
this.indexpatternDatasource.setup(core, dependencies);
78+
this.xyVisualization.setup(core, dependencies);
79+
this.datatableVisualization.setup(core, dependencies);
80+
this.metricVisualization.setup(core, dependencies);
81+
82+
visualizations.registerAlias(getLensAliasConfig());
83+
84+
kibanaLegacy.registerLegacyApp({
85+
id: 'lens',
86+
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
87+
mount: async (params: AppMountParameters) => {
88+
const { mountApp } = await import('./app_plugin/mounter');
89+
return mountApp(core, params, this.createEditorFrame!);
90+
},
91+
});
92+
}
93+
94+
start(core: CoreStart, startDependencies: LensPluginStartDependencies) {
95+
this.createEditorFrame = this.editorFrameService.start(core, startDependencies).createInstance;
96+
this.xyVisualization.start(core, startDependencies);
97+
this.datatableVisualization.start(core, startDependencies);
98+
}
99+
100+
stop() {
101+
stopReportManager();
102+
}
103+
}

0 commit comments

Comments
 (0)