From 33333d1ca839f1307bf7cae0384b379ba029c500 Mon Sep 17 00:00:00 2001 From: shuofan Date: Thu, 23 Dec 2021 09:55:01 +0800 Subject: [PATCH] Standard issue filter provider, add issue complexity and states --- conf/dop/dop.yaml | 7 +- .../dop/component-protocol/components/all.go | 1 + .../components/issue-kanban/scenario.go | 1 - .../issue-manage/issueFilter/model.go | 44 ++++--- .../issue-manage/issueFilter/state.go | 2 +- .../components/base/provider.go | 12 +- .../components/base/register.go | 7 +- .../components/base/register_test.go | 10 ++ .../issueFilter/conditions.go | 110 +++++++++++++----- .../issueFilter/filterset.go | 1 - .../issueFilter/filterset_test.go | 0 .../issueFilter/in_params.go | 0 .../issueFilter/options.go | 15 +++ .../issueFilter/provider.go | 79 ++++++++----- 14 files changed, 211 insertions(+), 78 deletions(-) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/conditions.go (55%) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/filterset.go (99%) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/filterset_test.go (100%) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/in_params.go (100%) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/options.go (79%) rename {modules/dop/component-protocol/components/issue-kanban => providers/component-protocol}/issueFilter/provider.go (80%) diff --git a/conf/dop/dop.yaml b/conf/dop/dop.yaml index 0b38d52c251..a80a888a302 100644 --- a/conf/dop/dop.yaml +++ b/conf/dop/dop.yaml @@ -55,7 +55,12 @@ erda.dop.contribution: # component-protocol framework component-protocol: + +# default components +component-protocol.default-components.issueFilter: + # components +## issue manage component-protocol.components.issue-manage.content: component-protocol.components.issue-manage.head: component-protocol.components.issue-manage.issueExport: @@ -305,7 +310,7 @@ component-protocol.components.requirement-task-overview.stackChartFilter: ## issue-kanban component-protocol.components.issue-kanban.toolbar: component-protocol.components.issue-kanban.issueExport: -component-protocol.components.issue-kanban.issueFilter: +# component-protocol.components.issue-kanban.issueFilter: component-protocol.components.issue-kanban.issueImport: component-protocol.components.issue-kanban.issueKanbanV2: component-protocol.components.issue-kanban.page: diff --git a/modules/dop/component-protocol/components/all.go b/modules/dop/component-protocol/components/all.go index 95ac15c8de1..38cc09b0f13 100644 --- a/modules/dop/component-protocol/components/all.go +++ b/modules/dop/component-protocol/components/all.go @@ -29,4 +29,5 @@ import ( _ "github.com/erda-project/erda/modules/dop/component-protocol/components/scenes-import-record" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/test-dashboard" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/test-report" + _ "github.com/erda-project/erda/providers/component-protocol/issueFilter" ) diff --git a/modules/dop/component-protocol/components/issue-kanban/scenario.go b/modules/dop/component-protocol/components/issue-kanban/scenario.go index 4f860b8f3e3..b8d871110b3 100644 --- a/modules/dop/component-protocol/components/issue-kanban/scenario.go +++ b/modules/dop/component-protocol/components/issue-kanban/scenario.go @@ -18,7 +18,6 @@ import ( _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/content" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/inputFilter" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/issueExport" - _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/issueFilter" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/issueImport" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/issueKanbanV2" _ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-kanban/issueOperations" diff --git a/modules/dop/component-protocol/components/issue-manage/issueFilter/model.go b/modules/dop/component-protocol/components/issue-manage/issueFilter/model.go index 11387084ac0..ac55caa4e93 100644 --- a/modules/dop/component-protocol/components/issue-manage/issueFilter/model.go +++ b/modules/dop/component-protocol/components/issue-manage/issueFilter/model.go @@ -60,6 +60,7 @@ type FrontendConditions struct { CreatedAtStartEnd []*int64 `json:"createdAtStartEnd,omitempty"` FinishedAtStartEnd []*int64 `json:"finishedAtStartEnd,omitempty"` ClosedAtStartEnd []*int64 `json:"closedAtStartEnd,omitempty"` + Complexities []apistructs.IssueComplexity `json:"complexities,omitempty"` } func (f *ComponentFilter) generateFrontendConditionProps(ctx context.Context, fixedIssueType string, state State) FrontendConditionProps { @@ -136,20 +137,18 @@ func (f *ComponentFilter) generateFrontendConditionProps(ctx context.Context, fi }, }, { - Key: PropConditionKeySeverities, - Label: cputil.I18n(ctx, "severity"), - EmptyText: cputil.I18n(ctx, "all"), - Fixed: false, - ShowIndex: 0, - HaveFilter: false, - Type: filter.PropConditionTypeSelect, - Placeholder: cputil.I18n(ctx, "choose-severity"), + Key: PropConditionKeyComplexity, + Label: cputil.I18n(ctx, "complexity"), + EmptyText: cputil.I18n(ctx, "all"), + Fixed: false, + ShowIndex: 0, + HaveFilter: false, + Type: filter.PropConditionTypeSelect, + // Placeholder: cputil.I18n(ctx, "choose-severity"), Options: []filter.PropConditionOption{ - {Label: cputil.I18n(ctx, "fatal"), Value: "FATAL", Icon: ""}, - {Label: cputil.I18n(ctx, "serious"), Value: "SERIOUS", Icon: ""}, - {Label: cputil.I18n(ctx, "ordinary"), Value: "NORMAL", Icon: ""}, - {Label: cputil.I18n(ctx, "slight"), Value: "SLIGHT", Icon: ""}, - {Label: cputil.I18n(ctx, "suggest"), Value: "SUGGEST", Icon: ""}, + {Label: cputil.I18n(ctx, "HARD"), Value: "HARD", Icon: ""}, + {Label: cputil.I18n(ctx, "NORMAL"), Value: "NORMAL", Icon: ""}, + {Label: cputil.I18n(ctx, "EASY"), Value: "EASY", Icon: ""}, }, }, { @@ -257,6 +256,24 @@ func (f *ComponentFilter) generateFrontendConditionProps(ctx context.Context, fi } if fixedIssueType == apistructs.IssueTypeBug.String() { + severity := filter.PropCondition{ + Key: PropConditionKeySeverities, + Label: cputil.I18n(ctx, "severity"), + EmptyText: cputil.I18n(ctx, "all"), + Fixed: false, + ShowIndex: 0, + HaveFilter: false, + Type: filter.PropConditionTypeSelect, + Placeholder: cputil.I18n(ctx, "choose-severity"), + Options: []filter.PropConditionOption{ + {Label: cputil.I18n(ctx, "fatal"), Value: "FATAL", Icon: ""}, + {Label: cputil.I18n(ctx, "serious"), Value: "SERIOUS", Icon: ""}, + {Label: cputil.I18n(ctx, "ordinary"), Value: "NORMAL", Icon: ""}, + {Label: cputil.I18n(ctx, "slight"), Value: "SLIGHT", Icon: ""}, + {Label: cputil.I18n(ctx, "suggest"), Value: "SUGGEST", Icon: ""}, + }, + } + conditionProps = append(conditionProps[:4], append([]filter.PropCondition{severity}, conditionProps[4:]...)...) conditionProps = append(conditionProps, filter.PropCondition{ Key: PropConditionKeyClosed, Label: cputil.I18n(ctx, "closed-at"), @@ -349,6 +366,7 @@ var ( PropConditionKeyCreatedAtStartEnd filter.PropConditionKey = "createdAtStartEnd" PropConditionKeyFinishedAtStartEnd filter.PropConditionKey = "finishedAtStartEnd" PropConditionKeyClosed filter.PropConditionKey = "closedAtStartEnd" + PropConditionKeyComplexity filter.PropConditionKey = "complexities" ) func GetAllOperations() map[filter.OperationKey]filter.Operation { diff --git a/modules/dop/component-protocol/components/issue-manage/issueFilter/state.go b/modules/dop/component-protocol/components/issue-manage/issueFilter/state.go index 49e751c0ca4..ccb1e9b17f1 100644 --- a/modules/dop/component-protocol/components/issue-manage/issueFilter/state.go +++ b/modules/dop/component-protocol/components/issue-manage/issueFilter/state.go @@ -108,7 +108,7 @@ func (f *ComponentFilter) generateIssuePagingRequest() (apistructs.IssuePagingRe StartClosedAt: startClosedAt, EndClosedAt: endClosedAt, Priority: f.State.FrontendConditionValues.Priorities, - Complexity: nil, + Complexity: f.State.FrontendConditionValues.Complexities, Severity: f.State.FrontendConditionValues.Severities, RelatedIssueIDs: nil, Source: "", diff --git a/modules/openapi/component-protocol/components/base/provider.go b/modules/openapi/component-protocol/components/base/provider.go index e2001b7aaf1..81731950d5f 100644 --- a/modules/openapi/component-protocol/components/base/provider.go +++ b/modules/openapi/component-protocol/components/base/provider.go @@ -70,11 +70,15 @@ func InitProvider(scenario, compName string) { // InitProviderWithCreator register component as provider with custom providerCreator. func InitProviderWithCreator(scenario, compName string, creator servicehub.Creator) { + initProviderWithCustomName(MakeComponentProviderName(scenario, compName), creator) +} + +func initProviderWithCustomName(providerName string, creator servicehub.Creator) { if creator == nil { creator = func() servicehub.Provider { return &DefaultProvider{} } } - servicehub.Register(MakeComponentProviderName(scenario, compName), &servicehub.Spec{Creator: creator}) - compCreatorMap[MakeComponentProviderName(scenario, compName)] = func() Creators { + servicehub.Register(providerName, &servicehub.Spec{Creator: creator}) + compCreatorMap[providerName] = func() Creators { switch creator().(type) { case cptype.IComponent: return Creators{ComponentCreator: func() cptype.IComponent { @@ -90,3 +94,7 @@ func InitProviderWithCreator(scenario, compName string, creator servicehub.Creat } }() } + +func InitProviderToDefaultNamespace(compName string, creator servicehub.Creator) { + initProviderWithCustomName(defaultComponentProviderNamePrefix+compName, creator) +} diff --git a/modules/openapi/component-protocol/components/base/register.go b/modules/openapi/component-protocol/components/base/register.go index e75de5468cd..9fcfec382f3 100644 --- a/modules/openapi/component-protocol/components/base/register.go +++ b/modules/openapi/component-protocol/components/base/register.go @@ -20,7 +20,8 @@ import ( ) const ( - componentProviderNamePrefix = "component-protocol.components." + componentProviderNamePrefix = "component-protocol.components." + defaultComponentProviderNamePrefix = "component-protocol.default-components." ) func MustGetScenarioAndCompNameFromProviderKey(providerKey string) (scenario, compName, instanceName string) { @@ -33,6 +34,10 @@ func MustGetScenarioAndCompNameFromProviderKey(providerKey string) (scenario, co } func GetScenarioAndCompNameFromProviderKey(providerKey string) (scenario, compName, instanceName string, err error) { + if strings.HasPrefix(providerKey, defaultComponentProviderNamePrefix) { + ss := strings.SplitN(providerKey, ".", 3) + return "", ss[2], ss[2], nil + } if !strings.HasPrefix(providerKey, componentProviderNamePrefix) { return "", "", "", fmt.Errorf("invalid prefix") } diff --git a/modules/openapi/component-protocol/components/base/register_test.go b/modules/openapi/component-protocol/components/base/register_test.go index 86b4ff6e499..3bc3dda6685 100644 --- a/modules/openapi/component-protocol/components/base/register_test.go +++ b/modules/openapi/component-protocol/components/base/register_test.go @@ -70,6 +70,16 @@ func TestGetScenarioAndCompNameFromProviderKey(t *testing.T) { wantInstanceName: "", haveErr: true, }, + { + name: "valid default namespace key", + args: args{ + providerKey: "component-protocol.default-components.filter", + }, + wantScenario: "", + wantCompName: "filter", + wantInstanceName: "filter", + haveErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/conditions.go b/providers/component-protocol/issueFilter/conditions.go similarity index 55% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/conditions.go rename to providers/component-protocol/issueFilter/conditions.go index 220f6e64cf8..eaa8ad1770b 100644 --- a/modules/dop/component-protocol/components/issue-kanban/issueFilter/conditions.go +++ b/providers/component-protocol/issueFilter/conditions.go @@ -15,12 +15,15 @@ package issueFilter import ( + "context" + "strings" + model "github.com/erda-project/erda-infra/providers/component-protocol/components/filter/models" "github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil" "github.com/erda-project/erda/apistructs" ) -var ( +const ( PropConditionKeyFilterID string = "filterID" // special, need emit it when hashing filter PropConditionKeyIterationIDs string = "iterationIDs" PropConditionKeyTitle string = "title" @@ -36,8 +39,28 @@ var ( PropConditionKeyCreatedAtStartEnd string = "createdAtStartEnd" PropConditionKeyFinishedAtStartEnd string = "finishedAtStartEnd" PropConditionKeyClosed string = "closedAtStartEnd" + PropConditionKeyComplexity string = "complexities" ) +type FrontendConditions struct { + FilterID string `json:"filterID,omitempty"` + IterationIDs []int64 `json:"iterationIDs,omitempty"` + Title string `json:"title,omitempty"` + StateBelongs []apistructs.IssueStateBelong `json:"stateBelongs,omitempty"` + States []int64 `json:"states,omitempty"` + LabelIDs []uint64 `json:"labelIDs,omitempty"` + Priorities []apistructs.IssuePriority `json:"priorities,omitempty"` + Severities []apistructs.IssueSeverity `json:"severities,omitempty"` + CreatorIDs []string `json:"creatorIDs,omitempty"` + AssigneeIDs []string `json:"assigneeIDs,omitempty"` + OwnerIDs []string `json:"ownerIDs,omitempty"` + BugStages []string `json:"bugStages,omitempty"` + CreatedAtStartEnd []*int64 `json:"createdAtStartEnd,omitempty"` + FinishedAtStartEnd []*int64 `json:"finishedAtStartEnd,omitempty"` + ClosedAtStartEnd []*int64 `json:"closedAtStartEnd,omitempty"` + Complexities []apistructs.IssueComplexity `json:"complexities,omitempty"` +} + func (f *IssueFilter) ConditionRetriever() ([]interface{}, error) { needIterationCond := true if f.InParams.FrontendFixedIteration != "" { @@ -89,6 +112,12 @@ func (f *IssueFilter) ConditionRetriever() ([]interface{}, error) { *model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "architecture-design"), "architectureDesign"), *model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "code-development"), "codeDevelopment"), } + if f.InParams.FrontendFixedIssueType == apistructs.IssueTypeTask.String() || f.InParams.FrontendFixedIssueType == apistructs.IssueTypeBug.String() { + stageOptions, err = f.getPropStagesOptions(f.InParams.FrontendFixedIssueType) + if err != nil { + return nil, err + } + } stage := model.NewSelectCondition(PropConditionKeyBugStages, func() string { switch f.InParams.FrontendFixedIssueType { case "ALL": @@ -110,35 +139,64 @@ func (f *IssueFilter) ConditionRetriever() ([]interface{}, error) { if needIterationCond { conditions = []interface{}{iterations} } + + complexityOptions := []model.SelectOption{ + *model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "HARD"), "HARD"), + *model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "NORMAL"), "NORMAL"), + *model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "EASY"), "EASY"), + } + complexity := model.NewSelectCondition(PropConditionKeyComplexity, cputil.I18n(f.sdk.Ctx, "complexity"), complexityOptions) + + // statesMap, err := f.issueStateSvc.GetIssueStatesMap(&apistructs.IssueStatesGetRequest{ + // ProjectID: f.InParams.ProjectID, + // }) + // if err != nil { + // return nil, err + // } + + // status := func() interface{} { + // switch f.InParams.FrontendFixedIssueType { + // case "ALL": + // return model.NewSelectConditionWithChildren(PropConditionKeyStates, cputil.I18n(f.sdk.Ctx, "state"), convertAllConditions(f.sdk.Ctx, statesMap)) + // case apistructs.IssueTypeRequirement.String(): + // return model.NewSelectCondition(PropConditionKeyStates, cputil.I18n(f.sdk.Ctx, "state"), convertConditions(statesMap[apistructs.IssueTypeRequirement])) + // case apistructs.IssueTypeTask.String(): + // return model.NewSelectCondition(PropConditionKeyStates, cputil.I18n(f.sdk.Ctx, "state"), convertConditions(statesMap[apistructs.IssueTypeTask])) + // case apistructs.IssueTypeBug.String(): + // return model.NewSelectCondition(PropConditionKeyStates, cputil.I18n(f.sdk.Ctx, "state"), convertConditions(statesMap[apistructs.IssueTypeBug])) + // } + // return nil + // }() + switch f.InParams.FrontendFixedIssueType { case apistructs.IssueTypeRequirement.String(): - conditions = append(conditions, labels, priority, creator, assignee, created, finished) + conditions = append(conditions, labels, priority, complexity, creator, assignee, created, finished) case apistructs.IssueTypeTask.String(): - conditions = append(conditions, labels, priority, creator, assignee, stage, created, finished) + conditions = append(conditions, labels, priority, complexity, creator, assignee, stage, created, finished) case apistructs.IssueTypeBug.String(): - conditions = append(conditions, labels, priority, severity, creator, assignee, owner, stage, created, finished, closed) + conditions = append(conditions, labels, priority, complexity, severity, creator, assignee, owner, stage, created, finished, closed) + case "ALL": + conditions = append(conditions, labels, priority, complexity, creator, assignee, owner, created, finished) } + return conditions, nil - // stateBelongs := map[string][]apistructs.IssueStateBelong{ - // "TASK": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking}, - // "REQUIREMENT": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking}, - // "BUG": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking, apistructs.IssueStateBelongWontfix, apistructs.IssueStateBelongReopen, apistructs.IssueStateBelongResolved}, - // "ALL": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking, apistructs.IssueStateBelongWontfix, apistructs.IssueStateBelongReopen, apistructs.IssueStateBelongResolved}, - // }[f.InParams.FrontendFixedIssueType] - // types := []apistructs.IssueType{apistructs.IssueTypeRequirement, apistructs.IssueTypeTask, apistructs.IssueTypeBug} - // res := make(map[string][]int64) - // res["ALL"] = make([]int64, 0) - // for _, v := range types { - // req := &apistructs.IssueStatesGetRequest{ - // ProjectID: f.InParams.ProjectID, - // StateBelongs: stateBelongs, - // IssueType: v, - // } - // ids, err := f.issueStateSvc.GetIssueStateIDs(req) - // if err != nil { - // panic(err) - // } - // res[v.String()] = ids - // res["ALL"] = append(res["ALL"], ids...) - // } +} + +func convertConditions(status []apistructs.IssueStatus) []model.SelectOption { + options := make([]model.SelectOption, 0, len(status)) + for _, i := range status { + options = append(options, *model.NewSelectOption(i.StateName, i.StateID)) + } + return options +} + +func convertAllConditions(ctx context.Context, stateMap map[apistructs.IssueType][]apistructs.IssueStatus) []model.SelectOptionWithChildren { + options := make([]model.SelectOptionWithChildren, 0, len(stateMap)) + for i, v := range stateMap { + options = append(options, model.SelectOptionWithChildren{ + SelectOption: *model.NewSelectOption(cputil.I18n(ctx, strings.ToLower(i.String())), i.String()), + Children: convertConditions(v), + }) + } + return options } diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/filterset.go b/providers/component-protocol/issueFilter/filterset.go similarity index 99% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/filterset.go rename to providers/component-protocol/issueFilter/filterset.go index ffd53f34593..f5f2c98ca0e 100644 --- a/modules/dop/component-protocol/components/issue-kanban/issueFilter/filterset.go +++ b/providers/component-protocol/issueFilter/filterset.go @@ -50,7 +50,6 @@ func (f *IssueFilter) FilterSet() ([]filter.SetItem, error) { if err != nil { return nil, err } - // for options = append(options, filter.SetItem{ ID: i.ID, Label: i.Name, diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/filterset_test.go b/providers/component-protocol/issueFilter/filterset_test.go similarity index 100% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/filterset_test.go rename to providers/component-protocol/issueFilter/filterset_test.go diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/in_params.go b/providers/component-protocol/issueFilter/in_params.go similarity index 100% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/in_params.go rename to providers/component-protocol/issueFilter/in_params.go diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/options.go b/providers/component-protocol/issueFilter/options.go similarity index 79% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/options.go rename to providers/component-protocol/issueFilter/options.go index 6380c26f6c0..2be010fe6e9 100644 --- a/modules/dop/component-protocol/components/issue-kanban/issueFilter/options.go +++ b/providers/component-protocol/issueFilter/options.go @@ -16,6 +16,7 @@ package issueFilter import ( model "github.com/erda-project/erda-infra/providers/component-protocol/components/filter/models" + "github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil" "github.com/erda-project/erda/apistructs" ) @@ -70,5 +71,19 @@ func (f *IssueFilter) getProjectMemberOptions() ([]model.SelectOption, error) { member.UserID, )) } + selectMe := model.NewSelectOption(cputil.I18n(f.sdk.Ctx, "choose-yourself"), f.sdk.Identity.UserID).WithFix(true) + results = append(results, *selectMe) return results, nil } + +func (f *IssueFilter) getPropStagesOptions(tp string) ([]model.SelectOption, error) { + stages, err := f.bdl.GetIssueStage(int64(f.InParams.OrgID), apistructs.IssueType(tp)) + if err != nil { + return nil, err + } + var options []model.SelectOption + for _, stage := range stages { + options = append(options, *model.NewSelectOption(stage.Name, stage.Value)) + } + return options, nil +} diff --git a/modules/dop/component-protocol/components/issue-kanban/issueFilter/provider.go b/providers/component-protocol/issueFilter/provider.go similarity index 80% rename from modules/dop/component-protocol/components/issue-kanban/issueFilter/provider.go rename to providers/component-protocol/issueFilter/provider.go index 2234d610b0c..4e08e44d718 100644 --- a/modules/dop/component-protocol/components/issue-kanban/issueFilter/provider.go +++ b/providers/component-protocol/issueFilter/provider.go @@ -46,9 +46,8 @@ type IssueFilter struct { filterReq apistructs.IssuePagingRequest `json:"-"` State State `json:"_"` - // FrontendConditionValues FrontendConditions `json:"-"` - InParams InParams `json:"-"` - Bms []issuefilterbm.MyFilterBm `json:"-"` + InParams InParams `json:"-"` + Bms []issuefilterbm.MyFilterBm `json:"-"` } type State struct { @@ -57,26 +56,16 @@ type State struct { SelectedFilterSet string `json:"selectedFilterSet,omitempty"` } -type FrontendConditions struct { - FilterID string `json:"filterID,omitempty"` - IterationIDs []int64 `json:"iterationIDs,omitempty"` - Title string `json:"title,omitempty"` - StateBelongs []apistructs.IssueStateBelong `json:"stateBelongs,omitempty"` - States []int64 `json:"states,omitempty"` - LabelIDs []uint64 `json:"labelIDs,omitempty"` - Priorities []apistructs.IssuePriority `json:"priorities,omitempty"` - Severities []apistructs.IssueSeverity `json:"severities,omitempty"` - CreatorIDs []string `json:"creatorIDs,omitempty"` - AssigneeIDs []string `json:"assigneeIDs,omitempty"` - OwnerIDs []string `json:"ownerIDs,omitempty"` - BugStages []string `json:"bugStages,omitempty"` - CreatedAtStartEnd []*int64 `json:"createdAtStartEnd,omitempty"` - FinishedAtStartEnd []*int64 `json:"finishedAtStartEnd,omitempty"` - ClosedAtStartEnd []*int64 `json:"closedAtStartEnd,omitempty"` +func (p *IssueFilter) Init(ctx servicehub.Context) error { + return p.DefaultProvider.Init(ctx) +} + +func (p *IssueFilter) Provide(ctx servicehub.DependencyContext, args ...interface{}) interface{} { + return p } func init() { - base.InitProviderWithCreator("issue-kanban", "issueFilter", func() servicehub.Provider { + base.InitProviderToDefaultNamespace("issueFilter", func() servicehub.Provider { return &IssueFilter{} }) } @@ -113,6 +102,16 @@ func (f *IssueFilter) RegisterInitializeOp() (opFunc cptype.OperationFunc) { panic(err) } } + // if f.State.FrontendConditionValues.States == nil { + // if err := f.setDefaultState(); err != nil { + // panic(err) + // } + // } + f.StdDataPtr.Operations = map[cptype.OperationKey]cptype.Operation{ + filter.OpFilter{}.OpKey(): cputil.NewOpBuilder().Build(), + filter.OpFilterItemSave{}.OpKey(): cputil.NewOpBuilder().Build(), + filter.OpFilterItemDelete{}.OpKey(): cputil.NewOpBuilder().Build(), + } } } @@ -242,17 +241,6 @@ func (f *IssueFilter) generateIssuePagingRequest() apistructs.IssuePagingRequest } } - // var iterations []int64 - // for _, i := range f.State.FrontendConditionValues.IterationIDs { - // // item, _ := strconv.Atoi(i) - // iterations = append(iterations, i) - // } - // var labels []uint64 - // for _, i := range f.State.FrontendConditionValues.LabelIDs { - // // item, _ := strconv.Atoi(i) - // labels = append(labels, i) - // } - req := apistructs.IssuePagingRequest{ PageNo: 1, // 每次走 filter,都需要重新查询,调整 pageNo 为 1 PageSize: 0, @@ -277,7 +265,7 @@ func (f *IssueFilter) generateIssuePagingRequest() apistructs.IssuePagingRequest StartClosedAt: startClosedAt, EndClosedAt: endClosedAt, Priority: f.State.FrontendConditionValues.Priorities, - Complexity: nil, + Complexity: f.State.FrontendConditionValues.Complexities, Severity: f.State.FrontendConditionValues.Severities, RelatedIssueIDs: nil, Source: "", @@ -295,3 +283,30 @@ func (f *IssueFilter) generateIssuePagingRequest() apistructs.IssuePagingRequest } return req } + +func (f *IssueFilter) setDefaultState() error { + stateBelongs := map[string][]apistructs.IssueStateBelong{ + "TASK": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking}, + "REQUIREMENT": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking}, + "BUG": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking, apistructs.IssueStateBelongWontfix, apistructs.IssueStateBelongReopen, apistructs.IssueStateBelongResolved}, + "ALL": {apistructs.IssueStateBelongOpen, apistructs.IssueStateBelongWorking, apistructs.IssueStateBelongWontfix, apistructs.IssueStateBelongReopen, apistructs.IssueStateBelongResolved}, + }[f.InParams.FrontendFixedIssueType] + types := []apistructs.IssueType{apistructs.IssueTypeRequirement, apistructs.IssueTypeTask, apistructs.IssueTypeBug} + res := make(map[string][]int64) + res["ALL"] = make([]int64, 0) + for _, v := range types { + req := &apistructs.IssueStatesGetRequest{ + ProjectID: f.InParams.ProjectID, + StateBelongs: stateBelongs, + IssueType: v, + } + ids, err := f.issueStateSvc.GetIssueStateIDs(req) + if err != nil { + return err + } + res[v.String()] = ids + res["ALL"] = append(res["ALL"], ids...) + } + f.State.FrontendConditionValues.States = res[f.InParams.FrontendFixedIssueType] + return nil +}