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(home): search templates by name and description (#42828)

yyh236b90a90cd2
diff --git a/web/features/home/home-content/__tests__/home-content.spec.tsx b/web/features/home/home-content/__tests__/home-content.spec.tsx
index 7466a7e4cd3..3b70b42f9d3 100644
--- a/web/features/home/home-content/__tests__/home-content.spec.tsx
+++ b/web/features/home/home-content/__tests__/home-content.spec.tsx
@@ -923,7 +923,9 @@ describe('HomeContent', () => {
renderHomeContent({ searchParams: { category: 'Writing' } })
- const input = screen.getByRole('searchbox', { name: 'common.operation.search' })
+ const input = screen.getByRole('searchbox', {
+ name: 'app.newAppFromTemplate.searchAllTemplate',
+ })
await user.type(input, 'alp')
await user.click(screen.getByRole('button', { name: 'common.operation.clear' }))
@@ -945,13 +947,47 @@ describe('HomeContent', () => {
}
renderHomeContent()
- const input = screen.getByRole('searchbox', { name: 'common.operation.search' })
+ const input = screen.getByRole('searchbox', {
+ name: 'app.newAppFromTemplate.searchAllTemplate',
+ })
await user.type(input, 'gam')
expect(screen.queryByText('Alpha')).not.toBeInTheDocument()
expect(screen.getByText('Gamma')).toBeInTheDocument()
})
+ it('should find templates by description and explain empty results', async () => {
+ vi.useRealTimers()
+ const user = userEvent.setup()
+ mockExploreData = {
+ categories: ['Writing'],
+ allList: [
+ createApp({ description: 'Summarize invoices' }),
+ createApp({
+ app_id: 'app-2',
+ app: { ...createApp().app, name: 'Gamma' },
+ description: 'Translate documents',
+ }),
+ ],
+ }
+ renderHomeContent()
+
+ const input = screen.getByRole('searchbox', {
+ name: 'app.newAppFromTemplate.searchAllTemplate',
+ })
+ await user.type(input, 'INVOICE')
+
+ expect(screen.getByText('Alpha')).toBeInTheDocument()
+ expect(screen.queryByText('Gamma')).not.toBeInTheDocument()
+
+ await user.clear(input)
+ await user.type(input, 'unmatched')
+
+ expect(screen.getByText('app.newApp.noTemplateFound')).toBeInTheDocument()
+ expect(screen.getByText('app.newApp.noTemplateFoundTip')).toBeInTheDocument()
+ expect(screen.getByRole('status')).toHaveTextContent('app.newApp.noTemplateFound')
+ })
+
it('should handle create flow from app card when outside cloud edition and confirm DSL when pending', async () => {
vi.useRealTimers()
mockExploreData = {
@@ -1388,7 +1424,9 @@ describe('HomeContent', () => {
}
renderHomeContent()
- const input = screen.getByRole('searchbox', { name: 'common.operation.search' })
+ const input = screen.getByRole('searchbox', {
+ name: 'app.newAppFromTemplate.searchAllTemplate',
+ })
await user.type(input, 'gam')
expect(screen.queryByText('Alpha')).not.toBeInTheDocument()
diff --git a/web/features/home/home-content/home-content.tsx b/web/features/home/home-content/home-content.tsx
index 4314a1dbe44..94b60ed7db0 100644
--- a/web/features/home/home-content/home-content.tsx
+++ b/web/features/home/home-content/home-content.tsx
@@ -53,7 +53,7 @@ const DSLConfirmModal = dynamic(
const HOME_STEP_BY_STEP_TOUR_TASK_ID = 'home' satisfies StepByStepTourTaskId
export function HomeContent() {
- const { t } = useTranslation(['explore'])
+ const { t } = useTranslation(['explore', 'app'])
const locale = useLocale()
const queryClient = useQueryClient()
const workspacePermissionKeys = useAtomValue(workspacePermissionKeysAtom)
@@ -134,13 +134,13 @@ export function HomeContent() {
}, [templatesData, activeCategory, allCategoriesEn])
const searchFilteredList = useMemo(() => {
- if (!keywords || !filteredList || filteredList.length === 0) return filteredList
-
- const lowerCaseSearchKeywords = keywords.toLowerCase()
+ const searchKeywords = keywords.trim().toLowerCase()
+ if (!searchKeywords) return filteredList
return filteredList.filter(
(item) =>
- item.app && item.app.name && item.app.name.toLowerCase().includes(lowerCaseSearchKeywords),
+ item.app?.name?.toLowerCase().includes(searchKeywords) ||
+ item.description?.toLowerCase().includes(searchKeywords),
)
}, [keywords, filteredList])
@@ -440,6 +440,18 @@ export function HomeContent() {
onTry={handleTryApp}
/>
))}
+ {searchFilteredList.length === 0 && (
+ <div role="status" className="col-span-full rounded-lg bg-workflow-process-bg p-4">
+ <p className="title-md-semi-bold text-text-primary">
+ {t(($) => $['newApp.noTemplateFound'], { ns: 'app' })}
+ </p>
+ {keywords.trim() && (
+ <p className="mt-2 system-sm-regular text-text-tertiary">
+ {t(($) => $['newApp.noTemplateFoundTip'], { ns: 'app' })}
+ </p>
+ )}
+ </div>
+ )}
</section>
</div>
</div>
diff --git a/web/features/home/home-content/templates-header.tsx b/web/features/home/home-content/templates-header.tsx
index b091a7179ac..0100e5096a8 100644
--- a/web/features/home/home-content/templates-header.tsx
+++ b/web/features/home/home-content/templates-header.tsx
@@ -19,7 +19,7 @@ export function HomeTemplatesHeader({
onCategoryChange: (category: string) => void
onKeywordsChange: (keywords: string) => void
}) {
- const { t } = useTranslation(['explore'])
+ const { t } = useTranslation(['explore', 'app'])
return (
<div className="sticky top-0 z-10 bg-background-body">
@@ -52,6 +52,7 @@ export function HomeTemplatesHeader({
<div className="flex shrink-0 items-center gap-3">
<SearchInput
className="w-40 shrink-0"
+ aria-label={t(($) => $['newAppFromTemplate.searchAllTemplate'], { ns: 'app' })}
value={keywords}
onValueChange={onKeywordsChange}
/>