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
c7fea515
Commit
c7fea515
authored
May 02, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
May 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `Thread` to make local `HiddenThreadCardHeader` unnecessary
Use `AnnotationHeader` directly
parent
db7f1226
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
39 deletions
+18
-39
Thread.js
src/sidebar/components/Thread.js
+15
-36
Thread-test.js
src/sidebar/components/test/Thread-test.js
+3
-3
No files found.
src/sidebar/components/Thread.js
View file @
c7fea515
...
...
@@ -12,40 +12,6 @@ import ModerationBanner from './ModerationBanner';
/** @typedef {import('../helpers/build-thread').Thread} Thread */
/**
* Render a header for a hidden top-level thread.
*
* Every ThreadCard should have a header of some sort representing its top-level
* thread. When a thread is visible, an Annotation is rendered which in turn
* renders an AnnotationHeader. But when a thread is hidden, Annotation is not
* rendered: use this header instead for hidden top-level threads.
*
* @param {object} props
* @param {Thread['annotation']} props.annotation
* @param {number} props.replyCount
* @param {boolean} props.threadIsCollapsed
*/
function
HiddenThreadCardHeader
({
annotation
,
...
restProps
})
{
const
store
=
useSidebarStore
();
// These two lines are copied from the AnnotationHeader component to mimic the
// exact same behaviour.
const
isSaving
=
annotation
&&
store
.
isSavingAnnotation
(
annotation
);
const
isEditing
=
annotation
&&
!!
store
.
getDraft
(
annotation
)
&&
!
isSaving
;
if
(
!
annotation
)
{
return
null
;
}
return
(
<
AnnotationHeader
annotation
=
{
annotation
}
isEditing
=
{
isEditing
}
{...
restProps
}
/
>
);
}
/**
* Render a gutter area to the left of a thread's content with a control for
* expanding/collapsing the thread and a visual vertical line showing the
...
...
@@ -131,6 +97,11 @@ function Thread({ thread, threadsService }) {
const
store
=
useSidebarStore
();
const
hasAppliedFilter
=
store
.
hasAppliedFilter
();
const
isSaving
=
thread
.
annotation
&&
store
.
isSavingAnnotation
(
thread
.
annotation
);
const
isEditing
=
thread
.
annotation
&&
!!
store
.
getDraft
(
thread
.
annotation
)
&&
!
isSaving
;
const
onToggleReplies
=
useCallback
(
()
=>
store
.
setExpanded
(
thread
.
id
,
!!
thread
.
collapsed
),
[
store
,
thread
.
id
,
thread
.
collapsed
]
...
...
@@ -187,9 +158,17 @@ function Thread({ thread, threadsService }) {
{
countHidden
(
thread
)
>
0
&&
(
<
div
className
=
"space-y-2"
>
{
!
thread
.
parent
&&
(
<
HiddenThreadCardHeader
{
// Every ThreadCard should have a header of some sort representing
// its top-level thread. When a thread is visible, an Annotation
// is rendered which in turn renders an AnnotationHeader. But when
// a thread is hidden, Annotation is not rendered: reander a header
// here instead for hidden top-level threads.
}
{
!
thread
.
parent
&&
thread
.
annotation
&&
(
<
AnnotationHeader
annotation
=
{
thread
.
annotation
}
isEditing
=
{
isEditing
}
replyCount
=
{
thread
.
replyCount
}
threadIsCollapsed
=
{
thread
.
collapsed
}
/
>
...
...
src/sidebar/components/test/Thread-test.js
View file @
c7fea515
...
...
@@ -236,7 +236,7 @@ describe('Thread', () => {
const
thread
=
createThread
();
const
wrapper
=
createComponent
({
thread
});
assert
.
isTrue
(
wrapper
.
find
(
'
HiddenThreadCard
Header'
).
exists
());
assert
.
isTrue
(
wrapper
.
find
(
'
Annotation
Header'
).
exists
());
});
it
(
"doesn't show the annotation header if top-level annotation is missing"
,
()
=>
{
...
...
@@ -244,7 +244,7 @@ describe('Thread', () => {
thread
.
annotation
=
null
;
const
wrapper
=
createComponent
({
thread
});
assert
.
is
True
(
wrapper
.
find
(
'HiddenThreadCardHeader'
).
isEmptyRender
());
assert
.
is
False
(
wrapper
.
find
(
'AnnotationHeader'
).
exists
());
});
it
(
"doesn't show the annotation header if thread is a child"
,
()
=>
{
...
...
@@ -252,7 +252,7 @@ describe('Thread', () => {
thread
.
parent
=
{};
// child threads have a parent
const
wrapper
=
createComponent
({
thread
});
assert
.
isFalse
(
wrapper
.
find
(
'
HiddenThreadCard
Header'
).
exists
());
assert
.
isFalse
(
wrapper
.
find
(
'
Annotation
Header'
).
exists
());
});
});
...
...
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