From fee1f3880db1528ff82188150582f2235abf4d36 Mon Sep 17 00:00:00 2001 From: erda-bot <81558540+erda-bot@users.noreply.github.com> Date: Thu, 14 Oct 2021 21:15:50 +0800 Subject: [PATCH] Fix default issue state coming from home page (#2268) (#2400) Co-authored-by: shuofan --- .../issue-manage/issueFilter/render.go | 9 ++++- .../issue-manage/issueFilter/render_test.go | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/dop/component-protocol/components/issue-manage/issueFilter/render.go b/modules/dop/component-protocol/components/issue-manage/issueFilter/render.go index a4b0fc71fe0..d86bbca4846 100644 --- a/modules/dop/component-protocol/components/issue-manage/issueFilter/render.go +++ b/modules/dop/component-protocol/components/issue-manage/issueFilter/render.go @@ -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 { diff --git a/modules/dop/component-protocol/components/issue-manage/issueFilter/render_test.go b/modules/dop/component-protocol/components/issue-manage/issueFilter/render_test.go index fa133b6f2bf..338357acc36 100644 --- a/modules/dop/component-protocol/components/issue-manage/issueFilter/render_test.go +++ b/modules/dop/component-protocol/components/issue-manage/issueFilter/render_test.go @@ -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) + }) + } +}