Commit aeff9249 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Rename sidebar configuration types for clarity

Rename these types:

* `MergedConfig` -> `SidebarSettings`
* `HostConfig` -> `ConfigFromHost`
* `SidebarConfig` -> `ConfigFromSidebar`

Also, update type usage to favor `SidebarSettings` in services and
components.
parent f864c5c7
......@@ -14,7 +14,7 @@ import AnnotationShareControl from './AnnotationShareControl';
/**
* @typedef {import("../../../types/api").SavedAnnotation} SavedAnnotation
* @typedef {import('../../../types/config').HostConfig} HostConfig
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
*/
/**
......@@ -22,11 +22,11 @@ import AnnotationShareControl from './AnnotationShareControl';
* @prop {SavedAnnotation} annotation - The annotation in question
* @prop {() => any} onReply - Callbacks for when action buttons are clicked/tapped
* @prop {import('../../services/annotations').AnnotationsService} annotationsService
* @prop {HostConfig} settings
* @prop {SidebarSettings} settings
* @prop {import('../../services/toast-messenger').ToastMessengerService} toastMessenger
*/
/** @param {HostConfig} settings */
/** @param {SidebarSettings} settings */
function flaggingEnabled(settings) {
const service = serviceConfig(settings);
if (service?.allowFlagging === false) {
......
......@@ -12,13 +12,13 @@ import TagList from '../TagList';
/**
* @typedef {import("../../../types/api").Annotation} Annotation
* @typedef {import("../../../types/config").MergedConfig} MergedConfig
* @typedef {import("../../../types/config").SidebarSettings} SidebarSettings
*/
/**
* @typedef AnnotationBodyProps
* @prop {Annotation} annotation - The annotation in question
* @prop {MergedConfig} settings
* @prop {SidebarSettings} settings
*/
/**
......
......@@ -13,14 +13,14 @@ import AnnotationPublishControl from './AnnotationPublishControl';
/**
* @typedef {import("../../../types/api").Annotation} Annotation
* @typedef {import("../../../types/config").MergedConfig} MergedConfig
* @typedef {import("../../../types/config").SidebarSettings} SidebarSettings
*/
/**
* @typedef AnnotationEditorProps
* @prop {Annotation} annotation - The annotation under edit
* @prop {import('../../services/annotations').AnnotationsService} annotationsService
* @prop {MergedConfig} settings - Injected service
* @prop {SidebarSettings} settings - Injected service
* @prop {import('../../services/toast-messenger').ToastMessengerService} toastMessenger
* @prop {import('../../services/tags').TagsService} tags
*/
......
......@@ -20,7 +20,7 @@ import AnnotationUser from './AnnotationUser';
/**
* @typedef {import("../../../types/api").Annotation} Annotation
* @typedef {import('../../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
*/
/**
......@@ -29,7 +29,7 @@ import AnnotationUser from './AnnotationUser';
* @prop {boolean} [isEditing] - Whether the annotation is actively being edited
* @prop {number} replyCount - How many replies this annotation currently has
* @prop {boolean} threadIsCollapsed - Is this thread currently collapsed?
* @prop {MergedConfig} settings - Injected
* @prop {SidebarSettings} settings - Injected
*
*/
......
......@@ -11,7 +11,7 @@ import MenuItem from '../MenuItem';
/**
* @typedef {import('../../../types/api').Annotation} Annotation
* @typedef {import('../../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
*/
/**
......@@ -20,7 +20,7 @@ import MenuItem from '../MenuItem';
* @prop {boolean} [isDisabled]
* - Should the save button be disabled? Hint: it will be if the annotation has no content
* @prop {() => any} onSave - Callback for save button click
* @prop {MergedConfig} settings - Injected service
* @prop {SidebarSettings} settings - Injected service
*/
/**
......
......@@ -8,14 +8,14 @@ import Excerpt from '../Excerpt';
/**
* @typedef {import('../../../types/api').Annotation} Annotation
* @typedef {import('../../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
*/
/**
* @typedef AnnotationQuoteProps
* @prop {Annotation} annotation
* @prop {boolean} [isFocused] - Is this annotation currently focused?
* @prop {MergedConfig} [settings] - Used for theming.
* @prop {SidebarSettings} [settings] - Used for theming.
*/
/**
......
......@@ -14,7 +14,7 @@ import MenuItem from '../MenuItem';
import GroupListSection from './GroupListSection';
/**
* @typedef {import('../../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../../types/api').Group} Group
*/
......@@ -29,7 +29,7 @@ function publisherProvidedIcon(settings) {
/**
* @typedef GroupListProps
* @prop {MergedConfig} settings
* @prop {SidebarSettings} settings
*/
/**
......
......@@ -21,7 +21,7 @@ import TopBar from './TopBar';
/**
* @typedef {import('../../types/api').Profile} Profile
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('./UserMenu').AuthState} AuthState
*/
......@@ -53,7 +53,7 @@ function authStateFromProfile(profile) {
* @typedef HypothesisAppProps
* @prop {import('../services/auth').AuthService} auth
* @prop {import('../services/frame-sync').FrameSyncService} frameSync
* @prop {MergedConfig} settings
* @prop {SidebarSettings} settings
* @prop {import('../services/session').SessionService} session
* @prop {import('../services/toast-messenger').ToastMessengerService} toastMessenger
*/
......
......@@ -6,7 +6,7 @@ import { useStoreProxy } from '../store/use-store';
import { withServices } from '../service-context';
/**
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../types/sidebar').TabName} TabName
*/
......@@ -76,7 +76,7 @@ function Tab({
/**
* @typedef SelectionTabsProps
* @prop {boolean} isLoading - Are we waiting on any annotations from the server?
* @prop {MergedConfig} settings - Injected service.
* @prop {SidebarSettings} settings - Injected service.
* @prop {import('../services/annotations').AnnotationsService} annotationsService
*/
......
......@@ -8,7 +8,7 @@ import { withServices } from '../service-context';
import Thread from './Thread';
/**
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
/**
......
......@@ -13,7 +13,7 @@ import StreamSearchInput from './StreamSearchInput';
import UserMenu from './UserMenu';
/**
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../components/UserMenu').AuthState} AuthState
*/
......@@ -25,7 +25,7 @@ import UserMenu from './UserMenu';
* @prop {() => any} onLogin - Callback invoked when user clicks "Login" button.
* @prop {() => any} onLogout - Callback invoked when user clicks "Logout" action in account menu.
* @prop {() => any} onSignUp - Callback invoked when user clicks "Sign up" button.
* @prop {MergedConfig} settings
* @prop {SidebarSettings} settings
* @prop {import('../services/streamer').StreamerService} streamer
*/
......
......@@ -11,7 +11,7 @@ import MenuItem from './MenuItem';
import MenuSection from './MenuSection';
/**
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* /
/**
......@@ -28,7 +28,7 @@ import MenuSection from './MenuSection';
* @prop {AuthStateLoggedIn} auth - object representing authenticated user and auth status
* @prop {() => any} onLogout - onClick callback for the "log out" button
* @prop {import('../services/frame-sync').FrameSyncService} frameSync
* @prop {MergedConfig} settings
* @prop {SidebarSettings} settings
*/
/**
......
......@@ -3,8 +3,8 @@ import { hostPageConfig } from './host-config';
import * as postMessageJsonRpc from '../util/postmessage-json-rpc';
/**
* @typedef {import('../../types/config').SidebarConfig} SidebarConfig
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').ConfigFromSidebar} ConfigFromSidebar
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
/**
......@@ -32,15 +32,15 @@ function getAncestorFrame(levels, window_ = window) {
*
* @param {object} appConfig - App config settings rendered into `app.html` by the h service.
* @param {object} hostPageConfig - App configuration specified by the embedding frame.
* @return {object} - The merged settings.
* @return {SidebarSettings} - The merged settings.
*/
function fetchConfigEmbed(appConfig, hostPageConfig) {
const mergedConfig = {
const sidebarSettings = {
...appConfig,
...hostPageConfig,
};
mergedConfig.apiUrl = getApiUrl(mergedConfig);
return mergedConfig;
sidebarSettings.apiUrl = getApiUrl(sidebarSettings);
return sidebarSettings;
}
/**
......@@ -66,8 +66,8 @@ async function fetchConfigRpc(appConfig, parentFrame, origin) {
// Closure for the RPC call to scope parentFrame and origin variables.
const rpcCall = (method, args = [], timeout = 3000) =>
postMessageJsonRpc.call(parentFrame, origin, method, args, timeout);
const mergedConfig = fetchConfigEmbed(appConfig, remoteConfig);
return fetchGroupsAsync(mergedConfig, rpcCall);
const sidebarSettings = fetchConfigEmbed(appConfig, remoteConfig);
return fetchGroupsAsync(sidebarSettings, rpcCall);
}
/**
......@@ -109,9 +109,9 @@ async function fetchGroupsAsync(config, rpcCall) {
* Direct embed - From the hash string of the embedder frame.
* RPC request to indicated parent frame
*
* @param {SidebarConfig} appConfig
* @param {ConfigFromSidebar} appConfig
* @param {Window} window_ - Test seam.
* @return {Promise<MergedConfig>} - The merged settings.
* @return {Promise<SidebarSettings>} - The merged settings.
*/
export async function fetchConfig(appConfig, window_ = window) {
const hostConfig = hostPageConfig(window);
......@@ -132,7 +132,7 @@ export async function fetchConfig(appConfig, window_ = window) {
window_
);
const rpcMergedConfig = await fetchConfigRpc(
const rpcSidebarSettings = await fetchConfigRpc(
appConfig,
parentFrame,
requestConfigFromFrame.origin
......@@ -140,7 +140,7 @@ export async function fetchConfig(appConfig, window_ = window) {
// Add back the optional focused group id from the host page config
// as this is needed in the Notebook.
return {
...rpcMergedConfig,
...rpcSidebarSettings,
...(hostConfig.group ? { group: hostConfig.group } : {}),
};
} else {
......
......@@ -6,14 +6,14 @@ import {
toString,
} from '../../shared/type-coercions';
/** @typedef {import('../../types/config').HostConfig} HostConfig */
/** @typedef {import('../../types/config').ConfigFromHost} ConfigFromHost */
/**
* Return the app configuration specified by the frame embedding the Hypothesis
* client.
*
* @param {Window} window
* @return {HostConfig}
* @return {ConfigFromHost}
*/
export function hostPageConfig(window) {
const config = parseConfigFragment(window.location.href);
......
/**
* @typedef {import('../../types/config').HostConfig} HostConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../types/config').Service} Service
*/
......@@ -7,7 +7,7 @@
* Return the configuration for the annotation service which the client would retrieve
* annotations from which may contain the authority, grantToken and icon.
*
* @param {HostConfig} settings
* @param {SidebarSettings} settings
* @return {Service|null}
*/
......
......@@ -47,8 +47,8 @@ describe('sidebar/config/fetch-config', () => {
// by h with the settings from `window.hypothesisConfig` in the parent
// window.
it('adds the apiUrl to the merged result', async () => {
const mergedConfig = await fetchConfig({});
assert.deepEqual(mergedConfig, { apiUrl: fakeApiUrl() });
const sidebarSettings = await fetchConfig({});
assert.deepEqual(sidebarSettings, { apiUrl: fakeApiUrl() });
});
it('does not fetch settings from ancestor frames', async () => {
......@@ -60,8 +60,8 @@ describe('sidebar/config/fetch-config', () => {
// hostPageConfig shall take precedent over appConfig
const appConfig = { foo: 'bar', appType: 'via' };
fakeHostPageConfig.returns({ foo: 'baz' });
const mergedConfig = await fetchConfig(appConfig);
assert.deepEqual(mergedConfig, {
const sidebarSettings = await fetchConfig(appConfig);
assert.deepEqual(sidebarSettings, {
foo: 'baz',
appType: 'via',
apiUrl: fakeApiUrl(),
......
/**
* @typedef {import('../../types/api').Annotation} Annotation
* @typedef {import('../../types/config').HostConfig} HostConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
import { serviceConfig } from '../config/service-config';
......@@ -63,7 +63,7 @@ export function isShareableURI(uri) {
* Is the sharing of annotations enabled? Check for any defined `serviceConfig`,
* but default to `true` if none found.
*
* @param {HostConfig} settings
* @param {SidebarSettings} settings
* @return {boolean}
*/
export function sharingEnabled(settings) {
......
/**
* @typedef {import('../../types/config').HostConfig} HostConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../types/api').Group} Group
* @typedef {import('../../types/api').GroupIdentifier} GroupIdentifier
*/
......@@ -15,7 +15,7 @@ import { serviceConfig } from '../config/service-config';
* explicitly disallowed in the service configuration of the
* `settings` object.
*
* @param {HostConfig} settings
* @param {SidebarSettings} settings
* @return {boolean}
*/
function allowLeavingGroups(settings) {
......@@ -35,7 +35,7 @@ function allowLeavingGroups(settings) {
* @param {Group[]} userGroups - groups the user is a member of
* @param {Group[]} featuredGroups - all other groups, may include some duplicates from the userGroups
* @param {string|null} uri - uri of the current page
* @param {HostConfig} settings
* @param {SidebarSettings} settings
*/
export function combineGroups(userGroups, featuredGroups, uri, settings) {
const worldGroup = featuredGroups.find(g => g.id === '__world__');
......
/**
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
import { serviceConfig } from '../config/service-config';
......@@ -12,7 +12,7 @@ import { serviceConfig } from '../config/service-config';
*
* If no custom annotation services are configured then return `false`.
*
* @param {MergedConfig} settings
* @param {SidebarSettings} settings
* @return {boolean}
*/
export function isThirdPartyService(settings) {
......
import { serviceConfig } from '../config/service-config';
/**
* @typedef {import('../../types/config').HostConfig} HostConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../types/api').Profile} Profile
*/
......@@ -31,7 +31,7 @@ export function shouldShowSidebarTutorial(sessionState) {
*
* @param {boolean} isSidebar - is the app currently displayed in a sidebar?
* @param {Profile} profile - User profile returned from the API
* @param {HostConfig} settings
* @param {SidebarSettings} settings
* @return {boolean} - Tutorial panel should be displayed automatically
*/
export function shouldAutoDisplayTutorial(isSidebar, profile, settings) {
......
......@@ -11,7 +11,7 @@ import { disableOpenerForExternalLinks } from './util/disable-opener-for-externa
import * as sentry from './util/sentry';
// Read settings rendered into sidebar app HTML by service/extension.
const appConfig = /** @type {import('../types/config').SidebarConfig} */ (
const appConfig = /** @type {import('../types/config').ConfigFromSidebar} */ (
parseJsonConfig(document)
);
......
......@@ -18,7 +18,7 @@ function getJSON(url) {
/**
* @typedef {import('../../types/api').RouteMap} RouteMap
* @typedef {import('../../types/config').SidebarConfig} SidebarConfig
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
/**
......@@ -27,7 +27,7 @@ function getJSON(url) {
// @inject
export class APIRoutesService {
/**
* @param {SidebarConfig} settings
* @param {SidebarSettings} settings
*/
constructor(settings) {
this._apiUrl = settings.apiUrl;
......
......@@ -51,7 +51,7 @@ import { viewerModule } from './modules/viewer';
*
* [1] https://redux.js.org
*
* @param {import('../../types/config').SidebarConfig} settings
* @param {import('../../types/config').SidebarSettings} settings
* @return {SidebarStore}
* @inject
*/
......
......@@ -44,7 +44,7 @@
*
* See `h.views.client` in the "h" application.
*
* @typedef SidebarConfig
* @typedef ConfigFromSidebar
* @prop {string} apiUrl
* @prop {string} authDomain
* @prop {string} oauthClientId
......@@ -65,7 +65,7 @@
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/ which
* excludes any keys used only by the "annotator" part of the application.
*
* @typedef HostConfig
* @typedef ConfigFromHost
* @prop {string} [annotations] - Direct-linked annotation ID
* @prop {string} [group] - Direct-linked group ID
* @prop {string} [query] - Initial filter query
......@@ -91,7 +91,7 @@
* (filtered and validated) configuration from the host page with configuration
* from h / the browser extension.
*
* @typedef {HostConfig & SidebarConfig} MergedConfig
* @typedef {ConfigFromHost & ConfigFromSidebar} SidebarSettings
*/
// Make TypeScript treat this file as a module.
......
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