Commit 8775ce22 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Adapt configuration to support the new user profile mini-app

parent fc9dba5f
...@@ -28,6 +28,7 @@ jobs: ...@@ -28,6 +28,7 @@ jobs:
environment: qa environment: qa
env: env:
NOTEBOOK_APP_URL: https://qa.hypothes.is/notebook NOTEBOOK_APP_URL: https://qa.hypothes.is/notebook
PROFILE_APP_URL: https://qa.hypothes.is/user-profile
SIDEBAR_APP_URL: https://qa.hypothes.is/app.html SIDEBAR_APP_URL: https://qa.hypothes.is/app.html
steps: steps:
...@@ -69,6 +70,7 @@ jobs: ...@@ -69,6 +70,7 @@ jobs:
environment: production environment: production
env: env:
NOTEBOOK_APP_URL: https://hypothes.is/notebook NOTEBOOK_APP_URL: https://hypothes.is/notebook
PROFILE_APP_URL: https://hypothes.is/user-profile
SIDEBAR_APP_URL: https://hypothes.is/app.html SIDEBAR_APP_URL: https://hypothes.is/app.html
steps: steps:
......
...@@ -21,6 +21,10 @@ const notebookAppUrl = process.env.NOTEBOOK_APP_URL ...@@ -21,6 +21,10 @@ const notebookAppUrl = process.env.NOTEBOOK_APP_URL
? `${process.env.NOTEBOOK_APP_URL}` ? `${process.env.NOTEBOOK_APP_URL}`
: `${localhost}:5000/notebook`; : `${localhost}:5000/notebook`;
const profileAppUrl = process.env.PROFILE_APP_URL
? `${process.env.PROFILE_APP_URL}`
: `${localhost}:5000/user-profile`;
const sidebarAppUrl = process.env.SIDEBAR_APP_URL const sidebarAppUrl = process.env.SIDEBAR_APP_URL
? `${process.env.SIDEBAR_APP_URL}` ? `${process.env.SIDEBAR_APP_URL}`
: `${localhost}:5000/app.html`; : `${localhost}:5000/app.html`;
...@@ -52,6 +56,7 @@ export default { ...@@ -52,6 +56,7 @@ export default {
values: { values: {
__ASSET_ROOT__: assetRoot, __ASSET_ROOT__: assetRoot,
__NOTEBOOK_APP_URL__: notebookAppUrl, __NOTEBOOK_APP_URL__: notebookAppUrl,
__PROFILE_APP_URL__: profileAppUrl,
__SIDEBAR_APP_URL__: sidebarAppUrl, __SIDEBAR_APP_URL__: sidebarAppUrl,
}, },
}), }),
......
...@@ -36,7 +36,7 @@ export function createAppConfig(appURL, config) { ...@@ -36,7 +36,7 @@ export function createAppConfig(appURL, config) {
appConfig.origin = new URL(appURL).origin; appConfig.origin = new URL(appURL).origin;
// Pass the version of the client, so we can check if it is the same as the // Pass the version of the client, so we can check if it is the same as the
// one used in the sidebar/notebook. // one used in the sidebar/notebook/profile.
appConfig.version = '__VERSION__'; appConfig.version = '__VERSION__';
// Pass the URL of the page that embedded the client. // Pass the URL of the page that embedded the client.
......
...@@ -23,7 +23,7 @@ import { urlFromLinkTag } from './url-from-link-tag'; ...@@ -23,7 +23,7 @@ import { urlFromLinkTag } from './url-from-link-tag';
* Named subset of the Hypothesis client configuration that is relevant in * Named subset of the Hypothesis client configuration that is relevant in
* a particular context. * a particular context.
* *
* @typedef {'sidebar'|'notebook'|'annotator'|'all'} Context * @typedef {'sidebar'|'notebook'|'profile'|'annotator'|'all'} Context
*/ */
/** /**
...@@ -61,6 +61,7 @@ function configurationKeys(context) { ...@@ -61,6 +61,7 @@ function configurationKeys(context) {
'theme', 'theme',
'usernameUrl', 'usernameUrl',
], ],
profile: ['profileAppUrl'],
}; };
switch (context) { switch (context) {
...@@ -70,9 +71,11 @@ function configurationKeys(context) { ...@@ -70,9 +71,11 @@ function configurationKeys(context) {
return contexts.sidebar; return contexts.sidebar;
case 'notebook': case 'notebook':
return contexts.notebook; return contexts.notebook;
case 'profile':
return contexts.profile;
case 'all': case 'all':
// Complete list of configuration keys used for testing. // Complete list of configuration keys used for testing.
return [...contexts.annotator, ...contexts.sidebar, ...contexts.notebook]; return Object.values(contexts).flat();
default: default:
throw new Error(`Invalid application context used: "${context}"`); throw new Error(`Invalid application context used: "${context}"`);
} }
...@@ -177,6 +180,11 @@ const configDefinitions = { ...@@ -177,6 +180,11 @@ const configDefinitions = {
defaultValue: null, defaultValue: null,
getValue: settings => settings.notebookAppUrl, getValue: settings => settings.notebookAppUrl,
}, },
profileAppUrl: {
allowInBrowserExt: true,
defaultValue: null,
getValue: settings => settings.profileAppUrl,
},
sidebarAppUrl: { sidebarAppUrl: {
allowInBrowserExt: true, allowInBrowserExt: true,
defaultValue: null, defaultValue: null,
......
...@@ -14,6 +14,7 @@ import { urlFromLinkTag } from './url-from-link-tag'; ...@@ -14,6 +14,7 @@ import { urlFromLinkTag } from './url-from-link-tag';
* @prop {string} clientUrl * @prop {string} clientUrl
* @prop {string} sidebarAppUrl * @prop {string} sidebarAppUrl
* @prop {string} notebookAppUrl * @prop {string} notebookAppUrl
* @prop {string} profileAppUrl
* @prop {(name: string) => unknown} hostPageSetting * @prop {(name: string) => unknown} hostPageSetting
*/ */
...@@ -175,6 +176,9 @@ export function settingsFrom(window_) { ...@@ -175,6 +176,9 @@ export function settingsFrom(window_) {
get notebookAppUrl() { get notebookAppUrl() {
return urlFromLinkTag(window_, 'notebook', 'html'); return urlFromLinkTag(window_, 'notebook', 'html');
}, },
get profileAppUrl() {
return urlFromLinkTag(window_, 'profile', 'html');
},
get showHighlights() { get showHighlights() {
return showHighlights(); return showHighlights();
}, },
......
...@@ -12,6 +12,7 @@ describe('annotator/config/index', () => { ...@@ -12,6 +12,7 @@ describe('annotator/config/index', () => {
clientUrl: 'fakeValue', clientUrl: 'fakeValue',
group: 'fakeValue', group: 'fakeValue',
notebookAppUrl: 'fakeValue', notebookAppUrl: 'fakeValue',
profileAppUrl: 'fakeValue',
showHighlights: 'fakeValue', showHighlights: 'fakeValue',
sidebarAppUrl: 'fakeValue', sidebarAppUrl: 'fakeValue',
query: 'fakeValue', query: 'fakeValue',
...@@ -83,6 +84,7 @@ describe('annotator/config/index', () => { ...@@ -83,6 +84,7 @@ describe('annotator/config/index', () => {
focus: null, focus: null,
group: 'fakeValue', group: 'fakeValue',
notebookAppUrl: 'fakeValue', notebookAppUrl: 'fakeValue',
profileAppUrl: 'fakeValue',
onLayoutChange: null, onLayoutChange: null,
openSidebar: true, // coerced openSidebar: true, // coerced
query: 'fakeValue', query: 'fakeValue',
...@@ -115,6 +117,7 @@ describe('annotator/config/index', () => { ...@@ -115,6 +117,7 @@ describe('annotator/config/index', () => {
focus: 'fakeValue', focus: 'fakeValue',
group: 'fakeValue', group: 'fakeValue',
notebookAppUrl: 'fakeValue', notebookAppUrl: 'fakeValue',
profileAppUrl: 'fakeValue',
onLayoutChange: 'fakeValue', onLayoutChange: 'fakeValue',
openSidebar: true, // coerced openSidebar: true, // coerced
query: 'fakeValue', query: 'fakeValue',
...@@ -171,6 +174,7 @@ describe('annotator/config/index', () => { ...@@ -171,6 +174,7 @@ describe('annotator/config/index', () => {
focus: null, focus: null,
group: null, group: null,
notebookAppUrl: null, notebookAppUrl: null,
profileAppUrl: null,
onLayoutChange: null, onLayoutChange: null,
openSidebar: false, openSidebar: false,
query: null, query: null,
...@@ -255,6 +259,10 @@ describe('annotator/config/index', () => { ...@@ -255,6 +259,10 @@ describe('annotator/config/index', () => {
'usernameUrl', 'usernameUrl',
], ],
}, },
{
app: 'profile',
expectedKeys: ['profileAppUrl'],
},
].forEach(test => { ].forEach(test => {
it(`ignores values not belonging to "${test.app}" context`, () => { it(`ignores values not belonging to "${test.app}" context`, () => {
const config = getConfig(test.app, 'WINDOW'); const config = getConfig(test.app, 'WINDOW');
......
...@@ -35,6 +35,16 @@ describe('annotator/config/settingsFrom', () => { ...@@ -35,6 +35,16 @@ describe('annotator/config/settingsFrom', () => {
}); });
}); });
describe('#profileAppUrl', () => {
it('calls urlFromLinkTag with appropriate params', () => {
assert.equal(
settingsFrom(window).profileAppUrl,
'http://example.com/app.html'
);
assert.calledWith(fakeUrlFromLinkTag, window, 'profile', 'html');
});
});
describe('#sidebarAppUrl', () => { describe('#sidebarAppUrl', () => {
it('calls urlFromLinkTag with appropriate params', () => { it('calls urlFromLinkTag with appropriate params', () => {
assert.equal( assert.equal(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* @typedef AnnotatorConfig * @typedef AnnotatorConfig
* @prop {string} assetRoot - The root URL to which URLs in `manifest` are relative * @prop {string} assetRoot - The root URL to which URLs in `manifest` are relative
* @prop {string} notebookAppUrl - The URL of the sidebar's notebook * @prop {string} notebookAppUrl - The URL of the sidebar's notebook
* @prop {string} profileAppUrl - The URL of the sidebar's user profile view
* @prop {string} sidebarAppUrl - The URL of the sidebar's HTML page * @prop {string} sidebarAppUrl - The URL of the sidebar's HTML page
* @prop {Record<string,string>} manifest - * @prop {Record<string,string>} manifest -
* A mapping from canonical asset path to cache-busted asset path * A mapping from canonical asset path to cache-busted asset path
...@@ -154,6 +155,9 @@ export function bootHypothesisClient(doc, config) { ...@@ -154,6 +155,9 @@ export function bootHypothesisClient(doc, config) {
// Register the URL of the notebook app which the Hypothesis client should load. // Register the URL of the notebook app which the Hypothesis client should load.
injectLink(doc, 'notebook', 'html', config.notebookAppUrl); injectLink(doc, 'notebook', 'html', config.notebookAppUrl);
// Register the URL of the user profile app which the Hypothesis client should load.
injectLink(doc, 'profile', 'html', config.profileAppUrl);
// Preload the styles used by the shadow roots of annotator UI elements. // Preload the styles used by the shadow roots of annotator UI elements.
preloadURL(doc, 'style', assetURL(config, 'styles/annotator.css')); preloadURL(doc, 'style', assetURL(config, 'styles/annotator.css'));
......
...@@ -39,6 +39,9 @@ if (isBrowserSupported()) { ...@@ -39,6 +39,9 @@ if (isBrowserSupported()) {
const notebookAppUrl = processUrlTemplate( const notebookAppUrl = processUrlTemplate(
annotatorConfig.notebookAppUrl || '__NOTEBOOK_APP_URL__' annotatorConfig.notebookAppUrl || '__NOTEBOOK_APP_URL__'
); );
const profileAppUrl = processUrlTemplate(
annotatorConfig.profileAppUrl || '__PROFILE_APP_URL__'
);
const sidebarAppUrl = processUrlTemplate( const sidebarAppUrl = processUrlTemplate(
annotatorConfig.sidebarAppUrl || '__SIDEBAR_APP_URL__' annotatorConfig.sidebarAppUrl || '__SIDEBAR_APP_URL__'
); );
...@@ -46,6 +49,7 @@ if (isBrowserSupported()) { ...@@ -46,6 +49,7 @@ if (isBrowserSupported()) {
assetRoot, assetRoot,
manifest, manifest,
notebookAppUrl, notebookAppUrl,
profileAppUrl,
sidebarAppUrl, sidebarAppUrl,
}); });
} }
......
/** /**
* @typedef {'annotation'|'notebook'|'stream'|'sidebar'} RouteName * @typedef {'annotation'|'notebook'|'profile'|'stream'|'sidebar'} RouteName
* @typedef {Record<string,string>} RouteParams * @typedef {Record<string,string>} RouteParams
*/ */
...@@ -58,6 +58,9 @@ export class RouterService { ...@@ -58,6 +58,9 @@ export class RouterService {
case 'notebook': case 'notebook':
route = 'notebook'; route = 'notebook';
break; break;
case 'user-profile':
route = 'profile';
break;
case 'stream': case 'stream':
route = 'stream'; route = 'stream';
break; break;
...@@ -90,6 +93,9 @@ export class RouterService { ...@@ -90,6 +93,9 @@ export class RouterService {
case 'notebook': case 'notebook':
url = '/notebook'; url = '/notebook';
break; break;
case 'profile':
url = '/user-profile';
break;
case 'stream': case 'stream':
url = '/stream'; url = '/stream';
break; break;
......
...@@ -15,6 +15,11 @@ const fixtures = [ ...@@ -15,6 +15,11 @@ const fixtures = [
route: 'notebook', route: 'notebook',
params: {}, params: {},
}, },
{
path: '/user-profile',
route: 'profile',
params: {},
},
{ {
path: '/a/foo', path: '/a/foo',
route: 'annotation', route: 'annotation',
......
import { createStoreModule, makeAction } from '../create-store'; import { createStoreModule, makeAction } from '../create-store';
/** /**
* @typedef {'annotation'|'notebook'|'sidebar'|'stream'} RouteName * @typedef {'annotation'|'notebook'|'profile'|'sidebar'|'stream'} RouteName
*/ */
const initialState = { const initialState = {
......
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