Skip to content

Commit

Permalink
issue-manage: adjust for issue-table
Browse files Browse the repository at this point in the history
  • Loading branch information
sfwn committed Dec 17, 2021
1 parent 51bf70f commit 3a67fd8
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 176 deletions.
3 changes: 0 additions & 3 deletions conf/dop/dop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ component-protocol.components.issue-manage.head:
component-protocol.components.issue-manage.issueAddButton:
component-protocol.components.issue-manage.issueExport:
component-protocol.components.issue-manage.issueFilter:
component-protocol.components.issue-manage.issueGantt:
component-protocol.components.issue-manage.issueImport:
component-protocol.components.issue-manage.issueKanban:
component-protocol.components.issue-manage.issueManage:
component-protocol.components.issue-manage.issueOperations:
component-protocol.components.issue-manage.issueTable:
component-protocol.components.issue-manage.issueViewGroup:
component-protocol.components.issue-manage.topHead:

component-protocol.components.code-coverage.treeMapChart:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 gshelper

import (
"github.com/mitchellh/mapstructure"

"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda/apistructs"
)

const (
keyIssuePagingRequest = "IssuePagingRequest"
)

type GSHelper struct {
gs *cptype.GlobalStateData
}

func NewGSHelper(gs *cptype.GlobalStateData) *GSHelper {
return &GSHelper{gs: gs}
}

func assign(src, dst interface{}) error {
if src == nil || dst == nil {
return nil
}

return mapstructure.Decode(src, dst)
}

func (h *GSHelper) SetIssuePagingRequest(req apistructs.IssuePagingRequest) {
if h.gs == nil {
return
}
(*h.gs)[keyIssuePagingRequest] = req
}

