Revert "[Remote Clusters] Clean up null properties depending on conection mode" (#162780)

Reverts elastic/kibana#162405
This commit is contained in:
Ignacio Rivas 2023-07-31 17:41:40 +03:00 committed by GitHub
parent bf5c2703f9
commit 46a073f01b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 98 deletions

View file

@ -1,18 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Create Remote cluster on component mount show request flyout doesnt contain null values 1`] = `
"PUT _cluster/settings
{
\\"persistent\\": {
\\"cluster\\": {
\\"remote\\": {
\\"\\": {
\\"skip_unavailable\\": false,
\\"mode\\": \\"sniff\\",
\\"node_connections\\": 3
}
}
}
}
}"
`;

View file

@ -48,14 +48,6 @@ describe('Create Remote cluster', () => {
expect(actions.skipUnavailableSwitch.isChecked()).toBe(true);
});
test('show request flyout doesnt contain null values', async () => {
await actions.showRequest.click();
const requestBody = actions.showRequest.getESRequestBody();
expect(requestBody).not.toContain('null');
expect(requestBody).toMatchSnapshot();
});
describe('on prem', () => {
test('should have a toggle to enable "proxy" mode for a remote cluster', () => {
expect(actions.connectionModeSwitch.exists()).toBe(true);

View file

@ -53,10 +53,6 @@ export interface RemoteClustersActions {
click: () => void;
isDisabled: () => boolean;
};
showRequest: {
click: () => void;
getESRequestBody: () => string;
};
getErrorMessages: () => string[];
globalErrorExists: () => boolean;
}
@ -174,23 +170,6 @@ export const createRemoteClustersActions = (testBed: TestBed): RemoteClustersAct
};
};
const createShowRequestActions = () => {
const click = () => {
act(() => {
find('remoteClustersRequestButton').simulate('click');
});
component.update();
};
return {
showRequest: {
click,
getESRequestBody: () => find('esRequestBody').text(),
},
};
};
const globalErrorExists = () => exists('remoteClusterFormGlobalError');
const createCloudUrlInputActions = () => {
@ -214,7 +193,6 @@ export const createRemoteClustersActions = (testBed: TestBed): RemoteClustersAct
...createProxyAddressActions(),
...createServerNameActions(),
...createSaveButtonActions(),
...createShowRequestActions(),
getErrorMessages: form.getErrorsMessages,
globalErrorExists,
};

View file

@ -7,7 +7,6 @@
import React, { PureComponent } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { transform, isObject, isEmpty, isNull } from 'lodash';
import {
EuiButtonEmpty,
@ -23,20 +22,6 @@ import {
import { Cluster, serializeCluster } from '../../../../../common/lib';
// Remove all null properties from an object
export function removeNullProperties(obj: any) {
return transform(obj, (result: any, value, key) => {
if (isObject(value)) {
result[key] = removeNullProperties(value);
if (isEmpty(result[key])) {
delete result[key];
}
} else if (!isNull(value)) {
result[key] = value;
}
});
}
interface Props {
close: () => void;
cluster: Cluster;
@ -47,11 +32,7 @@ export class RequestFlyout extends PureComponent<Props> {
const { close, cluster } = this.props;
const { name } = cluster;
const endpoint = 'PUT _cluster/settings';
// Given that the request still requires that we send all properties, regardless of whether they
// are null, we need to remove all null properties from the serialized cluster object that we
// render in the flyout.
const serializedCluster = removeNullProperties(serializeCluster(cluster));
const payload = JSON.stringify(serializedCluster, null, 2);
const payload = JSON.stringify(serializeCluster(cluster), null, 2);
const request = `${endpoint}\n${payload}`;
return (
@ -87,7 +68,7 @@ export class RequestFlyout extends PureComponent<Props> {
<EuiSpacer />
<EuiCodeBlock language="json" isCopyable data-test-subj="esRequestBody">
<EuiCodeBlock language="json" isCopyable>
{request}
</EuiCodeBlock>
</EuiFlyoutBody>

View file

@ -1,29 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { removeNullProperties } from './request_flyout';
describe('Remote cluster form Utils', () => {
test('can remote deeply nested null properties from object', () => {
const obj = {
a: 'a',
b: {
c: 'c',
d: null,
},
};
expect(removeNullProperties(obj)).toStrictEqual({
...obj,
b: {
c: 'c',
},
});
expect(removeNullProperties({ a: 'a', b: null })).toStrictEqual({ a: 'a' });
});
});