kibana/x-pack/plugins/monitoring/public/lib/get_cluster_from_clusters.js
igoristic 59315bc84d
[Monitoring] NP Migration complete client cutover (#62908)
* Final phase before the complete cutover

* NP migration

* lint fix

* More NP stuff

* Moved Stack Monitoring client plugin outside legacy and fixed all tests

* ...

* Removed unused files

* Fix for main links

* Fixed more tests

* Fixed redirect when clicking on SM icon again

* Code review feedback

* Addressed code review feedback

* Fixed return value
2020-04-30 15:59:35 -04:00

32 lines
860 B
JavaScript

/*
* 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 _ from 'lodash';
export function getClusterFromClusters(clusters, globalState) {
const cluster = (() => {
const existingCurrent = _.find(clusters, { cluster_uuid: globalState.cluster_uuid });
if (existingCurrent) {
return existingCurrent;
}
const firstCluster = _.first(clusters);
if (firstCluster && firstCluster.cluster_uuid) {
return firstCluster;
}
return null;
})();
if (cluster && cluster.license) {
globalState.cluster_uuid = cluster.cluster_uuid;
globalState.ccs = cluster.ccs;
globalState.save();
return cluster;
}
return null;
}