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

[CCI] Fix bottom bar visibility using createPortal #3978

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Table Visualization] Fix table rendering empty unused space ([#3797](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3797))
- [Table Visualization] Fix data table not adjusting height on the initial load ([#3816](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3816))
- Cleanup unused url ([#3847](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3847))
- [BUG] Docked navigation impacts visibility of bottom bar component ([#3978](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3978))

### 🚞 Infrastructure

Expand Down
1 change: 0 additions & 1 deletion src/core/public/rendering/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
// SASSTODO: Naming here is too embedded and high up that changing them could cause major breaks
#opensearch-dashboards-body {
overflow-x: hidden;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a known problem that sticky behavior doesn't work if we use overflow: hidden on the parent component. More information can be found at w3c/csswg-drafts#865. I don't really know why this property was written, but it seems like it was just inherited from the old code on refactoring.

History of changes:

  1. b576780#diff-b735d2f2b9d87d3791ea90563e79a98455f186249f531b068f629b46adb5b24cR9
  2. 1a99df7#diff-f2168606829459ec979e10448c792f49c49ca94dc0ef1eee8f4d7e3c63427445R10
  3. e6ca5fa#diff-f2168606829459ec979e10448c792f49c49ca94dc0ef1eee8f4d7e3c63427445R6
  4. 585a84c#diff-f2168606829459ec979e10448c792f49c49ca94dc0ef1eee8f4d7e3c63427445R5

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, Im good with that

min-height: 100%;
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/public/rendering/app_containers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('AppWrapper', () => {
expect(component.getDOMNode()).toMatchInlineSnapshot(`
<div
class="app-wrapper"
id="app-wrapper"
>
app-content
</div>
Expand All @@ -53,6 +54,7 @@ describe('AppWrapper', () => {
expect(component.getDOMNode()).toMatchInlineSnapshot(`
<div
class="app-wrapper hidden-chrome"
id="app-wrapper"
>
app-content
</div>
Expand All @@ -63,6 +65,7 @@ describe('AppWrapper', () => {
expect(component.getDOMNode()).toMatchInlineSnapshot(`
<div
class="app-wrapper"
id="app-wrapper"
>
app-content
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/core/public/rendering/app_containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const AppWrapper: React.FunctionComponent<{
chromeVisible$: Observable<boolean>;
}> = ({ chromeVisible$, children }) => {
const visible = useObservable(chromeVisible$);
return <div className={classNames('app-wrapper', { 'hidden-chrome': !visible })}>{children}</div>;
return (
<div id="app-wrapper" className={classNames('app-wrapper', { 'hidden-chrome': !visible })}>
{children}
</div>
);
};

export const AppContainer: React.FunctionComponent<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,3 @@
.mgtAdvancedSettingsForm__button {
width: 100%;
}

.osdBody--mgtAdvancedSettingsHasBottomBar .mgtPage__body {
padding-bottom: $euiSizeXL * 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

import React from 'react';
import ReactDOM from 'react-dom';
import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers';
import { UiSettingsType } from '../../../../../../core/public';

Expand All @@ -38,13 +39,20 @@ import { notificationServiceMock } from '../../../../../../core/public/mocks';
import { SettingsChanges } from '../../types';
import { Form } from './form';

jest.mock('react-dom', () => ({
...jest.requireActual('react-dom'),
createPortal: jest.fn((element) => element),
}));

jest.mock('../field', () => ({
Field: () => {
return 'field';
},
}));

beforeAll(() => {
ReactDOM.createPortal = jest.fn((children: any) => children);

const localStorage: Record<string, any> = {
'core.chrome.isLocked': true,
};
Expand All @@ -60,6 +68,7 @@ beforeAll(() => {
});

afterAll(() => {
(ReactDOM.createPortal as jest.Mock).mockClear();
delete (window as any).localStorage;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import {
import { FormattedMessage } from '@osd/i18n/react';
import { isEmpty } from 'lodash';
import { i18n } from '@osd/i18n';
import { DocLinksStart, ToastsStart } from 'opensearch-dashboards/public';
import { createPortal } from 'react-dom';
import { toMountPoint } from '../../../../../opensearch_dashboards_react/public';
import { DocLinksStart, ToastsStart } from '../../../../../../core/public';

import { getCategoryName } from '../../lib';
import { Field, getEditableValue } from '../field';
Expand Down Expand Up @@ -336,63 +337,69 @@ export class Form extends PureComponent<FormProps> {
};

renderBottomBar = () => {
const areChangesInvalid = this.areChangesInvalid();
return (
<EuiBottomBar data-test-subj="advancedSetting-bottomBar">
<EuiFlexGroup
justifyContent="spaceBetween"
alignItems="center"
responsive={false}
gutterSize="s"
>
<EuiFlexItem grow={false} className="mgtAdvancedSettingsForm__unsavedCount">
<p id="aria-describedby.countOfUnsavedSettings">{this.renderCountOfUnsaved()}</p>
</EuiFlexItem>
<EuiFlexItem />
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
size="s"
iconType="cross"
onClick={this.clearAllUnsaved}
aria-describedby="aria-describedby.countOfUnsavedSettings"
data-test-subj="advancedSetting-cancelButton"
>
{i18n.translate('advancedSettings.form.cancelButtonLabel', {
defaultMessage: 'Cancel changes',
})}
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip
content={
areChangesInvalid &&
i18n.translate('advancedSettings.form.saveButtonTooltipWithInvalidChanges', {
defaultMessage: 'Fix invalid settings before saving.',
})
}
>
<EuiButton
className="mgtAdvancedSettingsForm__button"
disabled={areChangesInvalid}
color="secondary"
fill
try {
const areChangesInvalid = this.areChangesInvalid();
const bottomBar = (
<EuiBottomBar data-test-subj="advancedSetting-bottomBar" position="sticky">
<EuiFlexGroup
justifyContent="spaceBetween"
alignItems="center"
responsive={false}
gutterSize="s"
>
<EuiFlexItem grow={false} className="mgtAdvancedSettingsForm__unsavedCount">
<p id="aria-describedby.countOfUnsavedSettings">{this.renderCountOfUnsaved()}</p>
</EuiFlexItem>
<EuiFlexItem />
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
size="s"
iconType="check"
onClick={this.saveAll}
iconType="cross"
onClick={this.clearAllUnsaved}
aria-describedby="aria-describedby.countOfUnsavedSettings"
isLoading={this.state.loading}
data-test-subj="advancedSetting-saveButton"
data-test-subj="advancedSetting-cancelButton"
>
{i18n.translate('advancedSettings.form.saveButtonLabel', {
defaultMessage: 'Save changes',
{i18n.translate('advancedSettings.form.cancelButtonLabel', {
defaultMessage: 'Cancel changes',
})}
</EuiButton>
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
);
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip
content={
areChangesInvalid &&
i18n.translate('advancedSettings.form.saveButtonTooltipWithInvalidChanges', {
defaultMessage: 'Fix invalid settings before saving.',
})
}
>
<EuiButton
className="mgtAdvancedSettingsForm__button"
disabled={areChangesInvalid}
color="secondary"
fill
size="s"
iconType="check"
onClick={this.saveAll}
aria-describedby="aria-describedby.countOfUnsavedSettings"
isLoading={this.state.loading}
data-test-subj="advancedSetting-saveButton"
>
{i18n.translate('advancedSettings.form.saveButtonLabel', {
defaultMessage: 'Save changes',
})}
</EuiButton>
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
);

return createPortal(bottomBar, document.getElementById('app-wrapper')!);
} catch (e) {
return null;
}
};

render() {
Expand All @@ -401,12 +408,6 @@ export class Form extends PureComponent<FormProps> {
const currentCategories: Category[] = [];
const hasUnsavedChanges = !isEmpty(unsavedChanges);

if (hasUnsavedChanges) {
document.body.classList.add('osdBody--mgtAdvancedSettingsHasBottomBar');
} else {
document.body.classList.remove('osdBody--mgtAdvancedSettingsHasBottomBar');
}

categories.forEach((category) => {
if (visibleSettings[category] && visibleSettings[category].length) {
currentCategories.push(category);
Expand Down