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 { useGitspaceEvents } from 'cde-gitness/hooks/useGitspaceEvents'
import { useGitspaceActions } from 'cde-gitness/hooks/useGitspaceActions' import { useGitspaceActions } from 'cde-gitness/hooks/useGitspaceActions'
import { useDeleteGitspaces } from 'cde-gitness/hooks/useDeleteGitspaces' import { useDeleteGitspaces } from 'cde-gitness/hooks/useDeleteGitspaces'
import { useGitspacesLogs } from 'cde-gitness/hooks/useGitspaceLogs'
import { useOpenVSCodeBrowserURL } from 'cde-gitness/hooks/useOpenVSCodeBrowserURL' import { useOpenVSCodeBrowserURL } from 'cde-gitness/hooks/useOpenVSCodeBrowserURL'
import { ErrorCard } from 'cde-gitness/components/ErrorCard/ErrorCard' import { ErrorCard } from 'cde-gitness/components/ErrorCard/ErrorCard'
import CopyButton from 'cde-gitness/components/CopyButton/CopyButton' 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 Logger from './Logger/Logger'
import css from './GitspaceDetails.module.scss' import css from './GitspaceDetails.module.scss'
@ -82,6 +85,13 @@ const GitspaceDetails = () => {
const { data: eventData, refetch: refetchEventData } = useGitspaceEvents({ gitspaceId }) 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: actionMutate, loading: mutateLoading } = useGitspaceActions({ gitspaceId })
const { mutate: deleteGitspace, loading: deleteLoading } = useDeleteGitspaces({ 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') && (item.event === 'agent_gitspace_creation_start' || item.event === 'agent_gitspace_deletion_start') &&
defaultTo(item?.timestamp, 0) >= defaultTo(data?.instance?.updated, 0) defaultTo(item?.timestamp, 0) >= defaultTo(data?.instance?.updated, 0)
) )
if (disabledActionButtons && filteredEvent?.length && !isStreamingLogs) { const refetchLogs = disabledActionButtons && filteredEvent?.length && !isStreamingLogs
setIsStreamingLogs(true) if (standalone) {
viewLogs() if (refetchLogs) {
} else if (filteredEvent?.length && !disabledActionButtons && isStreamingLogs) { refetchLogsData()
setIsStreamingLogs(false) setIsStreamingLogs(true)
viewLogs() } 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( usePolling(
async () => { async () => {
@ -173,6 +196,8 @@ const GitspaceDetails = () => {
}) })
} }
const formattedlogsdata = useGetLogStream({ response })
const [accountIdentifier, orgIdentifier, projectIdentifier] = data?.space_path?.split('/') || [] const [accountIdentifier, orgIdentifier, projectIdentifier] = data?.space_path?.split('/') || []
const { refetchToken, setSelectedRowUrl } = useOpenVSCodeBrowserURL() const { refetchToken, setSelectedRowUrl } = useOpenVSCodeBrowserURL()
@ -181,6 +206,16 @@ const GitspaceDetails = () => {
const myRef = useRef<any | null>(null) const myRef = useRef<any | null>(null)
const selectedIde = getIDEOption(data?.ide, getString) 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 () => { const triggerGitspace = async () => {
try { try {
setStartPolling(GitspaceActionType.START) setStartPolling(GitspaceActionType.START)
@ -197,7 +232,9 @@ const GitspaceDetails = () => {
const viewLogs = () => { const viewLogs = () => {
myRef.current?.scrollIntoView() myRef.current?.scrollIntoView()
accordionRef.current?.open('logsCard') accordionRef.current?.open('logsCard')
setExpandedTab('logsCard') if (!standalone) {
setExpandedTab('logsCard')
}
} }
const handleClick = () => { const handleClick = () => {
@ -447,7 +484,7 @@ const GitspaceDetails = () => {
summary={ summary={
<Layout.Vertical spacing="small"> <Layout.Vertical spacing="small">
<Text <Text
rightIcon={isStreamingLogs ? 'steps-spinner' : undefined} rightIcon={isStreamingLogs || logsLoading ? 'steps-spinner' : undefined}
className={css.containerlogsTitle} className={css.containerlogsTitle}
font={{ variation: FontVariation.CARD_TITLE }} font={{ variation: FontVariation.CARD_TITLE }}
margin={{ left: 'large' }}> margin={{ left: 'large' }}>
@ -458,26 +495,30 @@ const GitspaceDetails = () => {
} }
id={logCardId} id={logCardId}
details={ details={
<Container width="100%" className={css.consoleContainer}> standalone ? (
<Logger <ContainerLogs data={formattedlogsdata.data} />
value={data?.name ?? ''} ) : (
state={data?.state ?? ''} <Container width="100%" className={css.consoleContainer}>
logKey={data?.log_key ?? ''} <Logger
isStreaming={isStreamingLogs} value={data?.name ?? ''}
expanded={true} state={data?.state ?? ''}
localRef={containerRef} logKey={data?.log_key ?? ''}
setIsBottom={setIsBottom} isStreaming={isStreamingLogs}
/> expanded={true}
<Button localRef={containerRef}
size={ButtonSize.SMALL} setIsBottom={setIsBottom}
variation={ButtonVariation.PRIMARY} />
text={isBottom ? getString('top') : getString('bottom')} <Button
icon={isBottom ? 'arrow-up' : 'arrow-down'} size={ButtonSize.SMALL}
iconProps={{ size: 10 }} variation={ButtonVariation.PRIMARY}
onClick={handleClick} text={isBottom ? getString('top') : getString('bottom')}
className={css.scrollDownBtn} icon={isBottom ? 'arrow-up' : 'arrow-down'}
/> iconProps={{ size: 10 }}
</Container> onClick={handleClick}
className={css.scrollDownBtn}
/>
</Container>
)
} }
/> />
</Accordion> </Accordion>