Skip to content

Commit

Permalink
Add issue owner bar chart, structure change (#2404) (#2406)
Browse files Browse the repository at this point in the history
Co-authored-by: shuofan <fanshuo2015@gmail.com>
  • Loading branch information
erda-bot and shuofan authored Oct 15, 2021
1 parent 4ae9c1b commit 701c281
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conf/dop/dop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ component-protocol.components.issue-dashboard.assigneeHorizontalBarChart:
component-protocol.components.issue-dashboard.assigneeHorizontalBarChartExtra:
component-protocol.components.issue-dashboard.assigneeHorizontalBarChartFilter:

component-protocol.components.issue-dashboard.ownerHorizontalBarChart:
component-protocol.components.issue-dashboard.ownerHorizontalBarChartExtra:
component-protocol.components.issue-dashboard.ownerHorizontalBarChartFilter:

component-protocol.components.issue-dashboard.reset:
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ownerHorizontalBarChart

import (
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common"
"github.com/erda-project/erda/modules/dop/services/issuestate"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
)

type ComponentAction struct {
sdk *cptype.SDK
bdl *bundle.Bundle
issueStateSvc *issuestate.IssueState
State State `json:"state,omitempty"`
base.DefaultProvider
}

type State struct {
Values common.FilterConditions `json:"values,omitempty"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ownerHorizontalBarChart

import (
"context"
"encoding/json"

"github.com/go-echarts/go-echarts/v2/opts"

"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/chartbuilders"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/gshelper"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/stackhandlers"
"github.com/erda-project/erda/modules/dop/dao"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
)

func init() {
base.InitProviderWithCreator("issue-dashboard", "ownerHorizontalBarChart",
func() servicehub.Provider { return &ComponentAction{} })
}

func (f *ComponentAction) getState(c *cptype.Component) error {
d, err := json.Marshal(c.State)
if err != nil {
return err
}
return json.Unmarshal(d, &f.State)
}

func (f *ComponentAction) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error {

if err := f.getState(c); err != nil {
return err
}

helper := gshelper.NewGSHelper(gs)

members := helper.GetMembers()
memberMap := make(map[string]*apistructs.Member)
for i := range members {
m := &members[i]
memberMap[m.UserID] = m
}

issueList := helper.GetIssueList()
var bugList []interface{}
for i := range issueList {
bugList = append(bugList, &issueList[i])
}

handler := stackhandlers.NewStackRetriever(
stackhandlers.WithIssueStateList(helper.GetIssueStateList()),
stackhandlers.WithIssueStageList(helper.GetIssueStageList()),
).GetRetriever(f.State.Values.Type)

builder := &chartbuilders.BarBuilder{
Items: bugList,
StackHandler: handler,
FixedXAxisOrTop: chartbuilders.FixedXAxisOrTop{
Top: 500,
XIndexer: getXIndexer(),
XDisplayConverter: func(opt *chartbuilders.FixedXAxisOrTop) opts.XAxis {
return opts.XAxis{
Type: "value",
Max: opt.MaxValue,
}
},
},
YAxisOpt: chartbuilders.YAxisOpt{
YDisplayConverter: func(opt *chartbuilders.YAxisOpt) opts.YAxis {
var names []string
for _, userID := range opt.YAxis {
var name string
m, ok := memberMap[userID]
if ok && m != nil {
name = m.Nick
}
names = append(names, name)
}
return opts.YAxis{
Type: "category",
Data: names,
}
},
},
StackOpt: chartbuilders.StackOpt{
SkipEmpty: true,
},
DataHandleOpt: chartbuilders.DataHandleOpt{
SeriesConverter: chartbuilders.GetStackBarSingleSeriesConverter(),
DataWhiteList: f.State.Values.Value,
},
Result: chartbuilders.Result{
PostProcessor: chartbuilders.GetHorizontalPostProcessor(),
},
}

if err := builder.Generate(); err != nil {
return err
}

props := make(map[string]interface{})
props["title"] = "缺陷 - 按责任者分布(Top 500)"
props["chartType"] = "bar"
props["option"] = builder.Result.Bb
props["style"] = map[string]interface{}{"height": 400}

c.Props = props
c.State = nil
return nil
}

func getXIndexer() func(interface{}) string {
return func(item interface{}) string {
return item.(*dao.IssueItem).Owner
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ownerHorizontalBarChartExtra

import "github.com/erda-project/erda/modules/openapi/component-protocol/components/base"

func init() {
base.InitProvider("issue-dashboard", "ownerHorizontalBarChartExtra")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ownerHorizontalBarChartFilter

import (
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/filter"
)

type ComponentFilter struct {
sdk *cptype.SDK
filter.CommonFilter
State State `json:"state,omitempty"`
base.DefaultProvider
}

type State struct {
Conditions []filter.PropCondition `json:"conditions,omitempty"`
Values common.FilterConditions `json:"values,omitempty"`
FrontendChangedKey string `json:"changedKey,omitempty"`
}

const OperationKeyFilter filter.OperationKey = "filter"
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ownerHorizontalBarChartFilter

import (
"context"
"encoding/json"

"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/gshelper"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/stackhandlers"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/filter"
)

func init() {
base.InitProviderWithCreator("issue-dashboard", "ownerHorizontalBarChartFilter",
func() servicehub.Provider { return &ComponentFilter{} })
}

func (f *ComponentFilter) InitFromProtocol(ctx context.Context, c *cptype.Component) error {
// component 序列化
b, err := json.Marshal(c)
if err != nil {
return err
}
if err := json.Unmarshal(b, f); err != nil {
return err
}

// sdk
f.sdk = cputil.SDK(ctx)

return nil
}

func (f *ComponentFilter) SetToProtocolComponent(c *cptype.Component) error {
b, err := json.Marshal(f)
if err != nil {
return err
}
if err := json.Unmarshal(b, &c); err != nil {
return err
}
return nil
}

func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error {
if err := f.InitFromProtocol(ctx, c); err != nil {
return err
}

if err := f.InitDefaultOperation(ctx, f.State, gs); err != nil {
return err
}

return f.SetToProtocolComponent(c)
}

func (f *ComponentFilter) InitDefaultOperation(ctx context.Context, state State, gs *cptype.GlobalStateData) error {
if f.State.Values.Type == "" {
f.State.Values.Type = stackhandlers.Priority
}
if f.State.FrontendChangedKey == "type" {
f.State.Values.Value = nil
}
helper := gshelper.NewGSHelper(gs)
handler := stackhandlers.NewStackRetriever(
stackhandlers.WithIssueStateList(helper.GetIssueStateList()),
stackhandlers.WithIssueStageList(helper.GetIssueStageList()),
).GetRetriever(f.State.Values.Type)
f.State.Conditions = []filter.PropCondition{
{
EmptyText: "全部",
Fixed: true,
Key: "type",
Label: "类型",
Options: []filter.PropConditionOption{
{
Label: "优先级",
Value: stackhandlers.Priority,
},
{
Label: "复杂度",
Value: stackhandlers.Complexity,
},
{
Label: "严重程度",
Value: stackhandlers.Severity,
},
{
Label: "状态",
Value: stackhandlers.State,
},
{
Label: "引入源",
Value: stackhandlers.Stage,
},
},
Required: true,
Type: filter.PropConditionTypeSelect,
CustomProps: map[string]interface{}{
"mode": "single",
},
},
{
EmptyText: "全部",
Fixed: true,
Key: "value",
Label: "具体值",
Options: handler.GetFilterOptions(),
Type: filter.PropConditionTypeSelect,
},
}

f.Props = filter.Props{
Delay: 1000,
}
f.Operations = map[filter.OperationKey]filter.Operation{
OperationKeyFilter: {
Key: OperationKeyFilter,
Reload: true,
},
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/labelHorizontalBarChart"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/labelHorizontalBarChartExtra"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/labelHorizontalBarChartFilter"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChart"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChartExtra"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChartFilter"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/stateVerticalBarChart"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/stateVerticalBarChartExtra"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/bar/stateVerticalBarChartFilter"
Expand Down
Loading

0 comments on commit 701c281

Please sign in to comment.