Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sparse layout in tables #408

Merged
merged 4 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type ColorThemeConfig struct {

type TableUIThemeConfig struct {
ShowSeparator bool `yaml:"showSeparator" default:"true"`
Compact bool `yaml:"compact" default:"false"`
}

type UIThemeConfig struct {
Expand Down Expand Up @@ -208,10 +209,10 @@ func (parser ConfigParser) getDefaultConfig() Config {
Layout: LayoutConfig{
Prs: PrsLayoutConfig{
UpdatedAt: ColumnConfig{
Width: utils.IntPtr(lipgloss.Width("2mo ago")),
Width: utils.IntPtr(lipgloss.Width("2mo ")),
},
Repo: ColumnConfig{
Width: utils.IntPtr(15),
Width: utils.IntPtr(20),
},
Author: ColumnConfig{
Width: utils.IntPtr(15),
Expand All @@ -230,7 +231,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
},
Issues: IssuesLayoutConfig{
UpdatedAt: ColumnConfig{
Width: utils.IntPtr(lipgloss.Width("2mo ago")),
Width: utils.IntPtr(lipgloss.Width("2mo ")),
},
Repo: ColumnConfig{
Width: utils.IntPtr(15),
Expand Down Expand Up @@ -284,6 +285,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
SectionsShowCount: true,
Table: TableUIThemeConfig{
ShowSeparator: true,
Compact: false,
},
},
},
Expand Down
10 changes: 10 additions & 0 deletions docs/data/schemas/theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ properties:
schematize:
skip_schema_render: true
format: yaml
compact:
title: Compact
description: >-
Whether to show table rows in a compact way or not
type: boolean
default: false
schematize:
skip_schema_render: true
format: yaml
colors:
title: Theme Colors
description: Defines text, background, and border colors for the dashboard.
Expand Down Expand Up @@ -378,6 +387,7 @@ default:
sectionsShowCount: true
table:
showSeparators: true
compact: false
colors:
text:
primary: "#ffffff"
Expand Down
3 changes: 2 additions & 1 deletion ui/components/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/charmbracelet/lipgloss"

"github.com/dlvhdr/gh-dash/v4/data"
"github.com/dlvhdr/gh-dash/v4/ui/components"
"github.com/dlvhdr/gh-dash/v4/ui/components/table"
Expand All @@ -19,14 +20,14 @@ type Issue struct {

func (issue *Issue) ToTableRow() table.Row {
return table.Row{
issue.renderUpdateAt(),
issue.renderStatus(),
issue.renderRepoName(),
issue.renderTitle(),
issue.renderOpenedBy(),
issue.renderAssignees(),
issue.renderNumComments(),
issue.renderNumReactions(),
issue.renderUpdateAt(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions ui/components/issuessection/issuessection.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ func GetSectionColumns(
)

return []table.Column{
{
Title: "",
Width: updatedAtLayout.Width,
Hidden: updatedAtLayout.Hidden,
},
{
Title: "",
Width: stateLayout.Width,
Expand Down Expand Up @@ -222,6 +217,11 @@ func GetSectionColumns(
Width: &issueNumCommentsCellWidth,
Hidden: reactionsLayout.Hidden,
},
{
Title: "",
Width: updatedAtLayout.Width,
Hidden: updatedAtLayout.Hidden,
},
}
}

Expand Down
94 changes: 57 additions & 37 deletions ui/components/pr/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ func (pr *PullRequest) getTextStyle() lipgloss.Style {
func (pr *PullRequest) renderReviewStatus() string {
reviewCellStyle := pr.getTextStyle()
if pr.Data.ReviewDecision == "APPROVED" {
if pr.Data.State == "OPEN" {
reviewCellStyle = reviewCellStyle.Foreground(
pr.Ctx.Theme.SuccessText,
)
}
reviewCellStyle = reviewCellStyle.Foreground(
pr.Ctx.Theme.SuccessText,
)
return reviewCellStyle.Render("󰄬")
}

if pr.Data.ReviewDecision == "CHANGES_REQUESTED" {
if pr.Data.State == "OPEN" {
reviewCellStyle = reviewCellStyle.Foreground(
pr.Ctx.Theme.WarningText,
)
}
reviewCellStyle = reviewCellStyle.Foreground(
pr.Ctx.Theme.WarningText,
)
return reviewCellStyle.Render("󰌑")
}

Expand All @@ -51,16 +47,16 @@ func (pr *PullRequest) renderState() string {
switch pr.Data.State {
case "OPEN":
if pr.Data.IsDraft {
return mergeCellStyle.Foreground(pr.Ctx.Theme.FaintText).Render("")
return mergeCellStyle.Foreground(pr.Ctx.Theme.FaintText).Render(constants.DraftIcon)
} else {
return mergeCellStyle.Foreground(pr.Ctx.Styles.Colors.OpenPR).Render("")
return mergeCellStyle.Foreground(pr.Ctx.Styles.Colors.OpenPR).Render(constants.OpenIcon)
}
case "CLOSED":
return mergeCellStyle.Foreground(pr.Ctx.Styles.Colors.ClosedPR).
Render("")
Render(constants.ClosedIcon)
case "MERGED":
return mergeCellStyle.Foreground(pr.Ctx.Styles.Colors.MergedPR).
Render("")
Render(constants.MergedIcon)
default:
return mergeCellStyle.Foreground(pr.Ctx.Theme.FaintText).Render("-")
}
Expand Down Expand Up @@ -107,19 +103,15 @@ func (pr *PullRequest) renderCiStatus() string {
accStatus := pr.GetStatusChecksRollup()
ciCellStyle := pr.getTextStyle()
if accStatus == "SUCCESS" {
if pr.Data.State == "OPEN" {
ciCellStyle = ciCellStyle.Foreground(pr.Ctx.Theme.SuccessText)
}
ciCellStyle = ciCellStyle.Foreground(pr.Ctx.Theme.SuccessText)
return ciCellStyle.Render(constants.SuccessIcon)
}

if accStatus == "PENDING" {
return ciCellStyle.Render(pr.Ctx.Styles.Common.WaitingGlyph)
}

if pr.Data.State == "OPEN" {
ciCellStyle = ciCellStyle.Foreground(pr.Ctx.Theme.WarningText)
}
ciCellStyle = ciCellStyle.Foreground(pr.Ctx.Theme.WarningText)
return ciCellStyle.Render(constants.FailureIcon)
}

Expand All @@ -130,14 +122,8 @@ func (pr *PullRequest) renderLines(isSelected bool) string {
}

var additionsFg, deletionsFg lipgloss.AdaptiveColor
state := pr.Data.State
if state != "OPEN" {
additionsFg = pr.Ctx.Theme.FaintText
deletionsFg = pr.Ctx.Theme.FaintText
} else {
additionsFg = pr.Ctx.Theme.SuccessText
deletionsFg = pr.Ctx.Theme.WarningText
}
additionsFg = pr.Ctx.Theme.SuccessText
deletionsFg = pr.Ctx.Theme.WarningText

baseStyle := lipgloss.NewStyle()
if isSelected {
Expand Down Expand Up @@ -182,6 +168,22 @@ func (pr *PullRequest) renderTitle() string {
)
}

func (pr *PullRequest) renderExtendedTitle(isSelected bool) string {
baseStyle := lipgloss.NewStyle()
if isSelected {
baseStyle = baseStyle.Foreground(pr.Ctx.Theme.SecondaryText).Background(pr.Ctx.Theme.SelectedBackground)
}
repoName := baseStyle.Render(pr.Data.Repository.NameWithOwner)
prNumber := baseStyle.Render(fmt.Sprintf("#%d ", pr.Data.Number))
top := lipgloss.JoinHorizontal(lipgloss.Top, repoName, baseStyle.Render(" "), prNumber)
title := pr.Data.Title
width := max(lipgloss.Width(top), lipgloss.Width(title))
top = baseStyle.Foreground(pr.Ctx.Theme.SecondaryText).Width(width).Render(top)
title = baseStyle.Foreground(pr.Ctx.Theme.PrimaryText).Width(width).Render(title)

return baseStyle.Render(lipgloss.JoinVertical(lipgloss.Left, top, title))
}

func (pr *PullRequest) renderAuthor() string {
return pr.getTextStyle().Render(pr.Data.Author.Login)
}
Expand All @@ -195,8 +197,13 @@ func (pr *PullRequest) renderAssignees() string {
}

func (pr *PullRequest) renderRepoName() string {
repoName := pr.Data.HeadRepository.Name
return pr.getTextStyle().Render(repoName)
repoName := ""
if !pr.Ctx.Config.Theme.Ui.Table.Compact {
repoName = pr.Data.Repository.NameWithOwner
} else {
repoName = pr.Data.HeadRepository.Name
}
return pr.getTextStyle().Copy().Foreground(pr.Ctx.Theme.FaintText).Render(repoName)
}

func (pr *PullRequest) renderUpdateAt() string {
Expand All @@ -209,7 +216,7 @@ func (pr *PullRequest) renderUpdateAt() string {
updatedAtOutput = pr.Data.UpdatedAt.Format(timeFormat)
}

return pr.getTextStyle().Render(updatedAtOutput)
return pr.getTextStyle().Copy().Foreground(pr.Ctx.Theme.FaintText).Render(updatedAtOutput)
}

func (pr *PullRequest) renderBaseName() string {
Expand All @@ -220,31 +227,44 @@ func (pr *PullRequest) RenderState() string {
switch pr.Data.State {
case "OPEN":
if pr.Data.IsDraft {
return " Draft"
return constants.DraftIcon + " Draft"
} else {
return " Open"
return constants.OpenIcon + " Open"
}
case "CLOSED":
return "󰗨 Closed"
return constants.ClosedIcon + " Closed"
case "MERGED":
return " Merged"
return constants.MergedIcon + " Merged"
default:
return ""
}
}

func (pr *PullRequest) ToTableRow(isSelected bool) table.Row {
if !pr.Ctx.Config.Theme.Ui.Table.Compact {
return table.Row{
pr.renderState(),
pr.renderExtendedTitle(isSelected),
pr.renderBaseName(),
pr.renderAssignees(),
pr.renderReviewStatus(),
pr.renderCiStatus(),
pr.renderLines(isSelected),
pr.renderUpdateAt(),
}
}

return table.Row{
pr.renderUpdateAt(),
pr.renderState(),
pr.renderRepoName(),
pr.renderTitle(),
pr.renderAuthor(),
pr.renderAssignees(),
pr.renderBaseName(),
pr.renderAssignees(),
pr.renderReviewStatus(),
pr.renderCiStatus(),
pr.renderLines(isSelected),
pr.renderUpdateAt(),
}
}

Expand Down
57 changes: 52 additions & 5 deletions ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,56 @@ func GetSectionColumns(
ciLayout := config.MergeColumnConfigs(dLayout.Ci, sLayout.Ci)
linesLayout := config.MergeColumnConfigs(dLayout.Lines, sLayout.Lines)

if !ctx.Config.Theme.Ui.Table.Compact {
return []table.Column{
{
Title: "",
Width: utils.IntPtr(3),
Hidden: stateLayout.Hidden,
},
{
Title: "Title",
Grow: utils.BoolPtr(true),
Hidden: titleLayout.Hidden,
},
{
Title: "Assignees",
Width: assigneesLayout.Width,
Hidden: assigneesLayout.Hidden,
},
{
Title: "Base",
Width: baseLayout.Width,
Hidden: baseLayout.Hidden,
},
{
Title: "󰯢",
Width: utils.IntPtr(4),
Hidden: reviewStatusLayout.Hidden,
},
{
Title: "",
Width: &ctx.Styles.PrSection.CiCellWidth,
Grow: new(bool),
Hidden: ciLayout.Hidden,
},
{
Title: "",
Width: linesLayout.Width,
Hidden: linesLayout.Hidden,
},
{
Title: "",
Width: updatedAtLayout.Width,
Hidden: updatedAtLayout.Hidden,
},
}
}

return []table.Column{
{
Title: "",
Width: updatedAtLayout.Width,
Hidden: updatedAtLayout.Hidden,
},
{
Title: "",
Width: utils.IntPtr(3),
Hidden: stateLayout.Hidden,
},
{
Expand Down Expand Up @@ -262,6 +304,11 @@ func GetSectionColumns(
Width: linesLayout.Width,
Hidden: linesLayout.Hidden,
},
{
Title: "",
Width: updatedAtLayout.Width,
Hidden: updatedAtLayout.Hidden,
},
}
}

Expand Down
Loading
Loading