Skip to content

Commit 2b98b15

Browse files
committed
fix: lint issues
1 parent 08c958f commit 2b98b15

6 files changed

Lines changed: 119 additions & 108 deletions

File tree

src/generic/key-utils.test.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ describe('component utils', () => {
169169
});
170170

171171
describe('isContainerType', () => {
172-
for (const containerType of [
173-
ContainerType.Vertical,
174-
ContainerType.Sequential,
175-
ContainerType.Chapter,
176-
ContainerType.Unit,
177-
ContainerType.Subsection,
178-
ContainerType.Section,
179-
] as const) {
172+
for (
173+
const containerType of [
174+
ContainerType.Vertical,
175+
ContainerType.Sequential,
176+
ContainerType.Chapter,
177+
ContainerType.Unit,
178+
ContainerType.Subsection,
179+
ContainerType.Section,
180+
] as const
181+
) {
180182
it(`returns true for '${containerType}'`, () => {
181183
expect(isContainerType(containerType)).toBe(true);
182184
});
@@ -190,30 +192,34 @@ describe('component utils', () => {
190192
});
191193

192194
describe('isContainerUsageKey', () => {
193-
for (const usageKey of [
194-
'lct:org:lib:section:my-section-9284e2',
195-
'lct:org:lib:subsection:my-subsection-9284e2',
196-
'lct:org:lib:unit:my-unit-9284e2',
197-
'block-v1:org+type@chapter+block@1',
198-
'block-v1:org+type@sequential+block@1',
199-
'block-v1:org+type@vertical+block@1',
200-
'block-v1:org+type@section+block@1',
201-
'block-v1:org+type@subsection+block@1',
202-
'block-v1:org+type@unit+block@1',
203-
]) {
195+
for (
196+
const usageKey of [
197+
'lct:org:lib:section:my-section-9284e2',
198+
'lct:org:lib:subsection:my-subsection-9284e2',
199+
'lct:org:lib:unit:my-unit-9284e2',
200+
'block-v1:org+type@chapter+block@1',
201+
'block-v1:org+type@sequential+block@1',
202+
'block-v1:org+type@vertical+block@1',
203+
'block-v1:org+type@section+block@1',
204+
'block-v1:org+type@subsection+block@1',
205+
'block-v1:org+type@unit+block@1',
206+
]
207+
) {
204208
it(`returns true for '${usageKey}'`, () => {
205209
expect(isContainerUsageKey(usageKey)).toBe(true);
206210
});
207211
}
208212

209-
for (const usageKey of [
210-
'lb:org:lib:html:id',
211-
'block-v1:org+type@problem+block@1',
212-
'not a key',
213-
'',
214-
undefined,
215-
null,
216-
]) {
213+
for (
214+
const usageKey of [
215+
'lb:org:lib:html:id',
216+
'block-v1:org+type@problem+block@1',
217+
'not a key',
218+
'',
219+
undefined,
220+
null,
221+
]
222+
) {
217223
it(`returns false for '${usageKey}'`, () => {
218224
expect(isContainerUsageKey(usageKey as any)).toBe(false);
219225
});

src/library-authoring/LibraryBlock/LibraryBlock.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ export const LibraryBlock = ({
5353
const intl = useIntl();
5454
const params = new URLSearchParams();
5555

56-
if (version === 0) {
57-
return null;
58-
}
59-
6056
if (version) {
6157
params.set('version', version.toString());
6258
}
@@ -86,6 +82,10 @@ export const LibraryBlock = ({
8682

8783
useIframeContent(iframeRef, setIframeRef);
8884

85+
if (version === 0) {
86+
return null;
87+
}
88+
8989
return (
9090
<iframe
9191
ref={iframeRef}

src/library-authoring/component-comparison/CompareChangesWidget.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,19 @@ const CompareChangesWidget = ({
104104

105105
return (
106106
<div className="bg-light-300 py-2 px-1">
107-
{sideBySide ? (
108-
<Stack direction='horizontal' gap={3}>
109-
{oldBlock}
110-
{newBlock}
111-
</Stack>
112-
) : (
113-
<Tabs variant="tabs" defaultActiveKey="new" id="preview-version-toggle" mountOnEnter>
114-
{oldBlock && <Tab eventKey="old" title={oldTabMessage}>{oldBlock}</Tab>}
115-
<Tab eventKey="new" title={newTabMessage}>{newBlock}</Tab>
116-
</Tabs>
117-
)}
107+
{sideBySide ?
108+
(
109+
<Stack direction="horizontal" gap={3}>
110+
{oldBlock}
111+
{newBlock}
112+
</Stack>
113+
) :
114+
(
115+
<Tabs variant="tabs" defaultActiveKey="new" id="preview-version-toggle" mountOnEnter>
116+
{oldBlock && <Tab eventKey="old" title={oldTabMessage}>{oldBlock}</Tab>}
117+
<Tab eventKey="new" title={newTabMessage}>{newBlock}</Tab>
118+
</Tabs>
119+
)}
118120
</div>
119121
);
120122
};

src/library-authoring/generic/history-log/HistoryCompareChangesModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ const HistoryCompareChangesModal = ({
4343
isOpen={isOpen}
4444
onClose={onClose}
4545
size="xl"
46-
className={classNames({'w-xl-100 mw-xl': sideBySide})}
46+
className={classNames({ 'w-xl-100 mw-xl': sideBySide })}
4747
title={title}
4848
isOverflowVisible={false}
4949
>
5050
<ModalDialog.Header>
5151
<ModalDialog.Title>
52-
<Stack direction='horizontal' gap={2}>
52+
<Stack direction="horizontal" gap={2}>
5353
<FormattedMessage
5454
{...messages.previewChangesTitle}
5555
values={{
5656
title: (
5757
<>
58-
<Icon size='lg' src={getItemIcon(blockType)} className="mr-1" />
58+
<Icon size="lg" src={getItemIcon(blockType)} className="mr-1" />
5959
{oldTitle}
6060
</>
6161
),

src/library-authoring/generic/history-log/HistoryLog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const HistoryContainerLog = ({ containerId }: { containerId: string; }) =
9696
<div className="history-log">
9797
{draftHistory && draftHistory.length !== 0 && (
9898
<HistoryDraftLogGroup
99+
itemId={containerId}
99100
displayName={container?.displayName ?? ''}
100101
entries={draftHistory}
101102
/>

src/library-authoring/generic/history-log/HistoryLogGroup.tsx

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isContainerUsageKey } from '@src/generic/key-utils';
1212
import { LibraryHistoryEntry, LibraryPublishContributor, LibraryPublishHistoryGroup } from '../../data/api';
1313
import messages from './messages';
1414
import { getItemIcon } from '@src/generic/block-type-utils';
15-
import { useToggleWithValue } from "@src/hooks";
15+
import { useToggleWithValue } from '@src/hooks';
1616
import HistoryCompareChangesModal from './HistoryCompareChangesModal';
1717

1818
const MAX_VISIBLE_CONTRIBUTORS = 5;
@@ -111,7 +111,9 @@ const HistoryLogGroupEntries = ({
111111
}: HistoryLogGroupEntriesProps) => {
112112
const intl = useIntl();
113113
const isContainerItem = isContainerUsageKey(itemId);
114-
const [isChangeModalOpen, changeModalData, openChangeModal, closeChangeModal] = useToggleWithValue<LibraryHistoryEntry>();
114+
const [isChangeModalOpen, changeModalData, openChangeModal, closeChangeModal] = useToggleWithValue<
115+
LibraryHistoryEntry
116+
>();
115117

116118
const getEntryMessage = (entry: LibraryHistoryEntry) => {
117119
switch (entry.action) {
@@ -128,70 +130,70 @@ const HistoryLogGroupEntries = ({
128130

129131
return (
130132
<>
131-
<Stack gap={0}>
132-
<div className="history-log-vert" />
133-
{entries.map((entry) => {
134-
const entryMessage = getEntryMessage(entry);
133+
<Stack gap={0}>
134+
<div className="history-log-vert" />
135+
{entries.map((entry) => {
136+
const entryMessage = getEntryMessage(entry);
135137

136-
return (
137-
<div key={`${entry.changedAt}-${entry.oldVersion}`}>
138-
<Stack direction="horizontal" gap={2} className="ml-1.5">
139-
<ContributorAvatar
140-
username={entry.contributor?.username || intl.formatMessage(messages.historyEntryDefaultUser)}
141-
src={entry.contributor.profileImageUrls.medium}
142-
className="history-log-group-avatar small-avatar"
143-
size="sm"
144-
/>
145-
<Stack>
146-
<Stack direction="horizontal" gap={1}>
147-
<FormattedMessage
148-
{...entryMessage}
149-
values={{
150-
user: entry.contributor.username ?? intl.formatMessage(messages.historyEntryDefaultUser),
151-
displayName: <span className="history-log-title text-truncate">{entry.title}</span>,
152-
icon: <Icon src={getItemIcon(entry.itemType)} />,
153-
}}
154-
/>
138+
return (
139+
<div key={`${entry.changedAt}-${entry.oldVersion}`}>
140+
<Stack direction="horizontal" gap={2} className="ml-1.5">
141+
<ContributorAvatar
142+
username={entry.contributor?.username || intl.formatMessage(messages.historyEntryDefaultUser)}
143+
src={entry.contributor.profileImageUrls.medium}
144+
className="history-log-group-avatar small-avatar"
145+
size="sm"
146+
/>
147+
<Stack>
148+
<Stack direction="horizontal" gap={1}>
149+
<FormattedMessage
150+
{...entryMessage}
151+
values={{
152+
user: entry.contributor.username ?? intl.formatMessage(messages.historyEntryDefaultUser),
153+
displayName: <span className="history-log-title text-truncate">{entry.title}</span>,
154+
icon: <Icon src={getItemIcon(entry.itemType)} />,
155+
}}
156+
/>
157+
</Stack>
158+
<span className="small text-gray-500">
159+
{moment(entry.changedAt).fromNow()}
160+
</span>
155161
</Stack>
156-
<span className="small text-gray-500">
157-
{moment(entry.changedAt).fromNow()}
158-
</span>
162+
{!isContainerItem && (
163+
<Dropdown>
164+
<Dropdown.Toggle
165+
id={entry.changedAt}
166+
as={IconButton}
167+
src={MoreVert}
168+
iconAs={Icon}
169+
variant="primary"
170+
aria-label={intl.formatMessage(messages.moreActions)}
171+
/>
172+
<Dropdown.Menu>
173+
<Dropdown.Item onClick={() => openChangeModal(entry)}>
174+
{intl.formatMessage(messages.showThisVersion)}
175+
</Dropdown.Item>
176+
</Dropdown.Menu>
177+
</Dropdown>
178+
)}
159179
</Stack>
160-
{!isContainerItem && (
161-
<Dropdown>
162-
<Dropdown.Toggle
163-
id={entry.changedAt}
164-
as={IconButton}
165-
src={MoreVert}
166-
iconAs={Icon}
167-
variant="primary"
168-
aria-label={intl.formatMessage(messages.moreActions)}
169-
/>
170-
<Dropdown.Menu>
171-
<Dropdown.Item onClick={() => openChangeModal(entry)}>
172-
{intl.formatMessage(messages.showThisVersion)}
173-
</Dropdown.Item>
174-
</Dropdown.Menu>
175-
</Dropdown>
176-
)}
177-
</Stack>
178-
<div className="history-log-vert" />
179-
</div>
180-
);
181-
})}
182-
</Stack>
183-
{!isContainerItem && isChangeModalOpen && changeModalData && (
184-
<HistoryCompareChangesModal
185-
isOpen={isChangeModalOpen}
186-
onClose={closeChangeModal}
187-
usageKey={itemId}
188-
oldTitle={changeModalData.title}
189-
oldVersion={changeModalData.oldVersion}
190-
newVersion={changeModalData.newVersion || 'published'}
191-
/>
192-
)}
193-
</>
194-
)
180+
<div className="history-log-vert" />
181+
</div>
182+
);
183+
})}
184+
</Stack>
185+
{!isContainerItem && isChangeModalOpen && changeModalData && (
186+
<HistoryCompareChangesModal
187+
isOpen={isChangeModalOpen}
188+
onClose={closeChangeModal}
189+
usageKey={itemId}
190+
oldTitle={changeModalData.title}
191+
oldVersion={changeModalData.oldVersion}
192+
newVersion={changeModalData.newVersion || 'published'}
193+
/>
194+
)}
195+
</>
196+
);
195197
};
196198

197199
export const HistoryCreatedLogGroup = ({

0 commit comments

Comments
 (0)