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
3e0bbe14
Commit
3e0bbe14
authored
Aug 08, 2019
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UI to Focused User Mode
parent
674aa8bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
48 deletions
+127
-48
focused-mode-header.js
src/sidebar/components/focused-mode-header.js
+38
-21
focused-mode-header-test.js
src/sidebar/components/test/focused-mode-header-test.js
+62
-19
root-thread.js
src/sidebar/services/root-thread.js
+2
-1
focused-mode-header.scss
src/styles/sidebar/components/focused-mode-header.scss
+25
-7
No files found.
src/sidebar/components/focused-mode-header.js
View file @
3e0bbe14
...
@@ -4,42 +4,59 @@ const { createElement } = require('preact');
...
@@ -4,42 +4,59 @@ const { createElement } = require('preact');
const
useStore
=
require
(
'../store/use-store'
);
const
useStore
=
require
(
'../store/use-store'
);
const
SvgIcon
=
require
(
'./svg-icon'
);
/**
/**
* Render a control to interact with any focused "mode" in the sidebar.
* Render a control to interact with any focused "mode" in the sidebar.
* Currently only a user-focus mode is supported but this could be broadened
* Currently only a user-focus mode is supported but this could be broadened
* and abstracted if needed. Allow user to toggle in and out of the focus "mode."
* and abstracted if needed. Allow user to toggle in and out of the focus "mode."
*/
*/
function
FocusedModeHeader
()
{
function
FocusedModeHeader
()
{
const
store
=
useStore
(
store
=>
({
const
actions
=
useStore
(
store
=>
({
actions
:
{
setFocusModeFocused
:
store
.
setFocusModeFocused
,
setFocusModeFocused
:
store
.
setFocusModeFocused
,
}));
},
const
selectors
=
useStore
(
store
=>
({
selectors
:
{
focusModeFocused
:
store
.
focusModeFocused
(),
focusModeFocused
:
store
.
focusModeFocused
,
focusModeHasUser
:
store
.
focusModeHasUser
(),
focusModeUserPrettyName
:
store
.
focusModeUserPrettyName
,
focusModeUserPrettyName
:
store
.
focusModeUserPrettyName
(),
},
}));
}));
// Nothing to do here for now if we're not focused on a user
if
(
!
selectors
.
focusModeHasUser
)
{
return
null
;
}
const
toggleFocusedMode
=
()
=>
{
const
toggleFocusedMode
=
()
=>
{
store
.
actions
.
setFocusModeFocused
(
!
store
.
selectors
.
focusModeFocused
()
);
actions
.
setFocusModeFocused
(
!
selectors
.
focusModeFocused
);
};
};
const
buttonText
=
()
=>
{
const
filterStatus
=
(
if
(
store
.
selectors
.
focusModeFocused
())
{
<
div
className
=
"focused-mode-header__filter-status"
>
return
`Annotations by
${
store
.
selectors
.
focusModeUserPrettyName
()}
`
;
{
selectors
.
focusModeFocused
?
(
<
span
>
Annotations
by
<
strong
>
{
selectors
.
focusModeUserPrettyName
}
<
/strong>{' '
}
only
<
/span
>
)
:
(
<
span
>
Everybody
&
rsquo
;
s
annotations
<
/span
>
)}
<
/div
>
);
const
buttonText
=
(()
=>
{
if
(
selectors
.
focusModeFocused
)
{
return
'Show all'
;
}
else
{
}
else
{
return
'All annotations'
;
return
`Only
${
selectors
.
focusModeUserPrettyName
}
`
;
}
}
};
}
)()
;
return
(
return
(
<
div
className
=
"focused-mode-header"
>
<
div
className
=
"focused-mode-header sheet"
>
<
button
{
filterStatus
}
onClick
=
{
toggleFocusedMode
}
<
button
onClick
=
{
toggleFocusedMode
}
className
=
"focused-mode-header__btn"
>
className
=
"primary-action-btn primary-action-btn--short"
<
SvgIcon
name
=
"cancel"
className
=
"focused-mode-header__btn-icon"
/>
title
=
{
`Toggle to show annotations only by
${
store
.
selectors
.
focusModeUserPrettyName
()}
`
}
{
buttonText
}
>
{
buttonText
()}
<
/button
>
<
/button
>
<
/div
>
<
/div
>
);
);
...
...
src/sidebar/components/test/focused-mode-header-test.js
View file @
3e0bbe14
...
@@ -19,8 +19,9 @@ describe('FocusedModeHeader', function() {
...
@@ -19,8 +19,9 @@ describe('FocusedModeHeader', function() {
focused
:
true
,
focused
:
true
,
},
},
},
},
focusModeFocused
:
sinon
.
stub
().
returns
(
fals
e
),
focusModeFocused
:
sinon
.
stub
().
returns
(
tru
e
),
focusModeUserPrettyName
:
sinon
.
stub
().
returns
(
'Fake User'
),
focusModeUserPrettyName
:
sinon
.
stub
().
returns
(
'Fake User'
),
focusModeHasUser
:
sinon
.
stub
().
returns
(
true
),
setFocusModeFocused
:
sinon
.
stub
(),
setFocusModeFocused
:
sinon
.
stub
(),
};
};
FocusedModeHeader
.
$imports
.
$mock
({
FocusedModeHeader
.
$imports
.
$mock
({
...
@@ -32,29 +33,71 @@ describe('FocusedModeHeader', function() {
...
@@ -32,29 +33,71 @@ describe('FocusedModeHeader', function() {
FocusedModeHeader
.
$imports
.
$restore
();
FocusedModeHeader
.
$imports
.
$restore
();
});
});
it
(
'creates the component'
,
()
=>
{
context
(
'not in user-focused mode'
,
()
=>
{
const
wrapper
=
createComponent
();
it
(
'should not render anything if not in user-focused mode'
,
()
=>
{
assert
.
include
(
wrapper
.
text
(),
'All annotations'
);
fakeStore
.
focusModeHasUser
=
sinon
.
stub
().
returns
(
false
);
});
const
wrapper
=
createComponent
();
it
(
"sets the button's text to the user's name when focused"
,
()
=>
{
assert
.
isFalse
(
wrapper
.
exists
(
'.focused-mode-header'
));
fakeStore
.
focusModeFocused
=
sinon
.
stub
().
returns
(
true
);
});
const
wrapper
=
createComponent
();
assert
.
include
(
wrapper
.
text
(),
'Annotations by Fake User'
);
});
});
describe
(
'clicking the button shall toggle the focused mode'
,
function
()
{
context
(
'user-focused mode'
,
()
=>
{
it
(
'when focused is false, toggle to true'
,
()
=>
{
context
(
'focus is applied (focused/on)'
,
()
=>
{
const
wrapper
=
createComponent
();
it
(
"should render status text indicating only that user's annotations are visible"
,
()
=>
{
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
const
wrapper
=
createComponent
();
assert
.
calledWith
(
fakeStore
.
setFocusModeFocused
,
true
);
assert
.
match
(
wrapper
.
text
(),
/Annotations by.+Fake User/
);
});
it
(
'should render a button allowing the user to view all annotations'
,
()
=>
{
const
wrapper
=
createComponent
();
const
button
=
wrapper
.
find
(
'button'
);
assert
.
include
(
button
.
text
(),
'Show all'
);
});
});
});
it
(
'when focused is true, toggle to false'
,
()
=>
{
context
(
'focus is not applied (unfocused/off)'
,
()
=>
{
fakeStore
.
focusModeFocused
=
sinon
.
stub
().
returns
(
true
);
beforeEach
(()
=>
{
const
wrapper
=
createComponent
();
fakeStore
.
focusModeFocused
=
sinon
.
stub
().
returns
(
false
);
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
});
assert
.
calledWith
(
fakeStore
.
setFocusModeFocused
,
false
);
it
(
"should render status text indicating that all user's annotations are visible"
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
match
(
wrapper
.
text
(),
/Everybody.*s annotations/
);
});
it
(
"should render a button allowing the user to view only focus user's annotations"
,
()
=>
{
const
wrapper
=
createComponent
();
const
button
=
wrapper
.
find
(
'button'
);
assert
.
include
(
button
.
text
(),
'Only Fake User'
);
});
});
describe
(
'toggle button'
,
()
=>
{
it
(
'should toggle focus mode to false if clicked when focused'
,
()
=>
{
fakeStore
.
focusModeFocused
=
sinon
.
stub
().
returns
(
true
);
const
wrapper
=
createComponent
();
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
assert
.
calledWith
(
fakeStore
.
setFocusModeFocused
,
false
);
});
it
(
'should toggle focus mode to true if clicked when not focused'
,
()
=>
{
fakeStore
.
focusModeFocused
=
sinon
.
stub
().
returns
(
false
);
const
wrapper
=
createComponent
();
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
assert
.
calledWith
(
fakeStore
.
setFocusModeFocused
,
true
);
});
});
});
});
});
});
});
src/sidebar/services/root-thread.js
View file @
3e0bbe14
...
@@ -55,7 +55,8 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
...
@@ -55,7 +55,8 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
let
filterFn
;
let
filterFn
;
if
(
shouldFilterThread
())
{
if
(
shouldFilterThread
())
{
const
filters
=
searchFilter
.
generateFacetedFilter
(
state
.
filterQuery
,
{
const
filters
=
searchFilter
.
generateFacetedFilter
(
state
.
filterQuery
,
{
user
:
store
.
focusModeUsername
(),
// `null` if no focused user
// if a focus mode is applied (focused) and we're focusing on a user
user
:
store
.
focusModeFocused
()
&&
store
.
focusModeUsername
(),
});
});
filterFn
=
function
(
annot
)
{
filterFn
=
function
(
annot
)
{
...
...
src/styles/sidebar/components/focused-mode-header.scss
View file @
3e0bbe14
// A dark grey button used for the primary action
// in a form
.focused-mode-header
{
.focused-mode-header
{
margin-bottom
:
10px
;
display
:
flex
;
button
{
align-items
:
center
;
width
:
100%
;
height
:
24px
;
&
__btn
{
margin-right
:
10px
;
@include
primary-action-btn
;
&
:focus
{
@include
outline-on-keyboard-focus
;
outline
:
none
;
display
:
flex
;
margin-left
:
auto
;
height
:
30px
;
padding-left
:
6px
;
padding-right
:
10px
;
background-color
:
$grey-2
;
color
:
$grey-5
;
&
:hover:enabled
{
background-color
:
$grey-3
;
}
}
}
}
&
__btn-icon
{
margin-right
:
3px
;
}
&
__filter-status
{
font-weight
:
400
;
}
}
}
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