diff --git a/pkg/cmd/workspace/util/branch_wizard.go b/pkg/cmd/workspace/util/branch_wizard.go index 8196d92bb6..e8aff7e522 100644 --- a/pkg/cmd/workspace/util/branch_wizard.go +++ b/pkg/cmd/workspace/util/branch_wizard.go @@ -6,6 +6,7 @@ package util import ( "context" "errors" + "fmt" "net/url" apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient" @@ -18,6 +19,7 @@ type BranchWizardConfig struct { ApiClient *apiclient.APIClient ProviderId string NamespaceId string + Namespace string ChosenRepo *apiclient.GitRepository ProjectOrder int } @@ -58,8 +60,9 @@ func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, e } var branch *apiclient.GitBranch + parentIdentifier := fmt.Sprintf("%s/%s/%s", config.ProviderId, config.Namespace, config.ChosenRepo.Name) if len(prList) == 0 { - branch = selection.GetBranchFromPrompt(branchList, config.ProjectOrder) + branch = selection.GetBranchFromPrompt(branchList, config.ProjectOrder, parentIdentifier) if branch == nil { return nil, errors.New("must select a branch") } @@ -74,7 +77,7 @@ func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, e checkoutOptions = append(checkoutOptions, selection.CheckoutBranch) checkoutOptions = append(checkoutOptions, selection.CheckoutPR) - chosenCheckoutOption := selection.GetCheckoutOptionFromPrompt(config.ProjectOrder, checkoutOptions) + chosenCheckoutOption := selection.GetCheckoutOptionFromPrompt(config.ProjectOrder, checkoutOptions, parentIdentifier) if chosenCheckoutOption == selection.CheckoutDefault { // Get the default branch from context repo, res, err := config.ApiClient.GitProviderAPI.GetGitContext(ctx).Repository(apiclient.GetRepositoryContext{ @@ -90,14 +93,14 @@ func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, e } if chosenCheckoutOption == selection.CheckoutBranch { - branch = selection.GetBranchFromPrompt(branchList, config.ProjectOrder) + branch = selection.GetBranchFromPrompt(branchList, config.ProjectOrder, parentIdentifier) if branch == nil { return nil, errors.New("must select a branch") } config.ChosenRepo.Branch = branch.Name config.ChosenRepo.Sha = branch.Sha } else if chosenCheckoutOption == selection.CheckoutPR { - chosenPullRequest := selection.GetPullRequestFromPrompt(prList, config.ProjectOrder) + chosenPullRequest := selection.GetPullRequestFromPrompt(prList, config.ProjectOrder, parentIdentifier) if chosenPullRequest == nil { return nil, errors.New("must select a pull request") } diff --git a/pkg/cmd/workspace/util/repository_wizard.go b/pkg/cmd/workspace/util/repository_wizard.go index 0a063ffe9d..88167d8471 100644 --- a/pkg/cmd/workspace/util/repository_wizard.go +++ b/pkg/cmd/workspace/util/repository_wizard.go @@ -5,6 +5,7 @@ package util import ( "context" + "fmt" config_const "github.com/daytonaio/daytona/cmd/daytona/config" apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient" @@ -96,13 +97,20 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos return nil, err } + namespace := "" if len(namespaceList) == 1 { namespaceId = namespaceList[0].Id + namespace = namespaceList[0].Name } else { - namespaceId = selection.GetNamespaceIdFromPrompt(namespaceList, config.ProjectOrder) + namespaceId = selection.GetNamespaceIdFromPrompt(namespaceList, config.ProjectOrder, providerId) if namespaceId == "" { return nil, common.ErrCtrlCAbort } + for _, namespaceItem := range namespaceList { + if namespaceItem.Id == namespaceId { + namespace = namespaceItem.Name + } + } } var providerRepos []apiclient.GitRepository @@ -115,7 +123,8 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos return nil, err } - chosenRepo := selection.GetRepositoryFromPrompt(providerRepos, config.ProjectOrder, config.SelectedRepos) + parentIdentifier := fmt.Sprintf("%s/%s", providerId, namespace) + chosenRepo := selection.GetRepositoryFromPrompt(providerRepos, config.ProjectOrder, config.SelectedRepos, parentIdentifier) if chosenRepo == nil { return nil, common.ErrCtrlCAbort } @@ -128,6 +137,7 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos ApiClient: config.ApiClient, ProviderId: providerId, NamespaceId: namespaceId, + Namespace: namespace, ChosenRepo: chosenRepo, ProjectOrder: config.ProjectOrder, }) diff --git a/pkg/views/styles.go b/pkg/views/styles.go index f1629fff2a..f84e2af227 100644 --- a/pkg/views/styles.go +++ b/pkg/views/styles.go @@ -4,6 +4,7 @@ package views import ( + "fmt" "os" "github.com/charmbracelet/bubbles/list" @@ -45,7 +46,7 @@ var LogPrefixColors = []lipgloss.AdaptiveColor{ Blue, Orange, Cyan, Yellow, } -func GetStyledSelectList(items []list.Item) list.Model { +func GetStyledSelectList(items []list.Item, parentIdentifier ...string) list.Model { d := list.NewDefaultDelegate() @@ -68,7 +69,15 @@ func GetStyledSelectList(items []list.Item) list.Model { l.FilterInput.PromptStyle = lipgloss.NewStyle().Foreground(Green) l.FilterInput.TextStyle = lipgloss.NewStyle().Foreground(Green) - l.SetStatusBarItemName("item\n\n"+lipgloss.NewStyle().Foreground(LightGray).Render("==="), "items\n\n"+lipgloss.NewStyle().Foreground(LightGray).Render("===")) + singularItemName := "item " + SeparatorString + var pluralItemName string + if len(parentIdentifier) == 0 { + pluralItemName = fmt.Sprintf("items\n\n%s", SeparatorString) + } else { + pluralItemName = fmt.Sprintf("items (%s)\n\n%s", parentIdentifier[0], SeparatorString) + } + + l.SetStatusBarItemName(singularItemName, pluralItemName) return l } diff --git a/pkg/views/workspace/selection/branch.go b/pkg/views/workspace/selection/branch.go index 3fa7f2b367..48903f4849 100644 --- a/pkg/views/workspace/selection/branch.go +++ b/pkg/views/workspace/selection/branch.go @@ -14,7 +14,7 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -func selectBranchPrompt(branches []apiclient.GitBranch, projectOrder int, choiceChan chan<- string) { +func selectBranchPrompt(branches []apiclient.GitBranch, projectOrder int, parentIdentifier string, choiceChan chan<- string) { items := []list.Item{} // Populate items with titles and descriptions from workspaces. @@ -26,7 +26,7 @@ func selectBranchPrompt(branches []apiclient.GitBranch, projectOrder int, choice items = append(items, newItem) } - l := views.GetStyledSelectList(items) + l := views.GetStyledSelectList(items, parentIdentifier) title := "Choose a Branch" if projectOrder > 1 { @@ -49,10 +49,10 @@ func selectBranchPrompt(branches []apiclient.GitBranch, projectOrder int, choice } } -func GetBranchFromPrompt(branches []apiclient.GitBranch, projectOrder int) *apiclient.GitBranch { +func GetBranchFromPrompt(branches []apiclient.GitBranch, projectOrder int, parentIdentifier string) *apiclient.GitBranch { choiceChan := make(chan string) - go selectBranchPrompt(branches, projectOrder, choiceChan) + go selectBranchPrompt(branches, projectOrder, parentIdentifier, choiceChan) branchName := <-choiceChan diff --git a/pkg/views/workspace/selection/checkout.go b/pkg/views/workspace/selection/checkout.go index dc89d81765..a86372a130 100644 --- a/pkg/views/workspace/selection/checkout.go +++ b/pkg/views/workspace/selection/checkout.go @@ -24,7 +24,7 @@ var ( CheckoutPR = CheckoutOption{Title: "Pull/Merge requests", Id: "pullrequest"} ) -func selectCheckoutPrompt(checkoutOptions []CheckoutOption, projectOrder int, choiceChan chan<- string) { +func selectCheckoutPrompt(checkoutOptions []CheckoutOption, projectOrder int, parentIdentifier string, choiceChan chan<- string) { items := []list.Item{} for _, checkoutOption := range checkoutOptions { @@ -32,7 +32,7 @@ func selectCheckoutPrompt(checkoutOptions []CheckoutOption, projectOrder int, ch items = append(items, newItem) } - l := views.GetStyledSelectList(items) + l := views.GetStyledSelectList(items, parentIdentifier) title := "Cloning Options" if projectOrder > 1 { @@ -55,10 +55,10 @@ func selectCheckoutPrompt(checkoutOptions []CheckoutOption, projectOrder int, ch } } -func GetCheckoutOptionFromPrompt(projectOrder int, checkoutOptions []CheckoutOption) CheckoutOption { +func GetCheckoutOptionFromPrompt(projectOrder int, checkoutOptions []CheckoutOption, parentIdentifier string) CheckoutOption { choiceChan := make(chan string) - go selectCheckoutPrompt(checkoutOptions, projectOrder, choiceChan) + go selectCheckoutPrompt(checkoutOptions, projectOrder, parentIdentifier, choiceChan) checkoutOptionId := <-choiceChan diff --git a/pkg/views/workspace/selection/namespace.go b/pkg/views/workspace/selection/namespace.go index a951567236..4300f97289 100644 --- a/pkg/views/workspace/selection/namespace.go +++ b/pkg/views/workspace/selection/namespace.go @@ -13,7 +13,7 @@ import ( "github.com/daytonaio/daytona/pkg/views" ) -func selectNamespacePrompt(namespaces []apiclient.GitNamespace, projectOrder int, choiceChan chan<- string) { +func selectNamespacePrompt(namespaces []apiclient.GitNamespace, projectOrder int, parentIdentifier string, choiceChan chan<- string) { items := []list.Item{} var desc string @@ -28,7 +28,7 @@ func selectNamespacePrompt(namespaces []apiclient.GitNamespace, projectOrder int items = append(items, newItem) } - l := views.GetStyledSelectList(items) + l := views.GetStyledSelectList(items, parentIdentifier) title := "Choose a Namespace" if projectOrder > 1 { @@ -51,10 +51,10 @@ func selectNamespacePrompt(namespaces []apiclient.GitNamespace, projectOrder int } } -func GetNamespaceIdFromPrompt(namespaces []apiclient.GitNamespace, projectOrder int) string { +func GetNamespaceIdFromPrompt(namespaces []apiclient.GitNamespace, projectOrder int, parentIdentifier string) string { choiceChan := make(chan string) - go selectNamespacePrompt(namespaces, projectOrder, choiceChan) + go selectNamespacePrompt(namespaces, projectOrder, parentIdentifier, choiceChan) return <-choiceChan } diff --git a/pkg/views/workspace/selection/pullrequest.go b/pkg/views/workspace/selection/pullrequest.go index 661dc3071f..ecc1fc69ec 100644 --- a/pkg/views/workspace/selection/pullrequest.go +++ b/pkg/views/workspace/selection/pullrequest.go @@ -14,7 +14,7 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -func selectPullRequestPrompt(pullRequests []apiclient.GitPullRequest, projectOrder int, choiceChan chan<- string) { +func selectPullRequestPrompt(pullRequests []apiclient.GitPullRequest, projectOrder int, parentIdentifier string, choiceChan chan<- string) { items := []list.Item{} // Populate items with titles and descriptions from workspaces. @@ -28,7 +28,7 @@ func selectPullRequestPrompt(pullRequests []apiclient.GitPullRequest, projectOrd items = append(items, newItem) } - l := views.GetStyledSelectList(items) + l := views.GetStyledSelectList(items, parentIdentifier) title := "Choose a Pull/Merge Request" if projectOrder > 1 { @@ -51,10 +51,10 @@ func selectPullRequestPrompt(pullRequests []apiclient.GitPullRequest, projectOrd } } -func GetPullRequestFromPrompt(pullRequests []apiclient.GitPullRequest, projectOrder int) *apiclient.GitPullRequest { +func GetPullRequestFromPrompt(pullRequests []apiclient.GitPullRequest, projectOrder int, parentIdentifier string) *apiclient.GitPullRequest { choiceChan := make(chan string) - go selectPullRequestPrompt(pullRequests, projectOrder, choiceChan) + go selectPullRequestPrompt(pullRequests, projectOrder, parentIdentifier, choiceChan) pullRequestName := <-choiceChan diff --git a/pkg/views/workspace/selection/repository.go b/pkg/views/workspace/selection/repository.go index d0737fb162..ce52c2097d 100644 --- a/pkg/views/workspace/selection/repository.go +++ b/pkg/views/workspace/selection/repository.go @@ -14,7 +14,7 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -func selectRepositoryPrompt(repositories []apiclient.GitRepository, projectOrder int, choiceChan chan<- string, selectedRepos map[string]int) { +func selectRepositoryPrompt(repositories []apiclient.GitRepository, projectOrder int, choiceChan chan<- string, selectedRepos map[string]int, parentIdentifier string) { items := []list.Item{} // Populate items with titles and descriptions from workspaces. @@ -28,7 +28,7 @@ func selectRepositoryPrompt(repositories []apiclient.GitRepository, projectOrder items = append(items, newItem) } - l := views.GetStyledSelectList(items) + l := views.GetStyledSelectList(items, parentIdentifier) title := "Choose a Repository" if projectOrder > 1 { @@ -54,10 +54,10 @@ func selectRepositoryPrompt(repositories []apiclient.GitRepository, projectOrder } } -func GetRepositoryFromPrompt(repositories []apiclient.GitRepository, projectOrder int, selectedRepos map[string]int) *apiclient.GitRepository { +func GetRepositoryFromPrompt(repositories []apiclient.GitRepository, projectOrder int, selectedRepos map[string]int, parentIdentifier string) *apiclient.GitRepository { choiceChan := make(chan string) - go selectRepositoryPrompt(repositories, projectOrder, choiceChan, selectedRepos) + go selectRepositoryPrompt(repositories, projectOrder, choiceChan, selectedRepos, parentIdentifier) choice := <-choiceChan