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
8b8f1b39
Commit
8b8f1b39
authored
Mar 06, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract thread-count functions into utility
parent
29d35e80
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
22 deletions
+90
-22
annotation-thread.js
src/sidebar/components/annotation-thread.js
+5
-22
thread-test.js
src/sidebar/util/test/thread-test.js
+54
-0
thread.js
src/sidebar/util/thread.js
+31
-0
No files found.
src/sidebar/components/annotation-thread.js
View file @
8b8f1b39
function
hiddenCount
(
thread
)
{
const
isHidden
=
thread
.
annotation
&&
!
thread
.
visible
;
return
thread
.
children
.
reduce
(
function
(
count
,
reply
)
{
return
count
+
hiddenCount
(
reply
);
},
isHidden
?
1
:
0
);
}
function
visibleCount
(
thread
)
{
const
isVisible
=
thread
.
annotation
&&
thread
.
visible
;
return
thread
.
children
.
reduce
(
function
(
count
,
reply
)
{
return
count
+
visibleCount
(
reply
);
},
isVisible
?
1
:
0
);
}
import
{
countVisible
,
countHidden
}
from
'../util/thread'
;
function
showAllChildren
(
thread
,
showFn
)
{
thread
.
children
.
forEach
(
child
=>
{
...
...
@@ -72,7 +54,8 @@ function AnnotationThreadController(features, store) {
};
/**
* Show this thread and any of its children
* Show this thread and any of its children. This is available if filtering
* is applied that hides items in the thread.
*/
this
.
showThreadAndReplies
=
function
()
{
showAllParents
(
this
.
thread
,
this
.
onForceVisible
);
...
...
@@ -90,11 +73,11 @@ function AnnotationThreadController(features, store) {
* search filter.
*/
this
.
hiddenCount
=
function
()
{
return
hiddenCount
(
this
.
thread
);
return
countHidden
(
this
.
thread
);
};
this
.
shouldShowReply
=
function
(
child
)
{
return
visibleCount
(
child
)
>
0
;
return
countVisible
(
child
)
>
0
;
};
this
.
onForceVisible
=
function
(
thread
)
{
...
...
src/sidebar/util/test/thread-test.js
0 → 100644
View file @
8b8f1b39
import
*
as
threadUtil
from
'../thread'
;
describe
(
'sidebar/util/thread'
,
()
=>
{
const
fakeThread
=
()
=>
{
return
{
annotation
:
{},
visible
:
true
,
children
:
[
{
annotation
:
{},
visible
:
true
,
children
:
[
{
annotation
:
{},
visible
:
true
,
children
:
[]
},
{
annotation
:
{},
visible
:
false
,
children
:
[]
},
],
},
{
annotation
:
{},
visible
:
false
,
children
:
[{
annotation
:
{},
visible
:
true
,
children
:
[]
}],
},
{
annotation
:
{},
visible
:
true
,
children
:
[]
},
],
};
};
describe
(
'countVisible'
,
()
=>
{
it
(
'should count the number of visible entries in the thread'
,
()
=>
{
const
thread
=
fakeThread
();
assert
.
equal
(
threadUtil
.
countVisible
(
thread
),
5
);
});
it
(
'should calculate visible entries when top-level thread is hidden'
,
()
=>
{
const
thread
=
fakeThread
();
thread
.
visible
=
false
;
assert
.
equal
(
threadUtil
.
countVisible
(
thread
),
4
);
});
});
describe
(
'countHidden'
,
()
=>
{
it
(
'should count the number of hidden entries in the thread'
,
()
=>
{
const
thread
=
fakeThread
();
assert
.
equal
(
threadUtil
.
countHidden
(
thread
),
2
);
});
it
(
'should calculate visible entries when top-level thread is hidden'
,
()
=>
{
const
thread
=
fakeThread
();
thread
.
visible
=
false
;
assert
.
equal
(
threadUtil
.
countHidden
(
thread
),
3
);
});
});
});
src/sidebar/util/thread.js
0 → 100644
View file @
8b8f1b39
/**
* Count the number of annotations/replies in the `thread` whose `visible`
* property matches `visibility`.
*
* @param {Thread} thread
* @param {boolean} visibility — `true`: count visible annotations
* `false`: count hidden annotations
* @return {number}
*/
function
countByVisibility
(
thread
,
visibility
)
{
const
matchesVisibility
=
!!
thread
.
annotation
&&
thread
.
visible
===
visibility
;
return
thread
.
children
.
reduce
(
(
count
,
reply
)
=>
count
+
countByVisibility
(
reply
,
visibility
),
matchesVisibility
?
1
:
0
);
}
/**
* Count the hidden annotations/replies in the `thread`
*/
export
function
countHidden
(
thread
)
{
return
countByVisibility
(
thread
,
false
);
}
/**
* Count the visible annotations/replies in the `thread`
*/
export
function
countVisible
(
thread
)
{
return
countByVisibility
(
thread
,
true
);
}
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