Skip to content

Commit

Permalink
more aggressive lazy loading for ingest_manager (elastic#79633) (elas…
Browse files Browse the repository at this point in the history
…tic#79713)

* slim ingest_manager

* revert registerPackagePolicyComponent export
  • Loading branch information
mshustov authored Oct 6, 2020
1 parent 4e046e7 commit 570f2d2
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import type {
TutorialDirectoryNoticeComponent,
TutorialDirectoryHeaderLinkComponent,
TutorialModuleNoticeComponent,
} from 'src/plugins/home/public';
import { EuiLoadingSpinner } from '@elastic/eui';

const TutorialDirectoryNoticeLazy = React.lazy(() => import('./tutorial_directory_notice'));
export const TutorialDirectoryNotice: TutorialDirectoryNoticeComponent = () => (
<React.Suspense fallback={<EuiLoadingSpinner />}>
<TutorialDirectoryNoticeLazy />
</React.Suspense>
);

const TutorialDirectoryHeaderLinkLazy = React.lazy(
() => import('./tutorial_directory_header_link')
);
export const TutorialDirectoryHeaderLink: TutorialDirectoryHeaderLinkComponent = () => (
<React.Suspense fallback={<EuiLoadingSpinner />}>
<TutorialDirectoryHeaderLinkLazy />
</React.Suspense>
);

const TutorialModuleNoticeLazy = React.lazy(() => import('./tutorial_module_notice'));
export const TutorialModuleNotice: TutorialModuleNoticeComponent = ({
moduleName,
}: {
moduleName: string;
}) => (
<React.Suspense fallback={<EuiLoadingSpinner />}>
<TutorialModuleNoticeLazy moduleName={moduleName} />
</React.Suspense>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { memo, useState, useEffect } from 'react';
import { BehaviorSubject } from 'rxjs';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButtonEmpty } from '@elastic/eui';
import type { TutorialDirectoryHeaderLinkComponent } from 'src/plugins/home/public';
import { useLink, useCapabilities } from '../../hooks';

const tutorialDirectoryNoticeState$ = new BehaviorSubject({
settingsDataLoaded: false,
hasSeenNotice: false,
});

const TutorialDirectoryHeaderLink: TutorialDirectoryHeaderLinkComponent = memo(() => {
const { getHref } = useLink();
const { show: hasIngestManager } = useCapabilities();
const [noticeState, setNoticeState] = useState({
settingsDataLoaded: false,
hasSeenNotice: false,
});

useEffect(() => {
const subscription = tutorialDirectoryNoticeState$.subscribe((value) => setNoticeState(value));
return () => {
subscription.unsubscribe();
};
}, []);

return hasIngestManager && noticeState.settingsDataLoaded && noticeState.hasSeenNotice ? (
<EuiButtonEmpty size="s" iconType="link" flush="right" href={getHref('overview')}>
<FormattedMessage
id="xpack.ingestManager.homeIntegration.tutorialDirectory.ingestManagerAppButtonText"
defaultMessage="Try Ingest Manager Beta"
/>
</EuiButtonEmpty>
) : null;
});

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default TutorialDirectoryHeaderLink;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import {
EuiCallOut,
EuiSpacer,
} from '@elastic/eui';
import {
TutorialDirectoryNoticeComponent,
TutorialDirectoryHeaderLinkComponent,
} from 'src/plugins/home/public';
import type { TutorialDirectoryNoticeComponent } from 'src/plugins/home/public';
import { sendPutSettings, useGetSettings, useLink, useCapabilities } from '../../hooks';

const FlexItemButtonWrapper = styled(EuiFlexItem)`
Expand All @@ -33,7 +30,7 @@ const tutorialDirectoryNoticeState$ = new BehaviorSubject({
hasSeenNotice: false,
});

export const TutorialDirectoryNotice: TutorialDirectoryNoticeComponent = memo(() => {
const TutorialDirectoryNotice: TutorialDirectoryNoticeComponent = memo(() => {
const { getHref } = useLink();
const { show: hasIngestManager } = useCapabilities();
const { data: settingsData, isLoading } = useGetSettings();
Expand Down Expand Up @@ -128,27 +125,6 @@ export const TutorialDirectoryNotice: TutorialDirectoryNoticeComponent = memo(()
) : null;
});

export const TutorialDirectoryHeaderLink: TutorialDirectoryHeaderLinkComponent = memo(() => {
const { getHref } = useLink();
const { show: hasIngestManager } = useCapabilities();
const [noticeState, setNoticeState] = useState({
settingsDataLoaded: false,
hasSeenNotice: false,
});

useEffect(() => {
const subscription = tutorialDirectoryNoticeState$.subscribe((value) => setNoticeState(value));
return () => {
subscription.unsubscribe();
};
}, []);

return hasIngestManager && noticeState.settingsDataLoaded && noticeState.hasSeenNotice ? (
<EuiButtonEmpty size="s" iconType="link" flush="right" href={getHref('overview')}>
<FormattedMessage
id="xpack.ingestManager.homeIntegration.tutorialDirectory.ingestManagerAppButtonText"
defaultMessage="Try Ingest Manager Beta"
/>
</EuiButtonEmpty>
) : null;
});
// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default TutorialDirectoryNotice;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiText, EuiLink, EuiSpacer } from '@elastic/eui';
import { TutorialModuleNoticeComponent } from 'src/plugins/home/public';
import { useGetPackages, useLink, useCapabilities } from '../../hooks';

export const TutorialModuleNotice: TutorialModuleNoticeComponent = memo(({ moduleName }) => {
const TutorialModuleNotice: TutorialModuleNoticeComponent = memo(({ moduleName }) => {
const { getHref } = useLink();
const { show: hasIngestManager } = useCapabilities();
const { data: packagesData, isLoading } = useGetPackages();
Expand Down Expand Up @@ -72,3 +72,7 @@ export const TutorialModuleNotice: TutorialModuleNoticeComponent = memo(({ modul

return null;
});

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default TutorialModuleNotice;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { LicenseService } from '../services';
import { LicenseService } from '../../../../common/services/license';

export const licenseService = new LicenseService();

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {
registerPackagePolicyComponent,
} from './applications/ingest_manager/sections/agent_policy/create_package_policy_page/components/custom_package_policy';

export { NewPackagePolicy } from './applications/ingest_manager/types';
export type { NewPackagePolicy } from './applications/ingest_manager/types';
export * from './applications/ingest_manager/types/intra_app_route_state';

export { pagePathGetters } from './applications/ingest_manager/constants';
3 changes: 2 additions & 1 deletion x-pack/plugins/ingest_manager/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { BASE_PATH } from './applications/ingest_manager/constants';

import { IngestManagerConfigType } from '../common/types';
import { setupRouteService, appRoutesService } from '../common';
import { setHttpClient, licenseService } from './applications/ingest_manager/hooks';
import { licenseService } from './applications/ingest_manager/hooks/use_license';
import { setHttpClient } from './applications/ingest_manager/hooks/use_request/use_request';
import {
TutorialDirectoryNotice,
TutorialDirectoryHeaderLink,
Expand Down

0 comments on commit 570f2d2

Please sign in to comment.