mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 14:57:22 +03:00
Added behavior to mark active server in servers dropdown
This commit is contained in:
parent
fb407da3e8
commit
e1049a74a2
6 changed files with 50 additions and 14 deletions
|
@ -1,11 +1,21 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
import './Home.scss';
|
import './Home.scss';
|
||||||
|
import { resetSelectedServer } from '../servers/reducers/selectedServer';
|
||||||
|
|
||||||
export default () => {
|
export class Home extends React.Component {
|
||||||
return (
|
componentDidMount() {
|
||||||
<div className="home-container">
|
this.props.resetSelectedServer();
|
||||||
<h1 className="home-container__title">Welcome to Shlink</h1>
|
}
|
||||||
<h5 className="home-container__intro">Please, select a server.</h5>
|
|
||||||
</div>
|
render() {
|
||||||
);
|
return (
|
||||||
};
|
<div className="home-container">
|
||||||
|
<h1 className="home-container__title">Welcome to Shlink</h1>
|
||||||
|
<h5 className="home-container__intro">Please, select a server.</h5>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(null, { resetSelectedServer })(Home);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
@import "./utils/base";
|
||||||
|
|
||||||
* {
|
* {
|
||||||
outline: none !important;
|
outline: none !important;
|
||||||
}
|
}
|
||||||
|
@ -5,3 +7,7 @@
|
||||||
.nowrap {
|
.nowrap {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown-item.active {
|
||||||
|
background-color: $mainColor !important;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { assoc } from 'ramda';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { createServer } from './reducers/server';
|
import { createServer } from './reducers/server';
|
||||||
|
import { resetSelectedServer } from './reducers/selectedServer';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
import './CreateServer.scss';
|
import './CreateServer.scss';
|
||||||
|
@ -13,6 +14,10 @@ export class CreateServer extends React.Component {
|
||||||
apiKey: '',
|
apiKey: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.resetSelectedServer();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const submit = e => {
|
const submit = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -52,4 +57,7 @@ export class CreateServer extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(state => ({ selectedServer: state.selectedServer }), { createServer })(CreateServer);
|
export default connect(state => ({ selectedServer: state.selectedServer }), {
|
||||||
|
createServer,
|
||||||
|
resetSelectedServer
|
||||||
|
})(CreateServer);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { listServers } from './reducers/server';
|
||||||
|
|
||||||
export class ServersDropdown extends React.Component {
|
export class ServersDropdown extends React.Component {
|
||||||
renderServers = () => {
|
renderServers = () => {
|
||||||
const { servers } = this.props;
|
const { servers, currentServer } = this.props;
|
||||||
|
|
||||||
if (isEmpty(servers)) {
|
if (isEmpty(servers)) {
|
||||||
return <DropdownItem disabled><i>Add a server first...</i></DropdownItem>
|
return <DropdownItem disabled><i>Add a server first...</i></DropdownItem>
|
||||||
|
@ -16,7 +16,11 @@ export class ServersDropdown extends React.Component {
|
||||||
|
|
||||||
return Object.values(servers).map(({ name, id }) => (
|
return Object.values(servers).map(({ name, id }) => (
|
||||||
<span key={id}>
|
<span key={id}>
|
||||||
<DropdownItem tag={Link} to={`/server/${id}/list-short-urls/1`}>
|
<DropdownItem
|
||||||
|
tag={Link}
|
||||||
|
to={`/server/${id}/list-short-urls/1`}
|
||||||
|
active={currentServer && currentServer.id === id}
|
||||||
|
>
|
||||||
{name}
|
{name}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</span>
|
</span>
|
||||||
|
@ -38,7 +42,8 @@ export class ServersDropdown extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
servers: state.servers
|
servers: state.servers,
|
||||||
|
currentServer: state.selectedServer,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, { listServers })(ServersDropdown);
|
export default connect(mapStateToProps, { listServers })(ServersDropdown);
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
import { LIST_SHORT_URLS } from '../../short-urls/reducers/shortUrlsList';
|
import { LIST_SHORT_URLS } from '../../short-urls/reducers/shortUrlsList';
|
||||||
|
|
||||||
|
const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
|
||||||
|
|
||||||
export default function reducer(state = null, action) {
|
export default function reducer(state = null, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case LIST_SHORT_URLS:
|
case LIST_SHORT_URLS:
|
||||||
return action.selectedServer;
|
return action.selectedServer;
|
||||||
|
case RESET_SELECTED_SERVER:
|
||||||
|
return null;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
|
||||||
|
|
|
@ -71,6 +71,7 @@ class Row extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { shortUrl, selectedServer } = this.props;
|
const { shortUrl, selectedServer } = this.props;
|
||||||
|
const selectedServerUrl = selectedServer ? selectedServer.url : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
|
@ -81,8 +82,8 @@ class Row extends React.Component {
|
||||||
<Moment format="YYYY-MM-DD HH:mm" interval={0}>{shortUrl.dateCreated}</Moment>
|
<Moment format="YYYY-MM-DD HH:mm" interval={0}>{shortUrl.dateCreated}</Moment>
|
||||||
</td>
|
</td>
|
||||||
<td className="short-urls-list__cell">
|
<td className="short-urls-list__cell">
|
||||||
<a href={`${selectedServer.url}/${shortUrl.shortCode}`} target="_blank">
|
<a href={`${selectedServerUrl}/${shortUrl.shortCode}`} target="_blank">
|
||||||
{`${selectedServer.url}/${shortUrl.shortCode}`}
|
{`${selectedServerUrl}/${shortUrl.shortCode}`}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td className="short-urls-list__cell">
|
<td className="short-urls-list__cell">
|
||||||
|
|
Loading…
Reference in a new issue