consolidate AddState and AddDoneState

This commit is contained in:
Taybin Rutkin 2026-07-22 10:39:42 -04:00
parent 58ffd98249
commit 98a55ce534
No known key found for this signature in database
GPG key ID: 605FA2C570B6AC9E
3 changed files with 9 additions and 24 deletions

View file

@ -486,28 +486,17 @@ func (c *Config) GetStateColor(stateName string) string {
return "99"
}
// AddState adds a new state to the configuration
func (c *Config) AddState(name, color string) {
// Check if state already exists
for i, state := range c.States.States {
if state.Name == name {
c.States.States[i].Color = color
return
}
}
c.States.States = append(c.States.States, StateConfig{Name: name, Color: color})
}
// AddDoneState adds (or upgrades) a state and marks it as a done state.
func (c *Config) AddDoneState(name, color string) {
// AddState adds (or upgrades) a state in the configuration, marking it as a
// done state when done is true.
func (c *Config) AddState(name, color string, done bool) {
for i := range c.States.States {
if c.States.States[i].Name == name {
c.States.States[i].Color = color
c.States.States[i].Done = true
c.States.States[i].Done = done
return
}
}
c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: true})
c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: done})
}
// RemoveState removes a state from the configuration

View file

@ -52,7 +52,7 @@ func TestFillDefaultsLeavesExplicitDoneFlagsAlone(t *testing.T) {
func TestAddDoneState(t *testing.T) {
c := &Config{}
c.AddDoneState("CANCELLED", "240")
c.AddState("CANCELLED", "240", true)
if len(c.States.States) != 1 {
t.Fatalf("expected 1 state, got %d", len(c.States.States))
@ -63,8 +63,8 @@ func TestAddDoneState(t *testing.T) {
}
// Adding an existing name upgrades it to done.
c.AddState("REVIEW", "99")
c.AddDoneState("REVIEW", "99")
c.AddState("REVIEW", "99", false)
c.AddState("REVIEW", "99", true)
for _, st := range c.States.States {
if st.Name == "REVIEW" && !st.Done {
t.Fatal("expected REVIEW upgraded to done")

View file

@ -108,11 +108,7 @@ func (m *uiModel) applyStateForm() bool {
if color == "" {
color = "99"
}
if sf.done {
m.config.AddDoneState(name, color)
} else {
m.config.AddState(name, color)
}
m.config.AddState(name, color, sf.done)
m.setStatus(fmt.Sprintf("Added state '%s' (saved)", name))
return true
}