Skip to content

Commit

Permalink
Add request flyout to Remote Clusters. (elastic#42900)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal authored Aug 13, 2019
1 parent b527c00 commit 9470d8a
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 37 deletions.
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/remote_clusters/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const PLUGIN = {
};

export const API_BASE_PATH = '/api/remote_clusters';

export { deserializeCluster, serializeCluster } from './cluster_serialization';

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 @@ -38,6 +38,8 @@ import {
transportPortUrl,
} from '../../../services/documentation';

import { RequestFlyout } from './request_flyout';

import { validateName, validateSeeds, validateSeed } from './validators';

const defaultFields = {
Expand Down Expand Up @@ -78,9 +80,16 @@ export class RemoteClusterForm extends Component {
disabledFields,
fieldsErrors: this.getFieldsErrors(fieldsState),
areErrorsVisible: false,
isRequestVisible: false,
};
}

toggleRequest = () => {
this.setState(({ isRequestVisible }) => ({
isRequestVisible: !isRequestVisible,
}));
};

getFieldsErrors(fields, seedInput = '') {
const { name, seeds } = fields;
return {
Expand Down Expand Up @@ -385,7 +394,7 @@ export class RemoteClusterForm extends Component {

renderActions() {
const { isSaving, cancel } = this.props;
const { areErrorsVisible } = this.state;
const { areErrorsVisible, isRequestVisible } = this.state;

if (isSaving) {
return (
Expand Down Expand Up @@ -427,25 +436,47 @@ export class RemoteClusterForm extends Component {
const isSaveDisabled = areErrorsVisible && this.hasErrors();

return (
<EuiFlexGroup alignItems="center" gutterSize="m">
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="remoteClusterFormSaveButton"
color="secondary"
iconType="check"
onClick={this.save}
fill
disabled={isSaveDisabled}
aria-describedby={`${this.generateId(ERROR_TITLE_ID)} ${this.generateId(ERROR_LIST_ID)}`}
>
<FormattedMessage
id="xpack.remoteClusters.remoteClusterForm.saveButtonLabel"
defaultMessage="Save"
/>
</EuiButton>
<EuiFlexGroup alignItems="center" gutterSize="m">
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="remoteClusterFormSaveButton"
color="secondary"
iconType="check"
onClick={this.save}
fill
disabled={isSaveDisabled}
aria-describedby={`${this.generateId(ERROR_TITLE_ID)} ${this.generateId(ERROR_LIST_ID)}`}
>
<FormattedMessage
id="xpack.remoteClusters.remoteClusterForm.saveButtonLabel"
defaultMessage="Save"
/>
</EuiButton>
</EuiFlexItem>

{cancelButton}
</EuiFlexGroup>
</EuiFlexItem>

{cancelButton}
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={this.toggleRequest}
>
{isRequestVisible ? (
<FormattedMessage
id="xpack.remoteClusters.remoteClusterForm.hideRequestButtonLabel"
defaultMessage="Hide request"
/>
) : (
<FormattedMessage
id="xpack.remoteClusters.remoteClusterForm.showRequestButtonLabel"
defaultMessage="Show request"
/>
)}
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
);
}
Expand Down Expand Up @@ -593,6 +624,7 @@ export class RemoteClusterForm extends Component {
} = this.props;

const {
isRequestVisible,
areErrorsVisible,
fields: {
name,
Expand Down Expand Up @@ -667,6 +699,14 @@ export class RemoteClusterForm extends Component {
{this.renderActions()}

{this.renderSavingFeedback()}

{isRequestVisible ? (
<RequestFlyout
name={name}
cluster={this.getAllFields()}
close={() => this.setState({ isRequestVisible: false })}
/>
) : null}
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.
*/

/*
* 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, { PureComponent } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import PropTypes from 'prop-types';

import {
EuiButtonEmpty,
EuiCodeBlock,
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutFooter,
EuiFlyoutHeader,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';

import { serializeCluster } from '../../../../../common';

export class RequestFlyout extends PureComponent {
static propTypes = {
close: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
cluster: PropTypes.object.isRequired,
};

render() {
const { name, close, cluster } = this.props;
const endpoint = 'PUT _cluster/settings';
const payload = JSON.stringify(serializeCluster(cluster), null, 2);
const request = `${endpoint}\n${payload}`;

return (
<EuiFlyout maxWidth={480} onClose={close}>
<EuiFlyoutHeader>
<EuiTitle>
<h2>
{name ? (
<FormattedMessage
id="xpack.remoteClusters.requestFlyout.namedTitle"
defaultMessage="Request for '{name}'"
values={{ name }}
/>
) : (
<FormattedMessage
id="xpack.remoteClusters.requestFlyout.unnamedTitle"
defaultMessage="Request"
/>
)}
</h2>
</EuiTitle>
</EuiFlyoutHeader>

<EuiFlyoutBody>
<EuiText>
<p>
<FormattedMessage
id="xpack.remoteClusters.requestFlyout.descriptionText"
defaultMessage="This Elasticsearch request will create or update this remote cluster."
/>
</p>
</EuiText>

<EuiSpacer />

<EuiCodeBlock
language="json"
isCopyable
>
{request}
</EuiCodeBlock>
</EuiFlyoutBody>

<EuiFlyoutFooter>
<EuiButtonEmpty
iconType="cross"
onClick={close}
flush="left"
>
<FormattedMessage
id="xpack.remoteClusters.requestFlyout.closeButtonLabel"
defaultMessage="Close"
/>
</EuiButtonEmpty>
</EuiFlyoutFooter>
</EuiFlyout>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
RouterRouteHandler,
wrapCustomError,
} from '../../../../../server/lib/create_router';
import { serializeCluster } from '../../../common/cluster_serialization';
import { doesClusterExist } from '../../lib/does_cluster_exist';
import { serializeCluster } from '../../lib/cluster_serialization';

export const register = (router: Router): void => {
router.post('', addHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
wrapEsError,
wrapUnknownError,
} from '../../../../../server/lib/create_router';
import { serializeCluster } from '../../../common/cluster_serialization';
import { doesClusterExist } from '../../lib/does_cluster_exist';
import { serializeCluster } from '../../lib/cluster_serialization';

export const register = (router: Router, isEsError: any): void => {
router.delete('/{nameOrNames}', createDeleteHandler(isEsError));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { get } from 'lodash';

import { Router, RouterRouteHandler } from '../../../../../server/lib/create_router';
import { deserializeCluster } from '../../lib/cluster_serialization';
import { deserializeCluster } from '../../../common/cluster_serialization';

export const register = (router: Router): void => {
router.get('', getAllHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
RouterRouteHandler,
wrapCustomError,
} from '../../../../../server/lib/create_router';
import { serializeCluster, deserializeCluster } from '../../../common/cluster_serialization';
import { doesClusterExist } from '../../lib/does_cluster_exist';
import { serializeCluster, deserializeCluster } from '../../lib/cluster_serialization';

export const register = (router: Router): void => {
router.put('/{name}', updateHandler);
Expand Down

0 comments on commit 9470d8a

Please sign in to comment.