Merge branch 'feature/neighbors-cache-age' into develop

This commit is contained in:
Matthias Hannig 2018-10-02 10:49:01 +02:00
commit 498c1cd2b1
4 changed files with 53 additions and 14 deletions

View File

@ -115,12 +115,13 @@ export function loadRouteserverProtocolRequest(routeserverId) {
}
}
export function loadRouteserverProtocolSuccess(routeserverId, protocol) {
export function loadRouteserverProtocolSuccess(routeserverId, protocol, api) {
return {
type: LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
payload: {
routeserverId: routeserverId,
protocol: protocol
protocol: protocol,
api: api
}
}
}
@ -130,7 +131,12 @@ export function loadRouteserverProtocol(routeserverId) {
dispatch(loadRouteserverProtocolRequest(routeserverId));
axios.get(`/api/routeservers/${routeserverId}/neighbours`)
.then(({data}) => {
dispatch(loadRouteserverProtocolSuccess(routeserverId, data.neighbours));
console.log("LRS:", data);
dispatch(loadRouteserverProtocolSuccess(
routeserverId,
data.neighbours,
data.api,
));
})
.catch((error) => dispatch(apiError(error)));
}

View File

@ -61,7 +61,8 @@ class RouteserversPage extends React.Component {
</div>
<div className="col-lg-3 col-md-4 col-xs-12">
<div className="card">
<Status routeserverId={this.props.params.routeserverId} />
<Status routeserverId={this.props.params.routeserverId}
cacheStatus={this.props.cacheStatus} />
</div>
</div>
</div>
@ -77,7 +78,13 @@ export default connect(
filterValue: state.neighbors.filterValue,
sortColumn: state.neighbors.sortColumn,
sortOrder: state.neighbors.sortOrder
sortOrder: state.neighbors.sortOrder,
cacheStatus: {
generatedAt: state.neighbors.cachedAt,
ttl: state.neighbors.cacheTtl,
}
};
}
)(RouteserversPage);

View File

@ -7,6 +7,11 @@
import {SET_FILTER_VALUE} from './actions'
import {LOAD_ROUTESERVER_PROTOCOL_REQUEST,
LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
LOAD_ROUTESERVER_PROTOCOL_ERROR}
from '../actions'
const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
const DEFAULT_SORT_COLUMN = "asn";
@ -16,6 +21,11 @@ const initialState = {
sortColumn: DEFAULT_SORT_COLUMN,
sortOrder: DEFAULT_SORT_ORDER,
isLoading: false,
cachedAt: null,
cacheTtl: null,
filterQuery: "",
filterValue: ""
};
@ -49,6 +59,24 @@ export default function(state=initialState, action) {
filterValue: action.payload.value
});
case LOAD_ROUTESERVER_PROTOCOL_REQUEST:
return Object.assign({}, state, {
isLoading: true,
});
case LOAD_ROUTESERVER_PROTOCOL_ERROR:
return Object.assign({}, state, {
isLoading: false,
});
// TODO: move neighbors list here
case LOAD_ROUTESERVER_PROTOCOL_SUCCESS:
return Object.assign({}, state, {
isLoading: false,
cachedAt: action.payload.api.cache_status.cached_at,
cacheTtl: action.payload.api.ttl,
});
default:
}

View File

@ -27,22 +27,20 @@ class Details extends React.Component {
}
let cacheStatus = null;
if (this.props.cacheStatus) {
if (this.props.cacheStatus &&
this.props.cacheStatus.ttl &&
this.props.cacheStatus.generatedAt) {
const s = this.props.cacheStatus;
const generatedAt = moment(s.generatedAt);
const ttl = moment(s.ttl);
cacheStatus = [
<tr key="cache-status-cached-at">
<td><i className="fa fa-refresh"></i></td>
<td>
Generated <b>{s.generatedAt.fromNow()}</b><br />
Next refresh <b>{s.ttl.fromNow()}</b>
Generated <b>{generatedAt.fromNow()}</b> &middot; Next refresh <b>{ttl.fromNow()}</b>.
</td>
</tr>,
<tr key="cache-status-ttl">
<td></td>
<td>
</td>
</tr>
];
};