diff --git a/config/utils.go b/config/utils.go index 0e117930..0c72e03a 100644 --- a/config/utils.go +++ b/config/utils.go @@ -42,3 +42,14 @@ func (cfg IssuesSectionConfig) ToSectionConfig() SectionConfig { Limit: cfg.Limit, } } + +func MergeColumnConfigs(defaultCfg, sectionCfg ColumnConfig) ColumnConfig { + colCfg := defaultCfg + if sectionCfg.Width != nil { + colCfg.Width = sectionCfg.Width + } + if sectionCfg.Hidden != nil { + colCfg.Hidden = sectionCfg.Hidden + } + return colCfg +} diff --git a/ui/components/issuessection/issuessection.go b/ui/components/issuessection/issuessection.go index 051c726a..6733bd76 100644 --- a/ui/components/issuessection/issuessection.go +++ b/ui/components/issuessection/issuessection.go @@ -1,7 +1,6 @@ package issuessection import ( - "log" "sort" "github.com/charmbracelet/bubbles/key" @@ -31,7 +30,7 @@ func NewModel(id int, ctx *context.ProgramContext, cfg config.IssuesSectionConfi ctx, cfg.ToSectionConfig(), SectionType, - GetSectionColumns(ctx), + GetSectionColumns(cfg, ctx), "Issue", "Issues", ), @@ -115,49 +114,59 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) { return &m, tea.Batch(cmd, searchCmd) } -func GetSectionColumns(ctx *context.ProgramContext) []table.Column { - layout := ctx.Config.Defaults.Layout.Issues - log.Printf("updated at: %v\n", *layout.UpdatedAt.Width) +func GetSectionColumns(cfg config.IssuesSectionConfig, ctx *context.ProgramContext) []table.Column { + dLayout := ctx.Config.Defaults.Layout.Issues + sLayout := cfg.Layout + + updatedAtLayout := config.MergeColumnConfigs(dLayout.UpdatedAt, sLayout.UpdatedAt) + stateLayout := config.MergeColumnConfigs(dLayout.State, sLayout.State) + repoLayout := config.MergeColumnConfigs(dLayout.Repo, sLayout.Repo) + titleLayout := config.MergeColumnConfigs(dLayout.Title, sLayout.Title) + creatorLayout := config.MergeColumnConfigs(dLayout.Creator, sLayout.Creator) + assigneesLayout := config.MergeColumnConfigs(dLayout.Assignees, sLayout.Assignees) + commentsLayout := config.MergeColumnConfigs(dLayout.Comments, sLayout.Comments) + reactionsLayout := config.MergeColumnConfigs(dLayout.Reactions, sLayout.Reactions) + return []table.Column{ { Title: "", - Width: layout.UpdatedAt.Width, - Hidden: layout.UpdatedAt.Hidden, + Width: updatedAtLayout.Width, + Hidden: updatedAtLayout.Hidden, }, { Title: "", - Width: layout.State.Width, - Hidden: layout.State.Hidden, + Width: stateLayout.Width, + Hidden: stateLayout.Hidden, }, { Title: "", - Width: layout.Repo.Width, - Hidden: layout.Repo.Hidden, + Width: repoLayout.Width, + Hidden: repoLayout.Hidden, }, { Title: "Title", Grow: utils.BoolPtr(true), - Hidden: layout.Title.Hidden, + Hidden: titleLayout.Hidden, }, { Title: "Creator", - Width: layout.Creator.Width, - Hidden: layout.Creator.Hidden, + Width: creatorLayout.Width, + Hidden: creatorLayout.Hidden, }, { Title: "Assignees", - Width: layout.Assignees.Width, - Hidden: layout.Assignees.Hidden, + Width: assigneesLayout.Width, + Hidden: assigneesLayout.Hidden, }, { Title: "", Width: &issueNumCommentsCellWidth, - Hidden: layout.Comments.Hidden, + Hidden: commentsLayout.Hidden, }, { Title: "", Width: &issueNumCommentsCellWidth, - Hidden: layout.Reactions.Hidden, + Hidden: reactionsLayout.Hidden, }, } } diff --git a/ui/components/prssection/prssection.go b/ui/components/prssection/prssection.go index 2bf49921..d4e66c62 100644 --- a/ui/components/prssection/prssection.go +++ b/ui/components/prssection/prssection.go @@ -30,7 +30,7 @@ func NewModel(id int, ctx *context.ProgramContext, cfg config.PrsSectionConfig) ctx, cfg.ToSectionConfig(), SectionType, - GetSectionColumns(ctx), + GetSectionColumns(cfg, ctx), "PR", "Pull Requests", ), @@ -137,48 +137,59 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) { return &m, tea.Batch(cmd, searchCmd) } -func GetSectionColumns(ctx *context.ProgramContext) []table.Column { - layout := ctx.Config.Defaults.Layout.Prs +func GetSectionColumns(cfg config.PrsSectionConfig, ctx *context.ProgramContext) []table.Column { + dLayout := ctx.Config.Defaults.Layout.Prs + sLayout := cfg.Layout + + updatedAtLayout := config.MergeColumnConfigs(dLayout.UpdatedAt, sLayout.UpdatedAt) + repoLayout := config.MergeColumnConfigs(dLayout.Repo, sLayout.Repo) + titleLayout := config.MergeColumnConfigs(dLayout.Title, sLayout.Title) + authorLayout := config.MergeColumnConfigs(dLayout.Author, sLayout.Author) + reviewStatusLayout := config.MergeColumnConfigs(dLayout.ReviewStatus, sLayout.ReviewStatus) + stateLayout := config.MergeColumnConfigs(dLayout.State, sLayout.State) + ciLayout := config.MergeColumnConfigs(dLayout.Ci, sLayout.Ci) + linesLayout := config.MergeColumnConfigs(dLayout.Lines, sLayout.Lines) + return []table.Column{ { Title: "", - Width: layout.UpdatedAt.Width, - Hidden: layout.UpdatedAt.Hidden, + Width: updatedAtLayout.Width, + Hidden: updatedAtLayout.Hidden, }, { Title: "", - Width: layout.Repo.Width, - Hidden: layout.Repo.Hidden, + Width: repoLayout.Width, + Hidden: repoLayout.Hidden, }, { Title: "Title", Grow: utils.BoolPtr(true), - Hidden: layout.Title.Hidden, + Hidden: titleLayout.Hidden, }, { Title: "Author", - Width: layout.Author.Width, - Hidden: layout.Author.Hidden, + Width: authorLayout.Width, + Hidden: authorLayout.Hidden, }, { Title: "", Width: utils.IntPtr(4), - Hidden: layout.ReviewStatus.Hidden, + Hidden: reviewStatusLayout.Hidden, }, { Title: "", - Hidden: layout.State.Hidden, + Hidden: stateLayout.Hidden, }, { Title: "", Width: &ciCellWidth, Grow: new(bool), - Hidden: layout.Ci.Hidden, + Hidden: ciLayout.Hidden, }, { Title: "", - Width: layout.Lines.Width, - Hidden: layout.Lines.Hidden, + Width: linesLayout.Width, + Hidden: linesLayout.Hidden, }, } }