use links

This commit is contained in:
Annika Hannig 2023-11-28 14:33:52 +01:00
parent cd8fdfa610
commit 23e5539688
No known key found for this signature in database
GPG Key ID: 62E226E47DDCE58D
2 changed files with 42 additions and 5 deletions

View File

@ -30,7 +30,20 @@ export const getAttr = (r, path) => {
return path.split(".").reduce((acc, elem) => acc[elem], r);
}
// Linking: Create link targes as a function of the route
// Link to the route server
const linkRouteServer = (route) =>
`/routeservers/${route?.routeserver?.id}`;
// Create a link to the routes page of a neighbor
const linkNeighborRoutes = (route) => {
const rs = route?.routeserver?.id;
const neighbor = route?.neighbor_id;
return `/routeservers/${rs}/neighbors/${neighbor}/routes`;
}
// Default column: Show the attribute and bind the
// onClick attribute.
export const ColDefault = ({onClick, route, column}) => {
return (
<td>
@ -39,6 +52,20 @@ export const ColDefault = ({onClick, route, column}) => {
);
}
// ColLink provides a cell with a linkable target.
// The attribute `to` is a function of the `route`
// attribute, returning the url.
export const ColLink = ({to, route, column}) => {
const href = to(route);
return (
<td>
<a href={href} target="_blank" rel="noreferrer">
{getAttr(route, column)}
</a>
</td>
);
}
// Include filter and noexport reason in this column.
export const ColNetwork = ({onClick, route}) => {
return (
@ -83,19 +110,31 @@ export const ColFlags = ({route}) => {
);
}
export const ColRouteServer = ({route, column}) =>
<ColLink to={linkRouteServer} route={route} column={column} />;
export const ColNeighbor = ({route, column}) =>
<ColLink to={linkNeighborRoutes} route={route} column={column} />;
const RouteColumn = ({onClick, column, route}) => {
const widgets = {
const cells = {
"network": ColNetwork,
"flags": ColFlags,
"bgp.as_path": ColAsPath,
"Flags": ColFlags,
"ASPath": ColAsPath,
"routeserver.name": ColRouteServer,
"neighbor.description": ColNeighbor,
};
let Widget = widgets[column] || ColDefault;
let Cell = cells[column] || ColDefault;
return (
<Widget
<Cell
column={column}
route={route}
onClick={onClick} />

View File

@ -18,8 +18,6 @@ import { useErrorHandler }
from 'app/context/errors';
const initialState = {
asn: 0, // Our own ASN (might be abstracted in the future)
routes_columns: {},
routes_columns_order: [],
neighbors_columns: {},