Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
9909fd8a
Unverified
Commit
9909fd8a
authored
Jul 15, 2024
by
Johnny
Committed by
GitHub
Jul 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add snippet field to memo message (#3689)
parent
bcb88432
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
418 additions
and
380 deletions
+418
-380
apidocs.swagger.yaml
docs/apidocs.swagger.yaml
+6
-0
memo_service.proto
proto/api/v1/memo_service.proto
+3
-0
memo_service.pb.go
proto/gen/api/v1/memo_service.pb.go
+383
-372
memo_service.go
server/router/api/v1/memo_service.go
+20
-0
CreateMemoRelationDialog.tsx
web/src/components/CreateMemoRelationDialog.tsx
+6
-8
No files found.
docs/apidocs.swagger.yaml
View file @
9909fd8a
...
@@ -969,6 +969,9 @@ paths:
...
@@ -969,6 +969,9 @@ paths:
type
:
string
type
:
string
title
:
"
The
name
of
the
parent
memo.
\r\n
Format:
memos/{id}"
title
:
"
The
name
of
the
parent
memo.
\r\n
Format:
memos/{id}"
readOnly
:
true
readOnly
:
true
snippet
:
type
:
string
description
:
The snippet of the memo content. Plain text only.
tags
:
tags
:
-
MemoService
-
MemoService
/api/v1/{name_1}
:
/api/v1/{name_1}
:
...
@@ -2644,6 +2647,9 @@ definitions:
...
@@ -2644,6 +2647,9 @@ definitions:
type
:
string
type
:
string
title
:
"
The
name
of
the
parent
memo.
\r\n
Format:
memos/{id}"
title
:
"
The
name
of
the
parent
memo.
\r\n
Format:
memos/{id}"
readOnly
:
true
readOnly
:
true
snippet
:
type
:
string
description
:
The snippet of the memo content. Plain text only.
v1MemoProperty
:
v1MemoProperty
:
type
:
object
type
:
object
properties
:
properties
:
...
...
proto/api/v1/memo_service.proto
View file @
9909fd8a
...
@@ -206,6 +206,9 @@ message Memo {
...
@@ -206,6 +206,9 @@ message Memo {
// The name of the parent memo.
// The name of the parent memo.
// Format: memos/{id}
// Format: memos/{id}
optional
string
parent
=
18
[(
google.api.field_behavior
)
=
OUTPUT_ONLY
];
optional
string
parent
=
18
[(
google.api.field_behavior
)
=
OUTPUT_ONLY
];
// The snippet of the memo content. Plain text only.
string
snippet
=
19
;
}
}
message
MemoProperty
{
message
MemoProperty
{
...
...
proto/gen/api/v1/memo_service.pb.go
View file @
9909fd8a
This diff is collapsed.
Click to expand it.
server/router/api/v1/memo_service.go
View file @
9909fd8a
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"github.com/usememos/gomark/ast"
"github.com/usememos/gomark/ast"
"github.com/usememos/gomark/parser"
"github.com/usememos/gomark/parser"
"github.com/usememos/gomark/parser/tokenizer"
"github.com/usememos/gomark/parser/tokenizer"
"github.com/usememos/gomark/renderer"
"github.com/usememos/gomark/restore"
"github.com/usememos/gomark/restore"
expr
"google.golang.org/genproto/googleapis/api/expr/v1alpha1"
expr
"google.golang.org/genproto/googleapis/api/expr/v1alpha1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
...
@@ -869,6 +870,11 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
...
@@ -869,6 +870,11 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
return
nil
,
errors
.
Wrap
(
err
,
"failed to parse content"
)
return
nil
,
errors
.
Wrap
(
err
,
"failed to parse content"
)
}
}
snippet
,
err
:=
getMemoContentSnippet
(
memo
.
Content
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to get memo content snippet"
)
}
memoMessage
:=
&
v1pb
.
Memo
{
memoMessage
:=
&
v1pb
.
Memo
{
Name
:
name
,
Name
:
name
,
Uid
:
memo
.
UID
,
Uid
:
memo
.
UID
,
...
@@ -878,6 +884,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
...
@@ -878,6 +884,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
UpdateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
UpdatedTs
,
0
)),
UpdateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
UpdatedTs
,
0
)),
DisplayTime
:
timestamppb
.
New
(
time
.
Unix
(
displayTs
,
0
)),
DisplayTime
:
timestamppb
.
New
(
time
.
Unix
(
displayTs
,
0
)),
Content
:
memo
.
Content
,
Content
:
memo
.
Content
,
Snippet
:
snippet
,
Nodes
:
convertFromASTNodes
(
nodes
),
Nodes
:
convertFromASTNodes
(
nodes
),
Visibility
:
convertVisibilityFromStore
(
memo
.
Visibility
),
Visibility
:
convertVisibilityFromStore
(
memo
.
Visibility
),
Pinned
:
memo
.
Pinned
,
Pinned
:
memo
.
Pinned
,
...
@@ -1286,3 +1293,16 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*v1pb.WebhookRequestPayload,
...
@@ -1286,3 +1293,16 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*v1pb.WebhookRequestPayload,
Memo
:
memo
,
Memo
:
memo
,
},
nil
},
nil
}
}
func
getMemoContentSnippet
(
content
string
)
(
string
,
error
)
{
nodes
,
err
:=
parser
.
Parse
(
tokenizer
.
Tokenize
(
content
))
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"failed to parse content"
)
}
plainText
:=
renderer
.
NewStringRenderer
()
.
Render
(
nodes
)
if
len
(
plainText
)
>
100
{
return
plainText
[
:
100
]
+
"..."
,
nil
}
return
plainText
,
nil
}
web/src/components/CreateMemoRelationDialog.tsx
View file @
9909fd8a
...
@@ -104,16 +104,14 @@ const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
...
@@ -104,16 +104,14 @@ const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
value=
{
selectedMemos
}
value=
{
selectedMemos
}
multiple
multiple
onInputChange=
{
(
_
,
value
)
=>
setSearchText
(
value
.
trim
())
}
onInputChange=
{
(
_
,
value
)
=>
setSearchText
(
value
.
trim
())
}
getOptionKey=
{
(
option
)
=>
option
.
name
}
getOptionKey=
{
(
memo
)
=>
memo
.
name
}
getOptionLabel=
{
(
option
)
=>
option
.
content
}
getOptionLabel=
{
(
memo
)
=>
memo
.
content
}
isOptionEqualToValue=
{
(
option
,
value
)
=>
option
.
name
===
value
.
name
}
isOptionEqualToValue=
{
(
memo
,
value
)
=>
memo
.
name
===
value
.
name
}
renderOption=
{
(
props
,
option
)
=>
(
renderOption=
{
(
props
,
memo
)
=>
(
<
AutocompleteOption
{
...
props
}
>
<
AutocompleteOption
{
...
props
}
>
<
div
className=
"w-full flex flex-col justify-start items-start"
>
<
div
className=
"w-full flex flex-col justify-start items-start"
>
<
p
className=
"text-xs text-gray-400 select-none"
>
{
getDateTimeString
(
option
.
displayTime
)
}
</
p
>
<
p
className=
"text-xs text-gray-400 select-none"
>
{
getDateTimeString
(
memo
.
displayTime
)
}
</
p
>
<
p
className=
"mt-0.5 text-sm leading-5 line-clamp-2"
>
<
p
className=
"mt-0.5 text-sm leading-5 line-clamp-2"
>
{
searchText
?
getHighlightedContent
(
memo
.
content
)
:
memo
.
snippet
}
</
p
>
{
searchText
?
getHighlightedContent
(
option
.
content
)
:
option
.
content
}
</
p
>
</
div
>
</
div
>
</
AutocompleteOption
>
</
AutocompleteOption
>
)
}
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment