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
35e92333
Commit
35e92333
authored
Apr 20, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor focus-annotations functionality
parent
0374e506
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
107 additions
and
42 deletions
+107
-42
annotation-quote.js
src/sidebar/components/annotation-quote.js
+7
-6
annotation.js
src/sidebar/components/annotation.js
+7
-1
annotation-quote-test.js
src/sidebar/components/test/annotation-quote-test.js
+6
-1
annotation-test.js
src/sidebar/components/test/annotation-test.js
+17
-0
frame-sync.js
src/sidebar/services/frame-sync.js
+3
-2
frame-sync-test.js
src/sidebar/services/test/frame-sync-test.js
+18
-0
selection.js
src/sidebar/store/modules/selection.js
+12
-4
selection-test.js
src/sidebar/store/modules/test/selection-test.js
+18
-13
annotation-quote.scss
src/styles/sidebar/components/annotation-quote.scss
+19
-15
No files found.
src/sidebar/components/annotation-quote.js
View file @
35e92333
...
...
@@ -11,7 +11,7 @@ import Excerpt from './excerpt';
/**
* Display the selected text from the document associated with an annotation.
*/
function
AnnotationQuote
({
annotation
,
settings
=
{}
})
{
function
AnnotationQuote
({
annotation
,
isFocused
,
settings
=
{}
})
{
// The language for the quote may be different than the client's UI (set by
// `<html lang="...">`).
//
...
...
@@ -24,10 +24,10 @@ function AnnotationQuote({ annotation, settings = {} }) {
return
(
<
section
className
=
{
classnames
(
'
annotation-quote'
,
isOrphan
(
annotation
)
&&
'is-orphan'
)}
className
=
{
classnames
(
'annotation-quote'
,
{
'
is-orphan'
:
isOrphan
(
annotation
)
,
'is-focused'
:
isFocused
,
}
)}
>
<
Excerpt
collapsedHeight
=
{
35
}
...
...
@@ -49,7 +49,8 @@ function AnnotationQuote({ annotation, settings = {} }) {
AnnotationQuote
.
propTypes
=
{
annotation
:
propTypes
.
object
.
isRequired
,
/** Is this annotation currently focused? */
isFocused
:
propTypes
.
bool
,
// Used for theming.
settings
:
propTypes
.
object
,
};
...
...
src/sidebar/components/annotation.js
View file @
35e92333
...
...
@@ -27,6 +27,9 @@ function Annotation({
toastMessenger
,
})
{
const
createDraft
=
useStore
(
store
=>
store
.
createDraft
);
const
isFocused
=
useStore
(
store
=>
store
.
isAnnotationFocused
(
annotation
.
$tag
)
);
const
setCollapsed
=
useStore
(
store
=>
store
.
setCollapsed
);
// An annotation will have a draft if it is being edited
...
...
@@ -90,6 +93,7 @@ function Annotation({
className
=
{
classnames
(
'annotation'
,
{
'annotation--reply'
:
isReply
(
annotation
),
'is-collapsed'
:
threadIsCollapsed
,
'is-focused'
:
isFocused
,
})}
onKeyDown
=
{
onKeyDown
}
>
...
...
@@ -101,7 +105,9 @@ function Annotation({
threadIsCollapsed
=
{
threadIsCollapsed
}
/
>
{
hasQuote
&&
<
AnnotationQuote
annotation
=
{
annotation
}
/>
}
{
hasQuote
&&
(
<
AnnotationQuote
annotation
=
{
annotation
}
isFocused
=
{
isFocused
}
/
>
)}
{
!
isCollapsedReply
&&
(
<
AnnotationBody
...
...
src/sidebar/components/test/annotation-quote-test.js
View file @
35e92333
...
...
@@ -14,7 +14,12 @@ describe('AnnotationQuote', () => {
function
createQuote
(
props
)
{
return
mount
(
<
AnnotationQuote
annotation
=
{
fakeAnnotation
}
settings
=
{{}}
{...
props
}
/
>
<
AnnotationQuote
annotation
=
{
fakeAnnotation
}
isFocused
=
{
false
}
settings
=
{{}}
{...
props
}
/
>
);
}
...
...
src/sidebar/components/test/annotation-test.js
View file @
35e92333
...
...
@@ -69,6 +69,7 @@ describe('Annotation', () => {
getGroup
:
sinon
.
stub
().
returns
({
type
:
'private'
,
}),
isAnnotationFocused
:
sinon
.
stub
().
returns
(
false
),
isSavingAnnotation
:
sinon
.
stub
().
returns
(
false
),
profile
:
sinon
.
stub
().
returns
({
userid
:
'acct:foo@bar.com'
}),
setCollapsed
:
sinon
.
stub
(),
...
...
@@ -97,6 +98,14 @@ describe('Annotation', () => {
assert
.
isFalse
(
annot
.
hasClass
(
'is-collapsed'
));
});
it
(
'applies a focused class if annotation is focused'
,
()
=>
{
fakeStore
.
isAnnotationFocused
.
returns
(
true
);
const
wrapper
=
createComponent
({
threadIsCollapsed
:
false
});
const
annot
=
wrapper
.
find
(
'.annotation'
);
assert
.
isTrue
(
annot
.
hasClass
(
'is-focused'
));
});
it
(
'should assign a collapsed class if the annotation thread is collapsed'
,
()
=>
{
const
wrapper
=
createComponent
({
threadIsCollapsed
:
true
});
const
annot
=
wrapper
.
find
(
'.annotation'
);
...
...
@@ -114,6 +123,14 @@ describe('Annotation', () => {
assert
.
isTrue
(
quote
.
exists
());
});
it
(
'sets the quote to "focused" if annotation is currently focused'
,
()
=>
{
fakeStore
.
isAnnotationFocused
.
returns
(
true
);
fakeMetadata
.
quote
.
returns
(
'quote'
);
const
wrapper
=
createComponent
();
assert
.
isTrue
(
wrapper
.
find
(
'AnnotationQuote'
).
props
().
isFocused
);
});
it
(
'does not render quote if annotation does not have a quote'
,
()
=>
{
fakeMetadata
.
quote
.
returns
(
null
);
...
...
src/sidebar/services/frame-sync.js
View file @
35e92333
...
...
@@ -235,14 +235,15 @@ export default function FrameSync($rootScope, $window, store, bridge) {
};
/**
* Focus annotations with the given tags.
* Focus annotations with the given
$
tags.
*
* This is used to indicate the highlight in the document that corresponds to
* a given annotation in the sidebar.
*
* @param {string[]} tags
* @param {string[]} tags
- annotation $tags
*/
this
.
focusAnnotations
=
function
(
tags
)
{
store
.
focusAnnotations
(
tags
);
bridge
.
call
(
'focusAnnotations'
,
tags
);
};
...
...
src/sidebar/services/test/frame-sync-test.js
View file @
35e92333
...
...
@@ -401,4 +401,22 @@ describe('sidebar/services/frame-sync', function () {
assert
.
calledWith
(
fakeBridge
.
call
,
'setVisibleHighlights'
);
});
});
describe
(
'when annotations are focused in the sidebar'
,
()
=>
{
it
(
'should update the focused annotations in the store'
,
()
=>
{
frameSync
.
focusAnnotations
([
'a1'
,
'a2'
]);
assert
.
calledWith
(
fakeStore
.
focusAnnotations
,
sinon
.
match
.
array
.
deepEquals
([
'a1'
,
'a2'
])
);
});
it
(
'notify the host page'
,
()
=>
{
frameSync
.
focusAnnotations
([
1
,
2
]);
assert
.
calledWith
(
fakeBridge
.
call
,
'focusAnnotations'
,
sinon
.
match
.
array
.
deepEquals
([
1
,
2
])
);
});
});
});
src/sidebar/store/modules/selection.js
View file @
35e92333
...
...
@@ -92,8 +92,8 @@ const setTab = (selectedTab, newTab) => {
function
init
(
settings
)
{
return
{
//
Contains a map of annotation tag:true pairs.
focusedAnnotation
Map
:
null
,
//
An array of annotation `$tag`s representing annotations that are focused
focusedAnnotation
s
:
[]
,
// Contains a map of annotation id:true pairs.
selectedAnnotationMap
:
initialSelection
(
settings
),
...
...
@@ -153,7 +153,7 @@ const update = {
},
FOCUS_ANNOTATIONS
:
function
(
state
,
action
)
{
return
{
focusedAnnotation
Map
:
action
.
focused
};
return
{
focusedAnnotation
s
:
[...
action
.
focusedTags
]
};
},
SET_FOCUS_MODE_FOCUSED
:
function
(
state
,
action
)
{
...
...
@@ -318,7 +318,7 @@ function setForceVisible(id, visible) {
function
focusAnnotations
(
tags
)
{
return
{
type
:
actions
.
FOCUS_ANNOTATIONS
,
focused
:
freeze
(
toSet
(
tags
))
,
focused
Tags
:
tags
,
};
}
...
...
@@ -395,6 +395,13 @@ function setSortKey(key) {
};
}
/** Is the annotation referenced by `$tag` currently focused? */
function
isAnnotationFocused
(
state
,
$tag
)
{
return
state
.
selection
.
focusedAnnotations
.
some
(
focusedAnn
=>
$tag
&&
focusedAnn
===
$tag
);
}
/**
* Returns true if the annotation with the given `id` is selected.
*/
...
...
@@ -542,6 +549,7 @@ export default {
focusModeHasUser
,
focusModeUserId
,
focusModeUserPrettyName
,
isAnnotationFocused
,
isAnnotationSelected
,
getFirstSelectedAnnotationId
,
getSelectedAnnotationMap
,
...
...
src/sidebar/store/modules/test/selection-test.js
View file @
35e92333
...
...
@@ -43,28 +43,22 @@ describe('sidebar/store/modules/selection', () => {
});
describe
(
'focusAnnotations()'
,
function
()
{
it
(
'adds the p
assed annotations to the focusedAnnotationMap
'
,
function
()
{
it
(
'adds the p
rovided annotation IDs to the focused annotations
'
,
function
()
{
store
.
focusAnnotations
([
1
,
2
,
3
]);
assert
.
deepEqual
(
getSelectionState
().
focusedAnnotationMap
,
{
1
:
true
,
2
:
true
,
3
:
true
,
});
assert
.
deepEqual
(
getSelectionState
().
focusedAnnotations
,
[
1
,
2
,
3
]);
});
it
(
'replaces any
annotations originally in the map
'
,
function
()
{
it
(
'replaces any
other focused annotation IDs
'
,
function
()
{
store
.
focusAnnotations
([
1
]);
store
.
focusAnnotations
([
2
,
3
]);
assert
.
deepEqual
(
getSelectionState
().
focusedAnnotationMap
,
{
2
:
true
,
3
:
true
,
});
assert
.
deepEqual
(
getSelectionState
().
focusedAnnotations
,
[
2
,
3
]);
});
it
(
'
nulls the map if no annotations are focus
ed'
,
function
()
{
it
(
'
sets focused annotations to an empty array if no IDs provid
ed'
,
function
()
{
store
.
focusAnnotations
([
1
]);
store
.
focusAnnotations
([]);
assert
.
isNull
(
getSelectionState
().
focusedAnnotationMap
);
assert
.
isArray
(
getSelectionState
().
focusedAnnotations
);
assert
.
isEmpty
(
getSelectionState
().
focusedAnnotations
);
});
});
...
...
@@ -368,6 +362,17 @@ describe('sidebar/store/modules/selection', () => {
});
});
describe
(
'isAnnotationFocused'
,
()
=>
{
it
(
'returns true if the provided annotation ID is in the set of focused annotations'
,
()
=>
{
store
.
focusAnnotations
([
1
,
2
]);
assert
.
isTrue
(
store
.
isAnnotationFocused
(
2
));
});
it
(
'returns false if the provided annotation ID is not in the set of focused annotations'
,
()
=>
{
assert
.
isFalse
(
store
.
isAnnotationFocused
(
2
));
});
});
describe
(
'selectTab()'
,
function
()
{
it
(
'sets the selected tab'
,
function
()
{
store
.
selectTab
(
uiConstants
.
TAB_ANNOTATIONS
);
...
...
src/styles/sidebar/components/annotation-quote.scss
View file @
35e92333
...
...
@@ -2,13 +2,12 @@
.annotation-quote
{
margin
:
1em
0
;
}
.annotation-quote
.is-orphan
{
&
.is-orphan
{
text-decoration
:
line-through
;
}
}
.annotation-quote
__quote
{
&
__quote
{
@include
var
.
font-normal
;
border-left
:
3px
solid
var
.
$grey-3
;
...
...
@@ -21,4 +20,9 @@
// Prevent long URLs etc. in quote causing overflow
overflow-wrap
:
break-word
;
}
&
.is-focused
&
__quote
{
border-left
:
var
.
$highlight
3px
solid
;
}
}
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