func (h *GSHelper) GetIssuePagingRequest() (*apistructs.IssuePagingRequest, bool) {
if h.gs == nil {
return nil, false
}
v, ok := (*h.gs)[keyIssuePagingRequest]
if !ok {
return nil, false
}
var req apistructs.IssuePagingRequest
_ = assign(v, &req)
return &req, true
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (
"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/bundle"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-manage/common/gshelper"
"github.com/erda-project/erda/modules/dop/component-protocol/types"
"github.com/erda-project/erda/modules/dop/services/issuefilterbm"
"github.com/erda-project/erda/modules/dop/services/issuestate"
)

func (f *ComponentFilter) InitFromProtocol(ctx context.Context, c *cptype.Component) error {
func (f *ComponentFilter) InitFromProtocol(ctx context.Context, c *cptype.Component, gs *cptype.GlobalStateData) error {
// component 序列化
b, err := json.Marshal(c)
if err != nil {
Expand All @@ -46,5 +47,8 @@ func (f *ComponentFilter) InitFromProtocol(ctx context.Context, c *cptype.Compon
return err
}

// gs
f.gsHelper = gshelper.NewGSHelper(gs)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-manage/common/gshelper"
"github.com/erda-project/erda/modules/dop/services/issuefilterbm"
"github.com/erda-project/erda/modules/dop/services/issuestate"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
Expand All @@ -39,6 +40,7 @@ type ComponentFilter struct {
base.DefaultProvider
Bms []issuefilterbm.MyFilterBm `json:"-"` // bookmarks
FlushOptsFromBm string `json:"-"` // bm ID
gsHelper *gshelper.GSHelper
}

// FrontendConditions 前端支持的过滤参数
Expand Down Expand Up @@ -272,48 +274,6 @@ func (f *ComponentFilter) generateFrontendConditionProps(ctx context.Context, fi
})
}

v, ok := state.IssueViewGroupChildrenValue["kanban"]
if state.IssueViewGroupValue != "kanban" || !ok || v != "status" {
statesMap, err := f.issueStateSvc.GetIssueStatesMap(&apistructs.IssueStatesGetRequest{
ProjectID: f.InParams.ProjectID,
})
if err != nil {
return nil
}

status := filter.PropCondition{
Key: PropConditionKeyStates,
Label: cputil.I18n(ctx, "state"),
EmptyText: cputil.I18n(ctx, "all"),
Fixed: true,
ShowIndex: 3,
HaveFilter: false,
Type: filter.PropConditionTypeSelect,
Placeholder: "",
Options: func() []filter.PropConditionOption {
// open := filter.PropConditionOption{Label: cputil.I18n(ctx, "open"), Value: apistructs.IssueStateBelongOpen, Icon: ""}
// reopen := filter.PropConditionOption{Label: cputil.I18n(ctx, "reopen"), Value: apistructs.IssueStateBelongReopen, Icon: ""}
// resolved := filter.PropConditionOption{Label: cputil.I18n(ctx, "resolved"), Value: apistructs.IssueStateBelongResolved, Icon: ""}
// wontfix := filter.PropConditionOption{Label: cputil.I18n(ctx, "wontfix"), Value: apistructs.IssueStateBelongWontfix, Icon: ""}
// closed := filter.PropConditionOption{Label: cputil.I18n(ctx, "closed"), Value: apistructs.IssueStateBelongClosed, Icon: ""}
// working := filter.PropConditionOption{Label: cputil.I18n(ctx, "working"), Value: apistructs.IssueStateBelongWorking, Icon: ""}
// done := filter.PropConditionOption{Label: cputil.I18n(ctx, "done"), Value: apistructs.IssueStateBelongDone, Icon: ""}
switch fixedIssueType {
case "ALL":
return convertAllConditions(ctx, statesMap)
case apistructs.IssueTypeRequirement.String():
return convertConditions(statesMap[apistructs.IssueTypeRequirement])
case apistructs.IssueTypeTask.String():
return convertConditions(statesMap[apistructs.IssueTypeTask])
case apistructs.IssueTypeBug.String():
return convertConditions(statesMap[apistructs.IssueTypeBug])
}
return nil
}(),
}
conditionProps = append(conditionProps[:2], append([]filter.PropCondition{status}, conditionProps[2:]...)...)
}

return conditionProps
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ func Test_convertAllConditions(t *testing.T) {

func Test_generateFrontendConditionProps(t *testing.T) {
ctx := context.WithValue(context.Background(), cptype.GlobalInnerKeyCtxSDK, &cptype.SDK{Tran: &MockTran{}})
f := ComponentFilter{State: State{
IssueViewGroupValue: "kanban",
IssueViewGroupChildrenValue: map[string]string{"kanban": "status"},
}}
f := ComponentFilter{State: State{}}
props := f.generateFrontendConditionProps(ctx, "ALL", f.State)
assert.True(t, len(props) > 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func getMeta(ori map[string]interface{}, dst interface{}) error {

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

Expand Down Expand Up @@ -177,10 +177,11 @@ func (f *ComponentFilter) PostSetState() error {
// condition values

// issuePagingRequest
f.State.IssuePagingRequest, err = f.generateIssuePagingRequest()
issuePagingRequest, err := f.generateIssuePagingRequest()
if err != nil {
return err
}
f.gsHelper.SetIssuePagingRequest(issuePagingRequest)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ type State struct {

// 方便后端使用的 state
IssuePagingRequest apistructs.IssuePagingRequest `json:"issuePagingRequest,omitempty"`

IssueViewGroupValue string `json:"issueViewGroupValue"`
IssueViewGroupChildrenValue map[string]string `json:"issueViewGroupChildrenValue"`
}

// generateUrlQueryKey 实际上组件名在一个协议里是定义好的,即 issueFilter__urlQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/modules/dop/bdl"
"github.com/erda-project/erda/modules/dop/component-protocol/components/common"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-manage/issueViewGroup"
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-manage/common/gshelper"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
"github.com/erda-project/erda/pkg/strutil"

Expand Down Expand Up @@ -219,19 +219,6 @@ var (
)

func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error {
// visible
visible := true
if v, ok := c.State["issueViewGroupValue"]; ok {
if viewType, ok := v.(string); ok {
if viewType != issueViewGroup.ViewTypeTable {
visible = false
c.Props = map[string]interface{}{}
c.Props["visible"] = visible
return nil
}
}
}

sdk := cputil.SDK(ctx)

isGuest, err := ca.CheckUserPermission(ctx)
Expand Down Expand Up @@ -376,15 +363,10 @@ func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scen
}
userids := []string{}
cond := apistructs.IssuePagingRequest{}
filterCond, ok := c.State["filterConditions"]
gh := gshelper.NewGSHelper(gs)
filterCond, ok := gh.GetIssuePagingRequest()
if ok {
filterCondS, err := json.Marshal(filterCond)
if err != nil {
return err
}
if err := json.Unmarshal(filterCondS, &cond); err != nil {
return err
}
cond = *filterCond
resetPageInfo(&cond, c.State)
} else {
issuetype := sdk.InParams["fixedIssueType"].(string)
Expand Down Expand Up @@ -557,7 +539,6 @@ func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scen
"reload": true,
},
}
c.Props["visible"] = visible
(*gs)[protocol.GlobalInnerKeyUserIDs.String()] = userids
if c.State == nil {
c.State = map[string]interface{}{}
Expand Down
99 changes: 1 addition & 98 deletions modules/dop/component-protocol/scenarios/issue-manage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ hierarchy:
left: issueFilter
right: issueOperations
issueOperations:
- issueViewGroup
- issueExport
- issueImport
content:
- issueTable
- issueKanban
- issueGantt

options:
syncIntervalSecond: 0
Expand All @@ -29,7 +26,7 @@ components:
type: Container
head:
type: LRContainer
props:
props:
whiteBg: true
content:
type: Container
Expand All @@ -43,105 +40,11 @@ components:
type: Button
issueImport:
type: Button
issueViewGroup:
type: Radio
issueAddButton:
type: Button
issueTable:
type: Table
issueKanban:
type: IssueKanban
issueGantt:
type: Table

rendering:
# 前端触发组件
# 先渲染前端触发组件,再渲染关联组件
issueViewGroup:
# 关联渲染组件列表
- name: issueFilter
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "issueViewGroupChildrenValue"
value: "{{ issueViewGroup.childrenValue }}"
- name: issueTable
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueKanban
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "issueViewGroupChildrenValue"
value: "{{ issueViewGroup.childrenValue }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueGantt
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"

issueFilter:
- name: issueViewGroup
- name: issueTable
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueKanban
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "issueViewGroupChildrenValue"
value: "{{ issueViewGroup.childrenValue }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueGantt
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"

__DefaultRendering__:
- name: issueManage
- name: topHead
- name: issueAddButton
- name: head
- name: issueOperations
- name: issueViewGroup
- name: issueFilter
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "issueViewGroupChildrenValue"
value: "{{ issueViewGroup.childrenValue }}"
- name: issueExport
- name: issueImport
- name: content
- name: issueTable
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueKanban
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "issueViewGroupChildrenValue"
value: "{{ issueViewGroup.childrenValue }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"
- name: issueGantt
state:
- name: "issueViewGroupValue"
value: "{{ issueViewGroup.value }}"
- name: "filterConditions"
value: "{{ issueFilter.issuePagingRequest }}"

0 comments on commit 3a67fd8

Please sign in to comment.