Skip to content

Commit

Permalink
fix: 分组列表展示优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambition9186 committed Oct 21, 2024
1 parent 576eed7 commit d05d899
Show file tree
Hide file tree
Showing 8 changed files with 3,531 additions and 3,475 deletions.
7 changes: 6 additions & 1 deletion bcs-services/bcs-bscp/cmd/config-server/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *Service) UpdateGroup(ctx context.Context, req *pbcs.UpdateGroupReq) (*p
}

// ListAllGroups list all groups in biz
// nolint:funlen
func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq) (*pbcs.ListAllGroupsResp, error) {
grpcKit := kit.FromGrpcContext(ctx)
resp := new(pbcs.ListAllGroupsResp)
Expand All @@ -206,7 +207,10 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
}

// 1. list all groups
lgResp, err := s.client.DS.ListAllGroups(grpcKit.RpcCtx(), &pbds.ListAllGroupsReq{BizId: req.BizId})
lgResp, err := s.client.DS.ListAllGroups(grpcKit.RpcCtx(), &pbds.ListAllGroupsReq{
BizId: req.BizId,
TopIds: req.TopIds,
})
if err != nil {
logs.Errorf("list groups failed, err: %v, rid: %s", err, grpcKit.Rid)
return nil, err
Expand Down Expand Up @@ -282,6 +286,7 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
}
respData = append(respData, data)
}

resp.Details = respData

return resp, nil
Expand Down
4 changes: 3 additions & 1 deletion bcs-services/bcs-bscp/cmd/data-service/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbds.ListAllGroupsReq)

resp := new(pbds.ListAllGroupsResp)

details, err := s.dao.Group().ListAll(kt, req.BizId)
// StrToUint32Slice the comma separated string goes to uint32 slice
topIds, _ := tools.StrToUint32Slice(req.TopIds)
details, err := s.dao.Group().ListAll(kt, req.BizId, topIds)
if err != nil {
logs.Errorf("list group failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
Expand Down
15 changes: 12 additions & 3 deletions bcs-services/bcs-bscp/pkg/dal/dao/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/utils"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
)
Expand All @@ -35,7 +36,7 @@ type Group interface {
// GetByName get group by name.
GetByName(kit *kit.Kit, bizID uint32, name string) (*table.Group, error)
// ListAll list all the groups in biz.
ListAll(kit *kit.Kit, bizID uint32) ([]*table.Group, error)
ListAll(kit *kit.Kit, bizID uint32, topIds []uint32) ([]*table.Group, error)
// DeleteWithTx delete one group instance with transaction.
DeleteWithTx(kit *kit.Kit, tx *gen.QueryTx, group *table.Group) error
// ListAppGroups list all the groups of the app.
Expand Down Expand Up @@ -158,13 +159,21 @@ func (dao *groupDao) GetByName(kit *kit.Kit, bizID uint32, name string) (*table.
}

// ListAll list all the groups in biz.
func (dao *groupDao) ListAll(kit *kit.Kit, bizID uint32) ([]*table.Group, error) {
func (dao *groupDao) ListAll(kit *kit.Kit, bizID uint32, topIds []uint32) ([]*table.Group, error) {

if bizID == 0 {
return nil, errf.New(errf.InvalidParameter, "biz id is 0")
}
m := dao.genQ.Group
return m.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID)).Find()
q := dao.genQ.Group.WithContext(kit.Ctx)

if len(topIds) != 0 {
q = q.Order(utils.NewCustomExpr(`CASE WHEN id IN (?) THEN 0 ELSE 1 END,name ASC`, []interface{}{topIds}))
} else {
q = q.Order(m.Name)
}

return q.Where(m.BizID.Eq(bizID)).Find()

}

Expand Down
4,218 changes: 2,114 additions & 2,104 deletions bcs-services/bcs-bscp/pkg/protocol/config-server/config_service.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,7 @@ message DeleteGroupResp {}

message ListAllGroupsReq {
uint32 biz_id = 1;
string top_ids = 2;
}

message ListAllGroupsResp {
Expand Down
Loading

0 comments on commit d05d899

Please sign in to comment.