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

Move FunctionGenerator component to lazy loaded bundle #13

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions x-pack/plugins/canvas/public/components/help_menu/help_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useState } from 'react';
import React, { FC, useState, lazy, Suspense } from 'react';
import { EuiButtonEmpty, EuiPortal, EuiSpacer } from '@elastic/eui';
import { ComponentStrings } from '../../../i18n';
import { KeyboardShortcutsDoc } from '../keyboard_shortcuts_doc';
import { FunctionReferenceGenerator } from '../function_reference_generator';

let FunctionReferenceGenerator: null | React.LazyExoticComponent<any> = null;
if (process.env.NODE_ENV === 'development') {
FunctionReferenceGenerator = lazy(() =>
import('../function_reference_generator').then((module) => ({
default: module.FunctionReferenceGenerator,
}))
);
}

const { HelpMenu: strings } = ComponentStrings;

Expand All @@ -27,19 +35,19 @@ export const HelpMenu: FC<Props> = ({ functionRegistry }) => {
setFlyoutVisible(false);
};

const isDevelopment = !['production', 'test'].includes(process.env.NODE_ENV);

return (
<>
<EuiButtonEmpty size="xs" flush="left" iconType="keyboardShortcut" onClick={showFlyout}>
{strings.getKeyboardShortcutsLinkLabel()}
</EuiButtonEmpty>
{isDevelopment && (
<>

{FunctionReferenceGenerator ? (
<Suspense fallback={null}>
<EuiSpacer size="s" />
<FunctionReferenceGenerator functionRegistry={functionRegistry} />
</>
)}
</Suspense>
) : null}

{isFlyoutVisible && (
<EuiPortal>
<KeyboardShortcutsDoc onClose={hideFlyout} />
Expand Down