From 910b2d40122ed4f4a7c80fe5fb56901260a92e7a Mon Sep 17 00:00:00 2001
From: Gustavo Bazan <gus.bazan@hey.com>
Date: Fri, 8 Mar 2024 10:05:26 +0000
Subject: [PATCH 1/2] task: clean up unused om org select

---
 internal/prompt/config.go | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)

diff --git a/internal/prompt/config.go b/internal/prompt/config.go
index 23fc3274c8..a879ba14c3 100644
--- a/internal/prompt/config.go
+++ b/internal/prompt/config.go
@@ -22,7 +22,6 @@ import (
 	"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
 	"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/validate"
 	atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
-	atlas "go.mongodb.org/atlas/mongodbatlas"
 )
 
 func NewOrgIDInput() survey.Prompt {
@@ -88,41 +87,21 @@ func NewProfileReplaceConfirm(entry string) survey.Prompt {
 }
 
 // NewOrgSelect create a prompt to choice the organization.
-func NewOrgSelect(options *[]atlasv2.AtlasOrganization) survey.Prompt {
-	opt := make([]string, len(*options))
-	for i, o := range *options {
-		opt[i] = *o.Id
-	}
-
-	return &survey.Select{
-		Message: "Choose a default organization:",
-		Options: opt,
-		Description: func(_ string, i int) string {
-			return (*options)[i].Name
-		},
-		Filter: func(filter string, _ string, i int) bool {
-			filter = strings.ToLower(filter)
-			return strings.HasPrefix(strings.ToLower((*options)[i].Name), filter) || strings.HasPrefix(*(*options)[i].Id, filter)
-		},
-	}
-}
-
-// NewOnPremOrgSelect create a prompt to choice the organization.
-func NewOnPremOrgSelect(options []*atlas.Organization) survey.Prompt {
+func NewOrgSelect(options []atlasv2.AtlasOrganization) survey.Prompt {
 	opt := make([]string, len(options))
 	for i, o := range options {
-		opt[i] = o.ID
+		opt[i] = o.GetId()
 	}
 
 	return &survey.Select{
 		Message: "Choose a default organization:",
 		Options: opt,
 		Description: func(_ string, i int) string {
-			return options[i].Name
+			return options[i].GetName()
 		},
 		Filter: func(filter string, _ string, i int) bool {
 			filter = strings.ToLower(filter)
-			return strings.HasPrefix(strings.ToLower(options[i].Name), filter) || strings.HasPrefix(options[i].ID, filter)
+			return strings.HasPrefix(strings.ToLower(options[i].GetName()), filter) || strings.HasPrefix(options[i].GetId(), filter)
 		},
 	}
 }

From 3bc8e8fc120322d785e2b126bde98bc6e72595e9 Mon Sep 17 00:00:00 2001
From: Gustavo Bazan <gus.bazan@hey.com>
Date: Fri, 8 Mar 2024 10:17:50 +0000
Subject: [PATCH 2/2] pointers

---
 internal/cli/default_setter_opts.go      | 14 +++++++-------
 internal/cli/default_setter_opts_test.go |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/internal/cli/default_setter_opts.go b/internal/cli/default_setter_opts.go
index 2504646c79..94fbe1bbae 100644
--- a/internal/cli/default_setter_opts.go
+++ b/internal/cli/default_setter_opts.go
@@ -111,7 +111,7 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {
 }
 
 // Orgs fetches organizations, filtering by name.
-func (opts *DefaultSetterOpts) orgs(filter string) (results *[]atlasv2.AtlasOrganization, err error) {
+func (opts *DefaultSetterOpts) orgs(filter string) (results []atlasv2.AtlasOrganization, err error) {
 	spin := newSpinner()
 	spin.Start()
 	defer spin.Stop()
@@ -134,7 +134,7 @@ func (opts *DefaultSetterOpts) orgs(filter string) (results *[]atlasv2.AtlasOrga
 	if orgs.GetTotalCount() > resultsLimit {
 		return nil, errTooManyResults
 	}
-	return orgs.Results, nil
+	return orgs.GetResults(), nil
 }
 
 // ProjectExists checks if the project exists and the current user has access to it.
@@ -146,7 +146,7 @@ func (opts *DefaultSetterOpts) ProjectExists(id string) bool {
 }
 
 // AskProject will try to construct a select based on fetched projects.
-// If it fails or there are no projects to show we fallback to ask for project by ID.
+// If it fails or there are no projects to show we fall back to ask for project by ID.
 // If only one project, select it by default without prompting the user.
 func (opts *DefaultSetterOpts) AskProject() error {
 	ids, names, err := opts.projects()
@@ -203,7 +203,7 @@ func (opts *DefaultSetterOpts) OrgExists(id string) bool {
 }
 
 // AskOrg will try to construct a select based on fetched organizations.
-// If it fails or there are no organizations to show we fallback to ask for org by ID.
+// If it fails or there are no organizations to show we fall back to ask for org by ID.
 // If only one organization, select it by default without prompting the user.
 func (opts *DefaultSetterOpts) AskOrg() error {
 	return opts.askOrgWithFilter("")
@@ -274,9 +274,9 @@ func (opts *DefaultSetterOpts) manualOrgID() error {
 	return nil
 }
 
-func (opts *DefaultSetterOpts) selectOrg(orgs *[]atlasv2.AtlasOrganization) error {
-	if orgs != nil && len(*orgs) == 1 {
-		opts.OrgID = *(*orgs)[0].Id
+func (opts *DefaultSetterOpts) selectOrg(orgs []atlasv2.AtlasOrganization) error {
+	if len(orgs) == 1 {
+		opts.OrgID = orgs[0].GetId()
 		return nil
 	}
 
diff --git a/internal/cli/default_setter_opts_test.go b/internal/cli/default_setter_opts_test.go
index 9619bf8ae1..7fce68e4a6 100644
--- a/internal/cli/default_setter_opts_test.go
+++ b/internal/cli/default_setter_opts_test.go
@@ -120,7 +120,7 @@ func TestDefaultOpts_Orgs(t *testing.T) {
 		mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1)
 		gotOrgs, err := opts.orgs("")
 		require.NoError(t, err)
-		assert.Equal(t, expectedOrgs.Results, gotOrgs)
+		assert.Equal(t, expectedOrgs.GetResults(), gotOrgs)
 	})
 
 	t.Run("with no org", func(t *testing.T) {