Added Settings suffix to all settings sub-components

This commit is contained in:
Alejandro Celaya 2021-12-25 10:49:12 +01:00
parent 994f31b7e5
commit dbf4b0926e
14 changed files with 76 additions and 67 deletions

View file

@ -12,7 +12,7 @@ interface RealTimeUpdatesProps {
const intervalValue = (interval?: number) => !interval ? '' : `${interval}`; const intervalValue = (interval?: number) => !interval ? '' : `${interval}`;
const RealTimeUpdates = ( const RealTimeUpdatesSettings = (
{ settings: { realTimeUpdates }, toggleRealTimeUpdates, setRealTimeUpdatesInterval }: RealTimeUpdatesProps, { settings: { realTimeUpdates }, toggleRealTimeUpdates, setRealTimeUpdatesInterval }: RealTimeUpdatesProps,
) => ( ) => (
<SimpleCard title="Real-time updates" className="h-100"> <SimpleCard title="Real-time updates" className="h-100">
@ -50,4 +50,4 @@ const RealTimeUpdates = (
</SimpleCard> </SimpleCard>
); );
export default RealTimeUpdates; export default RealTimeUpdatesSettings;

View file

@ -3,11 +3,11 @@ import { DropdownItem, FormGroup } from 'reactstrap';
import { SimpleCard } from '../utils/SimpleCard'; import { SimpleCard } from '../utils/SimpleCard';
import ToggleSwitch from '../utils/ToggleSwitch'; import ToggleSwitch from '../utils/ToggleSwitch';
import { DropdownBtn } from '../utils/DropdownBtn'; import { DropdownBtn } from '../utils/DropdownBtn';
import { Settings, ShortUrlCreationSettings, TagFilteringMode } from './reducers/settings'; import { Settings, ShortUrlCreationSettings as ShortUrlsSettings, TagFilteringMode } from './reducers/settings';
interface ShortUrlCreationProps { interface ShortUrlCreationProps {
settings: Settings; settings: Settings;
setShortUrlCreationSettings: (settings: ShortUrlCreationSettings) => void; setShortUrlCreationSettings: (settings: ShortUrlsSettings) => void;
} }
const tagFilteringModeText = (tagFilteringMode: TagFilteringMode | undefined): string => const tagFilteringModeText = (tagFilteringMode: TagFilteringMode | undefined): string =>
@ -17,8 +17,8 @@ const tagFilteringModeHint = (tagFilteringMode: TagFilteringMode | undefined): R
? <>The list of suggested tags will contain those <b>including</b> provided input.</> ? <>The list of suggested tags will contain those <b>including</b> provided input.</>
: <>The list of suggested tags will contain those <b>starting with</b> provided input.</>; : <>The list of suggested tags will contain those <b>starting with</b> provided input.</>;
export const ShortUrlCreation: FC<ShortUrlCreationProps> = ({ settings, setShortUrlCreationSettings }) => { export const ShortUrlCreationSettings: FC<ShortUrlCreationProps> = ({ settings, setShortUrlCreationSettings }) => {
const shortUrlCreation: ShortUrlCreationSettings = settings.shortUrlCreation ?? { validateUrls: false }; const shortUrlCreation: ShortUrlsSettings = settings.shortUrlCreation ?? { validateUrls: false };
const changeTagsFilteringMode = (tagFilteringMode: TagFilteringMode) => () => setShortUrlCreationSettings( const changeTagsFilteringMode = (tagFilteringMode: TagFilteringMode) => () => setShortUrlCreationSettings(
{ ...shortUrlCreation ?? { validateUrls: false }, tagFilteringMode }, { ...shortUrlCreation ?? { validateUrls: false }, tagFilteringMode },
); );

View file

@ -3,14 +3,16 @@ import { FormGroup } from 'reactstrap';
import { OrderingDropdown } from '../utils/OrderingDropdown'; import { OrderingDropdown } from '../utils/OrderingDropdown';
import { SHORT_URLS_ORDERABLE_FIELDS } from '../short-urls/data'; import { SHORT_URLS_ORDERABLE_FIELDS } from '../short-urls/data';
import { SimpleCard } from '../utils/SimpleCard'; import { SimpleCard } from '../utils/SimpleCard';
import { DEFAULT_SHORT_URLS_ORDERING, Settings, ShortUrlsListSettings } from './reducers/settings'; import { DEFAULT_SHORT_URLS_ORDERING, Settings, ShortUrlsListSettings as ShortUrlsSettings } from './reducers/settings';
interface ShortUrlsListProps { interface ShortUrlsListProps {
settings: Settings; settings: Settings;
setShortUrlsListSettings: (settings: ShortUrlsListSettings) => void; setShortUrlsListSettings: (settings: ShortUrlsSettings) => void;
} }
export const ShortUrlsList: FC<ShortUrlsListProps> = ({ settings: { shortUrlsList }, setShortUrlsListSettings }) => ( export const ShortUrlsListSettings: FC<ShortUrlsListProps> = (
{ settings: { shortUrlsList }, setShortUrlsListSettings },
) => (
<SimpleCard title="Short URLs list" className="h-100"> <SimpleCard title="Short URLs list" className="h-100">
<FormGroup className="mb-0"> <FormGroup className="mb-0">
<label>Default ordering for short URLs list:</label> <label>Default ordering for short URLs list:</label>

View file

@ -5,14 +5,14 @@ import { TagsModeDropdown } from '../tags/TagsModeDropdown';
import { capitalize } from '../utils/utils'; import { capitalize } from '../utils/utils';
import { OrderingDropdown } from '../utils/OrderingDropdown'; import { OrderingDropdown } from '../utils/OrderingDropdown';
import { TAGS_ORDERABLE_FIELDS } from '../tags/data/TagsListChildrenProps'; import { TAGS_ORDERABLE_FIELDS } from '../tags/data/TagsListChildrenProps';
import { Settings, TagsSettings } from './reducers/settings'; import { Settings, TagsSettings as TagsSettingsOptions } from './reducers/settings';
interface TagsProps { interface TagsProps {
settings: Settings; settings: Settings;
setTagsSettings: (settings: TagsSettings) => void; setTagsSettings: (settings: TagsSettingsOptions) => void;
} }
export const Tags: FC<TagsProps> = ({ settings: { tags }, setTagsSettings }) => ( export const TagsSettings: FC<TagsProps> = ({ settings: { tags }, setTagsSettings }) => (
<SimpleCard title="Tags" className="h-100"> <SimpleCard title="Tags" className="h-100">
<FormGroup> <FormGroup>
<label>Default display mode when managing tags:</label> <label>Default display mode when managing tags:</label>

View file

@ -6,14 +6,14 @@ import { SimpleCard } from '../utils/SimpleCard';
import ToggleSwitch from '../utils/ToggleSwitch'; import ToggleSwitch from '../utils/ToggleSwitch';
import { changeThemeInMarkup, Theme } from '../utils/theme'; import { changeThemeInMarkup, Theme } from '../utils/theme';
import { Settings, UiSettings } from './reducers/settings'; import { Settings, UiSettings } from './reducers/settings';
import './UserInterface.scss'; import './UserInterfaceSettings.scss';
interface UserInterfaceProps { interface UserInterfaceProps {
settings: Settings; settings: Settings;
setUiSettings: (settings: UiSettings) => void; setUiSettings: (settings: UiSettings) => void;
} }
export const UserInterface: FC<UserInterfaceProps> = ({ settings: { ui }, setUiSettings }) => ( export const UserInterfaceSettings: FC<UserInterfaceProps> = ({ settings: { ui }, setUiSettings }) => (
<SimpleCard title="User interface" className="h-100"> <SimpleCard title="User interface" className="h-100">
<FormGroup> <FormGroup>
<FontAwesomeIcon icon={ui?.theme === 'dark' ? faMoon : faSun} className="user-interface__theme-icon" /> <FontAwesomeIcon icon={ui?.theme === 'dark' ? faMoon : faSun} className="user-interface__theme-icon" />

View file

@ -2,14 +2,14 @@ import { FormGroup } from 'reactstrap';
import { FC } from 'react'; import { FC } from 'react';
import { SimpleCard } from '../utils/SimpleCard'; import { SimpleCard } from '../utils/SimpleCard';
import { DateIntervalSelector } from '../utils/dates/DateIntervalSelector'; import { DateIntervalSelector } from '../utils/dates/DateIntervalSelector';
import { Settings, VisitsSettings } from './reducers/settings'; import { Settings, VisitsSettings as VisitsSettingsConfig } from './reducers/settings';
interface VisitsProps { interface VisitsProps {
settings: Settings; settings: Settings;
setVisitsSettings: (settings: VisitsSettings) => void; setVisitsSettings: (settings: VisitsSettingsConfig) => void;
} }
export const Visits: FC<VisitsProps> = ({ settings, setVisitsSettings }) => ( export const VisitsSettings: FC<VisitsProps> = ({ settings, setVisitsSettings }) => (
<SimpleCard title="Visits" className="h-100"> <SimpleCard title="Visits" className="h-100">
<FormGroup className="mb-0"> <FormGroup className="mb-0">
<label>Default interval to load on visits sections:</label> <label>Default interval to load on visits sections:</label>

View file

@ -1,5 +1,5 @@
import Bottle from 'bottlejs'; import Bottle from 'bottlejs';
import RealTimeUpdates from '../RealTimeUpdates'; import RealTimeUpdatesSettings from '../RealTimeUpdatesSettings';
import Settings from '../Settings'; import Settings from '../Settings';
import { import {
setRealTimeUpdatesInterval, setRealTimeUpdatesInterval,
@ -12,46 +12,46 @@ import {
} from '../reducers/settings'; } from '../reducers/settings';
import { ConnectDecorator } from '../../container/types'; import { ConnectDecorator } from '../../container/types';
import { withoutSelectedServer } from '../../servers/helpers/withoutSelectedServer'; import { withoutSelectedServer } from '../../servers/helpers/withoutSelectedServer';
import { ShortUrlCreation } from '../ShortUrlCreation'; import { ShortUrlCreationSettings } from '../ShortUrlCreationSettings';
import { UserInterface } from '../UserInterface'; import { UserInterfaceSettings } from '../UserInterfaceSettings';
import { Visits } from '../Visits'; import { VisitsSettings } from '../VisitsSettings';
import { Tags } from '../Tags'; import { TagsSettings } from '../TagsSettings';
import { ShortUrlsList } from '../ShortUrlsList'; import { ShortUrlsListSettings } from '../ShortUrlsListSettings';
const provideServices = (bottle: Bottle, connect: ConnectDecorator) => { const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
// Components // Components
bottle.serviceFactory( bottle.serviceFactory(
'Settings', 'Settings',
Settings, Settings,
'RealTimeUpdates', 'RealTimeUpdatesSettings',
'ShortUrlCreation', 'ShortUrlCreationSettings',
'ShortUrlsListSettings', 'ShortUrlsListSettings',
'UserInterface', 'UserInterfaceSettings',
'Visits', 'VisitsSettings',
'Tags', 'TagsSettings',
); );
bottle.decorator('Settings', withoutSelectedServer); bottle.decorator('Settings', withoutSelectedServer);
bottle.decorator('Settings', connect(null, [ 'resetSelectedServer' ])); bottle.decorator('Settings', connect(null, [ 'resetSelectedServer' ]));
bottle.serviceFactory('RealTimeUpdates', () => RealTimeUpdates); bottle.serviceFactory('RealTimeUpdatesSettings', () => RealTimeUpdatesSettings);
bottle.decorator( bottle.decorator(
'RealTimeUpdates', 'RealTimeUpdatesSettings',
connect([ 'settings' ], [ 'toggleRealTimeUpdates', 'setRealTimeUpdatesInterval' ]), connect([ 'settings' ], [ 'toggleRealTimeUpdates', 'setRealTimeUpdatesInterval' ]),
); );
bottle.serviceFactory('ShortUrlCreation', () => ShortUrlCreation); bottle.serviceFactory('ShortUrlCreationSettings', () => ShortUrlCreationSettings);
bottle.decorator('ShortUrlCreation', connect([ 'settings' ], [ 'setShortUrlCreationSettings' ])); bottle.decorator('ShortUrlCreationSettings', connect([ 'settings' ], [ 'setShortUrlCreationSettings' ]));
bottle.serviceFactory('UserInterface', () => UserInterface); bottle.serviceFactory('UserInterfaceSettings', () => UserInterfaceSettings);
bottle.decorator('UserInterface', connect([ 'settings' ], [ 'setUiSettings' ])); bottle.decorator('UserInterfaceSettings', connect([ 'settings' ], [ 'setUiSettings' ]));
bottle.serviceFactory('Visits', () => Visits); bottle.serviceFactory('VisitsSettings', () => VisitsSettings);
bottle.decorator('Visits', connect([ 'settings' ], [ 'setVisitsSettings' ])); bottle.decorator('VisitsSettings', connect([ 'settings' ], [ 'setVisitsSettings' ]));
bottle.serviceFactory('Tags', () => Tags); bottle.serviceFactory('TagsSettings', () => TagsSettings);
bottle.decorator('Tags', connect([ 'settings' ], [ 'setTagsSettings' ])); bottle.decorator('TagsSettings', connect([ 'settings' ], [ 'setTagsSettings' ]));
bottle.serviceFactory('ShortUrlsListSettings', () => ShortUrlsList); bottle.serviceFactory('ShortUrlsListSettings', () => ShortUrlsListSettings);
bottle.decorator('ShortUrlsListSettings', connect([ 'settings' ], [ 'setShortUrlsListSettings' ])); bottle.decorator('ShortUrlsListSettings', connect([ 'settings' ], [ 'setShortUrlsListSettings' ]));
// Actions // Actions

View file

@ -1,19 +1,22 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { Input } from 'reactstrap'; import { Input } from 'reactstrap';
import { RealTimeUpdatesSettings, Settings } from '../../src/settings/reducers/settings'; import {
import RealTimeUpdates from '../../src/settings/RealTimeUpdates'; RealTimeUpdatesSettings as RealTimeUpdatesSettingsOptions,
Settings,
} from '../../src/settings/reducers/settings';
import RealTimeUpdatesSettings from '../../src/settings/RealTimeUpdatesSettings';
import ToggleSwitch from '../../src/utils/ToggleSwitch'; import ToggleSwitch from '../../src/utils/ToggleSwitch';
describe('<RealTimeUpdates />', () => { describe('<RealTimeUpdatesSettings />', () => {
const toggleRealTimeUpdates = jest.fn(); const toggleRealTimeUpdates = jest.fn();
const setRealTimeUpdatesInterval = jest.fn(); const setRealTimeUpdatesInterval = jest.fn();
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const createWrapper = (realTimeUpdates: Partial<RealTimeUpdatesSettings> = {}) => { const createWrapper = (realTimeUpdates: Partial<RealTimeUpdatesSettingsOptions> = {}) => {
const settings = Mock.of<Settings>({ realTimeUpdates }); const settings = Mock.of<Settings>({ realTimeUpdates });
wrapper = shallow( wrapper = shallow(
<RealTimeUpdates <RealTimeUpdatesSettings
settings={settings} settings={settings}
toggleRealTimeUpdates={toggleRealTimeUpdates} toggleRealTimeUpdates={toggleRealTimeUpdates}
setRealTimeUpdatesInterval={setRealTimeUpdatesInterval} setRealTimeUpdatesInterval={setRealTimeUpdatesInterval}

View file

@ -1,17 +1,17 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { DropdownItem } from 'reactstrap'; import { DropdownItem } from 'reactstrap';
import { ShortUrlCreationSettings, Settings } from '../../src/settings/reducers/settings'; import { ShortUrlCreationSettings as ShortUrlsSettings, Settings } from '../../src/settings/reducers/settings';
import { ShortUrlCreation } from '../../src/settings/ShortUrlCreation'; import { ShortUrlCreationSettings } from '../../src/settings/ShortUrlCreationSettings';
import ToggleSwitch from '../../src/utils/ToggleSwitch'; import ToggleSwitch from '../../src/utils/ToggleSwitch';
import { DropdownBtn } from '../../src/utils/DropdownBtn'; import { DropdownBtn } from '../../src/utils/DropdownBtn';
describe('<ShortUrlCreation />', () => { describe('<ShortUrlCreationSettings />', () => {
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const setShortUrlCreationSettings = jest.fn(); const setShortUrlCreationSettings = jest.fn();
const createWrapper = (shortUrlCreation?: ShortUrlCreationSettings) => { const createWrapper = (shortUrlCreation?: ShortUrlsSettings) => {
wrapper = shallow( wrapper = shallow(
<ShortUrlCreation <ShortUrlCreationSettings
settings={Mock.of<Settings>({ shortUrlCreation })} settings={Mock.of<Settings>({ shortUrlCreation })}
setShortUrlCreationSettings={setShortUrlCreationSettings} setShortUrlCreationSettings={setShortUrlCreationSettings}
/>, />,
@ -68,9 +68,9 @@ describe('<ShortUrlCreation />', () => {
}); });
it.each([ it.each([
[ { tagFilteringMode: 'includes' } as ShortUrlCreationSettings, 'Suggest tags including input', 'including' ], [ { tagFilteringMode: 'includes' } as ShortUrlsSettings, 'Suggest tags including input', 'including' ],
[ [
{ tagFilteringMode: 'startsWith' } as ShortUrlCreationSettings, { tagFilteringMode: 'startsWith' } as ShortUrlsSettings,
'Suggest tags starting with input', 'Suggest tags starting with input',
'starting with', 'starting with',
], ],

View file

@ -1,16 +1,20 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { DEFAULT_SHORT_URLS_ORDERING, Settings, ShortUrlsListSettings } from '../../src/settings/reducers/settings'; import {
import { ShortUrlsList } from '../../src/settings/ShortUrlsList'; DEFAULT_SHORT_URLS_ORDERING,
Settings,
ShortUrlsListSettings as ShortUrlsSettings,
} from '../../src/settings/reducers/settings';
import { ShortUrlsListSettings } from '../../src/settings/ShortUrlsListSettings';
import { OrderingDropdown } from '../../src/utils/OrderingDropdown'; import { OrderingDropdown } from '../../src/utils/OrderingDropdown';
import { ShortUrlsOrder } from '../../src/short-urls/data'; import { ShortUrlsOrder } from '../../src/short-urls/data';
describe('<ShortUrlsList />', () => { describe('<ShortUrlsListSettings />', () => {
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const setSettings = jest.fn(); const setSettings = jest.fn();
const createWrapper = (shortUrlsList?: ShortUrlsListSettings) => { const createWrapper = (shortUrlsList?: ShortUrlsSettings) => {
wrapper = shallow( wrapper = shallow(
<ShortUrlsList settings={Mock.of<Settings>({ shortUrlsList })} setShortUrlsListSettings={setSettings} />, <ShortUrlsListSettings settings={Mock.of<Settings>({ shortUrlsList })} setShortUrlsListSettings={setSettings} />,
); );
return wrapper; return wrapper;

View file

@ -1,17 +1,17 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { FormGroup } from 'reactstrap'; import { FormGroup } from 'reactstrap';
import { Settings, TagsMode, TagsSettings } from '../../src/settings/reducers/settings'; import { Settings, TagsMode, TagsSettings as TagsSettingsOptions } from '../../src/settings/reducers/settings';
import { TagsModeDropdown } from '../../src/tags/TagsModeDropdown'; import { TagsModeDropdown } from '../../src/tags/TagsModeDropdown';
import { Tags } from '../../src/settings/Tags'; import { TagsSettings } from '../../src/settings/TagsSettings';
import { OrderingDropdown } from '../../src/utils/OrderingDropdown'; import { OrderingDropdown } from '../../src/utils/OrderingDropdown';
import { TagsOrder } from '../../src/tags/data/TagsListChildrenProps'; import { TagsOrder } from '../../src/tags/data/TagsListChildrenProps';
describe('<Tags />', () => { describe('<TagsSettings />', () => {
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const setTagsSettings = jest.fn(); const setTagsSettings = jest.fn();
const createWrapper = (tags?: TagsSettings) => { const createWrapper = (tags?: TagsSettingsOptions) => {
wrapper = shallow(<Tags settings={Mock.of<Settings>({ tags })} setTagsSettings={setTagsSettings} />); wrapper = shallow(<TagsSettings settings={Mock.of<Settings>({ tags })} setTagsSettings={setTagsSettings} />);
return wrapper; return wrapper;
}; };

View file

@ -3,15 +3,15 @@ import { Mock } from 'ts-mockery';
import { faMoon, faSun } from '@fortawesome/free-solid-svg-icons'; import { faMoon, faSun } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Settings, UiSettings } from '../../src/settings/reducers/settings'; import { Settings, UiSettings } from '../../src/settings/reducers/settings';
import { UserInterface } from '../../src/settings/UserInterface'; import { UserInterfaceSettings } from '../../src/settings/UserInterfaceSettings';
import ToggleSwitch from '../../src/utils/ToggleSwitch'; import ToggleSwitch from '../../src/utils/ToggleSwitch';
import { Theme } from '../../src/utils/theme'; import { Theme } from '../../src/utils/theme';
describe('<UserInterface />', () => { describe('<UserInterfaceSettings />', () => {
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const setUiSettings = jest.fn(); const setUiSettings = jest.fn();
const createWrapper = (ui?: UiSettings) => { const createWrapper = (ui?: UiSettings) => {
wrapper = shallow(<UserInterface settings={Mock.of<Settings>({ ui })} setUiSettings={setUiSettings} />); wrapper = shallow(<UserInterfaceSettings settings={Mock.of<Settings>({ ui })} setUiSettings={setUiSettings} />);
return wrapper; return wrapper;
}; };

View file

@ -1,15 +1,15 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { Settings } from '../../src/settings/reducers/settings'; import { Settings } from '../../src/settings/reducers/settings';
import { Visits } from '../../src/settings/Visits'; import { VisitsSettings } from '../../src/settings/VisitsSettings';
import { SimpleCard } from '../../src/utils/SimpleCard'; import { SimpleCard } from '../../src/utils/SimpleCard';
import { DateIntervalSelector } from '../../src/utils/dates/DateIntervalSelector'; import { DateIntervalSelector } from '../../src/utils/dates/DateIntervalSelector';
describe('<Visits />', () => { describe('<VisitsSettings />', () => {
let wrapper: ShallowWrapper; let wrapper: ShallowWrapper;
const setVisitsSettings = jest.fn(); const setVisitsSettings = jest.fn();
const createWrapper = (settings: Partial<Settings> = {}) => { const createWrapper = (settings: Partial<Settings> = {}) => {
wrapper = shallow(<Visits settings={Mock.of<Settings>(settings)} setVisitsSettings={setVisitsSettings} />); wrapper = shallow(<VisitsSettings settings={Mock.of<Settings>(settings)} setVisitsSettings={setVisitsSettings} />);
return wrapper; return wrapper;
}; };