Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(app): preserve sidebar header layout while loading (#43271)

yyhd7600ad9a72c
diff --git a/web/app/components/app-sidebar/app-detail-section.tsx b/web/app/components/app-sidebar/app-detail-section.tsx
index ddd05bec3a0..32dfd53fbdf 100644
--- a/web/app/components/app-sidebar/app-detail-section.tsx
+++ b/web/app/components/app-sidebar/app-detail-section.tsx
@@ -8,8 +8,6 @@ import { useAtomValue } from 'jotai'
import { Fragment, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { getAppIdFromPathname } from '@/app/components/app/app-detail-route'
-import AppIcon from '@/app/components/base/app-icon'
-import { SkeletonContainer, SkeletonRectangle } from '@/app/components/base/skeleton'
import { workspacePermissionKeysAtom } from '@/context/permission-state'
import { userProfileQueryOptions } from '@/features/account-profile/client'
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
@@ -18,6 +16,8 @@ import { consoleQuery } from '@/service/console'
import { AppModeEnum } from '@/types/app'
import { getAppACLCapabilities } from '@/utils/permission'
import { AppInfoView } from './app-info'
+import AppInfoHeader from './app-info/app-info-header'
+import { getAppModeLabel } from './app-info/app-mode-labels'
import NavLink from './nav-link'
type AppDetailNavItem = {
@@ -52,7 +52,7 @@ const AppDetailSection = ({ expand = true }: AppDetailSectionProps) => {
}
function AppDetailContent({ appId, expand }: { appId: string; expand: boolean }) {
- const { t } = useTranslation(['common', 'navigation'])
+ const { t } = useTranslation(['app', 'common', 'navigation'])
const pathname = usePathname()
const [detailQuery, featuresQuery, profileQuery] = useQueries({
queries: [
@@ -157,37 +157,10 @@ function AppDetailContent({ appId, expand }: { appId: string; expand: boolean })
]
}, [appDetail, t, currentUserId, workspacePermissionKeys, isRbacEnabled, systemFeatures])
- if (!appDetail || !systemFeatures || !currentUserId) {
- const failedQuery = [detailQuery, featuresQuery, profileQuery].find(
- (query) => query.isError && !query.data,
- )
- return (
- <div className={cn('px-3 py-2', !expand && 'px-2')}>
- <div className="flex h-13 items-center gap-2">
- <AppIcon size="large" rounded decorative />
- {expand && <SkeletonRectangle className="h-4 w-24" />}
- </div>
- {failedQuery ? (
- <div role="alert" className="mt-3 flex flex-col gap-2">
- {expand && (
- <p className="system-xs-regular text-text-tertiary">
- {t(($) => $['errorBoundary.message'], { ns: 'common' })}
- </p>
- )}
- <Button variant="secondary" onClick={() => void failedQuery.refetch()}>
- {t(($) => $['errorBoundary.tryAgain'], { ns: 'common' })}
- </Button>
- </div>
- ) : (
- <SkeletonContainer className="mt-3 gap-3" aria-busy="true">
- {[0, 1, 2, 3].map((row) => (
- <SkeletonRectangle key={row} className="h-8 w-full" />
- ))}
- </SkeletonContainer>
- )}
- </div>
- )
- }
+ const failedQuery = [detailQuery, featuresQuery, profileQuery].find(
+ (query) => query.isError && !query.data,
+ )
+ const appTitle = appDetail?.name ?? t(($) => $['menus.appDetail'], { ns: 'navigation' })
const hasLogsNavigation = navigation.some(isLogsNavItem)
const hasAnnotationsNavigation = navigation.some(isAnnotationsNavItem)
@@ -205,10 +178,35 @@ function AppDetailContent({ appId, expand }: { appId: string; expand: boolean })
</div>
)}
<div className={cn('px-1 py-2', expand && '-mx-2')}>
- <AppInfoView appDetail={appDetail} expand={expand} />
+ {appDetail && systemFeatures && currentUserId ? (
+ <AppInfoView appDetail={appDetail} expand={expand} />
+ ) : (
+ <AppInfoHeader
+ expand={expand}
+ appName={appTitle}
+ modeLabel={appDetail ? getAppModeLabel(appDetail.mode, t) : undefined}
+ iconType={appDetail?.icon_type}
+ icon={appDetail?.icon ?? undefined}
+ background={appDetail?.icon_background}
+ imageUrl={appDetail?.icon_url}
+ operationGroups={[]}
+ />
+ )}
</div>
+ {failedQuery && (
+ <div role="alert" className="flex flex-col gap-2 px-1 py-2">
+ {expand && (
+ <p className="system-xs-regular text-text-tertiary">
+ {t(($) => $['errorBoundary.message'], { ns: 'common' })}
+ </p>
+ )}
+ <Button variant="secondary" onClick={() => void failedQuery.refetch()}>
+ {t(($) => $['errorBoundary.tryAgain'], { ns: 'common' })}
+ </Button>
+ </div>
+ )}
<nav
- aria-label={appDetail.name}
+ aria-label={appTitle}
className={cn('flex flex-col gap-y-0.5 py-1', expand ? 'px-1' : 'px-3')}
>
{navigation.map((item) => {
diff --git a/web/app/components/app-sidebar/app-info/__tests__/app-info-trigger.spec.tsx b/web/app/components/app-sidebar/app-info/__tests__/app-info-trigger.spec.tsx
index 3c6c2a5c7ce..08f3da73558 100644
--- a/web/app/components/app-sidebar/app-info/__tests__/app-info-trigger.spec.tsx
+++ b/web/app/components/app-sidebar/app-info/__tests__/app-info-trigger.spec.tsx
@@ -168,7 +168,7 @@ describe('AppInfoTrigger', () => {
expect(readyProps.exportCheck).toHaveBeenCalledTimes(1)
})
- it('hides the operations trigger when no operation is permitted', () => {
+ it('keeps the operations trigger disabled when no operation is permitted', () => {
mockWorkspacePermissionKeys.value = []
render(
<AppInfoTrigger
@@ -181,6 +181,6 @@ describe('AppInfoTrigger', () => {
/>,
)
- expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ expect(getOperationsTrigger()).toBeDisabled()
})
})
diff --git a/web/app/components/app-sidebar/app-info/app-info-header.tsx b/web/app/components/app-sidebar/app-info/app-info-header.tsx
new file mode 100644
index 00000000000..1dd742b6873
--- /dev/null
+++ b/web/app/components/app-sidebar/app-info/app-info-header.tsx
@@ -0,0 +1,63 @@
+import type { ComponentProps } from 'react'
+import type { Operation } from './app-operations'
+import { cn } from '@langgenius/dify-ui/cn'
+import AppIcon from '../../base/app-icon'
+import AppOperations from './app-operations'
+
+type AppInfoHeaderProps = Pick<
+ ComponentProps<typeof AppIcon>,
+ 'iconType' | 'icon' | 'background' | 'imageUrl'
+> & {
+ expand: boolean
+ appName: string
+ modeLabel?: string
+ operationGroups: Operation[][]
+}
+
+export default function AppInfoHeader({
+ expand,
+ appName,
+ modeLabel,
+ iconType,
+ icon,
+ background,
+ imageUrl,
+ operationGroups,
+}: AppInfoHeaderProps) {
+ return (
+ <div
+ className={cn(
+ 'rounded-xl',
+ expand ? 'flex items-start gap-2 p-2' : 'flex items-center justify-center px-1 py-1.5',
+ )}
+ >
+ <div className="flex shrink-0 items-center">
+ <AppIcon
+ size="medium"
+ rounded
+ decorative
+ iconType={iconType}
+ icon={icon}
+ background={background}
+ imageUrl={imageUrl}
+ />
+ </div>
+ {expand && (
+ <div className="flex min-w-0 flex-1 flex-col items-start justify-center gap-0.5 self-stretch">
+ <div className="flex w-full min-w-0 items-center gap-2 pr-1">
+ <div
+ className="min-w-0 flex-1 truncate system-md-semibold text-text-secondary"
+ title={appName}
+ >
+ {appName}
+ </div>
+ <AppOperations appName={appName} operationGroups={operationGroups} />
+ </div>
+ <div className="min-h-3 system-2xs-medium-uppercase whitespace-nowrap text-text-tertiary">
+ {modeLabel}
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/web/app/components/app-sidebar/app-info/app-info-trigger.tsx b/web/app/components/app-sidebar/app-info/app-info-trigger.tsx
index 4d80f4fb5f3..6d97d49e0ec 100644
--- a/web/app/components/app-sidebar/app-info/app-info-trigger.tsx
+++ b/web/app/components/app-sidebar/app-info/app-info-trigger.tsx
@@ -1,7 +1,6 @@
import type { AppDetailWithSite } from '@dify/contracts/api/console/apps/types.gen'
import type { Operation } from './app-operations'
import type { AppInfoModalType } from './use-app-info-actions'
-import { cn } from '@langgenius/dify-ui/cn'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useAtomValue } from 'jotai'
import * as React from 'react'
@@ -10,9 +9,8 @@ import { workspacePermissionKeysAtom } from '@/context/permission-state'
import { userProfileQueryOptions } from '@/features/account-profile/client'
import { AppModeEnum } from '@/types/app'
import { getAppACLCapabilities, hasPermission } from '@/utils/permission'
-import AppIcon from '../../base/app-icon'
+import AppInfoHeader from './app-info-header'
import { getAppModeLabel } from './app-mode-labels'
-import AppOperations from './app-operations'
type AppInfoTriggerProps = {
appDetail: AppDetailWithSite
@@ -114,44 +112,16 @@ const AppInfoTrigger = ({
: []
return (
- <div
- className={cn(
- 'rounded-xl',
- expand ? 'flex items-start gap-2 p-2' : 'flex items-center justify-center px-1 py-1.5',
- )}
- >
- <div className="flex shrink-0 items-center">
- <div>
- <AppIcon
- size="medium"
- iconType={appDetail.icon_type}
- icon={appDetail.icon ?? undefined}
- background={appDetail.icon_background}
- imageUrl={appDetail.icon_url}
- />
- </div>
- </div>
- {expand && (
- <div className="flex min-w-0 flex-1 flex-col items-start justify-center gap-0.5 self-stretch">
- <div className="flex w-full min-w-0 items-center gap-2 pr-1">
- <div className="min-w-0 flex-1 truncate system-md-semibold text-text-secondary">
- {appDetail.name}
- </div>
- <AppOperations
- appName={appDetail.name}
- operationGroups={[
- mainOperations,
- destructiveOperations,
- workflowConversionOperations,
- ]}
- />
- </div>
- <div className="system-2xs-medium-uppercase whitespace-nowrap text-text-tertiary">
- {modeLabel}
- </div>
- </div>
- )}
- </div>
+ <AppInfoHeader
+ expand={expand}
+ appName={appDetail.name}
+ modeLabel={modeLabel}
+ iconType={appDetail.icon_type}
+ icon={appDetail.icon ?? undefined}
+ background={appDetail.icon_background}
+ imageUrl={appDetail.icon_url}
+ operationGroups={[mainOperations, destructiveOperations, workflowConversionOperations]}
+ />
)
}
diff --git a/web/app/components/app-sidebar/app-info/app-operations.tsx b/web/app/components/app-sidebar/app-info/app-operations.tsx
index 26fe65a8d45..b866e81b945 100644
--- a/web/app/components/app-sidebar/app-info/app-operations.tsx
+++ b/web/app/components/app-sidebar/app-info/app-operations.tsx
@@ -30,11 +30,10 @@ const AppOperations = ({ appName, operationGroups }: AppOperationsProps) => {
const { t } = useTranslation(['common'])
const visibleGroups = operationGroups.filter((group) => group.length > 0)
- if (!visibleGroups.length) return null
-
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger
+ disabled={!visibleGroups.length}
render={
<IconButton
aria-label={t(($) => $['operation.moreActionsFor'], {
diff --git a/web/app/components/app/__tests__/app-detail-loading.spec.tsx b/web/app/components/app/__tests__/app-detail-loading.spec.tsx
index 955c3751172..5a968a7315d 100644
--- a/web/app/components/app/__tests__/app-detail-loading.spec.tsx
+++ b/web/app/components/app/__tests__/app-detail-loading.spec.tsx
@@ -58,9 +58,11 @@ describe('App sidebar route loading', () => {
it('keeps the shell visible and consumes the in-flight prefetch without an App Store producer', async () => {
const pending = deferredResponse()
request.mockReturnValue(pending.promise)
- const view = renderWithConsoleQuery(<Route />)
+ renderWithConsoleQuery(<Route />)
expect(screen.getByRole('link', { name: 'Back to Apps' })).toBeVisible()
- expect(view.container.querySelector('[aria-busy="true"]')).toBeInTheDocument()
+ expect(screen.getByText('navigation.menus.appDetail')).toBeVisible()
+ expect(screen.getByRole('button', { name: /common\.operation\.moreActionsFor/ })).toBeDisabled()
+ expect(screen.getByRole('navigation', { name: 'navigation.menus.appDetail' })).toBeVisible()
expect(screen.queryByRole('link', { name: 'common.appMenus.overview' })).not.toBeInTheDocument()
await waitFor(() => expect(request).toHaveBeenCalledTimes(1))
await act(async () => pending.resolve(Response.json(app('app-1', 'First app'))))
diff --git a/web/app/components/app/app-publisher/__tests__/index.spec.tsx b/web/app/components/app/app-publisher/__tests__/index.spec.tsx
index e3eb1dc87ae..dcb0abf3421 100644
--- a/web/app/components/app/app-publisher/__tests__/index.spec.tsx
+++ b/web/app/components/app/app-publisher/__tests__/index.spec.tsx
@@ -1058,7 +1058,7 @@ describe('AppPublisher', () => {
it('waits for app details before exposing publishing actions', () => {
mockAppDetail = null
render(<AppPublisher appId="app-1" publishedAt={Date.now()} />)
- expect(screen.queryByText(/(?:^|\.)common\.publish(?=$|:)/)).not.toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /(?:^|\.)common\.publish(?=$|:)/ })).toBeDisabled()
expect(sectionProps.summary).toBeNull()
})
diff --git a/web/app/components/app/app-publisher/index.tsx b/web/app/components/app/app-publisher/index.tsx
index 23d87ec2d09..85db4642f88 100644
--- a/web/app/components/app/app-publisher/index.tsx
+++ b/web/app/components/app/app-publisher/index.tsx
@@ -1,8 +1,9 @@
import type { AppPublisherProps } from './types'
+import { Button } from '@langgenius/dify-ui/button'
import { useSuspenseQueries } from '@tanstack/react-query'
import { useAtom, useAtomValue } from 'jotai'
import { Suspense } from 'react'
-import { SkeletonRectangle } from '@/app/components/base/skeleton'
+import { useTranslation } from 'react-i18next'
import { workspacePermissionKeysAtom } from '@/context/permission-state'
import { userProfileQueryOptions } from '@/features/account-profile/client'
import { consoleQuery } from '@/service/console'
@@ -12,8 +13,16 @@ import { PublisherContent } from './publisher-content'
import { appPublisherOpenAtom, AppPublisherStateBoundary } from './state'
export function AppPublisher(props: AppPublisherProps) {
+ const { t } = useTranslation(['workflow'])
return (
- <Suspense fallback={<SkeletonRectangle className="h-8 w-20" />}>
+ <Suspense
+ fallback={
+ <Button variant="primary" className="py-2 pr-2 pl-3" disabled>
+ {t(($) => $['common.publish'], { ns: 'workflow' })}
+ <span className="i-ri-arrow-down-s-line size-4 text-components-button-primary-text" />
+ </Button>
+ }
+ >
<AppPublisherContent {...props} />
</Suspense>
)