diff --git a/src/App.tsx b/src/App.tsx index 75579032..4928f42d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -16,7 +16,7 @@ const App = ( CreateServer: FC, EditServer: FC, Settings: FC, - ShlinkVersions: FC, + ShlinkVersionsContainer: FC, ) => ({ fetchServers, servers }: AppProps) => { // On first load, try to fetch the remote servers if the list is empty useEffect(() => { @@ -41,8 +41,8 @@ const App = ( -
- +
+
diff --git a/src/common/ShlinkVersions.tsx b/src/common/ShlinkVersions.tsx index 5fb3eb6f..188f8f8d 100644 --- a/src/common/ShlinkVersions.tsx +++ b/src/common/ShlinkVersions.tsx @@ -1,16 +1,14 @@ -import classNames from 'classnames'; import { pipe } from 'ramda'; import { ExternalLink } from 'react-external-link'; import { versionToPrintable, versionToSemVer } from '../utils/helpers/version'; -import { isReachableServer, SelectedServer } from '../servers/data'; +import { isReachableServer } from '../servers/data'; +import { ShlinkVersionsContainerProps } from './ShlinkVersionsContainer'; const SHLINK_WEB_CLIENT_VERSION = '%_VERSION_%'; const normalizeVersion = pipe(versionToSemVer(), versionToPrintable); -export interface ShlinkVersionsProps { - selectedServer: SelectedServer; +export interface ShlinkVersionsProps extends ShlinkVersionsContainerProps { clientVersion?: string; - className?: string; } const VersionLink = ({ project, version }: { project: 'shlink' | 'shlink-web-client'; version: string }) => ( @@ -19,13 +17,11 @@ const VersionLink = ({ project, version }: { project: 'shlink' | 'shlink-web-cli ); -const ShlinkVersions = ( - { selectedServer, className, clientVersion = SHLINK_WEB_CLIENT_VERSION }: ShlinkVersionsProps, -) => { +const ShlinkVersions = ({ selectedServer, clientVersion = SHLINK_WEB_CLIENT_VERSION }: ShlinkVersionsProps) => { const normalizedClientVersion = normalizeVersion(clientVersion); return ( - + {isReachableServer(selectedServer) && <>Server: - } diff --git a/src/common/ShlinkVersionsContainer.tsx b/src/common/ShlinkVersionsContainer.tsx new file mode 100644 index 00000000..894174fc --- /dev/null +++ b/src/common/ShlinkVersionsContainer.tsx @@ -0,0 +1,25 @@ +import classNames from 'classnames'; +import { isReachableServer, SelectedServer } from '../servers/data'; +import ShlinkVersions from './ShlinkVersions'; + +export interface ShlinkVersionsContainerProps { + selectedServer: SelectedServer; +} + +const ShlinkVersionsContainer = ({ selectedServer }: ShlinkVersionsContainerProps) => { + const serverIsReachable = isReachableServer(selectedServer); + const colClasses = classNames('text-center', { + 'col-12': !serverIsReachable, + 'col-lg-10 offset-lg-2 col-md-9 offset-md-3': serverIsReachable, + }); + + return ( +
+
+ +
+
+ ); +}; + +export default ShlinkVersionsContainer; diff --git a/src/common/services/provideServices.ts b/src/common/services/provideServices.ts index 94f5d3bc..fd631e10 100644 --- a/src/common/services/provideServices.ts +++ b/src/common/services/provideServices.ts @@ -5,7 +5,7 @@ import Home from '../Home'; import MenuLayout from '../MenuLayout'; import AsideMenu from '../AsideMenu'; import ErrorHandler from '../ErrorHandler'; -import ShlinkVersions from '../ShlinkVersions'; +import ShlinkVersionsContainer from '../ShlinkVersionsContainer'; import { ConnectDecorator } from '../../container/types'; import { withoutSelectedServer } from '../../servers/helpers/withoutSelectedServer'; @@ -40,8 +40,8 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator, withRouter: bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton'); - bottle.serviceFactory('ShlinkVersions', () => ShlinkVersions); - bottle.decorator('ShlinkVersions', connect([ 'selectedServer' ])); + bottle.serviceFactory('ShlinkVersionsContainer', () => ShlinkVersionsContainer); + bottle.decorator('ShlinkVersionsContainer', connect([ 'selectedServer' ])); bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window', 'console'); }; diff --git a/src/container/index.ts b/src/container/index.ts index 685fbf84..5e746c62 100644 --- a/src/container/index.ts +++ b/src/container/index.ts @@ -31,7 +31,17 @@ const connect: ConnectDecorator = (propsFromState: string[] | null, actionServic actionServiceNames.reduce(mapActionService, {}), ); -bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer', 'EditServer', 'Settings', 'ShlinkVersions'); +bottle.serviceFactory( + 'App', + App, + 'MainHeader', + 'Home', + 'MenuLayout', + 'CreateServer', + 'EditServer', + 'Settings', + 'ShlinkVersionsContainer', +); bottle.decorator('App', connect([ 'servers' ], [ 'fetchServers' ])); provideCommonServices(bottle, connect, withRouter); diff --git a/test/common/ShlinkVersionsContainer.test.tsx b/test/common/ShlinkVersionsContainer.test.tsx new file mode 100644 index 00000000..063dcdf4 --- /dev/null +++ b/test/common/ShlinkVersionsContainer.test.tsx @@ -0,0 +1,27 @@ +import { shallow, ShallowWrapper } from 'enzyme'; +import { Mock } from 'ts-mockery'; +import ShlinkVersionsContainer from '../../src/common/ShlinkVersionsContainer'; +import { NonReachableServer, NotFoundServer, ReachableServer, SelectedServer } from '../../src/servers/data'; + +describe('', () => { + let wrapper: ShallowWrapper; + + const createWrapper = (selectedServer: SelectedServer) => { + wrapper = shallow(); + + return wrapper; + }; + + afterEach(() => wrapper?.unmount()); + + test.each([ + [ null, 'col-12' ], + [ Mock.of({ serverNotFound: true }), 'col-12' ], + [ Mock.of({ serverNotReachable: true }), 'col-12' ], + [ Mock.of({ printableVersion: 'v1.0.0' }), 'col-lg-10 offset-lg-2 col-md-9 offset-md-3' ], + ])('renders proper col classes based on type of selected server', (selectedServer, expectedClasses) => { + const wrapper = createWrapper(selectedServer); + + expect(wrapper.find('div').at(1).prop('className')).toEqual(`text-center ${expectedClasses}`); + }); +});