Skip to content

Commit

Permalink
feat: improve labels in pr sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Feb 22, 2025
1 parent 9a3c548 commit 0e37552
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 89 deletions.
12 changes: 6 additions & 6 deletions imposters/pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
],
"totalCount": 1
},
"latestReviews": {
"reviews": {
"totalCount": 2,
"nodes": [
{
Expand Down Expand Up @@ -243,7 +243,7 @@
{
"number": 2504,
"title": "feat(nvim): add dap.nvim",
"body": "",
"body": "# Nata honore curva feri arbor in memoris\n\n## Petis ius quem Iovemque si tempora tangi\n\nLorem markdownum rapta in ille est est Lycabas in occuluit coniugis palus\ncaerulaque partes fatebere. Sed [esse fidemque](http://lumina.org/), et fixerat\nisdem sed, Ceyca supra Cadmeida Cartheia altera culpavit, mihi **guttura**\nlaeva.\n\n> Ne [quae](http://externum-in.io/quos) ora notis inde illo levibus illos\n> prolemque [addidit](http://res.net/) thalamique meos fiducia ultime, non est\n> utque imagine cedere? Puppim cruore legem **eluserat Agyrtes** etiam avidamque\n> harundine ferrumque terga Amoris has palustribus vacuo. Fassaque convulso\n> quaerebatque erat iterum, in ora quoque esset quis! Esse Colchis et mecumque,\n> dixit quae excipis argentea dixit proles!\n\n## Visendae dat Aphidas satumque per creverunt perque\n\nSatis metu colle Diana; *tibi* ore honore, ipse tridente, huius. Inpubibus\ngemitus figis an geratur itque!\n\n1. Cautes cupressu expulsa\n2. Amori antemnas anguem sociorum arguit\n3. Inquit moveri dea maius munere\n4. Est requies trahebat\n5. Pectora etiam Invidit\n\n## Meum verum apertum terrae tenet angebar effecta\n\nTunc deas? Atque arbore, subducere pectus o *Stygia bracchia terras* pendentem\ntrahit contenta, usus fugias Aiax **illa**, quas.\n\nActa pars ponere consedere umectat victus solebat eluserat *modo*; futura clara,\ncaelo. Attulerat ense ovantem inter tumulo coniugium. Trementi ambo fontibus\ncomas. Bimembres amne, aut inde ipse quos amoris matri belli Phoebi Cypro; ignes\ncerto sonat per? Feroxque et lecto in ex transformia acerris quam placeat\nproperabat traxit Iovis.\n\n## Fueramque et quid scire Bacchus pondere\n\nEuphrates ut scissae, **cumque quos** latet *sunt sororque*; viridi concita\nconiunx. Coepta Elide tum illo mox vacuo unde cui novitatis quinque dummodo\nOsiris **tenui hic** eius esse dici. Est amnes tendit illa haerent leti sceptra\ntangit perforat, iaculo! Arce languor, feris erroribus tempora paterni sidus,\ncarmen, sua prius decidit dextraque perforat amaris.\n\nAtque nomen quod, est nec mentisque. Ita cadit Pittheia\n[sanguine](http://eram-huc.org/)! Electae tamen miles si quaerit ab conferat\nlatuere dicere gratia, Ceyx pariter; tumentem digitis. Phrygiae est signa est,\nurguere ille titubantis omnes, gratam nulla, poteris fero habet. *Et iuga*.",
"author": {
"login": "dlvhdr"
},
Expand Down Expand Up @@ -275,7 +275,7 @@
"nodes": [],
"totalCount": 0
},
"latestReviews": {
"reviews": {
"totalCount": 1,
"nodes": [{ "state": "CHANGES_REQUESTED" }]
},
Expand Down Expand Up @@ -389,7 +389,7 @@
"nodes": [],
"totalCount": 0
},
"latestReviews": {
"reviews": {
"totalCount": 1,
"nodes": [{ "state": "APPROVED" }]
},
Expand Down Expand Up @@ -479,7 +479,7 @@
}
]
},
"latestReviews": {
"reviews": {
"totalCount": 0,
"nodes": []
},
Expand Down Expand Up @@ -568,7 +568,7 @@
}
]
},
"latestReviews": {
"reviews": {
"totalCount": 0,
"nodes": []
},
Expand Down
5 changes: 4 additions & 1 deletion ui/common/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"github.com/charmbracelet/lipgloss"

"github.com/dlvhdr/gh-dash/v4/data"
)

