Skip to content

Commit bf24908

Browse files
committed
feature: update relation between trending and waterfall
1 parent f225174 commit bf24908

File tree

8 files changed

+93
-45
lines changed

8 files changed

+93
-45
lines changed

modules/dop/component-protocol/components/test-dashboard/at_case_rate_trending_chart_group/chart/render.go

+23-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"strconv"
2122

2223
"github.com/erda-project/erda-infra/base/servicehub"
2324
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
@@ -41,9 +42,10 @@ func init() {
4142
type Chart struct {
4243
base.DefaultProvider
4344

44-
PData []Data `json:"pData"`
45-
EData []Data `json:"eData"`
46-
XAxis XAxis `json:"xAxis"`
45+
PData []Data `json:"pData"`
46+
EData []Data `json:"eData"`
47+
XAxis XAxis `json:"xAxis"`
48+
State map[string]interface{} `json:"state"`
4749
}
4850

4951
type Props struct {
@@ -53,8 +55,8 @@ type Props struct {
5355
}
5456

5557
type Data struct {
56-
Value string `json:"value"`
57-
MetaData gshelper.SelectChartItemData `json:"metaData"`
58+
Value string `json:"value"`
59+
MetaData map[string]gshelper.SelectChartItemData `json:"metaData"`
5860
}
5961

6062
type TestPlanV2 struct {
@@ -109,6 +111,10 @@ type PData struct {
109111

110112
func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error {
111113
h := gshelper.NewGSHelper(gs)
114+
if c.State == nil {
115+
c.State = map[string]interface{}{}
116+
}
117+
c.State["isClick"] = false
112118
switch event.Operation {
113119
case RateTrendingSelectItemOperationKey:
114120
opData := OperationData{}
@@ -121,6 +127,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
121127
}
122128

123129
h.SetSelectChartItemData(opData.MetaData.Data.Data.MetaData)
130+
c.State["isClick"] = true
124131
return nil
125132
case cptype.InitializeOperation, cptype.DefaultRenderingKey, cptype.RenderingOperation:
126133
atPlans := h.GetRateTrendingFilterTestPlanList()
@@ -143,6 +150,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
143150
eData := make([]Data, 0, len(historyList))
144151
xAxis := make([]string, 0, len(historyList))
145152
var sucApiNum, execApiNum, totalApiNum int64
153+
metaData := make(map[string]gshelper.SelectChartItemData, 0)
146154
for _, v := range historyList {
147155
if v.Type != apistructs.AutoTestPlan {
148156
continue
@@ -154,7 +162,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
154162
sucApiNum += v.SuccessApiNum
155163
execApiNum += v.ExecuteApiNum
156164
totalApiNum += v.TotalApiNum
157-
metaData := gshelper.SelectChartItemData{
165+
metaData[strconv.FormatUint(v.PlanID, 10)] = gshelper.SelectChartItemData{
158166
PlanID: v.PlanID,
159167
Name: func() string {
160168
for _, v2 := range h.GetGlobalAutoTestPlanList() {
@@ -164,14 +172,19 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
164172
}
165173
return ""
166174
}(),
167-
PipelineID: v.PipelineID,
175+
PipelineID: v.PipelineID,
176+
ExecuteTime: v.ExecuteTime,
177+
}
178+
currMeta := make(map[string]gshelper.SelectChartItemData, 0)
179+
for k, data := range metaData {
180+
currMeta[k] = data
168181
}
169182
pData = append(pData, Data{
170-
MetaData: metaData,
183+
MetaData: currMeta,
171184
Value: calRate(sucApiNum, totalApiNum),
172185
})
173186
eData = append(eData, Data{
174-
MetaData: metaData,
187+
MetaData: currMeta,
175188
Value: calRate(execApiNum, totalApiNum),
176189
})
177190
xAxis = append(xAxis, v.ExecuteTime.Format("2006-01-02 15:04:05"))
@@ -181,23 +194,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
181194
ch.XAxis = XAxis{xAxis}
182195
c.Props = ch.convertToProps(ctx)
183196
c.Operations = getOperations()
184-
h.SetSelectChartItemData(func() gshelper.SelectChartItemData {
185-
if len(historyList) == 0 {
186-
return gshelper.SelectChartItemData{}
187-
}
188-
return gshelper.SelectChartItemData{
189-
PlanID: historyList[len(historyList)-1].PlanID,
190-
PipelineID: historyList[len(historyList)-1].PipelineID,
191-
Name: func() string {
192-
for _, v := range h.GetGlobalAutoTestPlanList() {
193-
if v.ID == historyList[len(historyList)-1].PlanID {
194-
return v.Name
195-
}
196-
}
197-
return ""
198-
}(),
199-
}
200-
}())
197+
h.SetSelectChartItemData(metaData)
201198
return nil
202199
}
203200
return nil

modules/dop/component-protocol/components/test-dashboard/at_plan_latest_waterfall_chart_group/chart/render.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (f *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptype
5151
}
5252

5353
atSvc := ctx.Value(types.AutoTestPlanService).(*autotestv2.Service)
54-
historyList, err := atSvc.ListExecHistorySceneSetByParentPID(h.GetSelectChartHistoryData().PipelineID)
54+
historyList, err := atSvc.ListExecHistorySceneSetByParentPID(h.GetWaterfallChartPipelineIDs()...)
5555
if err != nil {
5656
return err
5757
}

modules/dop/component-protocol/components/test-dashboard/at_plan_latest_waterfall_chart_group/filter/render.go

+30-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package filter
1717
import (
1818
"context"
1919
"encoding/json"
20+
"sort"
2021

2122
"github.com/erda-project/erda-infra/base/servicehub"
2223
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
@@ -42,6 +43,7 @@ type Filter struct {
4243
type State struct {
4344
Conditions []filter.PropCondition `json:"conditions,omitempty"`
4445
Values PipelineIDValues `json:"values,omitempty"`
46+
IsClick bool `json:"isClick"`
4547
}
4648

4749
type PipelineIDValues struct {
@@ -59,24 +61,47 @@ func (f *Filter) Render(ctx context.Context, c *cptype.Component, scenario cptyp
5961
}
6062

6163
h := gshelper.NewGSHelper(gs)
64+
data := h.GetSelectChartHistoryData()
65+
list := make([]gshelper.SelectChartItemData, 0, len(data))
6266
f.State.Conditions = []filter.PropCondition{
6367
{
6468
EmptyText: cputil.I18n(ctx, "all"),
6569
Fixed: true,
6670
Key: "pipelineID",
6771
Label: cputil.I18n(ctx, "Test Plan"),
6872
Options: func() (opts []filter.PropConditionOption) {
69-
data := h.GetSelectChartHistoryData()
70-
opts = append(opts, filter.PropConditionOption{
71-
Label: data.Name,
72-
Value: data.PipelineID,
73-
})
73+
for _, v := range data {
74+
list = append(list, v)
75+
sort.Slice(list, func(i, j int) bool {
76+
return list[i].ExecuteTime.After(list[j].ExecuteTime)
77+
})
78+
}
79+
for _, v := range list {
80+
opts = append(opts, filter.PropConditionOption{
81+
Label: v.Name,
82+
Value: v.PipelineID,
83+
})
84+
}
7485
return
7586
}(),
7687
Type: filter.PropConditionTypeSelect,
7788
},
7889
}
90+
f.State.Values = PipelineIDValues{
91+
PipelineID: func() []uint64 {
92+
if len(f.State.Values.PipelineID) != 0 && !f.State.IsClick {
93+
return f.State.Values.PipelineID
94+
}
95+
if len(list) == 0 {
96+
return nil
97+
}
98+
return []uint64{list[0].PipelineID}
99+
}(),
100+
}
101+
h.SetWaterfallChartPipelineIDs(f.State.Values.PipelineID)
79102

103+
// clear
104+
f.State.IsClick = false
80105
if err := f.setToComponent(c); err != nil {
81106
return err
82107
}

modules/dop/component-protocol/components/test-dashboard/common/gshelper/helper.go

+31-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package gshelper
1616

1717
import (
18+
"fmt"
19+
"time"
20+
1821
"github.com/mitchellh/mapstructure"
1922

2023
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
@@ -264,24 +267,28 @@ func (h *GSHelper) GetAtCaseRateTrendingTimeFilter() AtSceneAndApiTimeFilter {
264267
}
265268

266269
type SelectChartItemData struct {
267-
PlanID uint64 `json:"planID"`
268-
Name string `json:"name"`
269-
PipelineID uint64 `json:"pipelineID"`
270+
PlanID uint64 `json:"planID"`
271+
Name string `json:"name"`
272+
PipelineID uint64 `json:"pipelineID"`
273+
ExecuteTime time.Time `json:"-"`
270274
}
271275

272-
func (h *GSHelper) SetSelectChartItemData(t SelectChartItemData) {
276+
func (h *GSHelper) SetSelectChartItemData(t map[string]SelectChartItemData) {
273277
if h.gs == nil {
274278
return
275279
}
276280
(*h.gs)["GlobalSelectChartItemData"] = t
277281
}
278282

279-
func (h *GSHelper) GetSelectChartHistoryData() SelectChartItemData {
283+
func (h *GSHelper) GetSelectChartHistoryData() map[string]SelectChartItemData {
280284
if h.gs == nil {
281-
return SelectChartItemData{}
285+
return nil
286+
}
287+
data := make(map[string]SelectChartItemData, 0)
288+
err := assign((*h.gs)["GlobalSelectChartItemData"], &data)
289+
if err != nil {
290+
fmt.Println(err)
282291
}
283-
data := SelectChartItemData{}
284-
_ = assign((*h.gs)["GlobalSelectChartItemData"], &data)
285292
return data
286293
}
287294

@@ -325,3 +332,19 @@ func (h *GSHelper) GetGlobalQualityScore() float64 {
325332
}
326333
return v.(float64)
327334
}
335+
336+
func (h *GSHelper) SetWaterfallChartPipelineIDs(ids []uint64) {
337+
if h.gs == nil {
338+
return
339+
}
340+
(*h.gs)["GlobalWaterfallChartPipelineIDs"] = ids
341+
}
342+
343+
func (h *GSHelper) GetWaterfallChartPipelineIDs() []uint64 {
344+
if h.gs == nil {
345+
return nil
346+
}
347+
data := make([]uint64, 0)
348+
_ = assign((*h.gs)["GlobalWaterfallChartPipelineIDs"], &data)
349+
return data
350+
}

modules/dop/component-protocol/scenarios/test-dashboard.yml

+3
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ rendering:
282282

283283
at_case_rate_trending_chart:
284284
- name: at_plan_latest_waterfall_chart_filter
285+
state:
286+
- name: "isClick"
287+
value: "{{ at_case_rate_trending_chart.isClick }}"
285288
- name: at_plan_latest_waterfall_chart
286289

287290
scene_and_api_filter:

modules/dop/dao/autotest_exec_history.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func (client *DBClient) ExecHistoryApiStatusCount(req apistructs.StatisticsExecH
195195
}
196196

197197
// ListExecHistorySceneSetByParentPID .
198-
func (client *DBClient) ListExecHistorySceneSetByParentPID(parentPID uint64) (list []AutoTestExecHistory, err error) {
198+
func (client *DBClient) ListExecHistorySceneSetByParentPID(parentPIDs ...uint64) (list []AutoTestExecHistory, err error) {
199199
err = client.Model(AutoTestExecHistory{}).
200-
Where("parent_p_id = ?", parentPID).
200+
Where("parent_p_id IN (?)", parentPIDs).
201201
Where("type = ?", apistructs.AutotestSceneSet).
202202
Order("execute_time ASC").
203203
Find(&list).Error

modules/dop/services/autotest_v2/testplan_v2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ func (svc *Service) ExecHistoryApiStatusCount(req apistructs.StatisticsExecHisto
925925
}
926926

927927
// ListExecHistorySceneSetByParentPID .
928-
func (svc *Service) ListExecHistorySceneSetByParentPID(parentPID uint64) (history []apistructs.AutoTestExecHistoryDto, err error) {
929-
list, err := svc.db.ListExecHistorySceneSetByParentPID(parentPID)
928+
func (svc *Service) ListExecHistorySceneSetByParentPID(parentPIDs ...uint64) (history []apistructs.AutoTestExecHistoryDto, err error) {
929+
list, err := svc.db.ListExecHistorySceneSetByParentPID(parentPIDs...)
930930
if err != nil {
931931
return nil, err
932932
}

modules/dop/services/autotest_v2/testplan_v2_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestGetStepMapByGroupID(t *testing.T) {
8787

8888
func TestListExecHistorySceneSetByParentPID(t *testing.T) {
8989
var DB *dao.DBClient
90-
monkey.PatchInstanceMethod(reflect.TypeOf(DB), "ListExecHistorySceneSetByParentPID", func(*dao.DBClient, uint64) (history []dao.AutoTestExecHistory, err error) {
90+
monkey.PatchInstanceMethod(reflect.TypeOf(DB), "ListExecHistorySceneSetByParentPID", func(*dao.DBClient, ...uint64) (history []dao.AutoTestExecHistory, err error) {
9191
return []dao.AutoTestExecHistory{
9292
{
9393
BaseModel: dbengine.BaseModel{

0 commit comments

Comments
 (0)