Skip to content

Commit 86a27a7

Browse files
committed
Replace ui-constants module with sidebar typedefs
1 parent eb1f27c commit 86a27a7

25 files changed

+152
-174
lines changed

src/sidebar/components/AnnotationActionBar.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createElement } from 'preact';
22
import propTypes from 'prop-types';
33

4-
import uiConstants from '../ui-constants';
54
import { useStoreProxy } from '../store/use-store';
65
import {
76
sharingEnabled,
@@ -84,7 +83,7 @@ function AnnotationActionBar({
8483

8584
const onReplyClick = () => {
8685
if (!isLoggedIn) {
87-
store.openSidebarPanel(uiConstants.PANEL_LOGIN_PROMPT);
86+
store.openSidebarPanel('loginPrompt');
8887
return;
8988
}
9089
onReply();

src/sidebar/components/HelpPanel.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useCallback, useMemo, useState } from 'preact/hooks';
44
import propTypes from 'prop-types';
55

66
import { useStoreProxy } from '../store/use-store';
7-
import uiConstants from '../ui-constants';
87
import { withServices } from '../service-context';
98
import VersionData from '../helpers/version-data';
109

@@ -110,7 +109,7 @@ function HelpPanel({ auth, session }) {
110109
return (
111110
<SidebarPanel
112111
title="Help"
113-
panelName={uiConstants.PANEL_HELP}
112+
panelName="help"
114113
onActiveChanged={onActiveChanged}
115114
>
116115
<div className="HelpPanel__content u-vertical-rhythm">

src/sidebar/components/HypothesisApp.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import propTypes from 'prop-types';
66
import bridgeEvents from '../../shared/bridge-events';
77
import serviceConfig from '../config/service-config';
88
import { useStoreProxy } from '../store/use-store';
9-
import uiConstants from '../ui-constants';
109
import { parseAccountID } from '../helpers/account-id';
1110
import { shouldAutoDisplayTutorial } from '../helpers/session';
1211
import { applyTheme } from '../helpers/theme';
@@ -101,7 +100,7 @@ function HypothesisApp({
101100

102101
useEffect(() => {
103102
if (shouldAutoDisplayTutorial(isSidebar, profile, settings)) {
104-
store.openSidebarPanel(uiConstants.PANEL_HELP);
103+
store.openSidebarPanel('help');
105104
}
106105
}, [isSidebar, profile, settings, store]);
107106

@@ -115,7 +114,7 @@ function HypothesisApp({
115114
try {
116115
await auth.login();
117116

118-
store.closeSidebarPanel(uiConstants.PANEL_LOGIN_PROMPT);
117+
store.closeSidebarPanel('loginPrompt');
119118
store.clearGroups();
120119
session.reload();
121120
} catch (err) {

src/sidebar/components/LoginPromptPanel.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createElement } from 'preact';
22
import propTypes from 'prop-types';
33

44
import { useStoreProxy } from '../store/use-store';
5-
import uiConstants from '../ui-constants';
65

76
import Button from './Button';
87
import SidebarPanel from './SidebarPanel';
@@ -28,7 +27,7 @@ export default function LoginPromptPanel({ onLogin, onSignUp }) {
2827
<SidebarPanel
2928
icon="restricted"
3029
title="Login needed"
31-
panelName={uiConstants.PANEL_LOGIN_PROMPT}
30+
panelName="loginPrompt"
3231
>
3332
<p>Please log in to create annotations or highlights.</p>
3433
<div className="SidebarPanel__actions">

src/sidebar/components/NewNoteBtn.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createElement } from 'preact';
22
import propTypes from 'prop-types';
33

4-
import uiConstants from '../ui-constants';
54
import { useStoreProxy } from '../store/use-store';
65
import { withServices } from '../service-context';
76
import { applyTheme } from '../helpers/theme';
@@ -25,7 +24,7 @@ function NewNoteButton({ annotationsService, settings }) {
2524

2625
const onNewNoteBtnClick = function () {
2726
if (!isLoggedIn) {
28-
store.openSidebarPanel(uiConstants.PANEL_LOGIN_PROMPT);
27+
store.openSidebarPanel('loginPrompt');
2928
return;
3029
}
3130
if (!topLevelFrame) {

src/sidebar/components/SelectionTabs.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { createElement } from 'preact';
44
import propTypes from 'prop-types';
55

66
import { useStoreProxy } from '../store/use-store';
7-
import uiConstants from '../ui-constants';
87
import { withServices } from '../service-context';
98

109
import NewNoteBtn from './NewNoteBtn';
1110

1211
/**
1312
* @typedef {import('../../types/config').MergedConfig} MergedConfig
13+
* @typedef {import('../../types/sidebar').TabName} TabName
1414
*/
1515

1616
/**
@@ -98,54 +98,57 @@ function SelectionTabs({ isLoading, settings }) {
9898
const orphanCount = store.orphanCount();
9999
const isWaitingToAnchorAnnotations = store.isWaitingToAnchorAnnotations();
100100

101+
/**
102+
* @param {TabName} tabId
103+
*/
101104
const selectTab = tabId => {
102105
store.clearSelection();
103106
store.selectTab(tabId);
104107
};
105108

106109
const showAnnotationsUnavailableMessage =
107-
selectedTab === uiConstants.TAB_ANNOTATIONS &&
110+
selectedTab === 'annotation' &&
108111
annotationCount === 0 &&
109112
!isWaitingToAnchorAnnotations;
110113

111-
const showNotesUnavailableMessage =
112-
selectedTab === uiConstants.TAB_NOTES && noteCount === 0;
114+
const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0;
113115

114116
return (
115117
<div className="SelectionTabs-container">
116118
<div className="SelectionTabs" role="tablist">
117119
<Tab
118120
count={annotationCount}
119121
isWaitingToAnchor={isWaitingToAnchorAnnotations}
120-
isSelected={selectedTab === uiConstants.TAB_ANNOTATIONS}
122+
isSelected={selectedTab === 'annotation'}
121123
label="Annotations"
122-
onSelect={() => selectTab(uiConstants.TAB_ANNOTATIONS)}
124+
onSelect={() => selectTab('annotation')}
123125
>
124126
Annotations
125127
</Tab>
126128
<Tab
127129
count={noteCount}
128130
isWaitingToAnchor={isWaitingToAnchorAnnotations}
129-
isSelected={selectedTab === uiConstants.TAB_NOTES}
131+
isSelected={selectedTab === 'note'}
130132
label="Page notes"
131-
onSelect={() => selectTab(uiConstants.TAB_NOTES)}
133+
onSelect={() => selectTab('note')}
132134
>
133135
Page Notes
134136
</Tab>
135137
{orphanCount > 0 && (
136138
<Tab
137139
count={orphanCount}
138140
isWaitingToAnchor={isWaitingToAnchorAnnotations}
139-
isSelected={selectedTab === uiConstants.TAB_ORPHANS}
141+
isSelected={selectedTab === 'orphan'}
140142
label="Orphans"
141-
onSelect={() => selectTab(uiConstants.TAB_ORPHANS)}
143+
onSelect={() => selectTab('orphan')}
142144
>
143145
Orphans
144146
</Tab>
145147
)}
146148
</div>
147-
{selectedTab === uiConstants.TAB_NOTES &&
148-
settings.enableExperimentalNewNoteButton && <NewNoteBtn />}
149+
{selectedTab === 'note' && settings.enableExperimentalNewNoteButton && (
150+
<NewNoteBtn />
151+
)}
149152
{!isLoading && showNotesUnavailableMessage && (
150153
<div className="SelectionTabs__message">
151154
There are no page notes in this group.

src/sidebar/components/ShareAnnotationsPanel.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { SvgIcon } from '@hypothesis/frontend-shared';
33
import propTypes from 'prop-types';
44

55
import { useStoreProxy } from '../store/use-store';
6-
import uiConstants from '../ui-constants';
76
import { pageSharingLink } from '../helpers/annotation-sharing';
87
import { copyText } from '../util/copy-to-clipboard';
98
import { withServices } from '../service-context';
@@ -54,10 +53,7 @@ function ShareAnnotationsPanel({ analytics, toastMessenger }) {
5453
};
5554

5655
return (
57-
<SidebarPanel
58-
title={panelTitle}
59-
panelName={uiConstants.PANEL_SHARE_ANNOTATIONS}
60-
>
56+
<SidebarPanel title={panelTitle} panelName="shareGroupAnnotations">
6157
{!sharingReady && (
6258
<div className="ShareAnnotationsPanel__spinner">
6359
<Spinner />

src/sidebar/components/SidebarPanel.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import { useStoreProxy } from '../store/use-store';
99
import Button from './Button';
1010
import Slider from './Slider';
1111

12+
/**
13+
* @typedef {import("../../types/sidebar").PanelName} PanelName
14+
*/
15+
1216
/**
1317
* @typedef SidebarPanelProps
1418
* @prop {Object} [children]
1519
* @prop {string} [icon] - An optional icon name for display next to the panel's title
16-
* @prop {string} panelName -
20+
* @prop {PanelName} panelName -
1721
* A string identifying this panel. Only one `panelName` may be active at any time.
1822
* Multiple panels with the same `panelName` would be "in sync", opening and closing together.
1923
* @prop {string} title - The panel's title: rendered in its containing visual "frame"

src/sidebar/components/TopBar.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import propTypes from 'prop-types';
44
import bridgeEvents from '../../shared/bridge-events';
55
import serviceConfig from '../config/service-config';
66
import { useStoreProxy } from '../store/use-store';
7-
import uiConstants from '../ui-constants';
87
import isThirdPartyService from '../helpers/is-third-party-service';
98
import { withServices } from '../service-context';
109
import { applyTheme } from '../helpers/theme';
@@ -58,12 +57,12 @@ function TopBar({
5857
const applyPendingUpdates = () => streamer.applyPendingUpdates();
5958

6059
const toggleSharePanel = () => {
61-
store.toggleSidebarPanel(uiConstants.PANEL_SHARE_ANNOTATIONS);
60+
store.toggleSidebarPanel('shareGroupAnnotations');
6261
};
6362

64-
const isHelpPanelOpen = store.isSidebarPanelOpen(uiConstants.PANEL_HELP);
63+
const isHelpPanelOpen = store.isSidebarPanelOpen('help');
6564
const isAnnotationsPanelOpen = store.isSidebarPanelOpen(
66-
uiConstants.PANEL_SHARE_ANNOTATIONS
65+
'shareGroupAnnotations'
6766
);
6867

6968
/**
@@ -75,7 +74,7 @@ function TopBar({
7574
if (service && service.onHelpRequestProvided) {
7675
bridge.call(bridgeEvents.HELP_REQUESTED);
7776
} else {
78-
store.toggleSidebarPanel(uiConstants.PANEL_HELP);
77+
store.toggleSidebarPanel('help');
7978
}
8079
};
8180

src/sidebar/components/test/AnnotationActionBar-test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { act } from 'preact/test-utils';
55
import AnnotationActionBar from '../AnnotationActionBar';
66
import { $imports } from '../AnnotationActionBar';
77
import * as fixtures from '../../test/annotation-fixtures';
8-
import uiConstants from '../../ui-constants';
98

109
import { checkAccessibility } from '../../../test-util/accessibility';
1110
import mockImportedComponents from '../../../test-util/mock-imported-components';
@@ -210,10 +209,7 @@ describe('AnnotationActionBar', () => {
210209
button.props().onClick();
211210
});
212211

213-
assert.calledWith(
214-
fakeStore.openSidebarPanel,
215-
uiConstants.PANEL_LOGIN_PROMPT
216-
);
212+
assert.calledWith(fakeStore.openSidebarPanel, 'loginPrompt');
217213
assert.notCalled(fakeOnReply);
218214
});
219215

0 commit comments

Comments
 (0)