Skip to content
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

feat: App list item selectable, goto operation, icon update #3974

Merged
merged 2 commits into from
Jan 26, 2022
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
4 changes: 3 additions & 1 deletion conf/dop/i18n/cp/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ zh:
second: 秒
iterationUnassigned: 待处理
processTip: 执行成功 Action 数/ Action 总数
appNotAuthorized: 暂无所属应用权限
en:
issue-manage: issue manage
issue: issue
Expand Down Expand Up @@ -615,4 +616,5 @@ en:
openAll: Open all
second: Second
iterationUnassigned: Unassigned
processTip: Successful actions/Total actions
processTip: Successful actions/Total actions
appNotAuthorized: No application permission
2 changes: 2 additions & 0 deletions conf/dop/i18n/cp/scenarios/app-list-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zh:
secondAgo: "几秒前"
defaultAppDescription: 可在应用设置修改相关应用描述
myApp: 我参与的
publicProperty: 公开属性
en:
searchByName: Search by name
publicApp: Public application
Expand All @@ -42,3 +43,4 @@ en:
secondAgo: second(s) ago
defaultAppDescription: Edit description in application setting
myApp: My application
publicProperty: Public property
21 changes: 18 additions & 3 deletions modules/dop/component-protocol/components/app-list-all/list/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package list
import (
"strconv"

"github.com/sirupsen/logrus"

"github.com/erda-project/erda-infra/providers/component-protocol/components/list"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil"
Expand All @@ -26,14 +28,24 @@ import (

func (l *List) GenAppKvInfo(item apistructs.ApplicationDTO) (kvs []list.KvInfo) {
var isPublic = "privateApp"
var publicIcon = "private"
if item.IsPublic {
isPublic = "publicApp"
publicIcon = "public"
}
updated := common.UpdatedTime(l.sdk.Ctx, item.UpdatedAt)
runtimeUrlQuery, err := common.GenerateUrlQueryParams(map[string]interface{}{
"app": []string{item.Name},
})
if err != nil {
logrus.Errorf("run time url query encode failed, error: %v", err)
panic(err)
}
kvs = []list.KvInfo{
{
Icon: "lock",
Icon: publicIcon,
Value: l.sdk.I18n(isPublic),
Tip: l.sdk.I18n("publicProperty"),
},
{
Icon: "list-numbers",
Expand All @@ -46,9 +58,12 @@ func (l *List) GenAppKvInfo(item apistructs.ApplicationDTO) (kvs []list.KvInfo)
OpItemBasicServerData: list.OpItemBasicServerData{
Params: map[string]interface{}{
"projectId": item.ProjectID,
"appId": item.ID,
"env": "dev",
},
Target: "projectDeployEnv",
Query: map[string]interface{}{
"advanceFilter__urlQuery": runtimeUrlQuery,
},
Target: "deploy",
},
}).
Build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func (l *List) RegisterBatchOp(opData list.OpBatchRowsHandle) (opFunc cptype.Ope
func (l *List) doFilterApp() (data *list.Data) {
data = &list.Data{}
gh := gshelper.NewGSHelper(l.sdk.GlobalState)
apps, err := l.appListRetriever(gh.GetOption())
selectedOption := gh.GetOption()
apps, err := l.appListRetriever(selectedOption)
if err != nil {
logrus.Errorf("list query app workbench data failed, error: %v", err)
panic(err)
Expand All @@ -138,27 +139,55 @@ func (l *List) doFilterApp() (data *list.Data) {
},
}

myAppMap := make(map[uint64]bool)
if selectedOption != "my" {
orgID, err := strconv.Atoi(l.identity.OrgID)
if err != nil {
panic(err)
}
myApps, err := l.bdl.GetAllMyApps(l.identity.UserID, uint64(orgID), apistructs.ApplicationListRequest{
ProjectID: l.filterReq.ProjectID,
IsSimple: true,
Query: l.filterReq.Query,
PageNo: 1,
PageSize: 1000,
})
if err != nil {
panic(err)
}
for i := 0; i < len(myApps.List); i++ {
myAppMap[myApps.List[i].ID] = true
}
}

for _, p := range apps.List {
_, ok := myAppMap[p.ID]
authorized := selectedOption == "my" || ok
item := list.Item{
ID: strconv.FormatUint(p.ID, 10),
Icon: &commodel.Icon{URL: p.Logo},
Title: p.Name,
Selectable: true,
Selectable: authorized,
KvInfos: l.GenAppKvInfo(p),
Description: l.appDescription(p.Desc),
Operations: map[cptype.OperationKey]cptype.Operation{
list.OpItemClickGoto{}.OpKey(): cputil.NewOpBuilder().
WithSkipRender(true).
WithServerDataPtr(list.OpItemClickGotoServerData{
OpItemBasicServerData: list.OpItemBasicServerData{
Params: map[string]interface{}{
common.OpKeyProjectID: p.ProjectID,
common.OpKeyAppID: p.ID,
list.OpItemClickGoto{}.OpKey(): func() cptype.Operation {
builder := cputil.NewOpBuilder().
WithSkipRender(true).
WithServerDataPtr(list.OpItemClickGotoServerData{
OpItemBasicServerData: list.OpItemBasicServerData{
Params: map[string]interface{}{
common.OpKeyProjectID: p.ProjectID,
common.OpKeyAppID: p.ID,
},
Target: common.OpValTargetRepo,
},
Target: common.OpValTargetRepo,
},
}).
Build(),
})
if !authorized {
builder = builder.WithDisable(true, l.sdk.I18n("appNotAuthorized"))
}
return builder.Build()
}(),
},
}
data.List = append(data.List, item)
Expand Down
28 changes: 28 additions & 0 deletions modules/dop/component-protocol/components/common/urlQuery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 common

import (
"encoding/base64"
"encoding/json"
)

func GenerateUrlQueryParams(obj interface{}) (string, error) {
fb, err := json.Marshal(obj)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(fb), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type Name struct {
type ExtraContent struct {
RenderType string `json:"renderType"`
Value []Label `json:"value"`
ShowCount int `json:"showCount,omitempty"`
}

type Label struct {
Expand Down Expand Up @@ -783,6 +784,7 @@ func (ca *ComponentAction) getNameColumn(issue *apistructs.Issue) Name {
ExtraContent: ExtraContent{
RenderType: "tags",
Value: tags,
ShowCount: 4,
},
}
}
Expand Down