Skip to content

feature: update relation between trending and waterfall chart of test dashboard #3233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"

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

PData []Data `json:"pData"`
EData []Data `json:"eData"`
XAxis XAxis `json:"xAxis"`
PData []Data `json:"pData"`
EData []Data `json:"eData"`
XAxis XAxis `json:"xAxis"`
State map[string]interface{} `json:"state"`
}

type Props struct {
Expand All @@ -53,8 +55,8 @@ type Props struct {
}

type Data struct {
Value string `json:"value"`
MetaData gshelper.SelectChartItemData `json:"metaData"`
Value string `json:"value"`
MetaData map[string]gshelper.SelectChartItemData `json:"metaData"`
}

type TestPlanV2 struct {
Expand Down Expand Up @@ -109,6 +111,10 @@ type PData struct {

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

h.SetSelectChartItemData(opData.MetaData.Data.Data.MetaData)
c.State["isClick"] = true
return nil
case cptype.InitializeOperation, cptype.DefaultRenderingKey, cptype.RenderingOperation:
atPlans := h.GetRateTrendingFilterTestPlanList()
Expand All @@ -143,6 +150,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
eData := make([]Data, 0, len(historyList))
xAxis := make([]string, 0, len(historyList))
var sucApiNum, execApiNum, totalApiNum int64
metaData := make(map[string]gshelper.SelectChartItemData, 0)
for _, v := range historyList {
if v.Type != apistructs.AutoTestPlan {
continue
Expand All @@ -154,7 +162,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
sucApiNum += v.SuccessApiNum
execApiNum += v.ExecuteApiNum
totalApiNum += v.TotalApiNum
metaData := gshelper.SelectChartItemData{
metaData[strconv.FormatUint(v.PlanID, 10)] = gshelper.SelectChartItemData{
PlanID: v.PlanID,
Name: func() string {
for _, v2 := range h.GetGlobalAutoTestPlanList() {
Expand All @@ -164,14 +172,19 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
}
return ""
}(),
PipelineID: v.PipelineID,
PipelineID: v.PipelineID,
ExecuteTime: v.ExecuteTime.Format("2006-01-02 15:04"),
}
currMeta := make(map[string]gshelper.SelectChartItemData, 0)
for k, data := range metaData {
currMeta[k] = data
}
pData = append(pData, Data{
MetaData: metaData,
MetaData: currMeta,
Value: calRate(sucApiNum, totalApiNum),
})
eData = append(eData, Data{
MetaData: metaData,
MetaData: currMeta,
Value: calRate(execApiNum, totalApiNum),
})
xAxis = append(xAxis, v.ExecuteTime.Format("2006-01-02 15:04:05"))
Expand All @@ -181,23 +194,7 @@ func (ch *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptyp
ch.XAxis = XAxis{xAxis}
c.Props = ch.convertToProps(ctx)
c.Operations = getOperations()
h.SetSelectChartItemData(func() gshelper.SelectChartItemData {
if len(historyList) == 0 {
return gshelper.SelectChartItemData{}
}
return gshelper.SelectChartItemData{
PlanID: historyList[len(historyList)-1].PlanID,
PipelineID: historyList[len(historyList)-1].PipelineID,
Name: func() string {
for _, v := range h.GetGlobalAutoTestPlanList() {
if v.ID == historyList[len(historyList)-1].PlanID {
return v.Name
}
}
return ""
}(),
}
}())
h.SetSelectChartItemData(metaData)
return nil
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type InParams struct {
type State struct {
Conditions []filter.PropCondition `json:"conditions,omitempty"`
Values Values `json:"values,omitempty"`
IsClick bool `json:"isClick"`
}

type CustomProps struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (f *Filter) Render(ctx context.Context, c *cptype.Component, scenario cptyp
return err
}

f.State.IsClick = true
return f.setToComponent(c)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (f *Chart) Render(ctx context.Context, c *cptype.Component, scenario cptype
}

atSvc := ctx.Value(types.AutoTestPlanService).(*autotestv2.Service)
historyList, err := atSvc.ListExecHistorySceneSetByParentPID(h.GetSelectChartHistoryData().PipelineID)
historyList, err := atSvc.ListExecHistorySceneSetByParentPID(h.GetWaterfallChartPipelineID())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package filter
import (
"context"
"encoding/json"
"sort"

"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
Expand All @@ -42,10 +43,11 @@ type Filter struct {
type State struct {
Conditions []filter.PropCondition `json:"conditions,omitempty"`
Values PipelineIDValues `json:"values,omitempty"`
IsClick bool `json:"isClick"`
}

type PipelineIDValues struct {
PipelineID []uint64 `json:"pipelineID"`
PipelineID uint64 `json:"pipelineID"`
}

type AtPlanFilterStateValues struct {
Expand All @@ -59,24 +61,50 @@ func (f *Filter) Render(ctx context.Context, c *cptype.Component, scenario cptyp
}

h := gshelper.NewGSHelper(gs)
data := h.GetSelectChartHistoryData()
list := make([]gshelper.SelectChartItemData, 0, len(data))
f.State.Conditions = []filter.PropCondition{
{
CustomProps: map[string]interface{}{
"mode": "single",
},
EmptyText: cputil.I18n(ctx, "all"),
Fixed: true,
Key: "pipelineID",
Label: cputil.I18n(ctx, "Test Plan"),
Options: func() (opts []filter.PropConditionOption) {
data := h.GetSelectChartHistoryData()
opts = append(opts, filter.PropConditionOption{
Label: data.Name,
Value: data.PipelineID,
for _, v := range data {
list = append(list, v)
}
sort.Slice(list, func(i, j int) bool {
return list[i].ExecuteTime > list[j].ExecuteTime
})
for _, v := range list {
opts = append(opts, filter.PropConditionOption{
Label: v.Name,
Value: v.PipelineID,
})
}
return
}(),
Type: filter.PropConditionTypeSelect,
},
}
f.State.Values = PipelineIDValues{
PipelineID: func() uint64 {
if f.State.Values.PipelineID != 0 && !f.State.IsClick {
return f.State.Values.PipelineID
}
if len(list) == 0 {
return 0
}
return list[0].PipelineID
}(),
}
h.SetWaterfallChartPipelineID(f.State.Values.PipelineID)

// clear
f.State.IsClick = false
if err := f.setToComponent(c); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package gshelper

import (
"fmt"

"github.com/mitchellh/mapstructure"

"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
Expand Down Expand Up @@ -264,24 +266,28 @@ func (h *GSHelper) GetAtCaseRateTrendingTimeFilter() AtSceneAndApiTimeFilter {
}

type SelectChartItemData struct {
PlanID uint64 `json:"planID"`
Name string `json:"name"`
PipelineID uint64 `json:"pipelineID"`
PlanID uint64 `json:"planID"`
Name string `json:"name"`
PipelineID uint64 `json:"pipelineID"`
ExecuteTime string `json:"executeTime"`
}

func (h *GSHelper) SetSelectChartItemData(t SelectChartItemData) {
func (h *GSHelper) SetSelectChartItemData(t map[string]SelectChartItemData) {
if h.gs == nil {
return
}
(*h.gs)["GlobalSelectChartItemData"] = t
}

func (h *GSHelper) GetSelectChartHistoryData() SelectChartItemData {
func (h *GSHelper) GetSelectChartHistoryData() map[string]SelectChartItemData {
if h.gs == nil {
return SelectChartItemData{}
return nil
}
data := make(map[string]SelectChartItemData, 0)
err := assign((*h.gs)["GlobalSelectChartItemData"], &data)
if err != nil {
fmt.Println(err)
}
data := SelectChartItemData{}
_ = assign((*h.gs)["GlobalSelectChartItemData"], &data)
return data
}

Expand Down Expand Up @@ -325,3 +331,19 @@ func (h *GSHelper) GetGlobalQualityScore() float64 {
}
return v.(float64)
}

func (h *GSHelper) SetWaterfallChartPipelineID(id uint64) {
if h.gs == nil {
return
}
(*h.gs)["GlobalWaterfallChartPipelineIDs"] = id
}

func (h *GSHelper) GetWaterfallChartPipelineID() uint64 {
if h.gs == nil {
return 0
}
var data uint64
_ = assign((*h.gs)["GlobalWaterfallChartPipelineIDs"], &data)
return data
}
6 changes: 6 additions & 0 deletions modules/dop/component-protocol/scenarios/test-dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,16 @@ rendering:
at_case_rate_trending_chart_filter:
- name: at_case_rate_trending_chart
- name: at_plan_latest_waterfall_chart_filter
state:
- name: "isClick"
value: "{{ at_case_rate_trending_chart_filter.isClick }}"
- name: at_plan_latest_waterfall_chart

at_case_rate_trending_chart:
- name: at_plan_latest_waterfall_chart_filter
state:
- name: "isClick"
value: "{{ at_case_rate_trending_chart.isClick }}"
- name: at_plan_latest_waterfall_chart

scene_and_api_filter:
Expand Down