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

[ILM] Convert node details flyout to TS #73707

Merged
merged 34 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1781ca7
[ILM] Convert node allocation component to TS and use hooks
yuliacech Jul 22, 2020
9958274
[ILM] Fix jest tests
yuliacech Jul 23, 2020
4486489
[ILM] Fix i18n check
yuliacech Jul 23, 2020
af77efa
Merge branch 'master' into ilm_typescript
elasticmachine Jul 28, 2020
653ff5e
Merge branch 'master' into ilm_typescript
elasticmachine Jul 29, 2020
4cc9584
Merge branch 'master' into ilm_typescript
yuliacech Jul 29, 2020
fc0633e
[ILM] Implement code review suggestions
yuliacech Jul 29, 2020
1ccf12f
[ILM] Fix type check, docs link and button maxWidth in NodeAllocation…
yuliacech Jul 30, 2020
a557a5b
Merge branch 'master' into ilm_typescript
elasticmachine Jul 30, 2020
739be48
Fix internaliation error
yuliacech Jul 30, 2020
b380789
[ILM] Convert node details flyout to TS
yuliacech Jul 29, 2020
32a4dba
Merge remote-tracking branch 'origin/ilm_typescript' into ilm_node_de…
yuliacech Jul 31, 2020
1f76b82
[ILM] Fix useState declaration
yuliacech Jul 31, 2020
e9575f4
[ILM] Fix useState declaration
yuliacech Jul 31, 2020
8ad94dc
[ILM] Fix jest test
yuliacech Jul 31, 2020
062465a
Merge branch 'master' into ilm_typescript
elasticmachine Aug 3, 2020
1f04f67
Merge branch 'master' into ilm_typescript
elasticmachine Aug 5, 2020
594d017
Merge branch 'master' into ilm_typescript
elasticmachine Aug 6, 2020
22c6b86
[ILM] Change error message when unable to load node attributes
yuliacech Aug 6, 2020
07e8126
Merge branch 'ilm_typescript' into ilm_node_details_typescript
yuliacech Aug 6, 2020
1d2393f
[ILM] Change error message when unable to load node details
yuliacech Aug 6, 2020
3841a11
[ILM] Delete a period in error callout
yuliacech Aug 6, 2020
8a18859
Merge branch 'ilm_typescript' into ilm_node_details_typescript
yuliacech Aug 6, 2020
c210d49
[ILM] Delete a period in error callout
yuliacech Aug 6, 2020
abe230a
[ILM] Convert node details flyout to TS
yuliacech Jul 29, 2020
d88cab0
[ILM] Fix i18n check
yuliacech Jul 23, 2020
03e3972
[ILM] Fix useState declaration
yuliacech Jul 31, 2020
5ae1dd7
[ILM] Fix useState declaration
yuliacech Jul 31, 2020
1366535
[ILM] Fix jest test
yuliacech Jul 31, 2020
3ab56aa
[ILM] Change error message when unable to load node details
yuliacech Aug 6, 2020
be2e6a5
[ILM] Delete a period in error callout
yuliacech Aug 6, 2020
d8bda51
Merge remote-tracking branch 'origin/ilm_node_details_typescript' int…
yuliacech Aug 6, 2020
ffa4f85
Merge branch 'master' into ilm_node_details_typescript
elasticmachine Aug 6, 2020
3caa6cc
Merge branch 'master' into ilm_node_details_typescript
elasticmachine Aug 10, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ describe('edit policy', () => {
beforeEach(() => {
server.respondImmediately = true;
httpRequestsMockHelpers.setNodesListResponse({});
httpRequestsMockHelpers.setNodesDetailsResponse('attribute:true', [
{ nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } },
]);
});

test('should show number required error when trying to save empty warm phase', async () => {
Expand Down Expand Up @@ -395,7 +398,9 @@ describe('edit policy', () => {
rendered.update();
const flyoutButton = findTestSubject(rendered, 'warm-viewNodeDetailsFlyoutButton');
expect(flyoutButton.exists()).toBeTruthy();
flyoutButton.simulate('click');
await act(async () => {
await flyoutButton.simulate('click');
});
rendered.update();
expect(rendered.find('.euiFlyout').exists()).toBeTruthy();
});
Expand All @@ -404,6 +409,9 @@ describe('edit policy', () => {
beforeEach(() => {
server.respondImmediately = true;
httpRequestsMockHelpers.setNodesListResponse({});
httpRequestsMockHelpers.setNodesDetailsResponse('attribute:true', [
{ nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } },
]);
});
test('should allow 0 for phase timing', async () => {
const rendered = mountWithIntl(component);
Expand Down Expand Up @@ -470,7 +478,9 @@ describe('edit policy', () => {
rendered.update();
const flyoutButton = findTestSubject(rendered, 'cold-viewNodeDetailsFlyoutButton');
expect(flyoutButton.exists()).toBeTruthy();
flyoutButton.simulate('click');
await act(async () => {
await flyoutButton.simulate('click');
});
rendered.update();
expect(rendered.find('.euiFlyout').exists()).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setNodesDetailsResponse = (nodeAttributes: string, response: HttpResponse = []) => {
server.respondWith(`/api/index_lifecycle_management/nodes/${nodeAttributes}/details`, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response),
]);
};

return {
setPoliciesResponse,
setNodesListResponse,
setNodesDetailsResponse,
};
};

Expand Down
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 @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment } from 'react';
import React, { Fragment, useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import {
Expand All @@ -20,11 +20,11 @@ import { PHASE_NODE_ATTRS } from '../../../../constants';
import { LearnMoreLink } from '../../../components/learn_more_link';
import { ErrableFormRow } from '../../form_errors';
import { useLoadNodes } from '../../../../services/api';
import { NodeAttrsDetails } from '../node_attrs_details';

interface Props {
phase: string;
setPhaseData: (dataKey: string, value: any) => void;
showNodeDetailsFlyout: (nodeAttrs: any) => void;
errors: any;
phaseData: any;
isShowingErrors: boolean;
Expand All @@ -48,13 +48,16 @@ const learnMoreLink = (
export const NodeAllocation: React.FunctionComponent<Props> = ({
phase,
setPhaseData,
showNodeDetailsFlyout,
errors,
phaseData,
isShowingErrors,
}) => {
const { isLoading, data: nodes, error, sendRequest } = useLoadNodes();

const [selectedNodeAttrsForDetails, setSelectedNodeAttrsForDetails] = useState<string | null>(
null
);

if (isLoading) {
return (
<Fragment>
Expand Down Expand Up @@ -162,7 +165,7 @@ export const NodeAllocation: React.FunctionComponent<Props> = ({
data-test-subj={`${phase}-viewNodeDetailsFlyoutButton`}
flush="left"
iconType="eye"
onClick={() => showNodeDetailsFlyout(phaseData[PHASE_NODE_ATTRS])}
onClick={() => setSelectedNodeAttrsForDetails(phaseData[PHASE_NODE_ATTRS])}
>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.viewNodeDetailsButton"
Expand All @@ -172,6 +175,13 @@ export const NodeAllocation: React.FunctionComponent<Props> = ({
) : null}
{learnMoreLink}
<EuiSpacer size="m" />

{selectedNodeAttrsForDetails ? (
<NodeAttrsDetails
selectedNodeAttrs={selectedNodeAttrsForDetails}
close={() => setSelectedNodeAttrsForDetails(null)}
/>
) : null}
</Fragment>
);
};
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, message } = error;
content = (
<EuiCallOut
title={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.nodeDetailsLoadingFailedTitle"
defaultMessage="Unable to load node attribute details"
/>
}
color="danger"
>
<p>
{message} ({statusCode})
</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
Loading