From 848c15a265bf4a32ec51023a735cfeaf56985b74 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 20 May 2026 16:18:26 +0800 Subject: [PATCH] chore: update to only SaaS can view template (#36440) --- .../app-card/__tests__/index.spec.tsx | 22 ++++++++++++++++++ .../app/create-app-dialog/app-card/index.tsx | 20 ++++++++-------- .../explore/app-card/__tests__/index.spec.tsx | 22 ++++++++++++++++++ web/app/components/explore/app-card/index.tsx | 20 ++++++++-------- .../explore/app-list/__tests__/index.spec.tsx | 23 ++++++++++++++++--- 5 files changed, 84 insertions(+), 23 deletions(-) diff --git a/web/app/components/app/create-app-dialog/app-card/__tests__/index.spec.tsx b/web/app/components/app/create-app-dialog/app-card/__tests__/index.spec.tsx index d1b7dedac3..17194796f4 100644 --- a/web/app/components/app/create-app-dialog/app-card/__tests__/index.spec.tsx +++ b/web/app/components/app/create-app-dialog/app-card/__tests__/index.spec.tsx @@ -17,6 +17,20 @@ vi.mock('@/app/components/base/amplitude', () => ({ trackEvent: vi.fn(), })) +const mockConfig = vi.hoisted(() => ({ + isCloudEdition: true, +})) + +vi.mock('@/config', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + get IS_CLOUD_EDITION() { + return mockConfig.isCloudEdition + }, + } +}) + const mockApp: App = { can_trial: true, app: { @@ -70,6 +84,7 @@ describe('AppCard', () => { } beforeEach(() => { + mockConfig.isCloudEdition = true vi.clearAllMocks() }) @@ -261,6 +276,13 @@ describe('AppCard', () => { app: mockApp, }) }) + + it('should hide try button outside cloud edition', () => { + mockConfig.isCloudEdition = false + renderWithProvider() + + expect(screen.queryByRole('button', { name: /explore\.appCard\.try/ })).not.toBeInTheDocument() + }) }) describe('Keyboard Accessibility', () => { diff --git a/web/app/components/app/create-app-dialog/app-card/index.tsx b/web/app/components/app/create-app-dialog/app-card/index.tsx index 1b022eb961..899306c20a 100644 --- a/web/app/components/app/create-app-dialog/app-card/index.tsx +++ b/web/app/components/app/create-app-dialog/app-card/index.tsx @@ -4,14 +4,13 @@ import { PlusIcon } from '@heroicons/react/20/solid' import { Button } from '@langgenius/dify-ui/button' import { cn } from '@langgenius/dify-ui/cn' import { RiInformation2Line } from '@remixicon/react' -import { useSuspenseQuery } from '@tanstack/react-query' import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useContextSelector } from 'use-context-selector' import { trackEvent } from '@/app/components/base/amplitude' import AppIcon from '@/app/components/base/app-icon' +import { IS_CLOUD_EDITION } from '@/config' import AppListContext from '@/context/app-list-context' -import { systemFeaturesQueryOptions } from '@/service/system-features' import { AppTypeIcon, AppTypeLabel } from '../../type-selector' type AppCardProps = { @@ -27,8 +26,7 @@ const AppCard = ({ }: AppCardProps) => { const { t } = useTranslation() const { app: appBasicInfo } = app - const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions()) - const isTrialApp = app.can_trial && systemFeatures.enable_trial_app + const canViewApp = IS_CLOUD_EDITION const setShowTryAppPanel = useContextSelector(AppListContext, ctx => ctx.setShowTryAppPanel) const handleShowTryAppPanel = useCallback(() => { trackEvent('preview_template', { @@ -69,19 +67,21 @@ const AppCard = ({ {app.description} - {(canCreate || isTrialApp) && ( + {(canCreate || canViewApp) && ( - {isExplore && (canCreate || isTrialApp) && ( + {isExplore && (canCreate || canViewApp) && (