mirror of
https://github.com/skooner-k8s/skooner.git
synced 2026-08-24 04:16:18 +00:00
Merge pull request #53 from olivergg/href_for_urls_in_metadata
Href for urls in metadata
This commit is contained in:
@@ -1,16 +1,29 @@
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
import fromNow from '../utils/dates';
|
||||
import {isAValidURL} from '../utils/string';
|
||||
import Loading from './loading';
|
||||
import Sorter, {sortByDate} from './sorter';
|
||||
import ResourceSvg from '../art/resourceSvg';
|
||||
|
||||
export function objectMap(items = {}) {
|
||||
return Object.entries(items).map(([key, value]) => (
|
||||
<div key={key}>
|
||||
<span>{key}</span> • <span title={value}>{value.length <= 50 ? value : `${value.substr(0, 50)}...`}</span>
|
||||
</div>
|
||||
));
|
||||
return Object.entries(items).map(([key, value]) => {
|
||||
const substrValue = value.length <= 50 ? value : `${value.substr(0, 50)}...`;
|
||||
|
||||
if (isAValidURL(value)) {
|
||||
// Check valid URL
|
||||
return <div key={key}>
|
||||
<span>{key}</span> • <a title={value} target="_blank" href={value}>{substrValue}</a>
|
||||
</div>
|
||||
}
|
||||
// Note : alternative parsing could be implemented in other if clauses
|
||||
else {
|
||||
// By default, just display the raw value in a span
|
||||
return <div key={key}>
|
||||
<span>{key}</span> • <span title={value}> {substrValue} </span>
|
||||
</div>
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function TableBody({items, filter, colSpan, sort, row}) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Regular expression for URL validation created by @dperini.
|
||||
* https://gist.github.com/dperini/729294
|
||||
* (copy pasted from the official Kubernetes dashboard)
|
||||
*/
|
||||
const URL_REGEXP = new RegExp(
|
||||
'^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!' +
|
||||
'(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1' +
|
||||
',3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])' +
|
||||
'){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*' +
|
||||
'[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]' +
|
||||
'+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$',
|
||||
'i',
|
||||
);
|
||||
|
||||
/**
|
||||
* Check whether a string is a valid URL
|
||||
*/
|
||||
export function isAValidURL(str) {
|
||||
return URL_REGEXP.test(str.trim());
|
||||
}
|
||||
|
||||
/** ... Add other String utilities functions here */
|
||||
Reference in New Issue
Block a user