mirror of
https://github.com/langgenius/dify.git
synced 2026-05-10 05:56:31 +08:00
tweaks
This commit is contained in:
parent
2d6788fc43
commit
eb60ddc35f
@ -232,7 +232,7 @@ const CreateInstanceForm: FC<{ onClose: () => void }> = ({ onClose }) => {
|
||||
onClose()
|
||||
if (thenDeploy) {
|
||||
openDeployDrawer({
|
||||
appId: result.appInstanceId,
|
||||
appInstanceId: result.appInstanceId,
|
||||
releaseId: result.initialRelease?.id,
|
||||
})
|
||||
return
|
||||
|
||||
@ -15,13 +15,13 @@ import { DeployForm } from './deploy-drawer/form'
|
||||
const DeployDrawer: FC = () => {
|
||||
const { t } = useTranslation('deployments')
|
||||
const drawer = useDeploymentsStore(state => state.deployDrawer)
|
||||
const drawerAppId = drawer.appId
|
||||
const drawerAppInstanceId = drawer.appInstanceId
|
||||
const closeDeployDrawer = useDeploymentsStore(state => state.closeDeployDrawer)
|
||||
const startDeploy = useStartDeployment()
|
||||
const open = drawer.open
|
||||
const { data: releaseHistory } = useQuery({
|
||||
...deploymentReleaseHistoryQueryOptions(drawerAppId),
|
||||
enabled: open && Boolean(drawerAppId),
|
||||
...deploymentReleaseHistoryQueryOptions(drawerAppInstanceId),
|
||||
enabled: open && Boolean(drawerAppInstanceId),
|
||||
})
|
||||
const { data: environmentOptionsReply } = useQuery({
|
||||
...consoleQuery.deployments.deploymentEnvironmentOptions.queryOptions(),
|
||||
@ -35,7 +35,7 @@ const DeployDrawer: FC = () => {
|
||||
const environments = environmentOptions
|
||||
const releases = releaseHistory?.data?.map(row => row.release ?? row).filter(release => release.id) ?? []
|
||||
const defaultReleaseId = releases[0]?.id
|
||||
const formKey = `${drawer.appId ?? 'none'}-${drawer.environmentId ?? 'any'}-${drawer.releaseId ?? 'new'}-${open ? '1' : '0'}`
|
||||
const formKey = `${drawer.appInstanceId ?? 'none'}-${drawer.environmentId ?? 'any'}-${drawer.releaseId ?? 'new'}-${open ? '1' : '0'}`
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
@ -44,7 +44,7 @@ const DeployDrawer: FC = () => {
|
||||
>
|
||||
<DialogContent className="w-[560px] max-w-[90vw]">
|
||||
<DialogCloseButton />
|
||||
{!drawerAppId
|
||||
{!drawerAppInstanceId
|
||||
? <div className="p-4 text-text-tertiary">{t('deployDrawer.notFound')}</div>
|
||||
: (!releaseHistory || !environmentOptionsReply)
|
||||
? (
|
||||
@ -56,7 +56,7 @@ const DeployDrawer: FC = () => {
|
||||
: (
|
||||
<DeployForm
|
||||
key={formKey}
|
||||
appId={drawerAppId}
|
||||
appInstanceId={drawerAppInstanceId}
|
||||
environments={environments}
|
||||
releases={releases}
|
||||
defaultReleaseId={defaultReleaseId}
|
||||
@ -66,7 +66,7 @@ const DeployDrawer: FC = () => {
|
||||
onSubmit={({ environmentId, releaseId, releaseNote }) => {
|
||||
closeDeployDrawer()
|
||||
startDeploy.mutate({
|
||||
appId: drawerAppId,
|
||||
appInstanceId: drawerAppInstanceId,
|
||||
environmentId,
|
||||
releaseId,
|
||||
releaseNote,
|
||||
|
||||
@ -33,7 +33,7 @@ export type DeployFormSubmit = {
|
||||
}
|
||||
|
||||
type DeployFormProps = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
environments: EnvironmentOption[]
|
||||
releases: ConsoleReleaseSummary[]
|
||||
defaultReleaseId?: string
|
||||
@ -79,7 +79,7 @@ const RuntimeBindingGroup: FC<RuntimeBindingGroupProps> = ({ label, bindings, is
|
||||
}
|
||||
|
||||
export const DeployForm: FC<DeployFormProps> = ({
|
||||
appId,
|
||||
appInstanceId,
|
||||
environments,
|
||||
releases,
|
||||
defaultReleaseId,
|
||||
@ -105,9 +105,9 @@ export const DeployForm: FC<DeployFormProps> = ({
|
||||
const canDeploy = Boolean(selectedEnvironmentId && selectedEnvironment && !selectedEnvironment.disabled && (!isPromote || displayedRelease?.id || defaultReleaseId))
|
||||
const previewReleaseId = isPromote ? displayedRelease?.id ?? defaultReleaseId : undefined
|
||||
const releasePreview = useQuery(consoleQuery.deployments.previewRelease.queryOptions({
|
||||
input: appId && (!isPromote || previewReleaseId)
|
||||
input: appInstanceId && (!isPromote || previewReleaseId)
|
||||
? {
|
||||
params: { appInstanceId: appId },
|
||||
params: { appInstanceId },
|
||||
body: {
|
||||
releaseId: previewReleaseId,
|
||||
},
|
||||
|
||||
@ -46,20 +46,20 @@ const RollbackModal: FC = () => {
|
||||
const closeRollbackModal = useDeploymentsStore(state => state.closeRollbackModal)
|
||||
const rollbackDeployment = useStartDeployment()
|
||||
const { data: overview } = useQuery({
|
||||
...deploymentOverviewQueryOptions(modal.appId),
|
||||
enabled: modal.open && Boolean(modal.appId),
|
||||
...deploymentOverviewQueryOptions(modal.appInstanceId),
|
||||
enabled: modal.open && Boolean(modal.appInstanceId),
|
||||
})
|
||||
const { data: environmentDeployments } = useQuery({
|
||||
...deploymentEnvironmentDeploymentsQueryOptions(modal.appId),
|
||||
enabled: modal.open && Boolean(modal.appId),
|
||||
...deploymentEnvironmentDeploymentsQueryOptions(modal.appInstanceId),
|
||||
enabled: modal.open && Boolean(modal.appInstanceId),
|
||||
})
|
||||
const { data: environmentOptionsReply } = useQuery({
|
||||
...consoleQuery.deployments.deploymentEnvironmentOptions.queryOptions(),
|
||||
enabled: modal.open,
|
||||
})
|
||||
const { data: releaseHistory } = useQuery({
|
||||
...deploymentReleaseHistoryQueryOptions(modal.appId),
|
||||
enabled: modal.open && Boolean(modal.appId),
|
||||
...deploymentReleaseHistoryQueryOptions(modal.appInstanceId),
|
||||
enabled: modal.open && Boolean(modal.appInstanceId),
|
||||
})
|
||||
const environmentOptions = useMemo(
|
||||
() => environmentOptionsFromOptionsReply(environmentOptionsReply),
|
||||
@ -77,11 +77,11 @@ const RollbackModal: FC = () => {
|
||||
const app = toAppInfoFromOverview(overview?.instance)
|
||||
|
||||
const confirm = () => {
|
||||
if (!modal.appId || !modal.environmentId || !modal.targetReleaseId)
|
||||
if (!modal.appInstanceId || !modal.environmentId || !modal.targetReleaseId)
|
||||
return
|
||||
closeRollbackModal()
|
||||
rollbackDeployment.mutate({
|
||||
appId: modal.appId,
|
||||
appInstanceId: modal.appInstanceId,
|
||||
environmentId: modal.environmentId,
|
||||
releaseId: modal.targetReleaseId,
|
||||
})
|
||||
|
||||
@ -38,9 +38,9 @@ type DeployTabProps = {
|
||||
instanceId: string
|
||||
}
|
||||
|
||||
const DeployTab: FC<DeployTabProps> = ({ instanceId: appId }) => {
|
||||
const DeployTab: FC<DeployTabProps> = ({ instanceId: appInstanceId }) => {
|
||||
const { t } = useTranslation('deployments')
|
||||
const { data: environmentDeployments } = useQuery(deploymentEnvironmentDeploymentsQueryOptions(appId))
|
||||
const { data: environmentDeployments } = useQuery(deploymentEnvironmentDeploymentsQueryOptions(appInstanceId))
|
||||
const { data: environmentOptionsReply } = useQuery(consoleQuery.deployments.deploymentEnvironmentOptions.queryOptions())
|
||||
const openDeployDrawer = useDeploymentsStore(state => state.openDeployDrawer)
|
||||
const undeployDeployment = useUndeployDeployment()
|
||||
@ -108,7 +108,7 @@ const DeployTab: FC<DeployTabProps> = ({ instanceId: appId }) => {
|
||||
className="gap-2 px-3"
|
||||
onClick={() => {
|
||||
setDeployMenuOpen(false)
|
||||
openDeployDrawer({ appId })
|
||||
openDeployDrawer({ appInstanceId })
|
||||
}}
|
||||
>
|
||||
<span className="system-sm-regular text-text-secondary">{t('deployTab.deployToNewEnv')}</span>
|
||||
@ -125,7 +125,7 @@ const DeployTab: FC<DeployTabProps> = ({ instanceId: appId }) => {
|
||||
if (env.disabled)
|
||||
return
|
||||
setDeployMenuOpen(false)
|
||||
openDeployDrawer({ appId, environmentId: env.id })
|
||||
openDeployDrawer({ appInstanceId, environmentId: env.id })
|
||||
}}
|
||||
>
|
||||
<span className="system-sm-regular text-text-secondary">
|
||||
@ -170,7 +170,7 @@ const DeployTab: FC<DeployTabProps> = ({ instanceId: appId }) => {
|
||||
onClick={e => e.stopPropagation()}
|
||||
onKeyDown={e => e.stopPropagation()}
|
||||
>
|
||||
<Button size="small" variant="secondary" onClick={() => openDeployDrawer({ appId, environmentId: envId })}>
|
||||
<Button size="small" variant="secondary" onClick={() => openDeployDrawer({ appInstanceId, environmentId: envId })}>
|
||||
{isUndeployed
|
||||
? t('deployDrawer.deploy')
|
||||
: status === 'ready'
|
||||
@ -191,7 +191,7 @@ const DeployTab: FC<DeployTabProps> = ({ instanceId: appId }) => {
|
||||
<DropdownMenuItem
|
||||
className="gap-2 px-3"
|
||||
onClick={() => undeployDeployment.mutate({
|
||||
appId,
|
||||
appInstanceId,
|
||||
runtimeInstanceId: deploymentId(row),
|
||||
isDeploying: status === 'deploying',
|
||||
})}
|
||||
|
||||
@ -146,7 +146,7 @@ const OverviewTab: FC<OverviewTabProps> = ({ instanceId }) => {
|
||||
<div className="flex flex-col items-center gap-3 rounded-lg border border-dashed border-components-panel-border bg-components-panel-bg-blur px-4 py-8 text-center">
|
||||
<span className="i-ri-rocket-line h-5 w-5 text-text-quaternary" />
|
||||
<div className="system-sm-regular text-text-tertiary">{t('overview.notDeployedYet')}</div>
|
||||
<Button size="small" variant="primary" onClick={() => openDeployDrawer({ appId: app.id })}>
|
||||
<Button size="small" variant="primary" onClick={() => openDeployDrawer({ appInstanceId: app.id })}>
|
||||
{t('overview.deploy')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@ -99,7 +99,7 @@ const VersionsTab: FC<VersionsTabProps> = ({ instanceId: appId }) => {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 justify-end gap-1">
|
||||
<DeployReleaseMenu releaseId={release.id!} appId={appId} />
|
||||
<DeployReleaseMenu releaseId={release.id!} appInstanceId={appId} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
||||
@ -150,7 +150,7 @@ const VersionsTab: FC<VersionsTabProps> = ({ instanceId: appId }) => {
|
||||
))}
|
||||
</div>
|
||||
<div className="flex justify-end gap-1">
|
||||
<DeployReleaseMenu releaseId={release.id!} appId={appId} />
|
||||
<DeployReleaseMenu releaseId={release.id!} appInstanceId={appId} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -25,17 +25,17 @@ import {
|
||||
} from '../../utils'
|
||||
|
||||
type DeployReleaseMenuProps = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
releaseId: string
|
||||
}
|
||||
|
||||
export const DeployReleaseMenu: FC<DeployReleaseMenuProps> = ({ appId, releaseId }) => {
|
||||
export const DeployReleaseMenu: FC<DeployReleaseMenuProps> = ({ appInstanceId, releaseId }) => {
|
||||
const { t } = useTranslation('deployments')
|
||||
const openDeployDrawer = useDeploymentsStore(state => state.openDeployDrawer)
|
||||
const openRollbackModal = useDeploymentsStore(state => state.openRollbackModal)
|
||||
const [open, setOpen] = useState(false)
|
||||
const { data: environmentDeployments } = useQuery({
|
||||
...deploymentEnvironmentDeploymentsQueryOptions(appId),
|
||||
...deploymentEnvironmentDeploymentsQueryOptions(appInstanceId),
|
||||
enabled: open,
|
||||
})
|
||||
const { data: environmentOptionsReply } = useQuery({
|
||||
@ -81,14 +81,14 @@ export const DeployReleaseMenu: FC<DeployReleaseMenuProps> = ({ appId, releaseId
|
||||
return
|
||||
if (row) {
|
||||
openRollbackModal({
|
||||
appId,
|
||||
appInstanceId,
|
||||
environmentId: envId,
|
||||
deploymentId: deploymentId(row),
|
||||
targetReleaseId: releaseId,
|
||||
})
|
||||
return
|
||||
}
|
||||
openDeployDrawer({ appId, environmentId: envId, releaseId })
|
||||
openDeployDrawer({ appInstanceId, environmentId: envId, releaseId })
|
||||
}}
|
||||
>
|
||||
<span className="system-sm-regular text-text-secondary">
|
||||
|
||||
@ -4,7 +4,6 @@ import type { QueryClient, QueryKey } from '@tanstack/react-query'
|
||||
import type { ConsoleReleaseSummary } from '@/contract/console/deployments'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { consoleClient, consoleQuery } from '@/service/client'
|
||||
import { DEPLOYMENT_PAGE_SIZE } from '../data'
|
||||
import {
|
||||
deploymentAccessConfigQueryKey,
|
||||
deploymentAccessStateQueryKeys,
|
||||
@ -14,6 +13,7 @@ import {
|
||||
deploymentInstanceStateQueryKeys,
|
||||
deploymentReleaseHistoryQueryKey,
|
||||
deploymentsListQueryKey,
|
||||
deploymentsListQueryOptions,
|
||||
} from '../queries'
|
||||
|
||||
export type CreateDeploymentInstanceResult = {
|
||||
@ -22,7 +22,7 @@ export type CreateDeploymentInstanceResult = {
|
||||
}
|
||||
|
||||
type CreateDeploymentParams = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
environmentId: string
|
||||
releaseId?: string
|
||||
releaseNote?: string
|
||||
@ -35,7 +35,7 @@ type CreateInstanceParams = {
|
||||
}
|
||||
|
||||
type UndeployDeploymentParams = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
runtimeInstanceId: string
|
||||
isDeploying?: boolean
|
||||
}
|
||||
@ -106,12 +106,7 @@ export const useCreateDeploymentInstance = () => {
|
||||
if (delay > 0)
|
||||
await wait(delay)
|
||||
|
||||
const listResponse = await consoleClient.deployments.list({
|
||||
query: {
|
||||
pageNumber: 1,
|
||||
resultsPerPage: DEPLOYMENT_PAGE_SIZE,
|
||||
},
|
||||
}).catch(() => undefined)
|
||||
const listResponse = await queryClient.fetchQuery(deploymentsListQueryOptions()).catch(() => undefined)
|
||||
if (listResponse?.data?.some(app => app.id === response.appInstanceId))
|
||||
break
|
||||
}
|
||||
@ -153,7 +148,7 @@ export const useStartDeployment = () => {
|
||||
return useMutation({
|
||||
mutationKey: consoleQuery.deployments.createDeployment.mutationKey(),
|
||||
mutationFn: async ({
|
||||
appId,
|
||||
appInstanceId,
|
||||
environmentId,
|
||||
releaseId,
|
||||
releaseNote,
|
||||
@ -162,7 +157,7 @@ export const useStartDeployment = () => {
|
||||
let releaseWasCreated = false
|
||||
await consoleClient.deployments.previewRelease({
|
||||
params: {
|
||||
appInstanceId: appId,
|
||||
appInstanceId,
|
||||
},
|
||||
body: {
|
||||
releaseId: targetReleaseId,
|
||||
@ -174,7 +169,7 @@ export const useStartDeployment = () => {
|
||||
const trimmedReleaseNote = releaseNote?.trim()
|
||||
const response = await consoleClient.deployments.createRelease({
|
||||
params: {
|
||||
appInstanceId: appId,
|
||||
appInstanceId,
|
||||
},
|
||||
body: {
|
||||
name: trimmedReleaseNote || 'Release',
|
||||
@ -192,7 +187,7 @@ export const useStartDeployment = () => {
|
||||
|
||||
return await consoleClient.deployments.createDeployment({
|
||||
params: {
|
||||
appInstanceId: appId,
|
||||
appInstanceId,
|
||||
},
|
||||
body: {
|
||||
environmentId,
|
||||
@ -203,14 +198,14 @@ export const useStartDeployment = () => {
|
||||
catch (error) {
|
||||
if (releaseWasCreated) {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: deploymentReleaseHistoryQueryKey(appId),
|
||||
queryKey: deploymentReleaseHistoryQueryKey(appInstanceId),
|
||||
})
|
||||
}
|
||||
throw error
|
||||
}
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
return invalidateDeploymentState(queryClient, variables.appId)
|
||||
return invalidateDeploymentState(queryClient, variables.appInstanceId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -220,26 +215,26 @@ export const useUndeployDeployment = () => {
|
||||
|
||||
return useMutation({
|
||||
mutationKey: consoleQuery.deployments.undeployEnvironment.mutationKey(),
|
||||
mutationFn: ({ appId, runtimeInstanceId, isDeploying }: UndeployDeploymentParams) => {
|
||||
mutationFn: ({ appInstanceId, runtimeInstanceId, isDeploying }: UndeployDeploymentParams) => {
|
||||
if (!runtimeInstanceId)
|
||||
throw new Error('runtimeInstanceId is required to undeploy a deployment.')
|
||||
if (isDeploying) {
|
||||
return consoleClient.deployments.cancelDeployment({
|
||||
params: {
|
||||
appInstanceId: appId,
|
||||
appInstanceId,
|
||||
runtimeInstanceId,
|
||||
},
|
||||
})
|
||||
}
|
||||
return consoleClient.deployments.undeployEnvironment({
|
||||
params: {
|
||||
appInstanceId: appId,
|
||||
appInstanceId,
|
||||
runtimeInstanceId,
|
||||
},
|
||||
})
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
return invalidateDeploymentState(queryClient, variables.appId)
|
||||
return invalidateDeploymentState(queryClient, variables.appInstanceId)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ export const InstanceCard: FC<InstanceCardProps> = ({ app, summary }) => {
|
||||
<DropdownMenuContent placement="bottom-end" sideOffset={4} popupClassName="w-[216px]">
|
||||
<DropdownMenuItem
|
||||
className="gap-2 px-3"
|
||||
onClick={e => handleMenuAction(e, () => openDeployDrawer({ appId: app.id }))}
|
||||
onClick={e => handleMenuAction(e, () => openDeployDrawer({ appInstanceId: app.id }))}
|
||||
>
|
||||
<span className="system-sm-regular text-text-secondary">{t('card.menu.deploy')}</span>
|
||||
</DropdownMenuItem>
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
type OpenDeployDrawerParams = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
environmentId?: string
|
||||
releaseId?: string
|
||||
}
|
||||
|
||||
type OpenRollbackParams = {
|
||||
appId: string
|
||||
appInstanceId: string
|
||||
environmentId: string
|
||||
targetReleaseId: string
|
||||
deploymentId?: string
|
||||
@ -16,13 +16,13 @@ type OpenRollbackParams = {
|
||||
type DeploymentsStore = {
|
||||
deployDrawer: {
|
||||
open: boolean
|
||||
appId?: string
|
||||
appInstanceId?: string
|
||||
environmentId?: string
|
||||
releaseId?: string
|
||||
}
|
||||
rollbackModal: {
|
||||
open: boolean
|
||||
appId?: string
|
||||
appInstanceId?: string
|
||||
environmentId?: string
|
||||
deploymentId?: string
|
||||
targetReleaseId?: string
|
||||
@ -45,14 +45,14 @@ export const useDeploymentsStore = create<DeploymentsStore>()(set => ({
|
||||
openDeployDrawer: params => set({
|
||||
deployDrawer: {
|
||||
open: true,
|
||||
appId: params.appId,
|
||||
appInstanceId: params.appInstanceId,
|
||||
environmentId: params.environmentId,
|
||||
releaseId: params.releaseId,
|
||||
},
|
||||
}),
|
||||
closeDeployDrawer: () => set({ deployDrawer: { open: false } }),
|
||||
openRollbackModal: ({ appId, environmentId, deploymentId, targetReleaseId }) => set({
|
||||
rollbackModal: { open: true, appId, environmentId, deploymentId, targetReleaseId },
|
||||
openRollbackModal: ({ appInstanceId, environmentId, deploymentId, targetReleaseId }) => set({
|
||||
rollbackModal: { open: true, appInstanceId, environmentId, deploymentId, targetReleaseId },
|
||||
}),
|
||||
closeRollbackModal: () => set({ rollbackModal: { open: false } }),
|
||||
openCreateInstanceModal: () => set({ createInstanceModal: { open: true } }),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user