Skip to content

Commit

Permalink
feat(config): add ability to set layout config per section
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolev Hadar authored and dlvhdr committed Sep 25, 2022
1 parent 9f2b33e commit dc77cf8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
32 changes: 23 additions & 9 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ type SectionConfig struct {
Limit *int `yaml:"limit,omitempty"`
}

type PrsSectionConfig struct {
Title string
Filters string
Limit *int `yaml:"limit,omitempty"`
Layout PrsLayoutConfig `yaml:"layout,omitempty"`
}

type IssuesSectionConfig struct {
Title string
Filters string
Limit *int `yaml:"limit,omitempty"`
Layout IssuesLayoutConfig `yaml:"layout,omitempty"`
}

type PreviewConfig struct {
Open bool
Width int
Expand Down Expand Up @@ -127,13 +141,13 @@ type ThemeConfig struct {
}

type Config struct {
PRSections []SectionConfig `yaml:"prSections"`
IssuesSections []SectionConfig `yaml:"issuesSections"`
Defaults Defaults `yaml:"defaults"`
Keybindings Keybindings `yaml:"keybindings"`
RepoPaths map[string]string `yaml:"repoPaths"`
Theme *ThemeConfig `yaml:"theme,omitempty" validate:"omitempty,dive"`
Pager Pager `yaml:"pager"`
PRSections []PrsSectionConfig `yaml:"prSections"`
IssuesSections []IssuesSectionConfig `yaml:"issuesSections"`
Defaults Defaults `yaml:"defaults"`
Keybindings Keybindings `yaml:"keybindings"`
RepoPaths map[string]string `yaml:"repoPaths"`
Theme *ThemeConfig `yaml:"theme,omitempty" validate:"omitempty,dive"`
Pager Pager `yaml:"pager"`
}

type configError struct {
Expand Down Expand Up @@ -185,7 +199,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
},
},
},
PRSections: []SectionConfig{
PRSections: []PrsSectionConfig{
{
Title: "My Pull Requests",
Filters: "is:open author:@me",
Expand All @@ -199,7 +213,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
Filters: "is:open involves:@me -author:@me",
},
},
IssuesSections: []SectionConfig{
IssuesSections: []IssuesSectionConfig{
{
Title: "My Issues",
Filters: "is:open author:@me",
Expand Down
16 changes: 16 additions & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ func (cfg Config) GetFullScreenDiffPagerEnv() []string {

return env
}

func (cfg PrsSectionConfig) ToSectionConfig() SectionConfig {
return SectionConfig{
Title: cfg.Title,
Filters: cfg.Filters,
Limit: cfg.Limit,
}
}

func (cfg IssuesSectionConfig) ToSectionConfig() SectionConfig {
return SectionConfig{
Title: cfg.Title,
Filters: cfg.Filters,
Limit: cfg.Limit,
}
}
4 changes: 2 additions & 2 deletions ui/components/issuessection/issuessection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type Model struct {
Issues []data.IssueData
}

func NewModel(id int, ctx *context.ProgramContext, cfg config.SectionConfig) Model {
func NewModel(id int, ctx *context.ProgramContext, cfg config.IssuesSectionConfig) Model {
m := Model{
section.NewModel(
id,
ctx,
cfg,
cfg.ToSectionConfig(),
SectionType,
GetSectionColumns(ctx),
"Issue",
Expand Down
4 changes: 2 additions & 2 deletions ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ type Model struct {
Prs []data.PullRequestData
}

func NewModel(id int, ctx *context.ProgramContext, cfg config.SectionConfig) Model {
func NewModel(id int, ctx *context.ProgramContext, cfg config.PrsSectionConfig) Model {
m := Model{
section.NewModel(
id,
ctx,
cfg,
cfg.ToSectionConfig(),
SectionType,
GetSectionColumns(ctx),
"PR",
Expand Down
8 changes: 6 additions & 2 deletions ui/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ type ProgramContext struct {
func (ctx *ProgramContext) GetViewSectionsConfig() []config.SectionConfig {
var configs []config.SectionConfig
if ctx.View == config.PRsView {
configs = ctx.Config.PRSections
for _, cfg := range ctx.Config.PRSections {
configs = append(configs, cfg.ToSectionConfig())
}
} else {
configs = ctx.Config.IssuesSections
for _, cfg := range ctx.Config.IssuesSections {
configs = append(configs, cfg.ToSectionConfig())
}
}

return append([]config.SectionConfig{{Title: ""}}, configs...)
Expand Down
10 changes: 8 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,20 @@ func (m *Model) setCurrentViewSections(newSections []section.Section) {
search := prssection.NewModel(
0,
&m.ctx,
config.SectionConfig{Title: "", Filters: "archived:false"},
config.PrsSectionConfig{
Title: "",
Filters: "archived:false",
},
)
m.prs = append([]section.Section{&search}, newSections...)
} else {
search := issuessection.NewModel(
0,
&m.ctx,
config.SectionConfig{Title: "", Filters: ""},
config.IssuesSectionConfig{
Title: "",
Filters: "",
},
)
m.issues = append([]section.Section{&search}, newSections...)
}
Expand Down

0 comments on commit dc77cf8

Please sign in to comment.