mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
* Fix table search for clusters with proxy mode
* commit using @elastic.co
* Fix tests and add docs
* Add tests for different kinds of search
(cherry picked from commit 5e3d0b299c
)
Co-authored-by: Ignacio Rivas <rivasign@gmail.com>
This commit is contained in:
parent
17090a5634
commit
7bcead5218
2 changed files with 73 additions and 6 deletions
|
@ -77,6 +77,51 @@ describe('<RemoteClusterList />', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('can search', () => {
|
||||||
|
let table;
|
||||||
|
let component;
|
||||||
|
let form;
|
||||||
|
|
||||||
|
const remoteClusters = [
|
||||||
|
{
|
||||||
|
name: 'simple_remote_cluster',
|
||||||
|
seeds: ['127.0.0.1:2000', '127.0.0.2:3000'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'remote_cluster_with_proxy',
|
||||||
|
proxyAddress: '192.168.0.1:80',
|
||||||
|
mode: PROXY_MODE,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
({ table, component, form } = setup());
|
||||||
|
});
|
||||||
|
|
||||||
|
component.update();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('without any search params it should show all clusters', () => {
|
||||||
|
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
|
||||||
|
expect(tableCellsValues.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('search by seed works', () => {
|
||||||
|
form.setInputValue('remoteClusterSearch', 'simple');
|
||||||
|
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
|
||||||
|
expect(tableCellsValues.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('search by proxyAddress works', () => {
|
||||||
|
form.setInputValue('remoteClusterSearch', 'proxy');
|
||||||
|
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
|
||||||
|
expect(tableCellsValues.length).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when there are multiple pages of remote clusters', () => {
|
describe('when there are multiple pages of remote clusters', () => {
|
||||||
let table;
|
let table;
|
||||||
let actions;
|
let actions;
|
||||||
|
@ -91,10 +136,18 @@ describe('<RemoteClusterList />', () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < 29; i++) {
|
for (let i = 0; i < 29; i++) {
|
||||||
remoteClusters.push({
|
if (i % 2 === 0) {
|
||||||
name: `name${i}`,
|
remoteClusters.push({
|
||||||
seeds: [],
|
name: `cluster-${i}`,
|
||||||
});
|
seeds: [],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
remoteClusters.push({
|
||||||
|
name: `cluster_with_proxy-${i}`,
|
||||||
|
proxyAddress: `127.0.0.1:10${i}`,
|
||||||
|
mode: PROXY_MODE,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -31,13 +31,22 @@ const getFilteredClusters = (clusters, queryText) => {
|
||||||
const normalizedSearchText = queryText.toLowerCase();
|
const normalizedSearchText = queryText.toLowerCase();
|
||||||
|
|
||||||
return clusters.filter((cluster) => {
|
return clusters.filter((cluster) => {
|
||||||
const { name, seeds } = cluster;
|
const { name, seeds, proxyAddress } = cluster;
|
||||||
const normalizedName = name.toLowerCase();
|
const normalizedName = name.toLowerCase();
|
||||||
|
|
||||||
if (normalizedName.toLowerCase().includes(normalizedSearchText)) {
|
if (normalizedName.toLowerCase().includes(normalizedSearchText)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return seeds.some((seed) => seed.includes(normalizedSearchText));
|
if (proxyAddress && proxyAddress.toLowerCase().includes(normalizedSearchText)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seeds) {
|
||||||
|
return seeds.some((seed) => seed.includes(normalizedSearchText));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return clusters;
|
return clusters;
|
||||||
|
@ -81,6 +90,11 @@ export class RemoteClusterTable extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch = ({ query }) => {
|
onSearch = ({ query }) => {
|
||||||
|
// There's no need to update the state if there arent any search params
|
||||||
|
if (!query) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { clusters } = this.props;
|
const { clusters } = this.props;
|
||||||
const { text } = query;
|
const { text } = query;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue