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.

feat: optimize the page jump logic to prevent unnecessary jumps. (#26481)

Ponder31e6ef77a61f
diff --git a/web/app/components/base/pagination/index.tsx b/web/app/components/base/pagination/index.tsx
index 8126f663dd8..e0c02df2530 100644
--- a/web/app/components/base/pagination/index.tsx
+++ b/web/app/components/base/pagination/index.tsx
@@ -57,7 +57,34 @@ const CustomizedPagination: FC<Props> = ({
if (isNaN(Number.parseInt(value)))
return setInputValue('')
setInputValue(Number.parseInt(value))
- handlePaging(value)
+ }
+
+ const handleInputConfirm = () => {
+ if (inputValue !== '' && String(inputValue) !== String(current + 1)) {
+ handlePaging(String(inputValue))
+ return
+ }
+
+ if (inputValue === '')
+ setInputValue(current + 1)
+
+ setShowInput(false)
+ }
+
+ const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === 'Enter') {
+ e.preventDefault()
+ handleInputConfirm()
+ }
+ else if (e.key === 'Escape') {
+ e.preventDefault()
+ setInputValue(current + 1)
+ setShowInput(false)
+ }
+ }
+
+ const handleInputBlur = () => {
+ handleInputConfirm()
}
return (
@@ -105,7 +132,8 @@ const CustomizedPagination: FC<Props> = ({
autoFocus
value={inputValue}
onChange={handleInputChange}
- onBlur={() => setShowInput(false)}
+ onKeyDown={handleInputKeyDown}
+ onBlur={handleInputBlur}
/>
)}
<Pagination.NextButton