Expand All @@ -14,8 +15,10 @@ func RenderLabels(sidebarWidth int, labels []data.Label, pillStyle lipgloss.Styl
currentRowLabels := []string{}

for _, l := range labels {
c := lipgloss.Color("#" + l.Color)
currentLabel := pillStyle.
Background(lipgloss.Color("#" + l.Color)).
BorderForeground(c).
Background(c).
Render(l.Name)

currentLabelWidth := lipgloss.Width(currentLabel)
Expand Down
15 changes: 8 additions & 7 deletions ui/components/issuesidebar/issuesidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
)

var (
htmlCommentRegex = regexp.MustCompile("(?U)<!--(.|[[:space:]])*-->")
lineCleanupRegex = regexp.MustCompile(`((\n)+|^)([^\r\n]*\|[^\r\n]*(\n)?)+`)
commentPrompt = "Leave a comment..."
htmlCommentRegex = regexp.MustCompile("(?U)<!--(.|[[:space:]])*-->")
lineCleanupRegex = regexp.MustCompile(`((\n)+|^)([^\r\n]*\|[^\r\n]*(\n)?)+`)
commentPrompt = "Leave a comment..."
)

type Model struct {
Expand All @@ -30,9 +30,9 @@ type Model struct {
width int

ShowConfirmCancel bool
isCommenting bool
isAssigning bool
isUnassigning bool
isCommenting bool
isAssigning bool
isUnassigning bool

inputBox inputbox.Model
}
Expand Down Expand Up @@ -193,6 +193,7 @@ func (m *Model) renderStatusPill() string {
}

return m.ctx.Styles.PrSidebar.PillStyle.
BorderForeground(lipgloss.Color(bgColor)).
Background(lipgloss.Color(bgColor)).
Render(content)
}
Expand All @@ -205,7 +206,7 @@ func (m *Model) renderBody() string {

body = strings.TrimSpace(body)
if body == "" {
return lipgloss.NewStyle().Italic(true).Render("No description provided.")
return lipgloss.NewStyle().Italic(true).Foreground(m.ctx.Theme.FaintText).Render("No description provided.")
}

markdownRenderer := markdown.GetMarkdownRenderer(width)
Expand Down
91 changes: 23 additions & 68 deletions ui/components/prsidebar/prsidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ func (m Model) View() string {
s.WriteString("\n")

s.WriteString(m.renderTitle())
s.WriteString("\n")
s.WriteString("\n\n")
s.WriteString(m.renderBranches())

labels := m.renderLabels()
if labels != "" {
s.WriteString("\n\n")
s.WriteString(labels)
s.WriteString("\n\n")
}

s.WriteString("\n")
Expand All @@ -204,20 +203,23 @@ func (m Model) View() string {
}

func (m *Model) renderFullNameAndNumber() string {
return lipgloss.JoinHorizontal(lipgloss.Left, m.renderStatusPill(), lipgloss.NewStyle().
Foreground(m.ctx.Theme.SecondaryText).
Render(fmt.Sprintf(" · #%d · %s", m.pr.Data.GetNumber(), m.pr.Data.GetRepoNameWithOwner())))
return lipgloss.NewStyle().Foreground(m.ctx.Theme.SecondaryText).Render(fmt.Sprintf("#%d · %s", m.pr.Data.GetNumber(), m.pr.Data.GetRepoNameWithOwner()))
}

func (m *Model) renderTitle() string {
return m.ctx.Styles.Common.MainTextStyle.Width(m.getIndentedContentWidth()).
Render(m.pr.Data.Title)
return lipgloss.JoinHorizontal(
lipgloss.Top,
m.ctx.Styles.Common.MainTextStyle.Width(m.getIndentedContentWidth()).Render(m.pr.Data.Title),
)
}

func (m *Model) renderBranches() string {
return lipgloss.NewStyle().
Foreground(m.ctx.Theme.SecondaryText).
Render(m.pr.Data.BaseRefName + "  " + m.pr.Data.HeadRefName)
return lipgloss.JoinHorizontal(lipgloss.Left,
m.renderStatusPill(),
" ",
lipgloss.NewStyle().
Foreground(m.ctx.Theme.SecondaryText).
Render(m.pr.Data.BaseRefName+"  "+m.pr.Data.HeadRefName))
}

func (m *Model) renderStatusPill() string {
Expand All @@ -236,72 +238,25 @@ func (m *Model) renderStatusPill() string {
}

return m.ctx.Styles.PrSidebar.PillStyle.
BorderForeground(lipgloss.Color(bgColor)).
Background(lipgloss.Color(bgColor)).
Render(m.pr.RenderState())
}

func (m *Model) renderMergeablePill() string {
status := m.pr.Data.Mergeable
if status == "CONFLICTING" {
return m.ctx.Styles.PrSidebar.PillStyle.
Background(m.ctx.Theme.ErrorText).
Render("󰅖 Merge Conflicts")
} else if status == "MERGEABLE" {
return m.ctx.Styles.PrSidebar.PillStyle.
Background(m.ctx.Theme.SuccessText).
Render("󰃸 No Merge Conflicts")
}

return ""
}

func (m *Model) renderMergeStateStatusPill() string {
status := m.pr.Data.MergeStateStatus
if status == "CLEAN" {
return m.ctx.Styles.PrSidebar.PillStyle.
Background(m.ctx.Theme.SuccessText).
Render("󰄬 Branch Up-To-Date")
} else if status == "BLOCKED" {
return m.ctx.Styles.PrSidebar.PillStyle.
Background(m.ctx.Theme.ErrorText).
Render("󰅖 Branch Blocked")
} else if status == "BEHIND" {
return m.ctx.Styles.PrSidebar.PillStyle.
Background(m.ctx.Theme.WarningText).
Render(" Branch Behind")
}
return ""
}

func (m *Model) renderChecksPill() string {
s := m.ctx.Styles.PrSidebar.PillStyle
t := m.ctx.Theme

status := m.pr.GetStatusChecksRollup()
if status == "FAILURE" {
return s.
Background(t.ErrorText).
Render("󰅖 Checks")
} else if status == "PENDING" {
return s.
Background(t.FaintText).
Foreground(t.PrimaryText).
Faint(true).
Render(" Checks")
}

return s.
Background(t.SuccessText).
Foreground(t.InvertedText).
Render("󰄬 Checks")
}

func (m *Model) renderLabels() string {
width := m.getIndentedContentWidth()
labels := m.pr.Data.Labels.Nodes
style := m.ctx.Styles.PrSidebar.PillStyle
if len(labels) == 0 {
return ""
}

return common.RenderLabels(width, labels, style)
return lipgloss.JoinVertical(
lipgloss.Left,
lipgloss.NewStyle().Foreground(m.ctx.Theme.FaintText).Underline(true).Render("Labels"),
"",
common.RenderLabels(width, labels, style),
)
}

func (m *Model) renderDescription() string {
Expand All @@ -312,7 +267,7 @@ func (m *Model) renderDescription() string {

body = strings.TrimSpace(body)
if body == "" {
return lipgloss.NewStyle().Italic(true).Render("No description provided.")
return lipgloss.NewStyle().Italic(true).Foreground(m.ctx.Theme.FaintText).Render("No description provided.")
}

markdownRenderer := markdown.GetMarkdownRenderer(width)
Expand Down
5 changes: 2 additions & 3 deletions ui/context/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ func InitStyles(theme theme.Theme) Styles {
s.Common = common.BuildStyles(theme)

s.PrSidebar.PillStyle = s.Common.MainTextStyle.
Foreground(theme.InvertedText).
PaddingLeft(1).
PaddingRight(1)
Border(lipgloss.Border{Left: "", Right: ""}, false, true, false, true).
Foreground(theme.InvertedText)

s.Help.Text = lipgloss.NewStyle().Foreground(theme.SecondaryText)
s.Help.KeyText = lipgloss.NewStyle().Foreground(theme.PrimaryText)
Expand Down
14 changes: 10 additions & 4 deletions ui/markdown/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,38 @@ var (
H1: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "# ",
Color: stringPtr("#666CA6"),
Color: stringPtr("255"),
Bold: boolPtr(true),
},
},
H2: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("252"),
Prefix: "## ",
},
},
H3: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("251"),
Prefix: "### ",
},
},
H4: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("250"),
Prefix: "#### ",
},
},
H5: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("249"),
Prefix: "##### ",
},
},
H6: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "###### ",
Color: stringPtr("35"),
Color: stringPtr("248"),
Bold: boolPtr(false),
},
},
Expand Down Expand Up @@ -238,6 +242,8 @@ var (
}
)

func boolPtr(b bool) *bool { return &b }
func boolPtr(b bool) *bool { return &b }

func stringPtr(s string) *string { return &s }
func uintPtr(u uint) *uint { return &u }

func uintPtr(u uint) *uint { return &u }

0 comments on commit 0e37552

Please sign in to comment.