Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
Signed-off-by: bryans-go <sabrinabryan1990@gmail.com>
  • Loading branch information
divanshu-go committed Oct 23, 2024
1 parent b56e949 commit af683e5
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions pkg/views/workspace/create/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,46 @@ func (m SummaryModel) View() string {
return ""
}

helpLine := buildHelpLine(m)

if shouldDisplaySummary(m) {
return renderSummaryView(m, helpLine)
}

return renderSimpleView(m, helpLine)
}

func buildHelpLine(m SummaryModel) string {
helpLine := "enter: next • f10: advanced configuration"
if len(m.projectList) > 1 || ProjectsConfigurationChanged {
helpLine += "\n↑ up • ↓ down"
}
return helpLine
}

if len(m.projectList) > 1 || (len(m.projectList) == 1 && ProjectsConfigurationChanged) {
helpLine += "\n" + "↑ up • ↓ down"
summary, err := RenderSummary(m.name, m.projectList, m.defaults, m.nameLabel)
if err != nil {
log.Fatal(err)
}
var title string
if m.name == "" {
title = views.GetStyledMainTitle("SUMMARY")
} else {
title = views.GetStyledMainTitle(fmt.Sprintf("SUMMARY - %s %s", m.nameLabel, m.name))
}
m.viewport.SetContent(summary)
return title + views.GetBorderedMessage(m.viewport.View()) + "\n" + m.form.WithHeight(5).View() + "\n" + HelpStyle.Render(helpLine)
func shouldDisplaySummary(m SummaryModel) bool {
return len(m.projectList) > 1 || ProjectsConfigurationChanged
}

func renderSummaryView(m SummaryModel, helpLine string) string {
title := views.GetStyledMainTitle("SUMMARY")
if m.name != "" {
title = views.GetStyledMainTitle(fmt.Sprintf("SUMMARY - %s %s", m.nameLabel, m.name))
}

summary, err := RenderSummary(m.name, m.projectList, m.defaults, m.nameLabel)
if err != nil {
log.Fatal(err)
}

m.viewport.SetContent(summary)

return title +
views.GetBorderedMessage(m.viewport.View()) + "\n" +
m.form.WithHeight(5).View() + "\n" +
HelpStyle.Render(helpLine)
}

func renderSimpleView(m SummaryModel, helpLine string) string {
return m.form.WithHeight(5).View() + "\n" + HelpStyle.Render(helpLine)
}

0 comments on commit af683e5

Please sign in to comment.