chore: allow search comments

This commit is contained in:
Steven 2024-04-18 21:04:10 +08:00
parent 2cdcd17ba3
commit 339fecbfff
4 changed files with 11 additions and 3 deletions

View File

@ -667,6 +667,9 @@ func (s *APIV2Service) buildMemoFindWithFilter(ctx context.Context, find *store.
if filter.Limit != nil {
find.Limit = filter.Limit
}
if filter.IncludeComments {
find.ExcludeComments = false
}
}
// If the user is not authenticated, only public memos are visible.
@ -703,6 +706,7 @@ var SearchMemosFilterCELAttributes = []cel.EnvOption{
cel.Variable("row_status", cel.StringType),
cel.Variable("random", cel.BoolType),
cel.Variable("limit", cel.IntType),
cel.Variable("include_comments", cel.BoolType),
}
type SearchMemosFilter struct {
@ -716,6 +720,7 @@ type SearchMemosFilter struct {
RowStatus *store.RowStatus
Random bool
Limit *int
IncludeComments bool
}
func parseSearchMemosFilter(expression string) (*SearchMemosFilter, error) {
@ -779,6 +784,9 @@ func findSearchMemosField(callExpr *expr.Expr_Call, filter *SearchMemosFilter) {
} else if idExpr.Name == "limit" {
limit := int(callExpr.Args[1].GetConstExpr().GetInt64Value())
filter.Limit = &limit
} else if idExpr.Name == "include_comments" {
value := callExpr.Args[1].GetConstExpr().GetBoolValue()
filter.IncludeComments = value
}
return
}

View File

@ -30,7 +30,7 @@ const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
async () => {
setIsFetching(true);
try {
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`, `include_comments == true`];
if (searchText) {
filters.push(`content_search == [${JSON.stringify(searchText)}]`);
}

View File

@ -21,7 +21,7 @@ const EmbeddedMemo = ({ resourceId, params: paramsStr }: Props) => {
const resourceName = `memos/${resourceId}`;
useEffect(() => {
memoStore.searchMemos(`uid == "${resourceId}"`).finally(() => loadingState.setFinish());
memoStore.searchMemos(`uid == "${resourceId}" && include_comments == true`).finally(() => loadingState.setFinish());
}, [resourceId]);
if (loadingState.isLoading) {

View File

@ -17,7 +17,7 @@ const ReferencedMemo = ({ resourceId, params: paramsStr }: Props) => {
const params = new URLSearchParams(paramsStr);
useEffect(() => {
memoStore.searchMemos(`uid == "${resourceId}"`).finally(() => loadingState.setFinish());
memoStore.searchMemos(`uid == "${resourceId}" && include_comments == true`).finally(() => loadingState.setFinish());
}, [resourceId]);
if (loadingState.isLoading) {