Added list of servers connected to store in ServerError component

This commit is contained in:
Alejandro Celaya
2020-03-08 12:49:52 +01:00
parent d1a5ee43e9
commit 9804a2d18d
7 changed files with 18 additions and 14 deletions

View File

@@ -10,7 +10,6 @@ import './ServersListGroup.scss';
const propTypes = {
servers: PropTypes.arrayOf(serverType).isRequired,
children: PropTypes.node.isRequired,
className: PropTypes.string,
};
const ServerListItem = ({ id, name }) => (
@@ -25,15 +24,15 @@ ServerListItem.propTypes = {
name: PropTypes.string,
};
const ServersListGroup = ({ servers, children, className }) => (
<div className={className}>
const ServersListGroup = ({ servers, children }) => (
<React.Fragment>
<h5>{children}</h5>
{servers.length > 0 && (
<ListGroup className="servers-list__list-group">
<ListGroup className="servers-list__list-group mt-md-3">
{servers.map(({ id, name }) => <ServerListItem key={id} id={id} name={name} />)}
</ListGroup>
)}
</div>
</React.Fragment>
);
ServersListGroup.propTypes = propTypes;

View File

@@ -1,7 +1,6 @@
@import '../utils/mixins/vertical-align';
.servers-list__list-group {
margin-top: 1rem;
width: 100%;
max-width: 400px;
}
@@ -14,5 +13,6 @@
.servers-list__server-item-icon {
@include vertical-align();
right: 1rem;
}

View File

@@ -6,12 +6,13 @@ import ServersListGroup from '../ServersListGroup';
import './ServerError.scss';
const propTypes = {
servers: PropTypes.object,
type: PropTypes.oneOf([ 'not-found', 'not-reachable' ]).isRequired,
};
export const ServerError = ({ type }) => (
export const ServerError = ({ type, servers: { list } }) => (
<div className="server-error-container flex-column">
<div className="row w-100">
<div className="row w-100 mb-3 mb-md-5">
<Message type="error">
{type === 'not-found' && 'Could not find this Shlink server.'}
{type === 'not-reachable' && (
@@ -22,8 +23,8 @@ export const ServerError = ({ type }) => (
)}
</Message>
</div>
<ServersListGroup servers={[]} className="mt-3 mt-md-5">
These are the {type === 'not-reachable' ? 'other' : ''} servers currently configured. Choose one of
<ServersListGroup servers={Object.values(list)}>
These are the {type === 'not-reachable' ? 'other' : ''} Shlink servers currently configured. Choose one of
them or <Link to="/server/create">add a new one</Link>.
</ServersListGroup>
</div>

View File

@@ -7,6 +7,7 @@ import ImportServersBtn from '../helpers/ImportServersBtn';
import { resetSelectedServer, selectServer } from '../reducers/selectedServer';
import { createServer, createServers, deleteServer, listServers } from '../reducers/server';
import ForServerVersion from '../helpers/ForServerVersion';
import { ServerError } from '../helpers/ServerError';
import ServersImporter from './ServersImporter';
import ServersService from './ServersService';
import ServersExporter from './ServersExporter';
@@ -32,6 +33,9 @@ const provideServices = (bottle, connect, withRouter) => {
bottle.serviceFactory('ForServerVersion', () => ForServerVersion);
bottle.decorator('ForServerVersion', connect([ 'selectedServer' ]));
bottle.serviceFactory('ServerError', () => ServerError);
bottle.decorator('ServerError', connect([ 'servers' ]));
// Services
bottle.constant('csvjson', csvjson);
bottle.service('ServersImporter', ServersImporter, 'csvjson');