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

[Discover] Fix Fields flyout and Create Field flyouts on mobile #145650

Merged
merged 4 commits into from
Nov 19, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiFlexItem,
EuiText,
EuiTitle,
useIsWithinMaxBreakpoint,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -72,6 +73,8 @@ const FieldEditorFlyoutContentComponent = ({
const isEditingExistingField = !!fieldToEdit;
const { dataView, subfields$ } = useFieldEditorContext();

const isMobile = useIsWithinMaxBreakpoint('s');

const {
panel: { isVisible: isPanelVisible },
} = useFieldPreviewContext();
Expand Down Expand Up @@ -198,7 +201,7 @@ const FieldEditorFlyoutContentComponent = ({
<>
<FlyoutPanels.Group
flyoutClassName={euiFlyoutClassname}
maxWidth={1180}
maxWidth={isMobile ? false : 1180}
data-test-subj="fieldEditor"
fixedPanelWidths
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, {
useMemo,
useLayoutEffect,
} from 'react';
import { EuiFlexGroup, EuiFlexGroupProps } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexGroupProps, EuiFlyoutProps } from '@elastic/eui';

import './flyout_panels.scss';

Expand Down Expand Up @@ -47,7 +47,7 @@ export interface Props {
* The total max width with all the panels in the DOM
* Corresponds to the "maxWidth" prop passed to the EuiFlyout
*/
maxWidth: number;
maxWidth: EuiFlyoutProps['maxWidth'];
/** The className selector of the flyout */
flyoutClassName: string;
/** The size between the panels. Corresponds to EuiFlexGroup gutterSize */
Expand Down Expand Up @@ -110,20 +110,27 @@ export const Panels: React.FC<Props> = ({

let currentWidth: number;

if (fixedPanelWidths) {
const totalWidth = Object.values(panels).reduce((acc, { width = 0 }) => acc + width, 0);
currentWidth = Math.min(maxWidth, totalWidth);
// As EUI declares both min-width and max-width on the .euiFlyout CSS class
// we need to override both values
flyoutDOMelement.style.minWidth = `${limitWidthToWindow(currentWidth, window)}px`;
flyoutDOMelement.style.maxWidth = `${limitWidthToWindow(currentWidth, window)}px`;
if (typeof maxWidth === 'number') {
if (fixedPanelWidths) {
const totalWidth = Object.values(panels).reduce((acc, { width = 0 }) => acc + width, 0);
currentWidth = Math.min(maxWidth, totalWidth);
// As EUI declares both min-width and max-width on the .euiFlyout CSS class
// we need to override both values
flyoutDOMelement.style.minWidth = `${limitWidthToWindow(currentWidth, window)}px`;
flyoutDOMelement.style.maxWidth = `${limitWidthToWindow(currentWidth, window)}px`;
} else {
const totalPercentWidth = Math.min(
100,
Object.values(panels).reduce((acc, { width = 0 }) => acc + width, 0)
);
currentWidth = (maxWidth * totalPercentWidth) / 100;
flyoutDOMelement.style.maxWidth = `${limitWidthToWindow(currentWidth, window)}px`;
}
} else {
const totalPercentWidth = Math.min(
100,
Object.values(panels).reduce((acc, { width = 0 }) => acc + width, 0)
);
currentWidth = (maxWidth * totalPercentWidth) / 100;
flyoutDOMelement.style.maxWidth = `${limitWidthToWindow(currentWidth, window)}px`;
// maxWidth is false on smaller mobile screens when the preview panel is unused.
// Unset custom min/max widths and let EUI's default 90vw width be used
flyoutDOMelement.style.minWidth = '';
flyoutDOMelement.style.maxWidth = '';
}
}, [panels, maxWidth, fixedPanelWidths, flyoutClassName, flyoutDOMelement]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@include euiBreakpoint('xs', 's') {
width: 100%;
padding: $euiSize $euiSize 0 $euiSize;
padding: $euiSize;
background-color: $euiPageBackgroundColor;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,19 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
</h2>
</EuiTitle>
</EuiFlyoutHeader>
{/* Using only the direct flyout body class because we maintain scroll in a lower sidebar component. Needs a fix on the EUI side */}
<div className="euiFlyoutBody">
<DiscoverSidebar
{...props}
documents={documentState.result}
fieldCounts={fieldCounts.current}
fieldFilter={fieldFilter}
setFieldFilter={setFieldFilter}
alwaysShowActionButtons={true}
setFieldEditorRef={setFieldEditorRef}
closeFlyout={closeFlyout}
editField={editField}
createNewDataView={createNewDataView}
showDataViewPicker={true}
/>
</div>
<DiscoverSidebar
{...props}
documents={documentState.result}
fieldCounts={fieldCounts.current}
fieldFilter={fieldFilter}
setFieldFilter={setFieldFilter}
alwaysShowActionButtons={true}
setFieldEditorRef={setFieldEditorRef}
closeFlyout={closeFlyout}
editField={editField}
createNewDataView={createNewDataView}
showDataViewPicker={true}
/>
</EuiFlyout>
</EuiPortal>
)}
Expand Down