Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
651e8157
Commit
651e8157
authored
Nov 11, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Nov 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `AnnotationHeader` to TS
Simplify internal components (remove `HeaderRow` local component).
parent
50a70015
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
31 deletions
+28
-31
AnnotationHeader.tsx
src/sidebar/components/Annotation/AnnotationHeader.tsx
+20
-28
AnnotationHeader-test.js
...debar/components/Annotation/test/AnnotationHeader-test.js
+8
-3
No files found.
src/sidebar/components/Annotation/AnnotationHeader.
js
→
src/sidebar/components/Annotation/AnnotationHeader.
tsx
View file @
651e8157
...
@@ -5,6 +5,9 @@ import {
...
@@ -5,6 +5,9 @@ import {
}
from
'@hypothesis/frontend-shared/lib/next'
;
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
{
useMemo
}
from
'preact/hooks'
;
import
{
useMemo
}
from
'preact/hooks'
;
import
type
{
Annotation
}
from
'../../../types/api'
;
import
type
{
SidebarSettings
}
from
'../../../types/config'
;
import
{
withServices
}
from
'../../service-context'
;
import
{
withServices
}
from
'../../service-context'
;
import
{
useSidebarStore
}
from
'../../store'
;
import
{
useSidebarStore
}
from
'../../store'
;
import
{
import
{
...
@@ -24,29 +27,15 @@ import AnnotationShareInfo from './AnnotationShareInfo';
...
@@ -24,29 +27,15 @@ import AnnotationShareInfo from './AnnotationShareInfo';
import
AnnotationTimestamps
from
'./AnnotationTimestamps'
;
import
AnnotationTimestamps
from
'./AnnotationTimestamps'
;
import
AnnotationUser
from
'./AnnotationUser'
;
import
AnnotationUser
from
'./AnnotationUser'
;
/**
export
type
AnnotationHeaderProps
=
{
* @typedef {import("../../../types/api").Annotation} Annotation
annotation
:
Annotation
;
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
isEditing
?:
boolean
;
*/
replyCount
:
number
;
threadIsCollapsed
:
boolean
;
/** @param {{ children: import("preact").ComponentChildren}} props */
function
HeaderRow
({
children
})
{
return
(
<
div
className
=
"flex gap-x-1 items-baseline flex-wrap-reverse"
>
{
children
}
<
/div
>
);
}
/**
// injected
* @typedef AnnotationHeaderProps
settings
:
SidebarSettings
;
* @prop {Annotation} annotation
};
* @prop {boolean} [isEditing] - Whether the annotation is actively being edited
* @prop {number} replyCount - How many replies this annotation currently has
* @prop {boolean} threadIsCollapsed - Is this thread currently collapsed?
* @prop {SidebarSettings} settings - Injected
*
*/
/**
/**
* Render an annotation's header summary, including metadata about its user,
* Render an annotation's header summary, including metadata about its user,
...
@@ -61,7 +50,7 @@ function AnnotationHeader({
...
@@ -61,7 +50,7 @@ function AnnotationHeader({
replyCount
,
replyCount
,
threadIsCollapsed
,
threadIsCollapsed
,
settings
,
settings
,
})
{
}
:
AnnotationHeaderProps
)
{
const
store
=
useSidebarStore
();
const
store
=
useSidebarStore
();
const
defaultAuthority
=
store
.
defaultAuthority
();
const
defaultAuthority
=
store
.
defaultAuthority
();
...
@@ -112,13 +101,13 @@ function AnnotationHeader({
...
@@ -112,13 +101,13 @@ function AnnotationHeader({
const
onReplyCountClick
=
()
=>
const
onReplyCountClick
=
()
=>
// If an annotation has replies it must have been saved and therefore have
// If an annotation has replies it must have been saved and therefore have
// an ID.
// an ID.
store
.
setExpanded
(
/** @type {string} */
(
annotation
.
id
)
,
true
);
store
.
setExpanded
(
annotation
.
id
!
,
true
);
const
group
=
store
.
getGroup
(
annotation
.
group
);
const
group
=
store
.
getGroup
(
annotation
.
group
);
return
(
return
(
<
header
>
<
header
>
<
HeaderRow
>
<
div
className=
"flex gap-x-1 items-baseline flex-wrap-reverse"
>
{
isPrivate
(
annotation
.
permissions
)
&&
!
isEditing
&&
(
{
isPrivate
(
annotation
.
permissions
)
&&
!
isEditing
&&
(
<
LockIcon
<
LockIcon
className=
"text-tiny w-em h-em"
className=
"text-tiny w-em h-em"
...
@@ -147,10 +136,13 @@ function AnnotationHeader({
...
@@ -147,10 +136,13 @@ function AnnotationHeader({
/>
/>
</
div
>
</
div
>
)
}
)
}
<
/
HeaderRow
>
</
div
>
{
!
isReply
(
annotation
)
&&
(
{
!
isReply
(
annotation
)
&&
(
<
HeaderRow
>
<
div
className=
"flex gap-x-1 items-baseline flex-wrap-reverse"
data
-
testid=
"extended-header-info"
>
{
group
&&
(
{
group
&&
(
<
AnnotationShareInfo
<
AnnotationShareInfo
group=
{
group
}
group=
{
group
}
...
@@ -170,7 +162,7 @@ function AnnotationHeader({
...
@@ -170,7 +162,7 @@ function AnnotationHeader({
title=
{
documentInfo
.
titleText
}
title=
{
documentInfo
.
titleText
}
/>
/>
)
}
)
}
<
/
HeaderRow
>
</
div
>
)
}
)
}
</
header
>
</
header
>
);
);
...
...
src/sidebar/components/Annotation/test/AnnotationHeader-test.js
View file @
651e8157
...
@@ -284,8 +284,10 @@ describe('AnnotationHeader', () => {
...
@@ -284,8 +284,10 @@ describe('AnnotationHeader', () => {
fakeIsReply
.
returns
(
false
);
fakeIsReply
.
returns
(
false
);
const
wrapper
=
createAnnotationHeader
();
const
wrapper
=
createAnnotationHeader
();
// Extended header information is rendered in a second (flex) row
assert
.
equal
(
assert
.
equal
(
wrapper
.
find
(
'HeaderRow'
).
length
,
2
);
wrapper
.
find
(
'[data-testid="extended-header-info"]'
).
length
,
1
);
});
});
it
(
'should not render extended header information if annotation is reply'
,
()
=>
{
it
(
'should not render extended header information if annotation is reply'
,
()
=>
{
...
@@ -294,7 +296,10 @@ describe('AnnotationHeader', () => {
...
@@ -294,7 +296,10 @@ describe('AnnotationHeader', () => {
showDocumentInfo
:
true
,
showDocumentInfo
:
true
,
});
});
assert
.
equal
(
wrapper
.
find
(
'HeaderRow'
).
length
,
1
);
assert
.
equal
(
wrapper
.
find
(
'[data-testid="extended-header-info"]'
).
length
,
0
);
});
});
describe
(
'annotation is-highlight icon'
,
()
=>
{
describe
(
'annotation is-highlight icon'
,
()
=>
{
...
...
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