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 TopNavLinks to new Nav Bar Discover #7326

Merged
merged 2 commits into from
Jul 23, 2024
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/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ export interface AppMountParameters<HistoryLocationState = unknown> {
* Optional datasource id to pass while mounting app
*/
dataSourceId?: string;

optionalRef?: Record<string, React.RefObject<HTMLDivElement>>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import classNames from 'classnames';
import { compact, isEqual } from 'lodash';
import React, { useState } from 'react';
import { createPortal } from 'react-dom';
import {
DataSource,
IDataPluginServices,
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface QueryEditorTopRowProps {
isDirty: boolean;
timeHistory?: TimeHistoryContract;
indicateNoData?: boolean;
datePickerRef?: React.RefObject<HTMLDivElement>;
}

// Needed for React.lazy
Expand Down Expand Up @@ -294,7 +296,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {

return (
<NoDataPopover storage={storage} showNoDataPopover={props.indicateNoData}>
<EuiFlexGroup responsive={false} gutterSize="s">
<EuiFlexGroup responsive={false} gutterSize="s" alignItems="flexStart">
{renderDatePicker()}
<EuiFlexItem grow={false}>{button}</EuiFlexItem>
</EuiFlexGroup>
Expand Down Expand Up @@ -359,6 +361,14 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
'osdQueryEditor--withDatePicker': props.showDatePicker,
});

const datePicker = (
<EuiFlexGroup justifyContent="flexEnd" gutterSize="none" responsive={false}>
<EuiFlexItem grow={false} className="osdQueryEditor--updateButtonWrapper">
{renderUpdateButton()}
</EuiFlexItem>
</EuiFlexGroup>
);

return (
<EuiFlexGroup
className={classes}
Expand All @@ -367,11 +377,9 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
direction="column"
justifyContent="flexEnd"
>
<EuiFlexGroup justifyContent="flexEnd" gutterSize="none" responsive={false}>
<EuiFlexItem grow={false} className="osdQueryEditor--updateButtonWrapper">
{renderUpdateButton()}
</EuiFlexItem>
</EuiFlexGroup>
{props?.datePickerRef?.current && uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)
? createPortal(datePicker, props.datePickerRef.current)
: datePicker}
{renderQueryEditor()}
<EuiFlexItem>
<EuiFlexGroup responsive={false} gutterSize="none" direction="column">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { EuiSuperUpdateButton, OnRefreshProps, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import { Toast } from 'src/core/public';
import { createPortal } from 'react-dom';
import { IDataPluginServices, IIndexPattern, TimeRange, TimeHistoryContract, Query } from '../..';
import {
useOpenSearchDashboards,
Expand Down Expand Up @@ -83,6 +84,7 @@ export interface QueryBarTopRowProps {
isDirty: boolean;
timeHistory?: TimeHistoryContract;
indicateNoData?: boolean;
datePickerRef?: React.RefObject<HTMLDivElement>;
}

// Needed for React.lazy
Expand Down Expand Up @@ -262,7 +264,7 @@ export default function QueryBarTopRow(props: QueryBarTopRowProps) {

return (
<NoDataPopover storage={storage} showNoDataPopover={props.indicateNoData}>
<EuiFlexGroup responsive={false} gutterSize="s">
<EuiFlexGroup responsive={false} gutterSize="s" alignItems="flexStart">
{renderDatePicker()}
<EuiFlexItem grow={false}>{button}</EuiFlexItem>
</EuiFlexGroup>
Expand Down Expand Up @@ -393,7 +395,11 @@ export default function QueryBarTopRow(props: QueryBarTopRowProps) {
>
{renderQueryInput()}
{renderSharingMetaFields()}
<EuiFlexItem grow={false}>{renderUpdateButton()}</EuiFlexItem>
<EuiFlexItem grow={false}>
{props?.datePickerRef?.current && uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)
? createPortal(renderUpdateButton(), props.datePickerRef.current)
: renderUpdateButton()}
</EuiFlexItem>
</EuiFlexGroup>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export function createSearchBar({
onClearSavedQuery={defaultOnClearSavedQuery(props, clearSavedQuery)}
onSavedQueryUpdated={defaultOnSavedQueryUpdated(props, setSavedQuery)}
onSaved={defaultOnSavedQueryUpdated(props, setSavedQuery)}
datePickerRef={props.datePickerRef}
{...overrideDefaultBehaviors(props)}
/>
</OpenSearchDashboardsContextProvider>
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface SearchBarOwnProps {
refreshInterval?: number;
dateRangeFrom?: string;
dateRangeTo?: string;
datePickerRef?: React.RefObject<HTMLDivElement>;
// Query bar - should be in SearchBarInjectedDeps
query?: Query;
settings?: Settings;
Expand Down Expand Up @@ -482,6 +483,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
}
dataTestSubj={this.props.dataTestSubj}
indicateNoData={this.props.indicateNoData}
datePickerRef={this.props.datePickerRef}
/>
);
}
Expand Down Expand Up @@ -518,6 +520,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
filterBar={filterBar}
dataTestSubj={this.props.dataTestSubj}
indicateNoData={this.props.indicateNoData}
datePickerRef={this.props.datePickerRef}
/>
);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/plugins/data_explorer/public/components/app_container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ $osdHeaderOffset: $euiHeaderHeightCompensation;
.headerIsExpanded .deLayout {
height: calc(100vh - #{$osdHeaderOffset * 2});
}

.mainPage {
overflow-x: hidden;
overflow-y: auto;

.navBar {
padding: $euiSizeXS $euiSizeXS $euiSizeXS $euiSizeM;
border-bottom: $euiBorderThin;
}
}
108 changes: 76 additions & 32 deletions src/plugins/data_explorer/public/components/app_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { memo } from 'react';
import { EuiPage, EuiPageBody, EuiResizableContainer, useIsWithinBreakpoints } from '@elastic/eui';
import React, { memo, useRef } from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
EuiPage,
EuiPageBody,
EuiResizableContainer,
useIsWithinBreakpoints,
} from '@elastic/eui';
import { Suspense } from 'react';
import { AppMountParameters } from '../../../../core/public';
import { Sidebar } from './sidebar';
import { NoView } from './no_view';
import { View } from '../services/view_service/view';
import { shallowEqual } from '../utils/use/shallow_equal';
import './app_container.scss';
import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public';
import { IDataPluginServices } from '../../../data/public';
import { QUERY_ENHANCEMENT_ENABLED_SETTING } from './constants';

export const AppContainer = React.memo(
({ view, params }: { view?: View; params: AppMountParameters }) => {
const isMobile = useIsWithinBreakpoints(['xs', 's', 'm']);
// TODO: Make this more robust.

const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const { uiSettings } = opensearchDashboards.services;

const topLinkRef = useRef<HTMLDivElement>(null);
const datePickerRef = useRef<HTMLDivElement>(null);
if (!view) {
return <NoView />;
}
Expand All @@ -26,38 +41,67 @@
const MemoizedPanel = memo(Panel);
const MemoizedCanvas = memo(Canvas);

params.optionalRef = {
topLinkRef,
datePickerRef,
};

// Render the application DOM.
return (
<EuiPage className="deLayout" paddingSize="none">
{/* TODO: improve fallback state */}
<Suspense fallback={<div>Loading...</div>}>
<Context {...params}>
<EuiResizableContainer direction={isMobile ? 'vertical' : 'horizontal'}>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel
initialSize={20}
minSize="260px"
mode={['collapsible', { position: 'top' }]}
paddingSize="none"
>
<Sidebar>
<MemoizedPanel {...params} />
</Sidebar>
</EuiResizablePanel>
<EuiResizableButton />
<div className="mainPage">
{uiSettings?.get(QUERY_ENHANCEMENT_ENABLED_SETTING) && (
<EuiFlexGroup
direction="row"
className="mainPage navBar"
gutterSize="none"
alignItems="center"
justifyContent="spaceBetween"
>
<EuiFlexItem grow={false}>
<div ref={topLinkRef} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<div ref={datePickerRef} />
</EuiFlexItem>
</EuiFlexGroup>
)}

<EuiPage className="deLayout" paddingSize="none" grow={false}>
{/* TODO: improve fallback state */}
<Suspense fallback={<div>Loading...</div>}>
<Context {...params}>
<EuiResizableContainer direction={isMobile ? 'vertical' : 'horizontal'}>
{(EuiResizablePanel, EuiResizableButton) => (
<>

Check warning on line 75 in src/plugins/data_explorer/public/components/app_container.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_explorer/public/components/app_container.tsx#L75

Added line #L75 was not covered by tests
<EuiResizablePanel
initialSize={20}
minSize="260px"
mode={['collapsible', { position: 'top' }]}
paddingSize="none"
>
<Sidebar>
<MemoizedPanel {...params} />
</Sidebar>
</EuiResizablePanel>
<EuiResizableButton />

<EuiResizablePanel initialSize={80} minSize="65%" mode="main" paddingSize="none">
<EuiPageBody className="deLayout__canvas">
<MemoizedCanvas {...params} />
</EuiPageBody>
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
</Context>
</Suspense>
</EuiPage>
<EuiResizablePanel
initialSize={80}
minSize="65%"
mode="main"
paddingSize="none"
>
<EuiPageBody className="deLayout__canvas">
<MemoizedCanvas {...params} />
</EuiPageBody>
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
</Context>
</Suspense>
</EuiPage>
</div>
);
},
(prevProps, nextProps) => {
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data_explorer/public/components/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const QUERY_ENHANCEMENT_ENABLED_SETTING = 'query:enhancements:enabled';
1 change: 1 addition & 0 deletions src/plugins/discover/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export const CONTEXT_DEFAULT_SIZE_SETTING = 'context:defaultSize';
export const CONTEXT_STEP_SETTING = 'context:step';
export const CONTEXT_TIE_BREAKER_FIELDS_SETTING = 'context:tieBreakerFields';
export const MODIFY_COLUMNS_ON_SWITCH = 'discover:modifyColumnsOnSwitch';
export const QUERY_ENHANCEMENT_ENABLED_SETTING = 'query:enhancements:enabled';
Loading
Loading