import * as R from 'ramda'
import _ from 'lodash'
import i18n from '@/locales'
export const k8sStatusColumn = ({ path = 'podsInfo.warnings', statusModule = 'k8s_resource' } = {}) => {
return {
field: 'status',
title: i18n.t('k8s.text_35'),
width: 100,
slots: {
default: ({ row }, h) => {
const warnings = (_.get(row, path) || []).map(v => v.message)
let warnTooltip = null
if (warnings && warnings.length) {
warnTooltip = (
{ warnings.map(val => ( { val }
)) }
{ i18n.t('k8s.text_402') }
)
}
return [
{ warnTooltip }
,
]
},
},
}
}
export const k8sLabelColumn = ({ field = 'labels', title = i18n.t('k8s.text_82') } = {}) => {
return {
field,
title,
minWidth: 200,
slots: {
default: ({ row }, h) => {
if (!row[field] || !R.is(Object, row[field])) return '-'
const colors = ['pink', 'orange', 'green', 'cyan', 'blue', 'purple', 'red']
const labels = Object.entries(row[field]).map(arr => ({ key: arr[0], value: arr[1] }))
return [
{
labels.map((val, i) => {
return (
{ `${val.key}:${val.value}` }
)
})
}
,
]
},
},
}
}
export const k8sImageColumn = ({ field = 'containerImages', title = i18n.t('k8s.text_42'), itemField = 'image' } = {}) => {
return {
field,
title,
minWidth: 200,
slots: {
default: ({ row }, h) => {
if (!row[field] || !row[field].length) return '-'
return row[field].map(v => {
return (
{v.name}: { v[itemField] }
)
})
},
},
}
}
export const k8sEnvColumn = ({ field = 'env', title = i18n.t('k8s.text_111') } = {}) => {
return {
field,
title,
slots: {
default: ({ row }, h) => {
if (!row[field] || !R.is(Array, row[field])) return '-'
return [
{
row[field].map((val, i) => {
return (
{ `${val.name}:${val.value || '-'}` }
)
})
}
,
]
},
},
}
}
export const federatedResClusterCountColumn = () => ({
field: 'cluster_count',
title: i18n.t('k8s.text_403'),
minWidth: 100,
formatter: ({ row }) => `${row.cluster_count}` || '-',
})
export const federatednamespaceColumn = () => ({
field: 'federatednamespace',
title: i18n.t('dictionary.federatednamespaces'),
formatter: ({ row }) => row.federatednamespace || '-',
})