feat: downgrade modal

pull/19758/head
Joel 8 months ago committed by Junyan Qin
parent 86579cd35e
commit 727f1e9c1d
No known key found for this signature in database
GPG Key ID: 22FE3AFADC710CEB

@ -42,6 +42,7 @@ import { useAllToolProviders } from '@/service/use-tools'
import DeprecationNotice from '../base/deprecation-notice' import DeprecationNotice from '../base/deprecation-notice'
import { AutoUpdateLine } from '../../base/icons/src/vender/system' import { AutoUpdateLine } from '../../base/icons/src/vender/system'
import { timeOfDayToDayjs } from '../reference-setting-modal/auto-update-setting/utils' import { timeOfDayToDayjs } from '../reference-setting-modal/auto-update-setting/utils'
import DowngradeWarningModal from '../update-plugin/downgrade-warning-modal'
const i18nPrefix = 'plugin.action' const i18nPrefix = 'plugin.action'
@ -93,7 +94,6 @@ const DetailHeader = ({
const [targetVersion, setTargetVersion] = useState({ const [targetVersion, setTargetVersion] = useState({
version: latest_version, version: latest_version,
unique_identifier: latest_unique_identifier, unique_identifier: latest_unique_identifier,
isDowngrade: false,
}) })
const hasNewVersion = useMemo(() => { const hasNewVersion = useMemo(() => {
if (isFromMarketplace) if (isFromMarketplace)
@ -121,9 +121,9 @@ const DetailHeader = ({
setFalse: hideDowngradeWarningModal, setFalse: hideDowngradeWarningModal,
}] = useBoolean(false) }] = useBoolean(false)
const handleUpdate = async () => { const handleUpdate = async (isDowngrade?: boolean) => {
if (isFromMarketplace) { if (isFromMarketplace) {
if(isAutoUpgradeEnabled && targetVersion.isDowngrade) { if(isAutoUpgradeEnabled && isDowngrade) {
showDowngradeWarningModal() showDowngradeWarningModal()
return return
} }
@ -214,7 +214,7 @@ const DetailHeader = ({
currentVersion={version} currentVersion={version}
onSelect={(state) => { onSelect={(state) => {
setTargetVersion(state) setTargetVersion(state)
handleUpdate() handleUpdate(state.isDowngrade)
}} }}
trigger={ trigger={
<Badge <Badge
@ -249,7 +249,6 @@ const DetailHeader = ({
setTargetVersion({ setTargetVersion({
version: latest_version, version: latest_version,
unique_identifier: latest_unique_identifier, unique_identifier: latest_unique_identifier,
isDowngrade: false,
}) })
} }
handleUpdate() handleUpdate()
@ -363,7 +362,12 @@ const DetailHeader = ({
/> />
) )
} }
{ isShowDowngradeWarningModal && (<div>aaa</div>)} { isShowDowngradeWarningModal && (
<DowngradeWarningModal
onCancel={hideDowngradeWarningModal}
onSave={handleUpdatedFromMarketplace}
/>
)}
</div> </div>
) )
} }

@ -0,0 +1,37 @@
import { useTranslation } from 'react-i18next'
import Modal from '@/app/components/base/modal'
import Button from '@/app/components/base/button'
type Props = {
onCancel: () => void
onSave: () => void
confirmDisabled?: boolean
}
const DowngradeWarningModal = ({
onCancel,
onSave,
confirmDisabled = false,
}: Props) => {
const { t } = useTranslation()
return (
<Modal
isShow
onClose={() => onCancel()}
className='w-[480px]'
>
<div className='flex flex-col items-start gap-2 self-stretch pb-4'>
<div className='title-2xl-semi-bold text-text-primary'>Plugin Downgrade</div>
<div className='system-md-regular flex grow flex-col text-text-secondary'>
Auto-update is currently enabled for this plugin. Downgrading the version may cause your changes to be overwritten during the next automatic update.
</div>
</div>
<div className='flex items-start justify-end gap-2 self-stretch pt-6'>
<Button variant='secondary' onClick={() => onCancel()}>{t('app.newApp.Cancel')}</Button>
<Button variant='primary' destructive onClick={onSave} disabled={confirmDisabled}>{t('app.newApp.Confirm')}</Button>
</div>
</Modal>
)
}
export default DowngradeWarningModal
Loading…
Cancel
Save