Skip to content

Commit b67f1ff

Browse files
Merge pull request #3033 from devtron-labs/feat/ai-context
feat: update AIAgentContext handling across components for improved context management
2 parents 26fab4a + f0ce228 commit b67f1ff

File tree

6 files changed

+59
-56
lines changed

6 files changed

+59
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "1.22.0-beta-2",
7+
"@devtron-labs/devtron-fe-common-lib": "1.22.0-beta-4",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
*/
1616

1717
import { useEffect, useMemo, useState } from 'react'
18-
import { Route, useHistory, useLocation, useParams, useRouteMatch } from 'react-router-dom'
18+
import { Route, useHistory, useLocation, useParams } from 'react-router-dom'
1919

2020
import {
21+
AIAgentContextSourceType,
2122
BreadcrumbText,
2223
DevtronProgressing,
2324
ErrorScreenManager,
@@ -76,7 +77,6 @@ const CompareClusterButton = importComponentFromFELibrary('CompareClusterButton'
7677
const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) => {
7778
const params = useParams<ClusterDetailBaseParams>()
7879
const { clusterId } = params
79-
const { path } = useRouteMatch()
8080
const location = useLocation()
8181
const {
8282
tabs,
@@ -126,20 +126,22 @@ const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) =
126126

127127
return () => {
128128
setIntelligenceConfig(null)
129-
setAIAgentContext(null)
130129
}
131130
}, [])
132131
useEffectAfterMount(() => initTabsBasedOnRole(true), [clusterId])
133132

