Commit 50cdcc2e authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Update components to use store as source for `defaultAuthority`

* Update `GroupList` to use store as source of default authority
* Update `TagList` to use store as source of `defaultAuthority`
* Update `UserMenu` to use store as source for `defaultAuthority`
parent ba15a2b1
...@@ -61,8 +61,9 @@ function GroupList({ serviceUrl, settings }) { ...@@ -61,8 +61,9 @@ function GroupList({ serviceUrl, settings }) {
[currentGroups] [currentGroups]
); );
const { authDomain } = settings; const defaultAuthority = store.defaultAuthority();
const canCreateNewGroup = userid && !isThirdPartyUser(userid, authDomain); const canCreateNewGroup =
userid && !isThirdPartyUser(userid, defaultAuthority);
const newGroupLink = serviceUrl('groups.new'); const newGroupLink = serviceUrl('groups.new');
// The group whose submenu is currently open, or `null` if no group item is // The group whose submenu is currently open, or `null` if no group item is
......
import { useMemo } from 'preact/hooks'; import { useMemo } from 'preact/hooks';
import { useStoreProxy } from '../store/use-store';
import { isThirdPartyUser } from '../helpers/account-id'; import { isThirdPartyUser } from '../helpers/account-id';
import { withServices } from '../service-context'; import { withServices } from '../service-context';
...@@ -10,18 +11,19 @@ import { withServices } from '../service-context'; ...@@ -10,18 +11,19 @@ import { withServices } from '../service-context';
* @prop {Annotation} annotation - Annotation that owns the tags. * @prop {Annotation} annotation - Annotation that owns the tags.
* @prop {string[]} tags - List of tags as strings. * @prop {string[]} tags - List of tags as strings.
* @prop {(a: string, b: Object<'tag', string>) => any} serviceUrl - Services * @prop {(a: string, b: Object<'tag', string>) => any} serviceUrl - Services
* @prop {{ authDomain: string }} settings
*/ */
/** /**
* Component to render an annotation's tags. * Component to render an annotation's tags.
* @param {TagListProps} props * @param {TagListProps} props
*/ */
function TagList({ annotation, serviceUrl, settings, tags }) { function TagList({ annotation, serviceUrl, tags }) {
const store = useStoreProxy();
const defaultAuthority = store.defaultAuthority();
const renderLink = useMemo( const renderLink = useMemo(
// Show a link if the authority of the user is not 3rd party // Show a link if the authority of the user is not 3rd party
() => !isThirdPartyUser(annotation.user, settings.authDomain), () => !isThirdPartyUser(annotation.user, defaultAuthority),
[annotation, settings] [annotation, defaultAuthority]
); );
/** /**
...@@ -61,6 +63,6 @@ function TagList({ annotation, serviceUrl, settings, tags }) { ...@@ -61,6 +63,6 @@ function TagList({ annotation, serviceUrl, settings, tags }) {
); );
} }
TagList.injectedProps = ['serviceUrl', 'settings']; TagList.injectedProps = ['serviceUrl'];
export default withServices(TagList); export default withServices(TagList);
...@@ -42,7 +42,9 @@ import MenuSection from './MenuSection'; ...@@ -42,7 +42,9 @@ import MenuSection from './MenuSection';
*/ */
function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) { function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) {
const store = useStoreProxy(); const store = useStoreProxy();
const isThirdParty = isThirdPartyUser(auth.userid, settings.authDomain); const defaultAuthority = store.defaultAuthority();
const isThirdParty = isThirdPartyUser(auth.userid, defaultAuthority);
const service = serviceConfig(settings); const service = serviceConfig(settings);
const isNotebookEnabled = store.isFeatureEnabled('notebook_launch'); const isNotebookEnabled = store.isFeatureEnabled('notebook_launch');
const [isOpen, setOpen] = useState(false); const [isOpen, setOpen] = useState(false);
......
...@@ -48,10 +48,9 @@ describe('GroupList', () => { ...@@ -48,10 +48,9 @@ describe('GroupList', () => {
}; };
fakeServiceUrl = sinon.stub(); fakeServiceUrl = sinon.stub();
fakeSettings = { fakeSettings = {};
authDomain: 'hypothes.is',
};
fakeStore = { fakeStore = {
defaultAuthority: sinon.stub().returns('hypothes.is'),
getCurrentlyViewingGroups: sinon.stub().returns([]), getCurrentlyViewingGroups: sinon.stub().returns([]),
getFeaturedGroups: sinon.stub().returns([]), getFeaturedGroups: sinon.stub().returns([]),
getMyGroups: sinon.stub().returns([]), getMyGroups: sinon.stub().returns([]),
......
...@@ -6,9 +6,10 @@ import { $imports } from '../TagList'; ...@@ -6,9 +6,10 @@ import { $imports } from '../TagList';
import { checkAccessibility } from '../../../test-util/accessibility'; import { checkAccessibility } from '../../../test-util/accessibility';
import mockImportedComponents from '../../../test-util/mock-imported-components'; import mockImportedComponents from '../../../test-util/mock-imported-components';
describe('TagList', function () { describe('TagList', () => {
let fakeServiceUrl; let fakeServiceUrl;
let fakeIsThirdPartyUser; let fakeIsThirdPartyUser;
let fakeStore;
const fakeTags = ['tag1', 'tag2']; const fakeTags = ['tag1', 'tag2'];
function createComponent(props) { function createComponent(props) {
...@@ -19,21 +20,25 @@ describe('TagList', function () { ...@@ -19,21 +20,25 @@ describe('TagList', function () {
tags={fakeTags} tags={fakeTags}
// service props // service props
serviceUrl={fakeServiceUrl} serviceUrl={fakeServiceUrl}
settings={{}}
{...props} {...props}
/> />
); );
} }
beforeEach(function () { beforeEach(() => {
fakeServiceUrl = sinon.stub().returns('http://serviceurl.com'); fakeServiceUrl = sinon.stub().returns('http://serviceurl.com');
fakeIsThirdPartyUser = sinon.stub().returns(false); fakeIsThirdPartyUser = sinon.stub().returns(false);
fakeStore = {
defaultAuthority: sinon.stub().returns('hypothes.is'),
};
$imports.$mock(mockImportedComponents()); $imports.$mock(mockImportedComponents());
$imports.$mock({ $imports.$mock({
'../helpers/account-id': { '../helpers/account-id': {
isThirdPartyUser: fakeIsThirdPartyUser, isThirdPartyUser: fakeIsThirdPartyUser,
}, },
'../store/use-store': { useStoreProxy: () => fakeStore },
}); });
}); });
...@@ -69,7 +74,7 @@ describe('TagList', function () { ...@@ -69,7 +74,7 @@ describe('TagList', function () {
}); });
context('when `isThirdPartyUser` returns true', () => { context('when `isThirdPartyUser` returns true', () => {
beforeEach(function () { beforeEach(() => {
fakeIsThirdPartyUser.returns(true); fakeIsThirdPartyUser.returns(true);
}); });
......
...@@ -47,10 +47,9 @@ describe('UserMenu', () => { ...@@ -47,10 +47,9 @@ describe('UserMenu', () => {
fakeOnLogout = sinon.stub(); fakeOnLogout = sinon.stub();
fakeServiceConfig = sinon.stub(); fakeServiceConfig = sinon.stub();
fakeServiceUrl = sinon.stub(); fakeServiceUrl = sinon.stub();
fakeSettings = { fakeSettings = {};
authDomain: 'hypothes.is',
};
fakeStore = { fakeStore = {
defaultAuthority: sinon.stub().returns('hypothes.is'),
focusedGroupId: sinon.stub().returns('mygroup'), focusedGroupId: sinon.stub().returns('mygroup'),
isFeatureEnabled: sinon.stub().returns(false), isFeatureEnabled: sinon.stub().returns(false),
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment