mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 04:46:18 -05:00
ui: Common.js and thirteen more files off Semantic
Phase 2, part 3. Baseline 63 -> 50.
Common.js is the one that mattered: 51 files import it, so its Semantic usage
was propping up the rest of the migration. Everything in it now comes from the
library -- Paginator, the two search inputs, DirectorySearch, TabLinks, the
toggles, the messages, APIButton, Breadcrumbs, SimpleAccordion, IframeViewer,
CardPoster, FileIcon, LoadStatistic, the theme menu, and the hotspot icons.
Also migrated: Placeholder, Apps, ArchivePreview, CbzViewer, AddToPlaylist,
TaggedDeleteConfirmModal, the collection edit/tag forms, and four inventory
components.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>` with its grouped results shape
kept, because four call sites already build it. A real
combobox rather than a div that listens for clicks.
Pagination Semantic's prop names; onPageChange gets the page number.
TabBar the strip only -- routing stays with the caller.
IconStack Semantic's IconGroup, named once for assistive technology.
Table.HeaderCell sorted/onSort -- a real button carrying aria-sort.
Button/IconButton translate Semantic's size names.
That last one is defensive: unmigrated callers still pass size='tiny', and
Mantine drops a size it does not recognise without a word, so the button
quietly renders at the wrong size. Mapping here keeps the mixed state honest.
Three real bugs found and fixed on the way, none of them cosmetic:
* `fileSuffixIconName` returned fourteen icon names the map did not have, so
opening a folder with a PDF, a Word document or an archive in it logged an
error and drew a fallback glyph. All fourteen mapped, with a test that
walks the mapper's own return values, and another asserting every mapped
name resolves to a Tabler component that exists.
* `Statistic` relied on Semantic's `Statistic.Group` for its spacing, so on
the dashboard the load averages ran together into "1 MIN. LOAD5 MIN.
LOAD15 MIN. LOAD". It carries its own spacing now.
* Semantic's inverted stylesheet colors every descendant of an inverted
segment, so Toggle labels inherited #dddddd -- white pixels in night mode,
on the Settings page, which is exactly where someone adjusts their WROLPi
in the dark. Restated from tokens.
The baseline ratchet gained a third assertion: a migrated file may still lean
on Semantic's CSS classes without importing the library, which the import check
cannot see and which would collapse silently when Phase 4 deletes the
stylesheet. There is one such bridge today and it is now declared.
This commit is contained in:
parent
d359eea2d3
commit
6ea9d3645f
35 changed files with 978 additions and 1095 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react';
|
||||
import {Button, Form, Grid, Message} from 'semantic-ui-react';
|
||||
import {Header, Segment} from '../Theme';
|
||||
import {Button, Header, Message, Panel} from '../ui';
|
||||
import {TagsContext} from '../../Tags';
|
||||
import {WROLModeMessage} from '../Common';
|
||||
|
||||
|
|
@ -37,51 +36,63 @@ export function CollectionEditForm({
|
|||
}
|
||||
};
|
||||
|
||||
return <Segment>
|
||||
return <Panel>
|
||||
{title && <Header as="h1">{title}</Header>}
|
||||
{wrolModeContent && <WROLModeMessage content={wrolModeContent}/>}
|
||||
|
||||
{/* Display form-level errors */}
|
||||
{form.error && <Message error>
|
||||
<Message.Header>Error</Message.Header>
|
||||
{form.error && <Message kind='error' title='Error'>
|
||||
<p>{form.error}</p>
|
||||
</Message>}
|
||||
|
||||
<Form onSubmit={handleSubmit} loading={form.loading} autoComplete="off">
|
||||
<Grid stackable>
|
||||
<form onSubmit={handleSubmit} autoComplete="off">
|
||||
{/*
|
||||
* `ui stackable grid` replicates Semantic's own Grid CSS classes (still loaded
|
||||
* globally via semantic-ui-offline while other call sites remain unmigrated).
|
||||
* Callers of this component (Channels.js, Archive.js, Playlists.js) still pass
|
||||
* Semantic <Grid.Row>/<Grid.Column> children -- they have not migrated to the
|
||||
* component library yet. This div keeps their layout without importing
|
||||
* semantic-ui-react here. Replace with the real `Grid`/`Grid.Col` once every
|
||||
* caller has migrated.
|
||||
*/}
|
||||
<div
|
||||
className="ui stackable grid"
|
||||
style={form.loading ? {opacity: 0.6, pointerEvents: 'none'} : undefined}
|
||||
>
|
||||
{children}
|
||||
|
||||
{appliedTagName && <Grid.Row>
|
||||
<Grid.Column>
|
||||
{appliedTagName && <div className="row">
|
||||
<div className="column">
|
||||
<SingleTag name={appliedTagName}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
</div>
|
||||
</div>}
|
||||
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column>
|
||||
<div className="two column row">
|
||||
<div className="column">
|
||||
{actionButtons}
|
||||
{onCancel && <Button
|
||||
type='button'
|
||||
role='cancel'
|
||||
onClick={onCancel}
|
||||
disabled={form.disabled}
|
||||
className="action-button-spacing"
|
||||
>
|
||||
Cancel
|
||||
</Button>}
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
</div>
|
||||
<div className="column">
|
||||
<Button
|
||||
type='submit'
|
||||
color='violet'
|
||||
size='big'
|
||||
floated='right'
|
||||
role='save'
|
||||
size='lg'
|
||||
style={{float: 'right'}}
|
||||
disabled={form.disabled}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Form>
|
||||
</Segment>;
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Panel>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
|||
import {
|
||||
createMockDomain,
|
||||
createTestForm,
|
||||
hasInvertedStyling,
|
||||
render,
|
||||
renderInDarkMode,
|
||||
renderInLightMode,
|
||||
|
|
@ -210,7 +209,11 @@ describe('CollectionEditForm', () => {
|
|||
});
|
||||
|
||||
describe('Theme Integration', () => {
|
||||
it('applies inverted styling to Segment in dark mode', () => {
|
||||
// Panel/Header are token-driven (see ui/Surfaces.tsx): their colors come from CSS
|
||||
// variables scoped on `[data-theme]`, not from JS branching on the theme. There is
|
||||
// no more "inverted" prop/class to assert on -- just that the same markup renders
|
||||
// in both modes.
|
||||
it('renders a token-driven Panel in dark mode', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInDarkMode(
|
||||
|
|
@ -219,12 +222,10 @@ describe('CollectionEditForm', () => {
|
|||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
const segment = container.querySelector('.ui.segment');
|
||||
expect(segment).toBeInTheDocument();
|
||||
expect(hasInvertedStyling(segment)).toBe(true);
|
||||
expect(container.querySelector('.wrolpi-panel')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not apply inverted styling in light mode', () => {
|
||||
it('renders a token-driven Panel in light mode', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInLightMode(
|
||||
|
|
@ -233,12 +234,10 @@ describe('CollectionEditForm', () => {
|
|||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
const segment = container.querySelector('.ui.segment');
|
||||
expect(segment).toBeInTheDocument();
|
||||
expect(hasInvertedStyling(segment)).toBe(false);
|
||||
expect(container.querySelector('.wrolpi-panel')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies dark theme styling to Header in dark mode', () => {
|
||||
it('renders a token-driven Header for the title', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInDarkMode(
|
||||
|
|
@ -247,9 +246,9 @@ describe('CollectionEditForm', () => {
|
|||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
const header = container.querySelector('.ui.header');
|
||||
const header = container.querySelector('.wrolpi-header');
|
||||
expect(header).toBeInTheDocument();
|
||||
expect(header.style.color).toBe('rgb(238, 238, 238)'); // #eeeeee
|
||||
expect(header).toHaveTextContent('Test Collection');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import React, {useCallback, useEffect, useState} from 'react';
|
||||
import {Grid, Input} from 'semantic-ui-react';
|
||||
import Message from 'semantic-ui-react/dist/commonjs/collections/Message';
|
||||
import {Button, Modal} from '../Theme';
|
||||
import {Button, Message, Modal, Stack, TextInput} from '../ui';
|
||||
import {TagsSelector} from '../../Tags';
|
||||
import {APIButton, Toggle} from '../Common';
|
||||
|
||||
|
|
@ -107,54 +105,36 @@ export function CollectionTagModal({
|
|||
>
|
||||
<Modal.Header>{modalTitle}</Modal.Header>
|
||||
<Modal.Content>
|
||||
<Grid columns={1}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<TagsSelector
|
||||
limit={1}
|
||||
selectedTagNames={newTagName ? [newTagName] : []}
|
||||
onAdd={handleTagChange}
|
||||
onRemove={() => handleTagChange(null)}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Stack>
|
||||
<TagsSelector
|
||||
limit={1}
|
||||
selectedTagNames={newTagName ? [newTagName] : []}
|
||||
onAdd={handleTagChange}
|
||||
onRemove={() => handleTagChange(null)}
|
||||
/>
|
||||
{hasDirectory && (
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Toggle
|
||||
label='Move to directory: '
|
||||
checked={moveToTagDirectory}
|
||||
onChange={setMoveToTagDirectory}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Toggle
|
||||
label='Move to directory: '
|
||||
checked={moveToTagDirectory}
|
||||
onChange={setMoveToTagDirectory}
|
||||
/>
|
||||
)}
|
||||
{hasDirectory && (
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Input
|
||||
fluid
|
||||
value={newTagDirectory}
|
||||
onChange={(e, {value}) => setNewTagDirectory(value)}
|
||||
disabled={!moveToTagDirectory}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<TextInput
|
||||
value={newTagDirectory}
|
||||
onChange={(e) => setNewTagDirectory(e.currentTarget.value)}
|
||||
disabled={!moveToTagDirectory}
|
||||
/>
|
||||
)}
|
||||
{hasDirectory && conflictMessage && (
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Message warning>
|
||||
<Message.Header>Directory Conflict</Message.Header>
|
||||
<p>{conflictMessage}</p>
|
||||
</Message>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Message kind='warning' title='Directory Conflict'>
|
||||
<p>{conflictMessage}</p>
|
||||
</Message>
|
||||
)}
|
||||
</Grid>
|
||||
</Stack>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={handleClose}>Cancel</Button>
|
||||
<Button role='cancel' onClick={handleClose}>Cancel</Button>
|
||||
<APIButton
|
||||
color='violet'
|
||||
onClick={handleSave}
|
||||
|
|
|
|||
|
|
@ -3,31 +3,6 @@ import {act, render, screen, waitFor} from '../../test-utils';
|
|||
import userEvent from '@testing-library/user-event';
|
||||
import {CollectionTagModal} from './CollectionTagModal';
|
||||
|
||||
// Mock Theme components with compound patterns
|
||||
jest.mock('../Theme', () => {
|
||||
const MockModal = ({open, onClose, children, closeIcon}) => {
|
||||
if (!open) return null;
|
||||
return (
|
||||
<div data-testid="modal">
|
||||
{closeIcon && <button data-testid="close-icon" onClick={onClose}>×</button>}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
MockModal.Header = ({children}) => <div data-testid="modal-header">{children}</div>;
|
||||
MockModal.Content = ({children}) => <div data-testid="modal-content">{children}</div>;
|
||||
MockModal.Actions = ({children}) => <div data-testid="modal-actions">{children}</div>;
|
||||
MockModal.Description = ({children}) => <div data-testid="modal-description">{children}</div>;
|
||||
|
||||
return {
|
||||
...jest.requireActual('../Theme'),
|
||||
Modal: MockModal,
|
||||
Button: ({children, onClick, ...props}) => (
|
||||
<button onClick={onClick} data-testid={`button-${children}`} {...props}>{children}</button>
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
// Mock Common components
|
||||
jest.mock('../Common', () => ({
|
||||
...jest.requireActual('../Common'),
|
||||
|
|
@ -76,22 +51,22 @@ describe('CollectionTagModal', () => {
|
|||
describe('Modal Rendering', () => {
|
||||
it('renders modal when open is true', () => {
|
||||
render(<CollectionTagModal {...defaultProps} />);
|
||||
expect(screen.getByTestId('modal')).toBeInTheDocument();
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render modal when open is false', () => {
|
||||
render(<CollectionTagModal {...defaultProps} open={false}/>);
|
||||
expect(screen.queryByTestId('modal')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Add Tag" header when no current tag', () => {
|
||||
render(<CollectionTagModal {...defaultProps} currentTagName={null}/>);
|
||||
expect(screen.getByTestId('modal-header')).toHaveTextContent('Add Tag');
|
||||
expect(screen.getByRole('heading')).toHaveTextContent('Add Tag');
|
||||
});
|
||||
|
||||
it('shows "Modify Tag" header when there is a current tag', () => {
|
||||
render(<CollectionTagModal {...defaultProps} currentTagName="existing-tag"/>);
|
||||
expect(screen.getByTestId('modal-header')).toHaveTextContent('Modify Tag');
|
||||
expect(screen.getByRole('heading')).toHaveTextContent('Modify Tag');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -308,7 +283,7 @@ describe('CollectionTagModal', () => {
|
|||
const mockOnClose = jest.fn();
|
||||
render(<CollectionTagModal {...defaultProps} onClose={mockOnClose}/>);
|
||||
|
||||
const cancelButton = screen.getByTestId('button-Cancel');
|
||||
const cancelButton = screen.getByRole('button', {name: 'Cancel'});
|
||||
await userEvent.click(cancelButton);
|
||||
|
||||
expect(mockOnClose).toHaveBeenCalled();
|
||||
|
|
@ -341,7 +316,7 @@ describe('CollectionTagModal', () => {
|
|||
});
|
||||
|
||||
// Close the modal
|
||||
const cancelButton = screen.getByTestId('button-Cancel');
|
||||
const cancelButton = screen.getByRole('button', {name: 'Cancel'});
|
||||
await userEvent.click(cancelButton);
|
||||
|
||||
// Reopen modal
|
||||
|
|
|
|||
|
|
@ -340,10 +340,9 @@ describe('ConflictResolutionModal', () => {
|
|||
|
||||
// Confirming should re-call deleteFileGroups with force=true.
|
||||
api.deleteFileGroups.mockResolvedValueOnce({});
|
||||
// The TaggedDeleteConfirmModal's Delete button has the trash icon.
|
||||
const confirmButton = screen.getAllByRole('button')
|
||||
.find(b => b.classList.contains('red') && b.textContent.includes('Delete')
|
||||
&& b.querySelector('.trash.icon'));
|
||||
// The TaggedDeleteConfirmModal (a Confirm) names its destructive action "Delete",
|
||||
// distinct from the "Delete this file" icon buttons queried above.
|
||||
const confirmButton = screen.getByRole('button', {name: 'Delete'});
|
||||
fireEvent.click(confirmButton);
|
||||
|
||||
await waitFor(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue