Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: version refresh bug #5284

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const DevboxList = ({
height={'20px'}
alt={item.id}
src={`/images/${item.runtimeType}.svg`}
onError={(e) => {
e.currentTarget.src = '/images/custom.svg'
}}
/>
<Box color={'grayModern.900'} fontSize={'md'}>
{item.name}
Expand Down Expand Up @@ -376,6 +379,7 @@ const DevboxList = ({
devbox={delDevbox}
onClose={() => setDelDevbox(null)}
onSuccess={refetchDevboxList}
refetchDevboxList={refetchDevboxList}
/>
)}
{!!onOpenRelease && !!currentDevboxListItem && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const BasicInfo = () => {
height={'20px'}
alt={devboxDetail?.runtimeType}
src={`/images/${devboxDetail?.runtimeType}.svg`}
onError={(e) => {
e.currentTarget.src = '/images/custom.svg'
}}
/>
</Flex>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import IDEButton from '@/components/IDEButton'
import DelModal from '@/components/modals/DelModal'
import DevboxStatusTag from '@/components/DevboxStatusTag'
import { sealosApp } from 'sealos-desktop-sdk/app'
import { useQuery } from '@tanstack/react-query'

const Header = ({
refetchDevboxDetail,
Expand All @@ -29,12 +30,18 @@ const Header = ({
const t = useTranslations()
const { message: toast } = useMessage()

const { devboxDetail } = useDevboxStore()
const { devboxDetail, setDevboxList } = useDevboxStore()
const { screenWidth, setLoading } = useGlobalStore()

const [delDevbox, setDelDevbox] = useState<DevboxDetailType | null>(null)
const isBigButton = useMemo(() => screenWidth > 1000, [screenWidth])

const { refetch: refetchDevboxList } = useQuery(['devboxListQuery'], setDevboxList, {
onSettled(res) {
if (!res) return
}
})

const handlePauseDevbox = useCallback(
async (devbox: DevboxDetailType) => {
try {
Expand Down Expand Up @@ -276,6 +283,7 @@ const Header = ({
setDelDevbox(null)
router.push('/')
}}
refetchDevboxList={refetchDevboxList}
/>
)}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Version = () => {
{
refetchInterval:
devboxVersionList.length > 0 &&
devboxVersionList[0].status.value !== DevboxReleaseStatusEnum.Success
devboxVersionList[0].status.value === DevboxReleaseStatusEnum.Pending
? 3000
: false,
onSettled() {
Expand Down Expand Up @@ -131,6 +131,18 @@ const Version = () => {
title: t('delete_successful'),
status: 'success'
})
let retryCount = 0
const maxRetries = 3
const retryInterval = 3000

const retry = async () => {
if (retryCount < maxRetries) {
await new Promise((resolve) => setTimeout(resolve, retryInterval))
await refetch()
retryCount++
}
}
retry()
} catch (error: any) {
toast({
title: typeof error === 'string' ? error : error.message || t('delete_failed'),
Expand All @@ -140,8 +152,9 @@ const Version = () => {
}
setIsLoading(false)
},
[setIsLoading, toast, t]
[setIsLoading, toast, t, refetch]
)

const columns: {
title: string
dataIndex?: keyof DevboxVersionListItemType
Expand Down
17 changes: 16 additions & 1 deletion frontend/providers/devbox/components/modals/DelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import { DevboxDetailType, DevboxListItemType } from '@/types/devbox'
const DelModal = ({
devbox,
onClose,
refetchDevboxList,
onSuccess
}: {
devbox: DevboxListItemType | DevboxDetailType
onClose: () => void
onSuccess: () => void
refetchDevboxList: () => void
}) => {
const t = useTranslations()
const { message: toast } = useMessage()
Expand All @@ -48,6 +50,19 @@ const DelModal = ({
})
onSuccess()
onClose()

let retryCount = 0
const maxRetries = 3
const retryInterval = 3000

const retry = async () => {
if (retryCount < maxRetries) {
await new Promise((resolve) => setTimeout(resolve, retryInterval))
await refetchDevboxList()
retryCount++
}
}
retry()
} catch (error: any) {
toast({
title: typeof error === 'string' ? error : error.message || t('delete_failed'),
Expand All @@ -56,7 +71,7 @@ const DelModal = ({
console.error(error)
}
setLoading(false)
}, [devbox.name, removeDevboxIDE, toast, t, onSuccess, onClose])
}, [devbox.name, removeDevboxIDE, toast, t, onSuccess, onClose, refetchDevboxList])

return (
<Modal isOpen onClose={onClose} lockFocusAcrossFrames={false} size={'lg'}>
Expand Down
Loading