Skip to content

Commit

Permalink
Updated all pages with new header UI (#1056) (#1058)
Browse files Browse the repository at this point in the history
* updated all pages with new header UI



* fixed UTs



* fixed cross cluster API; cypress workflow



* fixed data source logic on page load for view/edit monitor; removed redundant code; updated tests



---------

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan authored Aug 21, 2024
1 parent 9f02ed5 commit 4362410
Show file tree
Hide file tree
Showing 50 changed files with 410 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run Opensearch with plugin
run: |
cd alerting
./gradlew run &
./gradlew :alerting:run &
timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
- name: Checkout OpenSearch Dashboards
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/composite_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('CompositeLevelMonitor', () => {
.type('{backspace}')
.type('Composite trigger');

cy.intercept('api/alerting/workflows').as('createMonitorRequest');
cy.intercept('api/alerting/workflows?*').as('createMonitorRequest');
cy.intercept(`api/alerting/monitors?*`).as('getMonitorsRequest');
cy.get('button').contains('Create').click({ force: true });

Expand Down Expand Up @@ -116,7 +116,7 @@ describe('CompositeLevelMonitor', () => {
cy.visit(
`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors/${
createdMonitor._id
}?action=update-monitor&type=workflow`
}?action=update-monitor&type=workflow&dataSourceId=`
);
} else {
cy.log('Failed to get created monitor ', SAMPLE_VISUAL_EDITOR_MONITOR);
Expand Down
16 changes: 5 additions & 11 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
"id": "alertingDashboards",
"version": "2.17.0.0",
"opensearchDashboardsVersion": "2.17.0",
"configPath": [
"opensearch_alerting"
],
"optionalPlugins": [
"dataSource",
"dataSourceManagement"
],
"configPath": ["opensearch_alerting"],
"optionalPlugins": ["dataSource", "dataSourceManagement"],
"requiredPlugins": [
"uiActions",
"dashboard",
"navigation",
"embeddable",
"opensearchDashboardsReact",
"savedObjects",
Expand All @@ -23,7 +19,5 @@
"server": true,
"ui": true,
"supportedOSDataSourceVersions": ">=2.13.0",
"requiredOSDataSourcePlugins": [
"opensearch-alerting"
]
}
"requiredOSDataSourcePlugins": ["opensearch-alerting"]
}
5 changes: 4 additions & 1 deletion public/components/ContentPanel/ContentPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ContentPanel = ({
horizontalRuleClassName = '',
actions,
children,
panelOptions = {},
}) => (
<EuiPanel style={{ paddingLeft: '0px', paddingRight: '0px', ...panelStyles }}>
<EuiFlexGroup style={{ padding: '0px 10px' }} justifyContent="spaceBetween" alignItems="center">
Expand All @@ -38,7 +39,9 @@ const ContentPanel = ({
<EuiText style={{ padding: '0px 10px' }} size={descriptionSize} color="subdued">
{description}
</EuiText>
<EuiHorizontalRule margin="xs" className={horizontalRuleClassName} />
{!panelOptions.hideTitleBorder && (
<EuiHorizontalRule margin="xs" className={horizontalRuleClassName} />
)}

<div style={{ padding: '0px 10px', ...bodyStyles }}>{children}</div>
</EuiPanel>
Expand Down
3 changes: 1 addition & 2 deletions public/components/DeleteModal/DeleteMonitorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
EuiLink,
EuiOverlayMask
} from '@elastic/eui';
import { PLUGIN_NAME } from '../../../utils/constants';
import { getDataSourceQueryObj, constructUrlFromDataSource } from '../../pages/utils/helpers';

interface DeleteModalProps {
Expand Down Expand Up @@ -55,7 +54,7 @@ export const DeleteMonitorModal = ({
{`The monitor ${monitorNames[0]} is currently being used as a delegate monitor for composite monitors. Unlink from the following composite monitors before deleting this monitor:`}
{ associatedWorkflows ?
<ul>
{associatedWorkflows.map(({ id, name }) => <li><EuiLink target='_blank' href={constructUrlFromDataSource(`${PLUGIN_NAME}#/monitors/${id}?type=workflow`)}>{name}</EuiLink></li>)}
{associatedWorkflows.map(({ id, name }) => <li><EuiLink target='_blank' href={constructUrlFromDataSource(`#/monitors/${id}?type=workflow`)}>{name}</EuiLink></li>)}
</ul>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { httpServiceMock, notificationServiceMock } from '../../../../../../src/
import { shallow } from 'enzyme';
import AddAlertingMonitor from './AddAlertingMonitor';
import { setClient, setNotifications } from '../../../services';
import { setupCoreStart } from '../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('AddAlertingMonitor', () => {
const httpClient = httpServiceMock.createStartContract();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useMemo } from 'react';
import { EuiHealth, EuiLink } from '@elastic/eui';
import { stateToLabel } from '../../../utils/contextMenu/monitors';
import { dateOptionsLong } from '../../../utils/contextMenu/helpers';
import { PLUGIN_NAME } from '../../../../utils/constants';
import { constructUrlFromDataSource } from '../../../pages/utils/helpers';

export const useColumns = ({ onUnlink, onEdit }) => {
Expand All @@ -20,7 +19,7 @@ export const useColumns = ({ onUnlink, onEdit }) => {
truncateText: true,
width: '50%',
render: (name, monitor) => (
<EuiLink href={constructUrlFromDataSource(`${PLUGIN_NAME}#/monitors/${monitor.id}`)} target="_blank">
<EuiLink href={constructUrlFromDataSource(`#/monitors/${monitor.id}`)} target="_blank">
{name}
</EuiLink>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
EuiSmallButtonIcon,
} from '@elastic/eui';
import { getTime } from '../../../../pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats';
import { PLUGIN_NAME } from '../../../../../utils/constants';
import {
ALERT_STATE,
DEFAULT_EMPTY_DATA,
Expand Down Expand Up @@ -585,7 +584,7 @@ export default class AlertsDashboardFlyoutComponent extends Component {
displayTableTabs = false;
break;
}
const monitorUrl = `${PLUGIN_NAME}#/monitors/${monitor_id}${
const monitorUrl = `#/monitors/${monitor_id}${
monitorType === MONITOR_TYPE.COMPOSITE_LEVEL ? '?type=workflow' : ''
}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ exports[`AlertsDashboardFlyoutComponent renders 1`] = `
</strong>
<p>
<EuiLink
href="alerting#/monitors/undefined"
href="#/monitors/undefined"
/>
</p>
</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`FormikSwitch renders 1`] = `
<div
class="euiSwitch euiSwitch--compressed"
class="euiSwitch euiSwitch--primary euiSwitch--compressed"
>
<button
aria-checked="false"
Expand Down
43 changes: 43 additions & 0 deletions public/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import {
TopNavControlData,
TopNavControlDescriptionData,
TopNavControlLinkData,
TopNavControlIconData
} from '../../../../../src/plugins/navigation/public';
import { getNavigationUI, getApplication, getUseUpdatedUx } from '../../services';


export interface PageHeaderProps {
appRightControls?: TopNavControlData[];
appBadgeControls?: TopNavControlData[];
appDescriptionControls?: (TopNavControlDescriptionData | TopNavControlLinkData | TopNavControlIconData)[];
appBottomControls?: TopNavControlData[];
}

export const PageHeader: React.FC<PageHeaderProps> = ({
children,
appBadgeControls,
appRightControls,
appDescriptionControls,
appBottomControls
}) => {
const { HeaderControl } = getNavigationUI();
const { setAppBadgeControls, setAppRightControls, setAppDescriptionControls, setAppBottomControls } = getApplication();

return getUseUpdatedUx() ? (
<>
<HeaderControl setMountPoint={setAppBadgeControls} controls={appBadgeControls} />
<HeaderControl setMountPoint={setAppRightControls} controls={appRightControls} />
<HeaderControl setMountPoint={setAppDescriptionControls} controls={appDescriptionControls} />
<HeaderControl setMountPoint={setAppBottomControls} controls={appBottomControls} />
</>
) : (
<>{children}</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { mount, render } from 'enzyme';
import { FeatureChart } from './FeatureChart';
import AlertingFakes from '../../../../../../test/utils/helpers';
import { AlertingFakes } from '../../../../../../test/utils/helpers';

const alertingFakes = new AlertingFakes('random seed');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
RECOMMENDED_DURATION,
} from '../../components/QueryPerformance/QueryPerformance';
import { isDataSourceChanged } from '../../../utils/helpers';
import { PageHeader } from '../../../../components/PageHeader/PageHeader';

export default class CreateMonitor extends Component {
static defaultProps = {
Expand Down Expand Up @@ -187,10 +188,12 @@ export default class CreateMonitor extends Component {
const isComposite = values.monitor_type === MONITOR_TYPE.COMPOSITE_LEVEL;
return (
<Fragment>
<EuiText size="s">
<h1>{edit ? 'Edit' : 'Create'} monitor</h1>
</EuiText>
<EuiSpacer />
<PageHeader>
<EuiText size="s">
<h1>{edit ? 'Edit' : 'Create'} monitor</h1>
</EuiText>
<EuiSpacer />
</PageHeader>

<MonitorDetails
values={values}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import CreateMonitor from './CreateMonitor';
import { historyMock, httpClientMock } from '../../../../../test/mocks';
import { FORMIK_INITIAL_VALUES } from './utils/constants';
import AlertingFakes from '../../../../../test/utils/helpers';
import { AlertingFakes, setupCoreStart } from '../../../../../test/utils/helpers';
import { SEARCH_TYPE } from '../../../../utils/constants';
import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants';
import { setClient, setNotifications } from '../../../../services';
Expand All @@ -37,6 +37,11 @@ const location = {
search: '',
state: undefined,
};

beforeAll(() => {
setupCoreStart();
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { historyMock, httpClientMock } from '../../../../../test/mocks';
import AcknowledgeAlertsModal from './AcknowledgeAlertsModal';
import { FORMIK_INITIAL_VALUES } from '../../../CreateMonitor/containers/CreateMonitor/utils/constants';
import coreMock from '../../../../../test/mocks/CoreMock';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeEach(() => {
jest.clearAllMocks();
setupCoreStart();
});

describe('AcknowledgeAlertsModal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const DashboardControls = ({
onPageChange,
isAlertsFlyout = false,
monitorType,
alertActions = [],
}) => {
let supportedStateOptions = stateOptions;
switch (monitorType) {
Expand All @@ -55,7 +56,7 @@ const DashboardControls = ({
break;
}
return (
<EuiFlexGroup style={{ padding: '0px 5px' }}>
<EuiFlexGroup style={{ padding: '0px 5px' }} gutterSize="s">
<EuiFlexItem>
<EuiCompressedFieldSearch
fullWidth={true}
Expand All @@ -67,7 +68,11 @@ const DashboardControls = ({

{isAlertsFlyout ? null : (
<EuiFlexItem grow={false}>
<EuiCompressedSelect options={severityOptions} value={severity} onChange={onSeverityChange} />
<EuiCompressedSelect
options={severityOptions}
value={severity}
onChange={onSeverityChange}
/>
</EuiFlexItem>
)}

Expand All @@ -79,6 +84,9 @@ const DashboardControls = ({
data-test-subj={'dashboardAlertStateFilter'}
/>
</EuiFlexItem>
{alertActions.map((action, idx) => (
<EuiFlexItem grow={false}>{action}</EuiFlexItem>
))}
<EuiFlexItem grow={false} style={{ justifyContent: 'center' }}>
<EuiPagination pageCount={pageCount} activePage={activePage} onPageClick={onPageChange} />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`DashboardControls renders 1`] = `
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
class="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--directionRow euiFlexGroup--responsive"
style="padding:0px 5px"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import PropTypes from 'prop-types';
import { EuiSmallButton, EuiSmallButtonEmpty, EuiEmptyPrompt, EuiText } from '@elastic/eui';

import { APP_PATH } from '../../../../utils/constants';
import { PLUGIN_NAME } from '../../../../../utils/constants';
import { MONITORS_NAV_ID } from '../../../../../utils/constants';
import { getUseUpdatedUx } from '../../../../services';

const createMonitorText =
'There are no existing alerts. Create a monitor to add triggers and actions. Once an alarm is triggered, the state will show in this table.';
Expand All @@ -17,8 +18,11 @@ const createTriggerText =
const editTriggerConditionsText =
'There are no existing alerts. Adjust trigger conditions to start alerting. Once an alarm is triggered, the state will show in this table.';

const createMonitorButton = (
<EuiSmallButton fill href={`${PLUGIN_NAME}#${APP_PATH.CREATE_MONITOR}`}>
const getCreateMonitorButton = () => (
<EuiSmallButton
fill
href={`${getUseUpdatedUx() ? MONITORS_NAV_ID : ''}#${APP_PATH.CREATE_MONITOR}`}
>
Create monitor
</EuiSmallButton>
);
Expand All @@ -37,7 +41,7 @@ const DashboardEmptyPrompt = ({ onCreateTrigger, isModal = false }) => {
? undefined
: isModal
? editMonitorButton(onCreateTrigger)
: createMonitorButton;
: getCreateMonitorButton();
return (
<EuiEmptyPrompt
style={{ maxWidth: '45em' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import React from 'react';
import { render } from 'enzyme';

import DashboardEmptyPrompt from './DashboardEmptyPrompt';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('DashboardEmptyPrompt', () => {
test('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`DashboardEmptyPrompt renders 1`] = `
/>
<a
class="euiButton euiButton--primary euiButton--small euiButton--fill"
href="alerting#/create-monitor"
href="#/create-monitor"
rel="noreferrer"
>
<span
Expand Down
Loading

0 comments on commit 4362410

Please sign in to comment.