Skip to content

Commit

Permalink
[ILM] Convert node details flyout to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Jul 31, 2020
1 parent 10f8bea commit b380789
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ import { SetPriorityInput } from '../set_priority_input';
export class ColdPhase extends PureComponent {
static propTypes = {
setPhaseData: PropTypes.func.isRequired,
showNodeDetailsFlyout: PropTypes.func.isRequired,

isShowingErrors: PropTypes.bool.isRequired,
errors: PropTypes.object.isRequired,
};
render() {
const {
setPhaseData,
showNodeDetailsFlyout,
phaseData,
errors,
isShowingErrors,
Expand Down Expand Up @@ -114,7 +112,6 @@ export class ColdPhase extends PureComponent {
<NodeAllocation
phase={PHASE_COLD}
setPhaseData={setPhaseData}
showNodeDetailsFlyout={showNodeDetailsFlyout}
errors={errors}
phaseData={phaseData}
isShowingErrors={isShowingErrors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EuiSelect, EuiButtonEmpty, EuiCallOut, EuiSpacer, EuiLoadingSpinner } f
import { PHASE_NODE_ATTRS } from '../../../../constants';
import { LearnMoreLink } from '../../../components/learn_more_link';
import { ErrableFormRow } from '../../form_errors';
import { NodeAttrsDetails } from '../node_attrs_details';

const learnMoreLinks = (
<Fragment>
Expand All @@ -30,20 +31,24 @@ const learnMoreLinks = (
);

export class NodeAllocation extends Component {
constructor(props) {
super(props);
this.state = {
isShowingNodeDetailsFlyout: false,
selectedNodeAttrsForDetails: undefined,
};
}

componentDidMount() {
this.props.fetchNodes();
}

showNodeDetailsFlyout = (selectedNodeAttrsForDetails) => {
this.setState({ isShowingNodeDetailsFlyout: true, selectedNodeAttrsForDetails });
};

render() {
const {
phase,
setPhaseData,
isShowingErrors,
phaseData,
showNodeDetailsFlyout,
nodeOptions,
errors,
} = this.props;
const { phase, setPhaseData, isShowingErrors, phaseData, nodeOptions, errors } = this.props;
if (!nodeOptions) {
return (
<Fragment>
Expand Down Expand Up @@ -100,9 +105,10 @@ export class NodeAllocation extends Component {
{!!phaseData[PHASE_NODE_ATTRS] ? (
<EuiButtonEmpty
data-test-subj={`${phase}-viewNodeDetailsFlyoutButton`}
style={{ maxWidth: 400 }}
flush="left"
iconType="eye"
onClick={() => showNodeDetailsFlyout(phaseData[PHASE_NODE_ATTRS])}
onClick={() => this.showNodeDetailsFlyout(phaseData[PHASE_NODE_ATTRS])}
>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.viewNodeDetailsButton"
Expand All @@ -114,6 +120,13 @@ export class NodeAllocation extends Component {
)}
{learnMoreLinks}
<EuiSpacer size="m" />

{this.state.isShowingNodeDetailsFlyout ? (
<NodeAttrsDetails
selectedNodeAttrs={this.state.selectedNodeAttrsForDetails}
close={() => this.setState({ isShowingNodeDetailsFlyout: false })}
/>
) : null}
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { NodeAttrsDetails } from './node_attrs_details.container';
export { NodeAttrsDetails } from './node_attrs_details';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import {
EuiFlyoutBody,
EuiFlyout,
EuiTitle,
EuiInMemoryTable,
EuiSpacer,
EuiPortal,
EuiLoadingContent,
EuiCallOut,
EuiButton,
} from '@elastic/eui';

import { useLoadNodeDetails } from '../../../../services/api';

interface Props {
close: () => void;
selectedNodeAttrs: string;
}

export const NodeAttrsDetails: React.FunctionComponent<Props> = ({ close, selectedNodeAttrs }) => {
const { data, isLoading, error, sendRequest } = useLoadNodeDetails(selectedNodeAttrs);
let content;
if (isLoading) {
content = <EuiLoadingContent lines={3} />;
} else if (error) {
const { statusCode, error: errorString, message } = error;
content = (
<EuiCallOut
title={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.nodeDetailsLoadingFailedTitle"
defaultMessage="Unable to load node attribute details."
/>
}
color="danger"
>
<p>
{statusCode}: {errorString}. {message}
</p>
<EuiButton onClick={sendRequest} iconType="refresh" color="danger">
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.nodeDetailsReloadButton"
defaultMessage="Try again"
/>
</EuiButton>
</EuiCallOut>
);
} else {
content = (
<EuiInMemoryTable
items={data || []}
columns={[
{
field: 'nodeId',
name: i18n.translate('xpack.indexLifecycleMgmt.nodeAttrDetails.idField', {
defaultMessage: 'ID',
}),
},
{
field: 'stats.name',
name: i18n.translate('xpack.indexLifecycleMgmt.nodeAttrDetails.nameField', {
defaultMessage: 'Name',
}),
},
{
field: 'stats.host',
name: i18n.translate('xpack.indexLifecycleMgmt.nodeAttrDetails.hostField', {
defaultMessage: 'Host',
}),
},
]}
pagination={true}
sorting={true}
/>
);
}
return (
<EuiPortal>
<EuiFlyout ownFocus onClose={close}>
<EuiFlyoutBody>
<EuiTitle>
<h2>
<FormattedMessage
id="xpack.indexLifecycleMgmt.nodeAttrDetails.title"
defaultMessage="Nodes that contain the attribute {selectedNodeAttrs}"
values={{ selectedNodeAttrs }}
/>
</h2>
</EuiTitle>
<EuiSpacer size="s" />
{content}
</EuiFlyoutBody>
</EuiFlyout>
</EuiPortal>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { MinAgeInput } from '../min_age_input';
export class WarmPhase extends PureComponent {
static propTypes = {
setPhaseData: PropTypes.func.isRequired,
showNodeDetailsFlyout: PropTypes.func.isRequired,

isShowingErrors: PropTypes.bool.isRequired,
errors: PropTypes.object.isRequired,
Expand All @@ -47,7 +46,6 @@ export class WarmPhase extends PureComponent {
render() {
const {
setPhaseData,
showNodeDetailsFlyout,
phaseData,
errors,
isShowingErrors,
Expand Down Expand Up @@ -152,7 +150,6 @@ export class WarmPhase extends PureComponent {
<NodeAllocation
phase={PHASE_WARM}
setPhaseData={setPhaseData}
showNodeDetailsFlyout={showNodeDetailsFlyout}
errors={errors}
phaseData={phaseData}
isShowingErrors={isShowingErrors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { toasts } from '../../services/notification';
import { findFirstError } from '../../services/find_errors';
import { LearnMoreLink } from '../components';
import { NodeAttrsDetails } from './components/node_attrs_details';
import { PolicyJsonFlyout } from './components/policy_json_flyout';
import { ErrableFormRow } from './form_errors';
import { HotPhase } from './components/hot_phase';
Expand All @@ -56,8 +55,6 @@ export class EditPolicy extends Component {
super(props);
this.state = {
isShowingErrors: false,
isShowingNodeDetailsFlyout: false,
selectedNodeAttrsForDetails: undefined,
isShowingPolicyJsonFlyout: false,
};
}
Expand Down Expand Up @@ -124,10 +121,6 @@ export class EditPolicy extends Component {
}
};

showNodeDetailsFlyout = (selectedNodeAttrsForDetails) => {
this.setState({ isShowingNodeDetailsFlyout: true, selectedNodeAttrsForDetails });
};

togglePolicyJsonFlyout = () => {
this.setState(({ isShowingPolicyJsonFlyout }) => ({
isShowingPolicyJsonFlyout: !isShowingPolicyJsonFlyout,
Expand Down Expand Up @@ -291,15 +284,13 @@ export class EditPolicy extends Component {

<WarmPhase
errors={errors[PHASE_WARM]}
showNodeDetailsFlyout={this.showNodeDetailsFlyout}
isShowingErrors={isShowingErrors && !!findFirstError(errors[PHASE_WARM], false)}
/>

<EuiHorizontalRule />

<ColdPhase
errors={errors[PHASE_COLD]}
showNodeDetailsFlyout={this.showNodeDetailsFlyout}
isShowingErrors={isShowingErrors && !!findFirstError(errors[PHASE_COLD], false)}
/>

Expand Down Expand Up @@ -370,13 +361,6 @@ export class EditPolicy extends Component {
</EuiFlexItem>
</EuiFlexGroup>

{this.state.isShowingNodeDetailsFlyout ? (
<NodeAttrsDetails
selectedNodeAttrs={this.state.selectedNodeAttrsForDetails}
close={() => this.setState({ isShowingNodeDetailsFlyout: false })}
/>
) : null}

{this.state.isShowingPolicyJsonFlyout ? (
<PolicyJsonFlyout
policyName={selectedPolicyName || ''}
Expand Down
Loading

0 comments on commit b380789

Please sign in to comment.