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
ffe0a408
Commit
ffe0a408
authored
Aug 06, 2020
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `sortKey` and `selectedTab` selectors
parent
dcf59584
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
13 deletions
+42
-13
sort-menu.js
src/sidebar/components/sort-menu.js
+1
-1
sort-menu-test.js
src/sidebar/components/test/sort-menu-test.js
+2
-10
selection.js
src/sidebar/store/modules/selection.js
+24
-2
selection-test.js
src/sidebar/store/modules/test/selection-test.js
+15
-0
No files found.
src/sidebar/components/sort-menu.js
View file @
ffe0a408
...
...
@@ -14,7 +14,7 @@ export default function SortMenu() {
setSortKey
:
store
.
setSortKey
,
}));
// The currently-applied sort order
const
sortKey
=
useStore
(
store
=>
store
.
getState
().
selection
.
sortKey
);
const
sortKey
=
useStore
(
store
=>
store
.
sortKey
()
);
// All available sorting options. These change depending on current
// "tab" or context.
const
sortKeysAvailable
=
useStore
(
store
=>
store
.
sortKeys
());
...
...
src/sidebar/components/test/sort-menu-test.js
View file @
ffe0a408
...
...
@@ -7,7 +7,6 @@ import { $imports } from '../sort-menu';
import
mockImportedComponents
from
'../../../test-util/mock-imported-components'
;
describe
(
'SortMenu'
,
()
=>
{
let
fakeState
;
let
fakeStore
;
const
createSortMenu
=
()
=>
{
...
...
@@ -15,14 +14,9 @@ describe('SortMenu', () => {
};
beforeEach
(()
=>
{
fakeState
=
{
selection
:
{
sortKey
:
'Location'
,
},
};
fakeStore
=
{
setSortKey
:
sinon
.
stub
(),
getState
:
sinon
.
stub
().
returns
(
fakeState
),
sortKey
:
sinon
.
stub
().
returns
(
'Location'
),
sortKeys
:
sinon
.
stub
().
returns
([
'Newest'
,
'Oldest'
,
'Location'
]),
};
...
...
@@ -55,9 +49,7 @@ describe('SortMenu', () => {
const
currentSortKeyMenuItem
=
wrapper
.
find
(
'MenuItem'
)
.
filterWhere
(
menuItem
=>
menuItem
.
prop
(
'label'
)
===
fakeState
.
selection
.
sortKey
);
.
filterWhere
(
menuItem
=>
menuItem
.
prop
(
'label'
)
===
fakeStore
.
sortKey
());
assert
.
isTrue
(
currentSortKeyMenuItem
.
prop
(
'isSelected'
));
});
...
...
src/sidebar/store/modules/selection.js
View file @
ffe0a408
...
...
@@ -529,6 +529,24 @@ const hasAppliedFilter = createSelector(
!!
filterQuery
||
focusModeActive
||
hasSelectedAnnotations
);
/**
* Return the currently-selected tab
*
* @return {'annotation'|'note'|'orphan'}
*/
function
selectedTab
(
state
)
{
return
state
.
selectedTab
;
}
/**
* Retrieve the current sort option key
*
* @return {string}
*/
function
sortKey
(
state
)
{
return
state
.
sortKey
;
}
/**
* Retrieve applicable sort options for the currently-selected tab.
*
...
...
@@ -585,8 +603,8 @@ const threadState = createSelector(
filters
,
forcedVisible
:
forcedVisibleAnnotations
(
selection
),
selected
:
selectedAnnotations
(
selection
),
sortKey
:
s
election
.
sortKey
,
// TODO: This should have a selector
selectedTab
:
select
ion
.
selectedTab
,
// TODO: This should have a selector
sortKey
:
s
ortKey
(
selection
),
selectedTab
:
select
edTab
(
selection
),
};
return
{
annotations
,
route
:
routeName
,
selection
:
selectionState
};
}
...
...
@@ -619,6 +637,8 @@ const threadState = createSelector(
* @prop {() => boolean} hasAppliedFilter
* @prop {() => boolean} hasSelectedAnnotations
* @prop {() => string[]} selectedAnnotations
* @prop {() => string} selectedTab
* @prop {() => string} sortKey
* @prop {() => string[]} sortKeys
*
* // Root Selectors
...
...
@@ -657,6 +677,8 @@ export default {
hasAppliedFilter
,
hasSelectedAnnotations
,
selectedAnnotations
,
selectedTab
,
sortKey
,
sortKeys
,
},
...
...
src/sidebar/store/modules/test/selection-test.js
View file @
ffe0a408
...
...
@@ -517,6 +517,21 @@ describe('sidebar/store/modules/selection', () => {
});
});
describe
(
'selectedTab'
,
()
=>
{
it
(
'should return the currently-selected tab'
,
()
=>
{
store
.
selectTab
(
uiConstants
.
TAB_NOTES
);
assert
.
equal
(
store
.
selectedTab
(),
uiConstants
.
TAB_NOTES
);
});
});
describe
(
'sortKey'
,
()
=>
{
it
(
'should return the currently-active sort key'
,
()
=>
{
store
.
setSortKey
(
'Newest'
);
assert
.
equal
(
store
.
sortKey
(),
'Newest'
);
});
});
describe
(
'ADD_ANNOTATIONS'
,
()
=>
{
it
(
'should select the page notes tab if all top-level annotations are page notes'
,
()
=>
{
store
.
dispatch
({
...
...
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