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
f178f8fe
Commit
f178f8fe
authored
Feb 27, 2019
by
Hannah Stepanek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getCurrentlyViewing/My/FeaturedGroups to store
parent
c0219680
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
230 additions
and
4 deletions
+230
-4
group-list.js
src/sidebar/components/group-list.js
+1
-0
groups.js
src/sidebar/store/modules/groups.js
+42
-0
groups-test.js
src/sidebar/store/modules/test/groups-test.js
+187
-4
No files found.
src/sidebar/components/group-list.js
View file @
f178f8fe
...
...
@@ -86,6 +86,7 @@ function GroupListController(
this
.
showGroupsMenu
=
()
=>
{
if
(
features
.
flagEnabled
(
'community_groups'
))
{
// Only show the drop down menu if there is more than one group.
return
this
.
groups
.
all
().
length
>
1
;
}
else
{
return
!
(
this
.
isThirdPartyService
&&
this
.
groups
.
all
().
length
<=
1
);
...
...
src/sidebar/store/modules/groups.js
View file @
f178f8fe
'use strict'
;
const
util
=
require
(
'../util'
);
const
{
selectors
:
sessionSelectors
}
=
require
(
'./session'
);
const
{
isLoggedIn
}
=
sessionSelectors
;
function
init
()
{
return
{
...
...
@@ -118,6 +120,43 @@ function getGroup(state, id) {
return
state
.
groups
.
find
(
g
=>
g
.
id
===
id
);
}
/**
* Return groups that don't show up in Featured and My Groups.
*
* @return {Group[]}
*/
function
getCurrentlyViewingGroups
(
state
)
{
const
myGroups
=
getMyGroups
(
state
);
const
featuredGroups
=
getFeaturedGroups
(
state
);
return
state
.
groups
.
filter
(
g
=>
!
myGroups
.
includes
(
g
)
&&
!
featuredGroups
.
includes
(
g
)
);
}
/**
* Return groups the logged in user is a member of.
*
* @return {Group[]}
*/
function
getMyGroups
(
state
)
{
// If logged out, the Public group still has isMember set to true so only
// return groups with membership in logged in state.
if
(
isLoggedIn
(
state
))
{
return
state
.
groups
.
filter
(
g
=>
g
.
isMember
);
}
return
[];
}
/**
* Return groups the user isn't a member of that are scoped to the URI.
*
* @return {Group[]}
*/
function
getFeaturedGroups
(
state
)
{
return
state
.
groups
.
filter
(
group
=>
!
group
.
isMember
&&
group
.
isScopedToUri
);
}
module
.
exports
=
{
init
,
update
,
...
...
@@ -128,6 +167,9 @@ module.exports = {
selectors
:
{
allGroups
,
getGroup
,
getCurrentlyViewingGroups
,
getFeaturedGroups
,
getMyGroups
,
focusedGroup
,
focusedGroupId
,
},
...
...
src/sidebar/store/modules/test/groups-test.js
View file @
f178f8fe
'use strict'
;
const
immutable
=
require
(
'seamless-immutable'
);
const
createStore
=
require
(
'../../create-store'
);
const
groups
=
require
(
'../groups'
);
describe
(
'sidebar.store.modules.groups'
,
()
=>
{
const
publicGroup
=
{
const
publicGroup
=
immutable
(
{
id
:
'__world__'
,
name
:
'Public'
,
};
isMember
:
true
,
isScopedToUri
:
true
,
});
const
privateGroup
=
{
id
:
'
foo
'
,
const
privateGroup
=
immutable
(
{
id
:
'
privateid
'
,
name
:
'Private'
,
isMember
:
true
,
isScopedToUri
:
true
,
});
const
restrictedGroup
=
immutable
({
id
:
'restrictid'
,
name
:
'Restricted'
,
isMember
:
false
,
isScopedToUri
:
true
,
});
const
restrictedOutOfScopeGroup
=
immutable
({
id
:
'rstrctdOOSid'
,
name
:
'Restricted OOS'
,
isMember
:
false
,
isScopedToUri
:
false
,
});
const
restrictedOutOfScopeMemberGroup
=
immutable
({
id
:
'rstrctdOOSmemberid'
,
name
:
'Restricted OOS Mem'
,
isMember
:
true
,
isScopedToUri
:
false
,
});
const
openGroup
=
immutable
({
id
:
'openid'
,
isMember
:
false
,
isScopedToUri
:
true
,
});
/*
* Returns groups from the specified group list in the store and asserts
* that none of the lists contain the same groups. The group lists are:
* myGroups, featuredGroups, or currentlyViewingGroups.
*/
const
getListAssertNoDupes
=
(
store
,
list
)
=>
{
const
allLists
=
{
myGroups
:
store
.
getMyGroups
(),
featuredGroups
:
store
.
getFeaturedGroups
(),
currentlyViewingGroups
:
store
.
getCurrentlyViewingGroups
(),
};
let
allGroups
=
[];
for
(
let
groups
of
Object
.
values
(
allLists
))
{
allGroups
=
allGroups
.
concat
(
groups
);
}
const
hasDuplicates
=
new
Set
(
allGroups
).
size
!==
allGroups
.
length
;
assert
.
isFalse
(
hasDuplicates
);
return
allLists
[
list
];
};
let
store
;
...
...
@@ -108,4 +164,131 @@ describe('sidebar.store.modules.groups', () => {
assert
.
equal
(
store
.
focusedGroupId
(),
privateGroup
.
id
);
});
});
describe
(
'getFeaturedGroups'
,
()
=>
{
[
{
description
:
'If logged in and there is a restricted group the user is not a member of, show it in `Featured Groups`.'
,
isLoggedIn
:
true
,
allGroups
:
[
restrictedGroup
],
expectedFeaturedGroups
:
[
restrictedGroup
],
},
{
description
:
'If logged in and there is an open group, show it in `Featured Groups`.'
,
isLoggedIn
:
true
,
allGroups
:
[
openGroup
],
expectedFeaturedGroups
:
[
openGroup
],
},
{
description
:
'If logged in and the user is a member of all the groups, do not show them in `Featured Groups`.'
,
isLoggedIn
:
true
,
allGroups
:
[
publicGroup
],
expectedFeaturedGroups
:
[],
},
{
description
:
'If logged out and there is an in-scope restricted group, show it in `Featured Groups`.'
,
isLoggedIn
:
false
,
allGroups
:
[
restrictedGroup
],
expectedFeaturedGroups
:
[
restrictedGroup
],
},
{
description
:
'If logged out and there is an open group, show it in `Featured Groups`.'
,
isLoggedIn
:
false
,
allGroups
:
[
openGroup
],
expectedFeaturedGroups
:
[
openGroup
],
},
].
forEach
(
({
description
,
isLoggedIn
,
allGroups
,
expectedFeaturedGroups
})
=>
{
it
(
description
,
()
=>
{
store
.
getState
().
session
=
{
userid
:
isLoggedIn
?
'1234'
:
null
};
store
.
loadGroups
(
allGroups
);
const
featuredGroups
=
getListAssertNoDupes
(
store
,
'featuredGroups'
);
assert
.
deepEqual
(
featuredGroups
,
expectedFeaturedGroups
);
});
}
);
});
describe
(
'getMyGroups'
,
()
=>
{
[
{
description
:
'If not logged in, do not show groups in `My Groups`'
,
isLoggedIn
:
false
,
allGroups
:
[
publicGroup
],
expectedMyGroups
:
[],
},
{
description
:
'If logged in and the user is a member of the group, show it in `My Groups`'
,
isLoggedIn
:
true
,
allGroups
:
[
openGroup
],
expectedMyGroups
:
[],
},
{
description
:
'If logged in and the user is a member of the unscoped group, show it in `My Groups`'
,
isLoggedIn
:
true
,
allGroups
:
[
restrictedOutOfScopeMemberGroup
],
expectedMyGroups
:
[
restrictedOutOfScopeMemberGroup
],
},
{
description
:
'If logged in and the user is a member of the group, show it in `My Groups`'
,
isLoggedIn
:
true
,
allGroups
:
[
publicGroup
],
expectedMyGroups
:
[
publicGroup
],
},
].
forEach
(({
description
,
isLoggedIn
,
allGroups
,
expectedMyGroups
})
=>
{
it
(
description
,
()
=>
{
store
.
getState
().
session
=
{
userid
:
isLoggedIn
?
'1234'
:
null
};
store
.
loadGroups
(
allGroups
);
const
myGroups
=
getListAssertNoDupes
(
store
,
'myGroups'
);
assert
.
deepEqual
(
myGroups
,
expectedMyGroups
);
});
});
});
describe
(
'getCurrentlyViewingGroups'
,
()
=>
{
[
{
description
:
'If logged out and there is an out-of-scope restricted group, show it in `Currently Viewing`'
,
isLoggedIn
:
false
,
allGroups
:
[
restrictedOutOfScopeGroup
],
},
{
description
:
'If logged out and only the Public group is present, show it in `Currently Viewing`'
,
isLoggedIn
:
false
,
allGroups
:
[
publicGroup
],
},
{
description
:
'If logged in and there is an out-of-scope restricted group that the user is not a memberof, show it in `Currently Viewing`'
,
isLoggedIn
:
true
,
allGroups
:
[
restrictedOutOfScopeGroup
],
},
].
forEach
(({
description
,
isLoggedIn
,
allGroups
})
=>
{
it
(
description
,
()
=>
{
store
.
getState
().
session
=
{
userid
:
isLoggedIn
?
'1234'
:
null
};
store
.
loadGroups
(
allGroups
);
const
currentlyViewing
=
getListAssertNoDupes
(
store
,
'currentlyViewingGroups'
);
assert
.
deepEqual
(
currentlyViewing
,
allGroups
);
});
});
});
});
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