feat: [CDE-177]: Fixes for delete and open vscode (#2523)

* feat: [CDE-177]: Fix lint issues
* feat: [CDE-177]: Fixes for delete and open vscode
* feat: [CDE-177]: Fixes for delete and open vscode
pull/3545/head
Deepesh Kumar 2024-08-16 10:03:40 +00:00 committed by Harness
parent 0f8eb568e2
commit 2ad02f1321
7 changed files with 105 additions and 31 deletions

View File

@ -22,11 +22,11 @@ const customGenerator = require('./scripts/swagger-custom-generator.js')
module.exports = {
code: {
output: 'src/services/cde/index.tsx',
file: 'src/services/cde/swagger.yaml',
output: 'src/services/code/index.tsx',
file: 'src/services/code/swagger.yaml',
customImport: `import { getConfig } from "../config";`,
customProps: {
base: `{getConfig("cde/api/v1")}`
base: `{getConfig("code/api/v1")}`
}
}
}

View File

@ -6,3 +6,9 @@
padding: var(--spacing-large) !important;
background-color: var(--grey-50) !important;
}
.repoIcon {
path {
fill: none !important;
}
}

View File

@ -18,3 +18,4 @@
// This is an auto-generated file
export declare const noReposContainer: string
export declare const repoAndBranch: string
export declare const repoIcon: string

View File

