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.

refactor & perf of files `datesets/Doc.tsx` and `template.xx.mdx` (#17951)

yusheng chenc9a594100bfd
diff --git a/web/app/(commonLayout)/datasets/Doc.tsx b/web/app/(commonLayout)/datasets/Doc.tsx
index 57d4b8dfef1..e79adbccd55 100644
--- a/web/app/(commonLayout)/datasets/Doc.tsx
+++ b/web/app/(commonLayout)/datasets/Doc.tsx
@@ -1,6 +1,6 @@
'use client'
-import { useEffect, useState } from 'react'
+import { useEffect, useMemo, useState } from 'react'
import { useContext } from 'use-context-selector'
import { useTranslation } from 'react-i18next'
import { RiListUnordered } from '@remixicon/react'
@@ -67,6 +67,17 @@ const Doc = ({ apiBaseUrl }: DocProps) => {
}
}
+ const Template = useMemo(() => {
+ switch (locale) {
+ case LanguagesSupported[1]:
+ return <TemplateZh apiBaseUrl={apiBaseUrl} />
+ case LanguagesSupported[7]:
+ return <TemplateJa apiBaseUrl={apiBaseUrl} />
+ default:
+ return <TemplateEn apiBaseUrl={apiBaseUrl} />
+ }
+ }, [apiBaseUrl, locale])
+
return (
<div className="flex">
<div className={`fixed right-20 top-32 z-10 transition-all ${isTocExpanded ? 'w-64' : 'w-10'}`}>
@@ -107,16 +118,7 @@ const Doc = ({ apiBaseUrl }: DocProps) => {
)}
</div>
<article className='prose-xl prose mx-1 rounded-t-xl bg-white px-4 pt-16 sm:mx-12'>
- {(() => {
- switch (locale) {
- case LanguagesSupported[1]:
- return <TemplateZh apiBaseUrl={apiBaseUrl} />
- case LanguagesSupported[7]:
- return <TemplateJa apiBaseUrl={apiBaseUrl} />
- default:
- return <TemplateEn apiBaseUrl={apiBaseUrl} />
- }
- })()}
+ {Template}
</article>
</div>
)
diff --git a/web/app/(commonLayout)/datasets/template/template.en.mdx b/web/app/(commonLayout)/datasets/template/template.en.mdx
index ca86c7e6d66..4faf26058e0 100644
--- a/web/app/(commonLayout)/datasets/template/template.en.mdx
+++ b/web/app/(commonLayout)/datasets/template/template.en.mdx
@@ -1,3 +1,8 @@
+{/**
+ * @typedef Props
+ * @property {string} apiBaseUrl
+ */}
+
import { CodeGroup } from '@/app/components/develop/code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, Paragraph } from '@/app/components/develop/md.tsx'
diff --git a/web/app/(commonLayout)/datasets/template/template.ja.mdx b/web/app/(commonLayout)/datasets/template/template.ja.mdx
index 45f3adfc4d8..a5e560df8cb 100644
--- a/web/app/(commonLayout)/datasets/template/template.ja.mdx
+++ b/web/app/(commonLayout)/datasets/template/template.ja.mdx
@@ -1,3 +1,8 @@
+{/**
+ * @typedef Props
+ * @property {string} apiBaseUrl
+ */}
+
import { CodeGroup } from '@/app/components/develop/code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, Paragraph } from '@/app/components/develop/md.tsx'
diff --git a/web/app/(commonLayout)/datasets/template/template.zh.mdx b/web/app/(commonLayout)/datasets/template/template.zh.mdx
index 20511b8cf77..8ff82ca1fb0 100644
--- a/web/app/(commonLayout)/datasets/template/template.zh.mdx
+++ b/web/app/(commonLayout)/datasets/template/template.zh.mdx
@@ -1,3 +1,8 @@
+{/**
+ * @typedef Props
+ * @property {string} apiBaseUrl
+ */}
+
import { CodeGroup } from '@/app/components/develop/code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, Paragraph } from '@/app/components/develop/md.tsx'