sidePageColumn.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import * as R from 'ramda'
  2. import _ from 'lodash'
  3. import i18n from '@/locales'
  4. const commonColumns = [
  5. {
  6. field: 'key',
  7. title: 'Key',
  8. minWidth: 200,
  9. showOverflow: 'ellipsis',
  10. },
  11. {
  12. field: 'label',
  13. title: 'Label',
  14. width: 200,
  15. },
  16. ]
  17. const taintsColumns = [
  18. {
  19. field: 'key',
  20. title: 'Key',
  21. minWidth: 200,
  22. showOverflow: 'ellipsis',
  23. },
  24. {
  25. field: 'effect',
  26. title: 'Effect',
  27. width: 200,
  28. },
  29. ]
  30. export const operatingSystemColumn = () => {
  31. return {
  32. title: i18n.t('k8s.text_141'),
  33. field: 'operatingSystem',
  34. slots: {
  35. default: ({ row }, h) => {
  36. const data = row.labels ? Object.entries(row.labels).map(val => ({ key: val[0], label: val[1] })).filter(val => !val.key.toLowerCase().includes('id')) : []
  37. return [
  38. <vxe-grid class="mb-2" data={ data } columns={ commonColumns } />,
  39. ]
  40. },
  41. },
  42. }
  43. }
  44. export const annotateColumn = () => {
  45. return {
  46. title: i18n.t('k8s.text_142'),
  47. field: 'annotate',
  48. slots: {
  49. default: ({ row }, h) => {
  50. const data = row.annotations ? Object.entries(row.annotations).map(val => ({ key: val[0], label: val[1] })) : []
  51. return [
  52. <vxe-grid class="mb-2" data={ data } columns={ commonColumns } />,
  53. ]
  54. },
  55. },
  56. }
  57. }
  58. export const tagColumn = () => {
  59. return {
  60. title: i18n.t('k8s.text_82'),
  61. field: 'tag',
  62. slots: {
  63. default: ({ row }, h) => {
  64. const data = row.labels ? Object.entries(row.labels).map(val => ({ key: val[0], label: val[1] })) : []
  65. return [
  66. <vxe-grid class="mb-2" data={ data } columns={ commonColumns } />,
  67. ]
  68. },
  69. },
  70. }
  71. }
  72. export const taintColumn = () => {
  73. return {
  74. title: 'Taints',
  75. field: 'taints',
  76. slots: {
  77. default: ({ row }, h) => {
  78. const data = row.taints || []
  79. return [
  80. <vxe-grid class="mb-2" data={ data } columns={ taintsColumns } />,
  81. ]
  82. },
  83. },
  84. }
  85. }
  86. export const roleRefColumn = (path = 'roleRef') => {
  87. return {
  88. field: 'roleRef',
  89. title: 'roleRef',
  90. slots: {
  91. default: ({ row }, h) => {
  92. const roleRef = _.get(row, path)
  93. if (!R.is(Object, roleRef)) return '-'
  94. const items = Object.keys(roleRef).map(key => {
  95. return (
  96. <div class="d-flex">
  97. <div style={{ width: '80px' }}>{ key }:</div>
  98. <div>{ roleRef[key] }</div>
  99. </div>
  100. )
  101. })
  102. return items
  103. },
  104. },
  105. }
  106. }
  107. export const subjectsColumn = (path = 'subjects') => {
  108. return {
  109. field: 'subjects',
  110. title: 'subjects',
  111. slots: {
  112. default: ({ row }, h) => {
  113. const subjects = _.get(row, path)
  114. if (!subjects) return '-'
  115. const columns = Object.keys(subjects[0]).filter(key => key !== '_XID').map(key => ({ field: key, title: key }))
  116. return <vxe-grid data={ subjects } columns={ columns } size="mini" />
  117. },
  118. },
  119. }
  120. }