@ -4,6 +4,7 @@ import { Button, ButtonVariation, Container, ExpandingSearchInput, Layout, Text
import { Menu, MenuItem } from '@blueprintjs/core'
import { Color } from '@harnessio/design-system'
import { Icon } from '@harnessio/icons'
import { Repository } from 'iconoir-react'
import { useFormikContext } from 'formik'
import type { TypesRepository } from 'services/code'
import { useGetSpaceParam } from 'hooks/useGetSpaceParam'
@ -17,14 +18,26 @@ import { EnumGitspaceCodeRepoType } from 'cde-gitness/constants'
import { GitspaceSelect } from '../GitspaceSelect/GitspaceSelect'
import css from './GitnessRepoImportForm.module.scss'
const RepositoryText = ({ repoList, value }: { repoList: TypesRepository[] | null; value?: string }) => {
const RepositoryText = ({
repoList,
value,
isCDE
}: {
repoList: TypesRepository[] | null
value?: string
isCDE?: boolean
}) => {
const { getString } = useStrings()
const repoMetadata = repoList?.find(repo => repo.git_url === value)
const repoName = repoMetadata?.path
return (
<Layout.Horizontal spacing={'medium'} flex={{ justifyContent: 'flex-start', alignItems: 'center' }}>
<img src={gitnessRepoLogo} height={24} width={24} />
{isCDE ? (
<Repository className={css.repoIcon} color="none" height={24} width={24} />
) : (
<img src={gitnessRepoLogo} height={24} width={24} />
)}
{repoName ? (
<Container margin={{ left: 'medium' }}>
<Layout.Vertical spacing="xsmall">
@ -127,7 +140,7 @@ export const GitnessRepoImportForm = ({ isCDE }: { isCDE?: boolean }) => {
loading={loading}
formikName="code_repo_url"
formInputClassName={css.repoAndBranch}
text={<RepositoryText value={values.code_repo_url} repoList={repositories} />}
text={<RepositoryText value={values.code_repo_url} repoList={repositories} isCDE={isCDE} />}
tooltipProps={{
onClose: () => {
setRepoSearch('')

View File

@ -120,6 +120,8 @@ export const getStatusText = (getString: UseStringsReturn['getString'], status?:
return getString('cde.listing.starting')
case GitspaceStatus.STOPPING:
return getString('cde.listing.stopping')
case GitspaceStatus.UNINITIALIZED:
return GitspaceStatus.UNINITIALIZED.toLowerCase()
default:
return getString('cde.listing.offline')
}
@ -356,12 +358,27 @@ const ActionMenu = ({
const { instance, ide, identifier = '', space_path = '', state } = data
const { url = '' } = instance || {}
const history = useHistory()
const { routes } = useAppContext()
const pathparamsList = space_path?.split('/') || []
const projectIdentifier = pathparamsList[pathparamsList.length - 1] || ''
const { routes, standalone } = useAppContext()
const [accountIdentifier, orgIdentifier, projectIdentifier] = space_path?.split('/') || []
const topBorder = state === GitspaceStatus.RUNNING && !actionLoading ? { top: true } : {}
const disabledActionButtons = [GitspaceStatus.STARTING, GitspaceStatus.STOPPING].includes(state as GitspaceStatus)
const { data: tokenData, refetch } = useGetToken({
accountIdentifier: '',
projectIdentifier: '',
orgIdentifier: '',
gitspace_identifier: '',
lazy: true
})
const [selectedRowUrl, setSelectedRowUrl] = useState<string | undefined>('')
useEffect(() => {
if (tokenData) {
window.open(`${selectedRowUrl}&token=${tokenData?.gitspace_token}`, '_blank')
}
}, [tokenData])
return (
<Container
className={css.listContainer}
@ -376,9 +393,24 @@ const ActionMenu = ({
e.preventDefault()
e.stopPropagation()
if (ide === IDEType.VSCODE) {
window.open(`vscode://harness-inc.oss-gitspaces/${projectIdentifier}/${identifier}?gitness`, '_blank')
const params = standalone ? '?gitness' : ''
const vscodeExtensionCode = standalone ? 'harness-inc.oss-gitspaces' : 'harness-inc.gitspaces'
const vsCodeURL = `vscode://${vscodeExtensionCode}/${projectIdentifier}/${identifier}${params}`
window.open(vsCodeURL, '_blank')
} else {
window.open(url || '', '_blank')
if (standalone) {
window.open(url || '', '_blank')
} else {
setSelectedRowUrl(url || '')
refetch({
pathParams: {
accountIdentifier,
projectIdentifier,
orgIdentifier,
gitspace_identifier: identifier || ''
}
})
}
}
}}
text={
@ -453,7 +485,7 @@ interface RenderActionsProps extends CellProps<TypesGitspaceConfig> {
export const RenderActions = ({ row, refreshList }: RenderActionsProps) => {
const { getString } = useStrings()
const history = useHistory()
const { routes } = useAppContext()
const { routes, standalone } = useAppContext()
const { showError, showSuccess } = useToaster()
const details = row.original
const { identifier, name, space_path } = details
@ -583,7 +615,7 @@ export const RenderActions = ({ row, refreshList }: RenderActionsProps) => {
try {
e.preventDefault()
e.stopPropagation()
await deleteGitspace(identifier || '')
await deleteGitspace(standalone ? {} : identifier || '')
showSuccess(getString('cde.deleteSuccess'))
await refreshList()
} catch (exception) {
@ -729,17 +761,14 @@ export const ListGitspaces = ({ data, refreshList }: { data: TypesGitspaceConfig
<TableV2<TypesGitspaceConfig>
className={standalone ? css.table : css.cdeTable}
onRowClick={row => {
// const pathparamsList = row?.space_path?.split('/') || []
// const projectIdentifier = pathparamsList[pathparamsList.length - 1] || ''
const [accountIdentifier, orgIdentifier, projectIdentifier] = row?.space_path?.split('/') || []
if (row?.state === GitspaceStatus.RUNNING) {
if (row?.ide === IDEType.VSCODE) {
window.open(
`vscode://harness-inc.oss-gitspaces/${projectIdentifier}/${row?.identifier}?gitness`,
'_blank'
)
const params = standalone ? '?gitness' : ''
const vscodeExtensionCode = standalone ? 'harness-inc.oss-gitspaces' : 'harness-inc.gitspaces'
const vsCodeURL = `vscode://${vscodeExtensionCode}/${projectIdentifier}/${row?.identifier}${params}`
window.open(vsCodeURL, '_blank')
} else {
if (standalone) {
window.open(row?.instance?.url || '', '_blank')

View File

@ -1,14 +1,14 @@
import { useMutate } from 'restful-react'
import { useGetCDEAPIParams } from 'cde-gitness/hooks/useGetCDEAPIParams'
import { useAppContext } from 'AppContext'
import { DeleteGitspacePathParams, useDeleteGitspace, UsererrorError } from 'services/cde'
import { useDeleteGitspace } from 'services/cde'
export const useDeleteGitspaces = ({ gitspaceId }: { gitspaceId: string }) => {
const { standalone } = useAppContext()
const { accountIdentifier = '', orgIdentifier = '', projectIdentifier = '', space } = useGetCDEAPIParams()
const gitness = useMutate<void, UsererrorError, void, string, DeleteGitspacePathParams>({
const gitness = useMutate<any>({
verb: 'DELETE',
path: `/api/v1/gitspaces/${space}/${gitspaceId}/+`
})

View File

@ -39,6 +39,7 @@ 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 { useGetToken } from 'services/cde'
import ContainerLogs from '../../components/ContainerLogs/ContainerLogs'
import { useGetLogStream } from '../../hooks/useGetLogStream'
import css from './GitspaceDetails.module.scss'
@ -46,7 +47,7 @@ import css from './GitspaceDetails.module.scss'
const GitspaceDetails = () => {
const space = useGetSpaceParam()
const { getString } = useStrings()
const { routes } = useAppContext()
const { routes, standalone } = useAppContext()
const { showError, showSuccess } = useToaster()
const history = useHistory()
const [startTriggred, setStartTriggred] = useState<boolean>(false)
@ -148,7 +149,7 @@ const GitspaceDetails = () => {
try {
e.preventDefault()
e.stopPropagation()
await deleteGitspace(gitspaceId)
await deleteGitspace(standalone ? {} : gitspaceId || '')
showSuccess(getString('cde.deleteSuccess'))
history.push(routes.toCDEGitspaces({ space }))
} catch (exception) {
@ -158,6 +159,24 @@ const GitspaceDetails = () => {
})
}
const [accountIdentifier, orgIdentifier, projectIdentifier] = data?.space_path?.split('/') || []
const { data: tokenData, refetch: refetchToken } = useGetToken({
accountIdentifier: '',
projectIdentifier: '',
orgIdentifier: '',
gitspace_identifier: '',
lazy: true
})
const [selectedRowUrl, setSelectedRowUrl] = useState<string | undefined>('')
useEffect(() => {
if (tokenData) {
window.open(`${selectedRowUrl}&token=${tokenData?.gitspace_token}`, '_blank')
}
}, [tokenData])
return (
<>
<Page.Header
@ -294,14 +313,20 @@ const GitspaceDetails = () => {
e.preventDefault()
e.stopPropagation()
if (data?.ide === StandaloneIDEType.VSCODE) {
const pathparamsList = data?.space_path?.split('/') || []
const projectIdentifier = pathparamsList[pathparamsList.length - 1] || ''
window.open(
`vscode://harness-inc.oss-gitspaces/${projectIdentifier}/${data?.identifier}?gitness`,
'_blank'
)
const params = standalone ? '?gitness' : ''
const vscodeExtensionCode = standalone ? 'harness-inc.oss-gitspaces' : 'harness-inc.gitspaces'
const vsCodeURL = `vscode://${vscodeExtensionCode}/${projectIdentifier}/${data?.identifier}${params}`
window.open(vsCodeURL, '_blank')
} else {
window.open(data?.instance?.url || '', '_blank')
setSelectedRowUrl(data?.instance?.url || '')
refetchToken({
pathParams: {
accountIdentifier,
projectIdentifier,
orgIdentifier,
gitspace_identifier: data?.identifier || ''
}
})
}
}}>
{data?.ide === StandaloneIDEType.VSCODE && getString('cde.details.openEditor')}