From 34af969785ef085c540751c8ad599b0ee063db90 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 22 Dec 2023 09:09:03 +0800 Subject: [PATCH] chore: fix list memos order by pinned --- api/v2/memo_service.go | 10 +++++++++- web/src/pages/Home.tsx | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/v2/memo_service.go b/api/v2/memo_service.go index 5f4b9568..6082e1c7 100644 --- a/api/v2/memo_service.go +++ b/api/v2/memo_service.go @@ -62,6 +62,9 @@ func (s *APIV2Service) ListMemos(ctx context.Context, request *apiv2pb.ListMemos if len(filter.Visibilities) > 0 { memoFind.VisibilityList = filter.Visibilities } + if filter.OrderByPinned { + memoFind.OrderByPinned = filter.OrderByPinned + } if filter.CreatedTsBefore != nil { memoFind.CreatedTsBefore = filter.CreatedTsBefore } @@ -516,17 +519,19 @@ func convertVisibilityToStore(visibility apiv2pb.Visibility) store.Visibility { // ListMemosFilterCELAttributes are the CEL attributes for ListMemosFilter. var ListMemosFilterCELAttributes = []cel.EnvOption{ + cel.Variable("content_search", cel.ListType(cel.StringType)), cel.Variable("visibilities", cel.ListType(cel.StringType)), + cel.Variable("order_by_pinned", cel.BoolType), cel.Variable("created_ts_before", cel.IntType), cel.Variable("created_ts_after", cel.IntType), cel.Variable("creator", cel.StringType), - cel.Variable("content_search", cel.ListType(cel.StringType)), cel.Variable("row_status", cel.StringType), } type ListMemosFilter struct { ContentSearch []string Visibilities []store.Visibility + OrderByPinned bool CreatedTsBefore *int64 CreatedTsAfter *int64 Creator *string @@ -570,6 +575,9 @@ func findField(callExpr *expr.Expr_Call, filter *ListMemosFilter) { visibilities = append(visibilities, store.Visibility(value)) } filter.Visibilities = visibilities + } else if idExpr.Name == "order_by_pinned" { + value := callExpr.Args[1].GetConstExpr().GetBoolValue() + filter.OrderByPinned = value } else if idExpr.Name == "created_ts_before" { createdTsBefore := callExpr.Args[1].GetConstExpr().GetInt64Value() filter.CreatedTsBefore = &createdTsBefore diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 9967fb31..6d33cf80 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -34,7 +34,7 @@ const Home = () => { }, [tagQuery, textQuery]); const fetchMemos = async () => { - const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`]; + const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`, `order_by_pinned == true`]; const contentSearch: string[] = []; if (tagQuery) { contentSearch.push(`"#${tagQuery}"`);