134133
useEffect(() => {
135134
setAIAgentContext({
136-
path,
137-
context: {
138-
...params,
135+
source: AIAgentContextSourceType.RESOURCE_BROWSER_CLUSTER,
136+
data: {
137+
clusterId: +clusterId || undefined,
139138
clusterName: selectedCluster.label,
140-
search: location.search,
141139
},
142140
})
141+
142+
return () => {
143+
setAIAgentContext(null)
144+
}
143145
}, [location.pathname, location.search, selectedCluster.label])
144146

145147
const refreshData = () => {

src/components/app/details/appDetails/AppDetails.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { generatePath, Route, useHistory, useLocation, useParams, useRouteMatch
2020
import {
2121
ACTION_STATE,
2222
aggregateNodes,
23+
AIAgentContextSourceType,
2324
AppStatusModal,
2425
AppStatusModalTabType,
2526
ArtifactInfoModal,
@@ -216,20 +217,30 @@ const Details: React.FC<DetailsType> = ({
216217
const params = useParams<{ appId: string; envId: string }>()
217218
const location = useLocation()
218219
const { replace, push } = useHistory()
219-
const { path, url } = useRouteMatch()
220+
const { url } = useRouteMatch()
220221

221222
const { setAIAgentContext } = useMainContext()
222223

223224
useEffect(() => {
224-
setAIAgentContext({
225-
path,
226-
context: {
227-
...params,
228-
environmentName: appDetails?.environmentName ?? '',
229-
appName: appDetails?.appName ?? '',
230-
},
231-
})
232-
}, [appDetails?.environmentName, appDetails?.appName, url])
225+
// This check is here since we don't clear appDetails on env/app change for some reason :/ and this will cause data mismatch
226+
if (appDetails?.environmentId === +params.envId && appDetails?.appId === +params.appId) {
227+
setAIAgentContext({
228+
source: AIAgentContextSourceType.APP_DETAILS,
229+
data: {
230+
appId: +params.appId,
231+
envId: +params.envId,
232+
clusterId: appDetails?.clusterId,
233+
envName: appDetails?.environmentName,
234+
appName: appDetails?.appName,
235+
appType: 'devtronApp',
236+
},
237+
})
238+
}
239+
240+
return () => {
241+
setAIAgentContext(null)
242+
}
243+
}, [appDetails?.environmentName, appDetails?.appName, appDetails?.clusterId, url])
233244

234245
const appDetailsFromIndexStore = IndexStore.getAppDetails()
235246

src/components/app/details/main.tsx

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,10 @@ const CIDetails = lazy(() => import('./cIDetails/CIDetails'))
5959
const AppDetails = lazy(() => import('./appDetails/AppDetails'))
6060
const CDDetails = lazy(() => import('./cdDetails/CDDetails'))
6161

62-
const AIAgentContextSetterWrapper = ({ children, appName }: PropsWithChildren<{ appName: string }>) => {
63-
const { setAIAgentContext } = useMainContext()
64-
const params = useParams()
65-
const { path, url } = useRouteMatch()
66-
67-
useEffect(() => {
68-
const contextData: Record<string, string> = {
69-
...params,
70-
}
71-
if (contextData.buildId) {
72-
// For build history page
73-
contextData['Workflow_id'] = contextData.buildId
74-
delete contextData.buildId
75-
}
76-
setAIAgentContext({ path, context: { appName, ...contextData } })
77-
}, [path, url])
78-
79-
return <>{children}</>
80-
}
81-
8262
export default function AppDetailsPage() {
8363
const { path } = useRouteMatch()
8464
const { appId } = useParams<{ appId }>()
85-
const { setIntelligenceConfig, setAIAgentContext } = useMainContext()
65+
const { setIntelligenceConfig } = useMainContext()
8666
const [appName, setAppName] = useState('')
8767
const [appMetaInfo, setAppMetaInfo] = useState<AppMetaInfo>()
8868
const [reloadMandatoryProjects, setReloadMandatoryProjects] = useState<boolean>(true)
@@ -159,7 +139,6 @@ export default function AppDetailsPage() {
159139
setSelectedGroupFilter([])
160140
setAppListOptions([])
161141
setIntelligenceConfig(null)
162-
setAIAgentContext(null)
163142
}
164143
}, [appId])
165144

@@ -421,26 +400,18 @@ export default function AppDetailsPage() {
421400
</Route>
422401
<Route
423402
path={`${path}/${URLS.APP_TRIGGER}`}
424-
render={() => (
425-
<AIAgentContextSetterWrapper appName={appName}>
426-
<TriggerView filteredEnvIds={_filteredEnvIds} />
427-
</AIAgentContextSetterWrapper>
428-
)}
403+
render={() => <TriggerView filteredEnvIds={_filteredEnvIds} />}
429404
/>
430405
<Route path={`${path}/${URLS.APP_CI_DETAILS}/:pipelineId(\\d+)?/:buildId(\\d+)?`}>
431-
<AIAgentContextSetterWrapper appName={appName}>
432-
<CIDetails key={appId} filteredEnvIds={_filteredEnvIds} />
433-
</AIAgentContextSetterWrapper>
406+
<CIDetails key={appId} filteredEnvIds={_filteredEnvIds} />
434407
</Route>
435408
<Route path={`${path}/${URLS.APP_DEPLOYMENT_METRICS}/:envId(\\d+)?`}>
436409
<DeploymentMetrics filteredEnvIds={_filteredEnvIds} />
437410
</Route>
438411
<Route
439412
path={`${path}/${URLS.APP_CD_DETAILS}/:envId(\\d+)?/:pipelineId(\\d+)?/:triggerId(\\d+)?`}
440413
>
441-
<AIAgentContextSetterWrapper appName={appName}>
442-
<CDDetails key={appId} filteredEnvIds={_filteredEnvIds} />
443-
</AIAgentContextSetterWrapper>
414+
<CDDetails key={appId} filteredEnvIds={_filteredEnvIds} />
444415
</Route>
445416
<Route path={`${path}/${CommonURLS.APP_CONFIG}`}>
446417
<AppConfig

src/components/v2/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import { Redirect, Route, Switch, useHistory, useLocation, useParams, useRouteMa
1919

2020
import {
2121
abortPreviousRequests,
22+
AIAgentContextSourceType,
2223
API_STATUS_CODES,
2324
DetailsProgressing,
2425
ErrorScreenManager,
2526
getIsRequestAborted,
2627
showError,
28+
useMainContext,
2729
} from '@devtron-labs/devtron-fe-common-lib'
2830

2931
import { URLS } from '../../config'
@@ -49,6 +51,8 @@ const RouterComponent = () => {
4951
const { path } = useRouteMatch()
5052
const location = useLocation()
5153
const history = useHistory()
54+
const { setAIAgentContext } = useMainContext()
55+
5256
const abortControllerRef = useRef<AbortController>(new AbortController())
5357

5458
const [errorResponseCode, setErrorResponseCode] = useState(undefined)
@@ -86,6 +90,7 @@ const RouterComponent = () => {
8690

8791
useEffect(
8892
() => () => {
93+
setAIAgentContext(null)
8994
abortControllerRef.current.abort()
9095
},
9196
[],
@@ -143,6 +148,20 @@ const RouterComponent = () => {
143148
...response.result,
144149
helmReleaseStatus: response.result?.releaseStatus || appDetailsRef.current?.helmReleaseStatus,
145150
}
151+
152+
// There is no env change so can handle AIAgentContext here directly instead of useEffect
153+
setAIAgentContext({
154+
source: AIAgentContextSourceType.APP_DETAILS,
155+
data: {
156+
appId: +params.appId,
157+
envId: +params.envId,
158+
clusterId: appDetailsRef.current.clusterId,
159+
appName: appDetailsRef.current.appName,
160+
envName: appDetailsRef.current.environmentName,
161+
appType: 'devtronHelmChart'
162+
}
163+
})
164+
146165
IndexStore.publishAppDetails(appDetailsRef.current, AppType.DEVTRON_HELM_CHART)
147166
setErrorResponseCode(undefined)
148167
}

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,9 @@ __metadata:
17291729
languageName: node
17301730
linkType: hard
17311731

1732-
"@devtron-labs/devtron-fe-common-lib@npm:1.22.0-beta-2":
1733-
version: 1.22.0-beta-2
1734-
resolution: "@devtron-labs/devtron-fe-common-lib@npm:1.22.0-beta-2"
1732+
"@devtron-labs/devtron-fe-common-lib@npm:1.22.0-beta-4":
1733+
version: 1.22.0-beta-4
1734+
resolution: "@devtron-labs/devtron-fe-common-lib@npm:1.22.0-beta-4"
17351735
dependencies:
17361736
"@codemirror/autocomplete": "npm:6.18.6"
17371737
"@codemirror/lang-json": "npm:6.0.1"
@@ -1785,7 +1785,7 @@ __metadata:
17851785
react-select: 5.8.0
17861786
rxjs: ^7.8.1
17871787
yaml: ^2.4.1
1788-
checksum: 10c0/01afa9776f529db4280dbfb8aff10d434c46c22447f19297fe75fed00aa805b618f0974f9543388cefb80104e32d1fb72e0972c716a61d2843789edbdf310a73
1788+
checksum: 10c0/df50e3eb2b7a498824bfe812c1165141ad9c5d55cf52e130f9708a0c9f14b586b50f8fab9baa23d375fe45a8ec72fe7538b8ada01f7358cc047a1db4d6c920a3
17891789
languageName: node
17901790
linkType: hard
17911791

@@ -5599,7 +5599,7 @@ __metadata:
55995599
version: 0.0.0-use.local
56005600
resolution: "dashboard@workspace:."
56015601
dependencies:
5602-
"@devtron-labs/devtron-fe-common-lib": "npm:1.22.0-beta-2"
5602+
"@devtron-labs/devtron-fe-common-lib": "npm:1.22.0-beta-4"
56035603
"@esbuild-plugins/node-globals-polyfill": "npm:0.2.3"
56045604
"@playwright/test": "npm:^1.32.1"
56055605
"@rjsf/core": "npm:^5.13.3"

0 commit comments

Comments
 (0)