Skip to content

Commit

Permalink
Fix default issue state coming from home page (#2268) (#2400)
Browse files Browse the repository at this point in the history
Co-authored-by: shuofan <[email protected]>
  • Loading branch information
erda-bot and shuofan authored Oct 14, 2021
1 parent 7f5af92 commit fee1f38
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,18 @@ func (f *ComponentFilter) InitDefaultOperation(ctx context.Context, state State)
if err := f.flushOptsByFilter(filterID, f.InParams.FrontendUrlQuery); err != nil {
return err
}
} else {
f.State.FrontendConditionValues.States = res[f.InParams.FrontendFixedIssueType]
}

f.setDefaultState(res, f.InParams.FrontendFixedIssueType)
return nil
}

func (f *ComponentFilter) setDefaultState(stateMap map[string][]int64, key string) {
if f.State.FrontendConditionValues.States == nil {
f.State.FrontendConditionValues.States = stateMap[key]
}
}

func (f *ComponentFilter) determineFilterID(filterEntity string) string {
for _, bm := range f.Bms {
if bm.FilterEntity == filterEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,42 @@ func Test_determineFilterID(t *testing.T) {
}
assert.Equal(t, "123", f.determineFilterID("eyJzdGF0ZXMiOls2NTddLCJhc3NpZ25lZUlEcyI6WyIyIl19"))
}

func TestComponentFilter_setDefaultState(t *testing.T) {
type args struct {
stateMap map[string][]int64
key string
}
tests := []struct {
name string
args args
}{
{
name: "test",
args: args{
stateMap: map[string][]int64{
"t": {1},
},
key: "t",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &ComponentFilter{}
f.setDefaultState(tt.args.stateMap, tt.args.key)
assert.Equal(t, []int64{1}, f.State.FrontendConditionValues.States)
})
t.Run(tt.name, func(t *testing.T) {
f := &ComponentFilter{
State: State{
FrontendConditionValues: FrontendConditions{
States: []int64{2},
},
},
}
f.setDefaultState(tt.args.stateMap, tt.args.key)
assert.Equal(t, []int64{2}, f.State.FrontendConditionValues.States)
})
}
}

0 comments on commit fee1f38

Please sign in to comment.