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
3ba2f41e
Commit
3ba2f41e
authored
Aug 15, 2018
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inject a default organization into groups objects without organizations
parent
bcd94af1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
groups.js
src/sidebar/services/groups.js
+27
-0
groups-test.js
src/sidebar/services/test/groups-test.js
+15
-0
No files found.
src/sidebar/services/groups.js
View file @
3ba2f41e
'use strict'
;
'use strict'
;
var
STORAGE_KEY
=
'hypothesis.groups.focus'
;
var
STORAGE_KEY
=
'hypothesis.groups.focus'
;
const
DEFAULT_ORG_ID
=
'__default__'
;
/**
* FIXME: There is almost assuredly a better way to handle a fallback, default logo
*/
const
DEFAULT_ORGANIZATION
=
{
id
:
DEFAULT_ORG_ID
,
logo
:
'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon masthead-logo" height="28" viewBox="0 0 24 28" width="24"><path d="M3.886 3.945H21.03v16.047H3.886z" fill="#fff" /><path d="M0 2.005C0 .898.897 0 2.005 0h19.99C23.102 0 24 .897 24 2.005v19.99A2.005 2.005 0 0 1 21.995 24H2.005A2.005 2.005 0 0 1 0 21.995V2.005zM9 24l3 4 3-4H9zM7.008 4H4v16h3.008v-4.997C7.008 12.005 8.168 12.01 9 12c1 .007 2.019.06 2.019 2.003V20h3.008v-6.891C14.027 10 12 9.003 10 9.003c-1.99 0-2 0-2.992 1.999V4zM19 19.987c1.105 0 2-.893 2-1.994A1.997 1.997 0 0 0 19 16c-1.105 0-2 .892-2 1.993s.895 1.994 2 1.994z" fill="currentColor" fill-rule="evenodd" /></svg>'
,
};
var
events
=
require
(
'../events'
);
var
events
=
require
(
'../events'
);
var
{
awaitStateChange
}
=
require
(
'../util/state-util'
);
var
{
awaitStateChange
}
=
require
(
'../util/state-util'
);
...
@@ -72,6 +81,22 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -72,6 +81,22 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
});
});
}
}
/**
* For any group that does not have an associated organization, populate with
* the default Hypothesis organization.
*
* Mutates group objects in place
*
* @param {Group[]} groups
*/
function
injectOrganizations
(
groups
)
{
groups
.
forEach
(
group
=>
{
if
(
!
group
.
organization
||
typeof
group
.
organization
!==
'object'
)
{
group
.
organization
=
DEFAULT_ORGANIZATION
;
}
});
}
// The document URI passed to the most recent `GET /api/groups` call in order
// The document URI passed to the most recent `GET /api/groups` call in order
// to include groups associated with this page. This is retained to determine
// to include groups associated with this page. This is retained to determine
// whether we need to re-fetch groups if the URLs of frames connected to the
// whether we need to re-fetch groups if the URLs of frames connected to the
...
@@ -111,6 +136,8 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -111,6 +136,8 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
var
directLinkedAnnotation
=
settings
.
annotations
;
var
directLinkedAnnotation
=
settings
.
annotations
;
return
filterGroups
(
data
,
isLoggedIn
,
directLinkedAnnotation
);
return
filterGroups
(
data
,
isLoggedIn
,
directLinkedAnnotation
);
}).
then
(
groups
=>
{
}).
then
(
groups
=>
{
injectOrganizations
(
groups
);
var
isFirstLoad
=
store
.
allGroups
().
length
===
0
;
var
isFirstLoad
=
store
.
allGroups
().
length
===
0
;
var
prevFocusedGroup
=
localStorage
.
getItem
(
STORAGE_KEY
);
var
prevFocusedGroup
=
localStorage
.
getItem
(
STORAGE_KEY
);
...
...
src/sidebar/services/test/groups-test.js
View file @
3ba2f41e
...
@@ -205,6 +205,21 @@ describe('groups', function() {
...
@@ -205,6 +205,21 @@ describe('groups', function() {
});
});
});
});
it
(
'injects a defalt organization if group is missing an organization'
,
function
()
{
var
svc
=
service
();
const
groups
=
[
{
id
:
'39r39f'
,
name
:
'Ding Dong!'
},
];
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
({
token
:
'1234'
,
data
:
groups
,
}));
return
svc
.
load
().
then
(
groups
=>
{
assert
.
isObject
(
groups
[
0
].
organization
);
assert
.
hasAllKeys
(
groups
[
0
].
organization
,
[
'id'
,
'logo'
]);
});
});
truthTable
(
3
).
forEach
(([
loggedIn
,
pageHasAssociatedGroups
,
directLinkToPublicAnnotation
])
=>
{
truthTable
(
3
).
forEach
(([
loggedIn
,
pageHasAssociatedGroups
,
directLinkToPublicAnnotation
])
=>
{
it
(
'excludes the "Public" group if user logged out and page has associated groups'
,
()
=>
{
it
(
'excludes the "Public" group if user logged out and page has associated groups'
,
()
=>
{
var
svc
=
service
();
var
svc
=
service
();
...
...
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