feat: [CDE-755]: Fix gitness UI redirection is broken, and logs are not loading (#3625)

* fix: fixed gitness breaking changes
<img width="1691" alt="Screenshot 2025-04-29 at 7 49 56 PM"
src="https://github.com/user-attachments/assets/07a858d5-cc7f-4cb8-8c9b-2e723ba6a120"
/>


(cherry picked from commit cd395e8406)

Co-authored-by: Deepesh Kumar <deepesh.kumar@harness.io>
This commit is contained in:
Ansuman Satapathy 2025-04-29 21:03:43 +05:30 committed by GitHub
parent 8d0c8b2f1e
commit fe2b2dfc26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,9 +54,12 @@ import { useGitspaceDetails } from 'cde-gitness/hooks/useGitspaceDetails'
import { useGitspaceEvents } from 'cde-gitness/hooks/useGitspaceEvents'
import { useGitspaceActions } from 'cde-gitness/hooks/useGitspaceActions'
import { useDeleteGitspaces } from 'cde-gitness/hooks/useDeleteGitspaces'
import { useGitspacesLogs } from 'cde-gitness/hooks/useGitspaceLogs'
import { useOpenVSCodeBrowserURL } from 'cde-gitness/hooks/useOpenVSCodeBrowserURL'
import { ErrorCard } from 'cde-gitness/components/ErrorCard/ErrorCard'
import CopyButton from 'cde-gitness/components/CopyButton/CopyButton'
import ContainerLogs from '../../components/ContainerLogs/ContainerLogs'
import { useGetLogStream } from '../../hooks/useGetLogStream'
import Logger from './Logger/Logger'
import css from './GitspaceDetails.module.scss'
@ -82,6 +85,13 @@ const GitspaceDetails = () => {
const { data: eventData, refetch: refetchEventData } = useGitspaceEvents({ gitspaceId })
const {
refetch: refetchLogsData,
response,
error: streamLogsError,
loading: logsLoading
} = useGitspacesLogs({ gitspaceId })
const { mutate: actionMutate, loading: mutateLoading } = useGitspaceActions({ gitspaceId })
const { mutate: deleteGitspace, loading: deleteLoading } = useDeleteGitspaces({ gitspaceId })
@ -105,14 +115,27 @@ const GitspaceDetails = () => {
(item.event === 'agent_gitspace_creation_start' || item.event === 'agent_gitspace_deletion_start') &&
defaultTo(item?.timestamp, 0) >= defaultTo(data?.instance?.updated, 0)
)
if (disabledActionButtons && filteredEvent?.length && !isStreamingLogs) {
const refetchLogs = disabledActionButtons && filteredEvent?.length && !isStreamingLogs
if (standalone) {
if (refetchLogs) {
refetchLogsData()
setIsStreamingLogs(true)
} else if (
(filteredEvent?.length && !disabledActionButtons && isStreamingLogs) ||
(isStreamingLogs && streamLogsError)
) {
setIsStreamingLogs(false)
}
} else {
if (refetchLogs) {
setIsStreamingLogs(true)
viewLogs()
} else if (filteredEvent?.length && !disabledActionButtons && isStreamingLogs) {
setIsStreamingLogs(false)
viewLogs()
}
}, [eventData, data?.instance?.updated, disabledActionButtons])
}
}, [eventData, data?.instance?.updated, disabledActionButtons, streamLogsError])
usePolling(
async () => {
@ -173,6 +196,8 @@ const GitspaceDetails = () => {
})
}
const formattedlogsdata = useGetLogStream({ response })
const [accountIdentifier, orgIdentifier, projectIdentifier] = data?.space_path?.split('/') || []
const { refetchToken, setSelectedRowUrl } = useOpenVSCodeBrowserURL()
@ -181,6 +206,16 @@ const GitspaceDetails = () => {
const myRef = useRef<any | null>(null)
const selectedIde = getIDEOption(data?.ide, getString)
useEffect(() => {
if (standalone) {
if (formattedlogsdata.data) {
accordionRef.current?.open('logsCard')
} else {
accordionRef.current?.close('logsCard')
}
}
}, [standalone, formattedlogsdata.data])
const triggerGitspace = async () => {
try {
setStartPolling(GitspaceActionType.START)
@ -197,8 +232,10 @@ const GitspaceDetails = () => {
const viewLogs = () => {
myRef.current?.scrollIntoView()
accordionRef.current?.open('logsCard')
if (!standalone) {
setExpandedTab('logsCard')
}
}
const handleClick = () => {
const logContainer = containerRef.current as HTMLDivElement
@ -447,7 +484,7 @@ const GitspaceDetails = () => {
summary={
<Layout.Vertical spacing="small">
<Text
rightIcon={isStreamingLogs ? 'steps-spinner' : undefined}
rightIcon={isStreamingLogs || logsLoading ? 'steps-spinner' : undefined}
className={css.containerlogsTitle}
font={{ variation: FontVariation.CARD_TITLE }}
margin={{ left: 'large' }}>
@ -458,6 +495,9 @@ const GitspaceDetails = () => {
}
id={logCardId}
details={
standalone ? (
<ContainerLogs data={formattedlogsdata.data} />
) : (
<Container width="100%" className={css.consoleContainer}>
<Logger
value={data?.name ?? ''}
@ -478,6 +518,7 @@ const GitspaceDetails = () => {
className={css.scrollDownBtn}
/>
</Container>
)
}
/>
</Accordion>