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

Resize Painless Lab bottom bar to accommodate nav drawer width #60833

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, DevToolsStart> {
getSortedDevTools: this.getSortedDevTools.bind(this),
};
}

public stop() {}
}
27 changes: 23 additions & 4 deletions x-pack/plugins/painless_lab/public/application/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useEffect, FunctionComponent } from 'react';
import React, { useState, useEffect } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { formatRequestPayload, formatJson } from '../lib/format';
Expand All @@ -17,11 +17,19 @@ import { Editor } from './editor';
import { RequestFlyout } from './request_flyout';
import { useAppContext } from '../context';

export const Main: FunctionComponent = () => {
const { state, updateState, services, links } = useAppContext();
export const Main = () => {
const {
state,
updateState,
services: {
http,
chrome: { getIsNavDrawerLocked$ },
},
links,
} = useAppContext();

const [isRequestFlyoutOpen, setRequestFlyoutOpen] = useState(false);
const { inProgress, response, submit } = useSubmitCode(services.http);
const { inProgress, response, submit } = useSubmitCode(http);

// Live-update the output and persist state as the user changes it.
useEffect(() => {
Expand All @@ -32,6 +40,16 @@ export const Main: FunctionComponent = () => {
setRequestFlyoutOpen(!isRequestFlyoutOpen);
};

const [isNavDrawerLocked, setIsNavDrawerLocked] = useState(false);

useEffect(() => {
const subscription = getIsNavDrawerLocked$().subscribe((newIsNavDrawerLocked: boolean) => {
setIsNavDrawerLocked(newIsNavDrawerLocked);
});

return () => subscription.unsubscribe();
});

return (
<div className="painlessLabMainContainer">
<EuiFlexGroup className="painlessLabPanelsContainer" responsive={false} gutterSize="none">
Expand Down Expand Up @@ -61,6 +79,7 @@ export const Main: FunctionComponent = () => {
toggleRequestFlyout={toggleRequestFlyout}
isRequestFlyoutOpen={isRequestFlyoutOpen}
reset={() => updateState(() => ({ code: exampleScript }))}
isNavDrawerLocked={isNavDrawerLocked}
/>

{isRequestFlyoutOpen && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useState } from 'react';
import classNames from 'classnames';
import {
EuiPopover,
EuiBottomBar,
Expand All @@ -23,9 +24,16 @@ interface Props {
isLoading: boolean;
reset: () => void;
links: Links;
isNavDrawerLocked: boolean;
}

export function MainControls({ toggleRequestFlyout, isRequestFlyoutOpen, reset, links }: Props) {
export function MainControls({
toggleRequestFlyout,
isRequestFlyoutOpen,
reset,
links,
isNavDrawerLocked,
}: Props) {
const [isHelpOpen, setIsHelpOpen] = useState(false);

const items = [
Expand Down Expand Up @@ -79,8 +87,12 @@ export function MainControls({ toggleRequestFlyout, isRequestFlyoutOpen, reset,
</EuiContextMenuItem>,
];

const classes = classNames('painlessLab__bottomBar', {
'painlessLab__bottomBar-isNavDrawerLocked': isNavDrawerLocked,
});

return (
<EuiBottomBar paddingSize="s">
<EuiBottomBar paddingSize="s" className={classes}>
<EuiFlexGroup gutterSize="s" justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="s" justifyContent="flexStart">
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/painless_lab/public/application/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface AppContextProviderArgs {

export const AppContextProvider = ({
children,
value: { http, links },
value: { http, links, chrome },
}: AppContextProviderArgs) => {
const [state, setState] = useState<Store>(() => ({
...initialState,
Expand All @@ -51,7 +51,7 @@ export const AppContextProvider = ({
};

return (
<AppContext.Provider value={{ updateState, state, services: { http }, links }}>
<AppContext.Provider value={{ updateState, state, services: { http, chrome }, links }}>
{children}
</AppContext.Provider>
);
Expand Down
33 changes: 0 additions & 33 deletions x-pack/plugins/painless_lab/public/application/index.scss

This file was deleted.

6 changes: 3 additions & 3 deletions x-pack/plugins/painless_lab/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ interface AppDependencies {
I18nContext: CoreStart['i18n']['Context'];
uiSettings: CoreSetup['uiSettings'];
links: Links;
chrome: CoreSetup['chrome'];
}

export function renderApp(
element: HTMLElement | null,
{ http, I18nContext, uiSettings, links }: AppDependencies
{ http, I18nContext, uiSettings, links, chrome }: AppDependencies
) {
if (!element) {
return () => undefined;
}

const { Provider: KibanaReactContextProvider } = createKibanaReactContext({
uiSettings,
});
render(
<I18nContext>
<KibanaReactContextProvider>
<AppContextProvider value={{ http, links }}>
<AppContextProvider value={{ http, links, chrome }}>
<Main />
</AppContextProvider>
</KibanaReactContextProvider>
Expand Down
13 changes: 12 additions & 1 deletion x-pack/plugins/painless_lab/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class PainlessLabUIPlugin implements Plugin<void, void, PluginDependencie
i18n: { Context: I18nContext },
notifications,
docLinks,
chrome,
} = core;

this.languageService.setup();
Expand All @@ -90,7 +91,17 @@ export class PainlessLabUIPlugin implements Plugin<void, void, PluginDependencie
}

const { renderApp } = await import('./application');
return renderApp(element, { I18nContext, http, uiSettings, links: getLinks(docLinks) });
const tearDownApp = renderApp(element, {
I18nContext,
http,
uiSettings,
links: getLinks(docLinks),
chrome,
});

return () => {
tearDownApp();
};
},
});
}
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/painless_lab/public/styles/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '@elastic/eui/src/components/header/variables';
@import '@elastic/eui/src/components/nav_drawer/variables';

/**
* This is a very brittle way of preventing the editor and other content from disappearing
Expand Down Expand Up @@ -42,3 +43,15 @@ $bottomBarHeight: calc(#{$euiSize} * 3);
// The panels container should adopt the height of the main container
height: 100%;
}

/**
* 1. Hack EUI so the bottom bar doesn't obscure the nav drawer flyout.
*/
.painlessLab__bottomBar {
z-index: 0; /* 1 */
left: $euiNavDrawerWidthCollapsed;
}

.painlessLab__bottomBar-isNavDrawerLocked {
left: $euiNavDrawerWidthExpanded;
}