From b34b9c6d81f75b91f5c71599b3b7360b51a0f22e Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Thu, 6 Jan 2022 14:08:46 +0000 Subject: [PATCH] Fix Fleet GitRepo initial target mode - `fleet.cattle.io.GitRepo` `spec.targets` can contain multiple selectors per target - https://fleet.rancher.io/gitrepo-targets/#target-matching - UI handles this use case by an 'advanced' mode where user can enter free text (otherwise `target` can only contain a single selector type) - When attempting to edit a GitRepo that has a multi-selector target now we now correctly identify it and start in 'advanced' mode - Addresses #4788 --- models/fleet.cattle.io.gitrepo.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/models/fleet.cattle.io.gitrepo.js b/models/fleet.cattle.io.gitrepo.js index 7f28c3625fe..ce740dfcb6c 100644 --- a/models/fleet.cattle.io.gitrepo.js +++ b/models/fleet.cattle.io.gitrepo.js @@ -241,20 +241,20 @@ export default class GitRepo extends SteveModel { } else if ( targets.length === 1) { const target = targets[0]; - if ( target.clusterGroup ) { + if (Object.keys(target).length > 1) { + // There are multiple properties in a single target, so use the 'advanced' mode + // (otherwise any existing content is nuked for what we provide) + mode = 'advanced'; + } else if ( target.clusterGroup ) { clusterGroup = target.clusterGroup; if ( !mode ) { mode = 'clusterGroup'; } - } - - if ( target.clusterName ) { + } else if ( target.clusterName ) { mode = 'cluster'; cluster = target.clusterName; - } - - if ( target.clusterSelector ) { + } else if ( target.clusterSelector ) { if ( Object.keys(target.clusterSelector).length === 0 ) { mode = 'all'; } else {