fix: [code-821]: redirect to space after creation (#408)

This commit is contained in:
Calvin Lee 2023-09-06 22:33:55 +00:00 committed by Harness
parent 0405deba25
commit c9b7d28b50
3 changed files with 17 additions and 1 deletions

View File

@ -54,6 +54,7 @@ export interface NewSpaceModalButtonProps extends Omit<ButtonProps, 'onClick'> {
submitButtonTitle?: string submitButtonTitle?: string
cancelButtonTitle?: string cancelButtonTitle?: string
onRefetch: () => void onRefetch: () => void
handleNavigation?: (value: string) => void
} }
export interface OpenapiCreateSpaceRequestExtended extends OpenapiCreateSpaceRequest { export interface OpenapiCreateSpaceRequestExtended extends OpenapiCreateSpaceRequest {
parent_id?: number parent_id?: number
@ -65,6 +66,7 @@ export const NewSpaceModalButton: React.FC<NewSpaceModalButtonProps> = ({
submitButtonTitle, submitButtonTitle,
cancelButtonTitle, cancelButtonTitle,
onRefetch, onRefetch,
handleNavigation,
...props ...props
}) => { }) => {
const ModalComponent: React.FC = () => { const ModalComponent: React.FC = () => {
@ -90,6 +92,7 @@ export const NewSpaceModalButton: React.FC<NewSpaceModalButtonProps> = ({
createSpace(payload) createSpace(payload)
.then(() => { .then(() => {
hideModal() hideModal()
handleNavigation?.(formData.name)
onRefetch() onRefetch()
}) })
.catch(_error => { .catch(_error => {

View File

@ -43,7 +43,6 @@ export const SpaceSelector: React.FC<SpaceSelectorProps> = ({ onSelect }) => {
const [opened, setOpened] = React.useState(false) const [opened, setOpened] = React.useState(false)
const [searchTerm, setSearchTerm] = useState('') const [searchTerm, setSearchTerm] = useState('')
// const [page, setPage] = usePageIndex(1) // const [page, setPage] = usePageIndex(1)
const { data, error } = useGetSpace({ space_ref: encodeURIComponent(space), lazy: !space }) const { data, error } = useGetSpace({ space_ref: encodeURIComponent(space), lazy: !space })
const { const {
@ -64,6 +63,14 @@ export const SpaceSelector: React.FC<SpaceSelectorProps> = ({ onSelect }) => {
[onSelect] [onSelect]
) )
useEffect(() => {
//space is used in the api call to get data, so it'll always be the same
if (space && data) {
selectSpace(data, false)
refetch()
}
}, [data])
useEffect(() => { useEffect(() => {
if (space && !selectedSpace && data) { if (space && !selectedSpace && data) {
selectSpace(data, false) selectSpace(data, false)

View File

@ -2,6 +2,7 @@ import React from 'react'
import { ButtonVariation, Container, Layout, PageBody, Text } from '@harnessio/uicore' import { ButtonVariation, Container, Layout, PageBody, Text } from '@harnessio/uicore'
import { FontVariation } from '@harnessio/design-system' import { FontVariation } from '@harnessio/design-system'
import { useGet } from 'restful-react' import { useGet } from 'restful-react'
import { useHistory } from 'react-router-dom'
// import type { TypesSpace } from 'services/code' // import type { TypesSpace } from 'services/code'
import { useStrings } from 'framework/strings' import { useStrings } from 'framework/strings'
// import { usePageIndex } from 'hooks/usePageIndex' // import { usePageIndex } from 'hooks/usePageIndex'
@ -13,6 +14,8 @@ import css from './Home.module.scss'
export default function Home() { export default function Home() {
const { getString } = useStrings() const { getString } = useStrings()
const history = useHistory()
const { routes } = useAppContext()
// const [searchTerm, setSearchTerm] = useState('') // const [searchTerm, setSearchTerm] = useState('')
// const [page, setPage] = usePageIndex(1) // const [page, setPage] = usePageIndex(1)
const { currentUser } = useAppContext() const { currentUser } = useAppContext()
@ -32,6 +35,9 @@ export default function Home() {
width={173} width={173}
height={48} height={48}
onRefetch={refetch} onRefetch={refetch}
handleNavigation={spaceName => {
history.push(routes.toCODERepositories({ space: spaceName }))
}}
/> />
) )
return ( return (