Skip to content

Commit

Permalink
moved redux logic to connected
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Feb 6, 2020
1 parent 2349f0d commit ca1ace9
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export { KueryBar } from './kuerybar/kuery_bar_container';
export { FilterGroup } from './filter_group/filter_group_container';
export { MonitorStatusDetails } from './monitor/status_details_container';
export { MonitorStatusBar } from './monitor/status_bar_container';
export { MonitorListDrawer } from './monitor/list_drawer_container';
export { MonitorListActionsPopover } from './monitor/drawer_popover_container';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { connect } from 'react-redux';
import { AppState } from '../../../state';
import { isIntegrationsPopupOpen } from '../../../state/selectors';
import { PopoverState, toggleIntegrationsPopover } from '../../../state/actions';
import { MonitorListActionsPopoverComponent } from '../../functional/monitor_list/monitor_list_drawer';

const mapStateToProps = (state: AppState) => ({
popoverState: isIntegrationsPopupOpen(state),
});

const mapDispatchToProps = (dispatch: any) => ({
togglePopoverIsVisible: (popoverState: PopoverState) => {
return dispatch(toggleIntegrationsPopover(popoverState));
},
});

export const MonitorListActionsPopover = connect(
mapStateToProps,
mapDispatchToProps
)(MonitorListActionsPopoverComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { AppState } from '../../../state';
import { getMonitorDetails } from '../../../state/selectors';
import { MonitorDetailsActionPayload } from '../../../state/actions/types';
import { fetchMonitorDetails } from '../../../state/actions/monitor';
import { MonitorListDrawerComponent } from '../../functional/monitor_list/monitor_list_drawer/monitor_list_drawer';
import { useUrlParams } from '../../../hooks';
import { MonitorSummary } from '../../../../common/graphql/types';
import { MonitorDetails } from '../../../../common/runtime_types/monitor';

interface ContainerProps {
summary: MonitorSummary;
monitorDetails: MonitorDetails;
loadMonitorDetails: typeof fetchMonitorDetails;
}

const Container: React.FC<ContainerProps> = ({ summary, loadMonitorDetails, monitorDetails }) => {
const monitorId = summary?.monitor_id;

const [getUrlParams] = useUrlParams();
const { dateRangeStart: dateStart, dateRangeEnd: dateEnd } = getUrlParams();

useEffect(() => {
loadMonitorDetails({
dateStart,
dateEnd,
monitorId,
});
}, [dateStart, dateEnd, monitorId, loadMonitorDetails]);
return <MonitorListDrawerComponent monitorDetails={monitorDetails} summary={summary} />;
};

const mapStateToProps = (state: AppState, { summary }: any) => ({
monitorDetails: getMonitorDetails(state, summary),
});

const mapDispatchToProps = (dispatch: any) => ({
loadMonitorDetails: (actionPayload: MonitorDetailsActionPayload) =>
dispatch(fetchMonitorDetails(actionPayload)),
});

export const MonitorListDrawer = connect(mapStateToProps, mapDispatchToProps)(Container);
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface OwnProps {

type Props = OwnProps & StateProps & DispatchProps;

export const Container: React.FC<Props> = ({
const Container: React.FC<Props> = ({
loadMonitorStatus,
monitorId,
monitorStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

export { DonutChart } from './charts/donut_chart';
export { EmptyState } from './empty_state';
export { IntegrationLink } from './integration_link';
export { KueryBarComponent } from './kuery_bar/kuery_bar';
export { MonitorCharts } from './monitor_charts';
export { MonitorList } from './monitor_list';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import {
import { MonitorListStatusColumn } from './monitor_list_status_column';
import { formatUptimeGraphQLErrorList } from '../../../lib/helper/format_error_list';
import { ExpandedRowMap } from './types';
import { MonitorListDrawer } from './monitor_list_drawer';
import { MonitorBarSeries } from '../charts';
import { MonitorPageLink } from './monitor_page_link';
import { OverviewPageLink } from './overview_page_link';
import * as labels from './translations';
import { MonitorListDrawer } from '../../connected';

interface MonitorListQueryResult {
monitorStates?: MonitorSummaryResult;
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { MonitorSummary } from '../../../../common/graphql/types';
import { MonitorSummary } from '../../../../../../common/graphql/types';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { IntegrationGroup } from '../integration_group';

Expand All @@ -26,12 +26,12 @@ describe('IntegrationGroup', () => {
it('will not display APM links when APM is unavailable', () => {
const component = shallowWithIntl(
<IntegrationGroup
basePath="foo"
dateRangeStart="now-12m"
dateRangeEnd="now-1m"
isApmAvailable={false}
isInfraAvailable={true}
isLogsAvailable={true}
// basePath="foo"
// dateRangeStart="now-12m"
// dateRangeEnd="now-1m"
// isApmAvailable={false}
// isInfraAvailable={true}
// isLogsAvailable={true}
summary={summary}
/>
);
Expand All @@ -41,12 +41,12 @@ describe('IntegrationGroup', () => {
it('will not display infra links when infra is unavailable', () => {
const component = shallowWithIntl(
<IntegrationGroup
basePath="foo"
dateRangeStart="now-12m"
dateRangeEnd="now-1m"
isApmAvailable={true}
isInfraAvailable={false}
isLogsAvailable={true}
// basePath="foo"
// dateRangeStart="now-12m"
// dateRangeEnd="now-1m"
// isApmAvailable={true}
// isInfraAvailable={false}
// isLogsAvailable={true}
summary={summary}
/>
);
Expand All @@ -56,12 +56,12 @@ describe('IntegrationGroup', () => {
it('will not display logging links when logging is unavailable', () => {
const component = shallowWithIntl(
<IntegrationGroup
basePath="foo"
dateRangeStart="now-12m"
dateRangeEnd="now-1m"
isApmAvailable={true}
isInfraAvailable={true}
isLogsAvailable={false}
// basePath="foo"
// dateRangeStart="now-12m"
// dateRangeEnd="now-1m"
// isApmAvailable={true}
// isInfraAvailable={true}
// isLogsAvailable={false}
summary={summary}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import 'jest';
import { MonitorSummary, Check } from '../../../../../../common/graphql/types';
import React from 'react';
import { MonitorSummary, Check } from '../../../../../../common/graphql/types';
import { MonitorListDrawerComponent } from '../monitor_list_drawer';
import { MonitorDetails } from '../../../../../../common/runtime_types';
import { shallowWithRouter } from '../../../../../lib';

describe('MonitorListDrawer component', () => {
let summary: MonitorSummary;
let loadMonitorDetails: any;
let monitorDetails: MonitorDetails;

beforeEach(() => {
Expand Down Expand Up @@ -47,39 +45,26 @@ describe('MonitorListDrawer component', () => {
'Get https://expired.badssl.com: x509: certificate has expired or is not yet valid',
},
};
loadMonitorDetails = () => null;
});

it('renders nothing when no summary data is present', () => {
const component = shallowWithRouter(
<MonitorListDrawerComponent
loadMonitorDetails={loadMonitorDetails}
summary={summary}
monitorDetails={monitorDetails}
/>
<MonitorListDrawerComponent summary={summary} monitorDetails={monitorDetails} />
);
expect(component).toEqual({});
});

it('renders nothing when no check data is present', () => {
delete summary.state.checks;
const component = shallowWithRouter(
<MonitorListDrawerComponent
summary={summary}
loadMonitorDetails={loadMonitorDetails}
monitorDetails={monitorDetails}
/>
<MonitorListDrawerComponent summary={summary} monitorDetails={monitorDetails} />
);
expect(component).toEqual({});
});

it('renders a MonitorListDrawer when there is only one check', () => {
const component = shallowWithRouter(
<MonitorListDrawerComponent
summary={summary}
loadMonitorDetails={loadMonitorDetails}
monitorDetails={monitorDetails}
/>
<MonitorListDrawerComponent summary={summary} monitorDetails={monitorDetails} />
);
expect(component).toMatchSnapshot();
});
Expand Down Expand Up @@ -110,11 +95,7 @@ describe('MonitorListDrawer component', () => {
];
summary.state.checks = checks;
const component = shallowWithRouter(
<MonitorListDrawerComponent
summary={summary}
loadMonitorDetails={loadMonitorDetails}
monitorDetails={monitorDetails}
/>
<MonitorListDrawerComponent summary={summary} monitorDetails={monitorDetails} />
);
expect(component).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { MonitorListDrawer } from './monitor_list_drawer';
export { LocationLink } from './location_link';
export { MonitorListActionsPopoverComponent } from './monitor_list_actions_popover';
Loading

0 comments on commit ca1ace9

Please sign in to comment.