Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions src/containers/Cluster/ClusterInfo/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export const getInfo = (cluster: TClusterInfo, additionalInfo: InfoItem[]) => {
/**
* parses stringified json in format {url: "href"}
*/
function prepareClusterLink(rawLink?: string) {
function prepareClusterCoresLink(rawCoresString?: string) {
try {
const linkObject = parseJson(rawLink) as unknown;
const linkObject = parseJson(rawCoresString) as unknown;

if (
linkObject &&
Expand All @@ -95,26 +95,56 @@ function prepareClusterLink(rawLink?: string) {
return undefined;
}

/**
* parses stringified json in format {url: "href", slo_logs_url: "href"}
*/
function prepareClusterLoggingLinks(rawLoggingString?: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great if you added couple of tests for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests

try {
const linkObject = parseJson(rawLoggingString) as unknown;

if (linkObject && typeof linkObject === 'object') {
const logsUrl =
'url' in linkObject && typeof linkObject.url === 'string'
? linkObject.url
: undefined;
const sloLogsUrl =
'slo_logs_url' in linkObject && typeof linkObject.slo_logs_url === 'string'
? linkObject.slo_logs_url
: undefined;
return {logsUrl, sloLogsUrl};
}
} catch {}

return {};
}

export function useClusterLinks() {
const {cores, logging} = useClusterBaseInfo();

return React.useMemo(() => {
const result: ClusterLink[] = [];

const coresLink = prepareClusterLink(cores);
const loggingLink = prepareClusterLink(logging);
const coresUrl = prepareClusterCoresLink(cores);
const {logsUrl, sloLogsUrl} = prepareClusterLoggingLinks(logging);

if (coresLink) {
if (coresUrl) {
result.push({
title: i18n('link_cores'),
url: coresLink,
url: coresUrl,
});
}

if (loggingLink) {
if (logsUrl) {
result.push({
title: i18n('link_logging'),
url: loggingLink,
url: logsUrl,
});
}

if (sloLogsUrl) {
result.push({
title: i18n('link_slo-logs'),
url: sloLogsUrl,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/containers/Cluster/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"links": "Links",
"link_cores": "Coredumps",
"link_logging": "Logging",
"link_slo-logs": "Slo Logs",
"context_cores": "cores",
"title_cpu": "CPU",
"title_storage": "Storage",
Expand Down
Loading