Skip to content

Commit

Permalink
Merge pull request #13 from crob611/pr/49402
Browse files Browse the repository at this point in the history
Move FunctionGenerator component to lazy loaded bundle
  • Loading branch information
cqliu1 authored Aug 5, 2020
2 parents e095781 + 0e88aad commit c639ace
Showing 1 changed file with 16 additions and 8 deletions.
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

0 comments on commit c639ace

Please sign in to comment.