From 470295ad14cbdf44638ba3f98201b39e160f28ab Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 22 Aug 2019 15:17:59 -0600 Subject: [PATCH] Expose a getOrderedManagers() function for use elsewhere --- src/integrations/IntegrationManagers.js | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/integrations/IntegrationManagers.js b/src/integrations/IntegrationManagers.js index f663698da9..98f605353c 100644 --- a/src/integrations/IntegrationManagers.js +++ b/src/integrations/IntegrationManagers.js @@ -144,22 +144,28 @@ export class IntegrationManagers { return this._managers.length > 0; } + getOrderedManagers(): IntegrationManagerInstance[] { + const ordered = []; + for (const kind of KIND_PREFERENCE) { + const managers = this._managers.filter(m => m.kind === kind); + if (!managers || !managers.length) continue; + + if (kind === KIND_ACCOUNT) { + // Order by state_keys (IDs) + managers.sort((a, b) => a.id.localeCompare(b.id)); + } + + ordered.push(...managers); + } + return ordered; + } + getPrimaryManager(): IntegrationManagerInstance { if (this.hasManager()) { if (this._primaryManager) return this._primaryManager; - for (const kind of KIND_PREFERENCE) { - const managers = this._managers.filter(m => m.kind === kind); - if (!managers || !managers.length) continue; - - if (kind === KIND_ACCOUNT) { - // Order by state_keys (IDs) - managers.sort((a, b) => a.id.localeCompare(b.id)); - } - - this._primaryManager = managers[0]; - return this._primaryManager; - } + this._primaryManager = this.getOrderedManagers()[0]; + return this._primaryManager; } else { return null; }