Skip to content

Commit fee1f38

Browse files
erda-botshuofan
andauthored
Fix default issue state coming from home page (#2268) (#2400)
Co-authored-by: shuofan <[email protected]>
1 parent 7f5af92 commit fee1f38

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

modules/dop/component-protocol/components/issue-manage/issueFilter/render.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,18 @@ func (f *ComponentFilter) InitDefaultOperation(ctx context.Context, state State)
245245
if err := f.flushOptsByFilter(filterID, f.InParams.FrontendUrlQuery); err != nil {
246246
return err
247247
}
248-
} else {
249-
f.State.FrontendConditionValues.States = res[f.InParams.FrontendFixedIssueType]
250248
}
251249

250+
f.setDefaultState(res, f.InParams.FrontendFixedIssueType)
252251
return nil
253252
}
254253

254+
func (f *ComponentFilter) setDefaultState(stateMap map[string][]int64, key string) {
255+
if f.State.FrontendConditionValues.States == nil {
256+
f.State.FrontendConditionValues.States = stateMap[key]
257+
}
258+
}
259+
255260
func (f *ComponentFilter) determineFilterID(filterEntity string) string {
256261
for _, bm := range f.Bms {
257262
if bm.FilterEntity == filterEntity {

modules/dop/component-protocol/components/issue-manage/issueFilter/render_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,42 @@ func Test_determineFilterID(t *testing.T) {
8383
}
8484
assert.Equal(t, "123", f.determineFilterID("eyJzdGF0ZXMiOls2NTddLCJhc3NpZ25lZUlEcyI6WyIyIl19"))
8585
}
86+
87+
func TestComponentFilter_setDefaultState(t *testing.T) {
88+
type args struct {
89+
stateMap map[string][]int64
90+
key string
91+
}
92+
tests := []struct {
93+
name string
94+
args args
95+
}{
96+
{
97+
name: "test",
98+
args: args{
99+
stateMap: map[string][]int64{
100+
"t": {1},
101+
},
102+
key: "t",
103+
},
104+
},
105+
}
106+
for _, tt := range tests {
107+
t.Run(tt.name, func(t *testing.T) {
108+
f := &ComponentFilter{}
109+
f.setDefaultState(tt.args.stateMap, tt.args.key)
110+
assert.Equal(t, []int64{1}, f.State.FrontendConditionValues.States)
111+
})
112+
t.Run(tt.name, func(t *testing.T) {
113+
f := &ComponentFilter{
114+
State: State{
115+
FrontendConditionValues: FrontendConditions{
116+
States: []int64{2},
117+
},
118+
},
119+
}
120+
f.setDefaultState(tt.args.stateMap, tt.args.key)
121+
assert.Equal(t, []int64{2}, f.State.FrontendConditionValues.States)
122+
})
123+
}
124+
}

0 commit comments

Comments
 (0)