Skip to content

Commit 3646fa5

Browse files
authored
Merge pull request #2827 from devtron-labs/fix/events-explain
fix: events explain button not visible
2 parents ac99ee3 + 3da1c81 commit 3646fa5

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/components/ResourceBrowser/ResourceBrowser.service.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ import {
3636
getClusterListMinWithInstalledClusters,
3737
getClusterListWithInstalledClusters,
3838
} from '@Components/ClusterNodes/clusterNodes.service'
39+
import { importComponentFromFELibrary } from '@Components/common'
3940

4041
import { Routes } from '../../config'
4142
import { SIDEBAR_KEYS } from './Constants'
4243
import { ClusterDetailBaseParams, GetResourceDataType, NodeRowDetail } from './Types'
4344
import { parseNodeList, removeDefaultForStorageClass } from './Utils'
4445

46+
const ExplainWithAIButton = importComponentFromFELibrary('ExplainWithAIButton', null, 'function')
47+
4548
export const namespaceListByClusterId = async (clusterId: string) => {
4649
const response = await get<string[]>(`${Routes.CLUSTER_NAMESPACE}/${clusterId}`)
4750

@@ -136,8 +139,11 @@ export const getResourceData = async ({
136139
? removeDefaultForStorageClass(response.result.data)
137140
: response.result.data
138141

142+
const isEventList = selectedResource.gvk.Kind === Nodes.Event
143+
139144
return {
140145
...response.result,
146+
headers: [...response.result.headers, ...(isEventList && ExplainWithAIButton ? ['explainButton'] : [])],
141147
data: data.map((entry, index) => ({
142148
...entry,
143149
id: `${idPrefix}${index}`,

src/components/ResourceBrowser/ResourceList/K8SResourceList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ export const K8SResourceList = ({
186186
(header) =>
187187
({
188188
field: isNodeListing ? NODE_LIST_HEADERS_TO_KEY_MAP[header] : header,
189-
label: header === 'type' && isEventListing ? '' : header,
189+
label: (header === 'type' || header === 'explainButton') && isEventListing ? '' : header,
190190
size: getColumnSize(header, isEventListing),
191191
CellComponent: K8sResourceListTableCellComponent,
192192
comparator: getColumnComparator(header, isEventListing),
193-
isSortable: !isEventListing || (header !== 'message' && header !== 'type'),
193+
isSortable:
194+
!isEventListing ||
195+
(header !== 'message' && header !== 'type' && header !== 'explainButton'),
194196
horizontallySticky:
195197
header === 'name' || (isEventListing && (header === 'message' || header === 'type')),
196198
}) as TableColumnType,

src/components/ResourceBrowser/ResourceList/K8sResourceListTableCellComponent.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { AddEnvironmentFormPrefilledInfoType } from '@Pages/GlobalConfigurations
2727
import { ClusterEnvironmentDrawer } from '@Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer'
2828
import { ADD_ENVIRONMENT_FORM_LOCAL_STORAGE_KEY } from '@Pages/GlobalConfigurations/ClustersAndEnvironments/constants'
2929

30-
import { AI_BUTTON_CONFIG_MAP, K8S_EMPTY_GROUP } from '../Constants'
30+
import { AI_BUTTON_CONFIG_MAP, EVENT_LIST, K8S_EMPTY_GROUP } from '../Constants'
3131
import { ClusterDetailBaseParams } from '../Types'
3232
import { getRenderInvolvedObjectButton, getRenderNodeButton, renderResourceValue } from '../Utils'
3333
import NodeActionsMenu from './NodeActionsMenu'
@@ -201,6 +201,16 @@ const K8sResourceListTableCellComponent = ({
201201
)
202202
}
203203

204+
const eventDetails = {
205+
message: resourceData.message as string,
206+
namespace: resourceData.namespace as string,
207+
object: resourceData[EVENT_LIST.dataKeys.involvedObject] as string,
208+
source: resourceData.source as string,
209+
count: resourceData.count as number,
210+
age: resourceData.age as string,
211+
lastSeen: resourceData[EVENT_LIST.dataKeys.lastSeen] as string,
212+
}
213+
204214
return (
205215
<>
206216
{columnName === 'name' ? (
@@ -296,6 +306,19 @@ const K8sResourceListTableCellComponent = ({
296306
</Tooltip>
297307
</>
298308
)}
309+
{ExplainWithAIButton &&
310+
columnName === 'explainButton' &&
311+
isEventListing &&
312+
resourceData.type === 'Warning' && (
313+
<ExplainWithAIButton
314+
intelligenceConfig={{
315+
clusterId,
316+
metadata: eventDetails,
317+
prompt: JSON.stringify(eventDetails),
318+
analyticsCategory: getAIAnalyticsEvents('RB_RESOURCE'),
319+
}}
320+
/>
321+
)}
299322
<span>
300323
{columnName === 'restarts' && Number(resourceData.restarts) !== 0 && PodRestartIcon && (
301324
<PodRestartIcon

src/components/ResourceBrowser/ResourceList/utils.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ export const getColumnSize = (field: string, isEventListing: boolean) => {
270270
startWidth: 140,
271271
},
272272
}
273+
case 'explainButton':
274+
return { fixed: 80 }
273275
default:
274276
return {
275277
range: {

0 commit comments

Comments
 (0)