-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support new page header Signed-off-by: Lin Wang <[email protected]> * Updatenew home page title text Signed-off-by: Lin Wang <[email protected]> * Fix unit tests for page header Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]>
- Loading branch information
Showing
6 changed files
with
225 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
public/components/monitoring/__tests__/monitoring_page_header.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { applicationServiceMock } from '../../../../../../src/core/public/mocks'; | ||
import { navigationPluginMock } from '../../../../../../src/plugins/navigation/public/mocks'; | ||
|
||
import { render, screen } from '../../../../test/test_utils'; | ||
import { MonitoringPageHeader, MonitoringPageHeaderProps } from '../monitoring_page_header'; | ||
|
||
jest.mock('../../../apis/connector'); | ||
|
||
async function setup(options: Partial<MonitoringPageHeaderProps>) { | ||
const setBreadcrumbsMock = jest.fn(); | ||
const onRefreshMock = jest.fn(); | ||
const applicationStartMock = applicationServiceMock.createStartContract(); | ||
const navigationStartMock = navigationPluginMock.createStartContract(); | ||
const user = userEvent.setup({}); | ||
|
||
navigationStartMock.ui.HeaderControl = ({ controls }) => { | ||
return controls?.[0].renderComponent ?? null; | ||
}; | ||
|
||
const renderResult = render( | ||
<MonitoringPageHeader | ||
navigation={navigationStartMock} | ||
application={applicationStartMock} | ||
setBreadcrumbs={setBreadcrumbsMock} | ||
onRefresh={onRefreshMock} | ||
useNewPageHeader={true} | ||
{...options} | ||
/> | ||
); | ||
|
||
return { | ||
user, | ||
renderResult, | ||
setBreadcrumbsMock, | ||
onRefreshMock, | ||
applicationStartMock, | ||
navigationStartMock, | ||
}; | ||
} | ||
|
||
describe('<MonitoringPageHeader />', () => { | ||
it('should old page header and refresh button when usePageHeader is false', async () => { | ||
await setup({ | ||
useNewPageHeader: false, | ||
}); | ||
expect(screen.getByText('Overview')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('set refresh interval')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should set breadcrumbs and render refresh button', async () => { | ||
const { setBreadcrumbsMock } = await setup({ | ||
useNewPageHeader: true, | ||
recordsCount: 2, | ||
}); | ||
|
||
expect(setBreadcrumbsMock).toHaveBeenCalledWith([ | ||
{ | ||
text: 'AI models (2)', | ||
}, | ||
]); | ||
expect(screen.getByLabelText('set refresh interval')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import React, { useEffect, useMemo } from 'react'; | ||
import { EuiPageHeader, EuiSpacer } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
|
||
import type { ChromeBreadcrumb } from 'opensearch-dashboards/public'; | ||
|
||
import { RefreshInterval } from '../common/refresh_interval'; | ||
import { NavigationPublicPluginStart } from '../../../../../src/plugins/navigation/public'; | ||
import { ApplicationStart } from '../../../../../src/core/public'; | ||
|
||
export interface MonitoringPageHeaderProps { | ||
navigation: NavigationPublicPluginStart; | ||
application: ApplicationStart; | ||
onRefresh: () => void; | ||
recordsCount?: number; | ||
setBreadcrumbs: (breadcrumbs: ChromeBreadcrumb[]) => void; | ||
useNewPageHeader: boolean; | ||
} | ||
|
||
export const MonitoringPageHeader = ({ | ||
onRefresh, | ||
navigation, | ||
recordsCount, | ||
setBreadcrumbs, | ||
application, | ||
useNewPageHeader, | ||
}: MonitoringPageHeaderProps) => { | ||
const { HeaderControl } = navigation.ui; | ||
const { setAppRightControls } = application; | ||
const controls = useMemo(() => { | ||
if (useNewPageHeader) { | ||
return [ | ||
{ | ||
renderComponent: <RefreshInterval onRefresh={onRefresh} />, | ||
}, | ||
]; | ||
} | ||
return []; | ||
}, [useNewPageHeader, onRefresh]); | ||
|
||
useEffect(() => { | ||
if (useNewPageHeader) { | ||
setBreadcrumbs([ | ||
{ | ||
text: i18n.translate('machineLearning.AIModels.page.title', { | ||
defaultMessage: | ||
'AI models {recordsCount, select, undefined {} other {({recordsCount})}}', | ||
values: { | ||
recordsCount, | ||
}, | ||
}), | ||
}, | ||
]); | ||
} | ||
}, [useNewPageHeader, recordsCount, setBreadcrumbs]); | ||
|
||
if (useNewPageHeader) { | ||
return <HeaderControl setMountPoint={setAppRightControls} controls={controls} />; | ||
} | ||
return ( | ||
<> | ||
<EuiSpacer size="s" /> | ||
<EuiSpacer size="xs" /> | ||
<EuiPageHeader | ||
pageTitle="Overview" | ||
rightSideItems={[<RefreshInterval onRefresh={onRefresh} />]} | ||
/> | ||
<EuiSpacer size="m" /> | ||
</> | ||
); | ||
}; |