From 1957277463510d4b1d6ad04a867531fe561c106e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 2 Dec 2020 09:43:54 +0100 Subject: [PATCH] implement client list filtering --- src/client/ClientListViewModel.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/client/ClientListViewModel.js b/src/client/ClientListViewModel.js index 713ee48..ebf1cc0 100644 --- a/src/client/ClientListViewModel.js +++ b/src/client/ClientListViewModel.js @@ -15,6 +15,7 @@ limitations under the License. */ import {isWebPlatform, Platform} from "./Platform.js"; +import {Maturity} from "./types.js"; import {ClientViewModel} from "./ClientViewModel.js"; import {ViewModel} from "../utils/ViewModel.js"; @@ -22,17 +23,35 @@ export class ClientListViewModel extends ViewModel { constructor(options) { super(options); const {clients, client, link} = options; - this.clientList = clients.map(client => new ClientViewModel(this.childOptions({ - client, - link, - pickClient: client => this._pickClient(client) - }))); + this._clients = clients; + this._link = link; + this.clientList = null; + this._showExperimental = true; + this._showUnsupportedPlatform = true; + this._filterClients(); this.clientViewModel = null; if (client) { this._pickClient(client); } } + _filterClients() { + this.clientList = this._clients.filter(client => { + if (!this._showExperimental && !this.platforms.map(p => client.getMaturity(p)).includes(Maturity.Stable)) { + return false; + } + if (!this._showUnsupportedPlatform && !client.platforms.some(p => this.platforms.includes(p))) { + return false; + } + return true; + }).map(client => new ClientViewModel(this.childOptions({ + client, + link: this._link, + pickClient: client => this._pickClient(client) + }))); + this.emitChange(); + } + _pickClient(client) { this.clientViewModel = this.clientList.find(vm => vm.clientId === client.id); this.emitChange();