Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
41115a96
authored
Dec 18, 2023
by
Archer
Committed by
GitHub
Dec 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: prompt textarea (#625)
parent
b14a1db2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
65 deletions
+52
-65
projects/app/src/components/common/Textarea/PromptTextarea/index.tsx
+26
-44
projects/app/src/components/core/module/AIChatSettingsModal.tsx
+4
-6
projects/app/src/components/core/module/Flow/components/render/RenderInput/templates/Textarea.tsx
+18
-10
projects/app/src/pages/app/detail/components/AdEdit/Header.tsx
+2
-2
projects/app/src/pages/app/detail/components/SimpleEdit/index.tsx
+2
-3
No files found.
projects/app/src/components/common/Textarea/PromptTextarea/index.tsx
View file @
41115a96
import
React
,
{
use
Memo
,
useState
}
from
'react'
;
import
React
,
{
use
Ref
}
from
'react'
;
import
{
import
{
Box
,
Box
,
...
@@ -16,11 +16,13 @@ import MyModal from '@/components/MyModal';
...
@@ -16,11 +16,13 @@ import MyModal from '@/components/MyModal';
type
Props
=
TextareaProps
&
{
type
Props
=
TextareaProps
&
{
title
?:
string
;
title
?:
string
;
showSetModalModeIcon
?:
boolean
;
// variables: string[];
// variables: string[];
};
};
const
PromptTextarea
=
(
props
:
Props
)
=>
{
const
PromptTextarea
=
(
props
:
Props
)
=>
{
const
ModalTextareaRef
=
useRef
<
HTMLTextAreaElement
>
(
null
);
const
TextareaRef
=
useRef
<
HTMLTextAreaElement
>
(
null
);
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
title
=
t
(
'core.app.edit.Prompt Editor'
),
value
,
...
childProps
}
=
props
;
const
{
title
=
t
(
'core.app.edit.Prompt Editor'
),
value
,
...
childProps
}
=
props
;
...
@@ -28,21 +30,30 @@ const PromptTextarea = (props: Props) => {
...
@@ -28,21 +30,30 @@ const PromptTextarea = (props: Props) => {
return
(
return
(
<>
<>
<
Editor
{
...
childProps
}
value=
{
value
}
showSetModalModeIcon
onSetModalMode
=
{
onOpen
}
/>
<
Editor
textareaRef=
{
TextareaRef
}
{
...
childProps
}
onOpenModal
=
{
onOpen
}
/>
{
isOpen
&&
(
{
isOpen
&&
(
<
MyModal
iconSrc=
"/imgs/modal/edit.svg"
title=
{
title
}
isOpen
onClose=
{
onClose
}
>
<
MyModal
iconSrc=
"/imgs/modal/edit.svg"
title=
{
title
}
isOpen
onClose=
{
onClose
}
>
<
ModalBody
>
<
ModalBody
>
<
Editor
<
Editor
textareaRef=
{
ModalTextareaRef
}
{
...
childProps
}
{
...
childProps
}
value=
{
value
}
minH=
{
'300px'
}
minH=
{
'300px'
}
maxH=
{
'auto'
}
maxH=
{
'auto'
}
minW=
{
[
'100%'
,
'512px'
]
}
minW=
{
[
'100%'
,
'512px'
]
}
showSetModalModeIcon=
{
false
}
/>
/>
</
ModalBody
>
</
ModalBody
>
<
ModalFooter
>
<
ModalFooter
>
<
Button
onClick=
{
onClose
}
>
{
t
(
'common.Confirm'
)
}
</
Button
>
<
Button
onClick=
{
()
=>
{
if
(
ModalTextareaRef
.
current
&&
TextareaRef
.
current
)
{
TextareaRef
.
current
.
value
=
ModalTextareaRef
.
current
.
value
;
}
onClose
();
}
}
>
{
t
(
'common.Confirm'
)
}
</
Button
>
</
ModalFooter
>
</
ModalFooter
>
</
MyModal
>
</
MyModal
>
)
}
)
}
...
@@ -53,23 +64,26 @@ const PromptTextarea = (props: Props) => {
...
@@ -53,23 +64,26 @@ const PromptTextarea = (props: Props) => {
export
default
PromptTextarea
;
export
default
PromptTextarea
;
const
Editor
=
React
.
memo
(
function
Editor
({
const
Editor
=
React
.
memo
(
function
Editor
({
showSetModalModeIcon
=
true
,
onOpenModal
,
onSetModalMode
,
textareaRef
,
...
props
...
props
}:
Props
&
{
onSetModalMode
?:
()
=>
void
})
{
}:
Props
&
{
textareaRef
:
React
.
RefObject
<
HTMLTextAreaElement
>
;
onOpenModal
?:
()
=>
void
;
})
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
return
(
return
(
<
Box
h=
{
'100%'
}
w=
{
'100%'
}
position=
{
'relative'
}
>
<
Box
h=
{
'100%'
}
w=
{
'100%'
}
position=
{
'relative'
}
>
<
Textarea
wordBreak=
{
'break-all'
}
maxW=
{
'100%'
}
{
...
props
}
/>
<
Textarea
ref=
{
textareaRef
}
wordBreak=
{
'break-all'
}
maxW=
{
'100%'
}
{
...
props
}
/>
{
showSetModalModeIcon
&&
(
{
onOpenModal
&&
(
<
Box
<
Box
zIndex=
{
1
}
zIndex=
{
1
}
position=
{
'absolute'
}
position=
{
'absolute'
}
bottom=
{
1
}
bottom=
{
1
}
right=
{
2
}
right=
{
2
}
cursor=
{
'pointer'
}
cursor=
{
'pointer'
}
onClick=
{
on
SetModalMode
}
onClick=
{
on
OpenModal
}
>
>
<
MyTooltip
label=
{
t
(
'common.ui.textarea.Magnifying'
)
}
>
<
MyTooltip
label=
{
t
(
'common.ui.textarea.Magnifying'
)
}
>
<
MyIcon
name=
{
'fullScreenLight'
}
w=
{
'14px'
}
color=
{
'myGray.600'
}
/>
<
MyIcon
name=
{
'fullScreenLight'
}
w=
{
'14px'
}
color=
{
'myGray.600'
}
/>
...
@@ -79,35 +93,3 @@ const Editor = React.memo(function Editor({
...
@@ -79,35 +93,3 @@ const Editor = React.memo(function Editor({
</
Box
>
</
Box
>
);
);
});
});
const
VariableSelectBlock
=
React
.
memo
(
function
VariableSelectBlock
({
variables
}:
{
variables
:
string
[];
})
{
return
<></>;
});
const
Placeholder
=
React
.
memo
(
function
Placeholder
({
placeholder
=
''
}:
{
placeholder
?:
string
;
})
{
return
(
<
Box
zIndex=
{
0
}
userSelect=
{
'none'
}
color=
{
'myGray.400'
}
px=
{
3
}
py=
{
2
}
position=
{
'absolute'
}
top=
{
0
}
right=
{
0
}
bottom=
{
0
}
left=
{
0
}
fontSize=
{
'sm'
}
>
{
placeholder
}
</
Box
>
);
});
projects/app/src/components/core/module/AIChatSettingsModal.tsx
View file @
41115a96
...
@@ -194,9 +194,8 @@ const AIChatSettingsModal = ({
...
@@ -194,9 +194,8 @@ const AIChatSettingsModal = ({
placeholder=
{
t
(
'template.Quote Content Tip'
,
{
placeholder=
{
t
(
'template.Quote Content Tip'
,
{
default
:
Prompt_QuoteTemplateList
[
0
].
value
default
:
Prompt_QuoteTemplateList
[
0
].
value
})
}
})
}
showSetModalModeIcon
defaultValue=
{
getValues
(
ModuleInputKeyEnum
.
aiChatQuoteTemplate
)
}
value=
{
getValues
(
ModuleInputKeyEnum
.
aiChatQuoteTemplate
)
}
onBlur=
{
(
e
)
=>
{
onChange=
{
(
e
)
=>
{
setValue
(
ModuleInputKeyEnum
.
aiChatQuoteTemplate
,
e
.
target
.
value
);
setValue
(
ModuleInputKeyEnum
.
aiChatQuoteTemplate
,
e
.
target
.
value
);
setRefresh
(
!
refresh
);
setRefresh
(
!
refresh
);
}
}
}
}
...
@@ -220,9 +219,8 @@ const AIChatSettingsModal = ({
...
@@ -220,9 +219,8 @@ const AIChatSettingsModal = ({
placeholder=
{
t
(
'template.Quote Prompt Tip'
,
{
placeholder=
{
t
(
'template.Quote Prompt Tip'
,
{
default
:
Prompt_QuotePromptList
[
0
].
value
default
:
Prompt_QuotePromptList
[
0
].
value
})
}
})
}
showSetModalModeIcon
defaultValue=
{
getValues
(
ModuleInputKeyEnum
.
aiChatQuotePrompt
)
}
value=
{
getValues
(
ModuleInputKeyEnum
.
aiChatQuotePrompt
)
}
onBlur=
{
(
e
)
=>
{
onChange=
{
(
e
)
=>
{
setValue
(
ModuleInputKeyEnum
.
aiChatQuotePrompt
,
e
.
target
.
value
);
setValue
(
ModuleInputKeyEnum
.
aiChatQuotePrompt
,
e
.
target
.
value
);
setRefresh
(
!
refresh
);
setRefresh
(
!
refresh
);
}
}
}
}
...
...
projects/app/src/components/core/module/Flow/components/render/RenderInput/templates/Textarea.tsx
View file @
41115a96
import
React
from
'react'
;
import
React
,
{
useCallback
}
from
'react'
;
import
type
{
RenderInputProps
}
from
'../type'
;
import
type
{
RenderInputProps
}
from
'../type'
;
import
{
onChangeNode
}
from
'../../../../FlowProvider'
;
import
{
onChangeNode
}
from
'../../../../FlowProvider'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
...
@@ -6,6 +6,22 @@ import PromptTextarea from '@/components/common/Textarea/PromptTextarea';
...
@@ -6,6 +6,22 @@ import PromptTextarea from '@/components/common/Textarea/PromptTextarea';
const
TextareaRender
=
({
item
,
moduleId
}:
RenderInputProps
)
=>
{
const
TextareaRender
=
({
item
,
moduleId
}:
RenderInputProps
)
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
update
=
useCallback
(
(
value
:
string
)
=>
{
onChangeNode
({
moduleId
,
type
:
'updateInput'
,
key
:
item
.
key
,
value
:
{
...
item
,
value
}
});
},
[
item
,
moduleId
]
);
return
(
return
(
<
PromptTextarea
<
PromptTextarea
title=
{
t
(
item
.
label
)
}
title=
{
t
(
item
.
label
)
}
...
@@ -15,15 +31,7 @@ const TextareaRender = ({ item, moduleId }: RenderInputProps) => {
...
@@ -15,15 +31,7 @@ const TextareaRender = ({ item, moduleId }: RenderInputProps) => {
resize=
{
'both'
}
resize=
{
'both'
}
defaultValue=
{
item
.
value
}
defaultValue=
{
item
.
value
}
onBlur=
{
(
e
)
=>
{
onBlur=
{
(
e
)
=>
{
onChangeNode
({
update
(
e
.
target
.
value
);
moduleId
,
type
:
'updateInput'
,
key
:
item
.
key
,
value
:
{
...
item
,
value
:
e
.
target
.
value
}
});
}
}
}
}
/>
/>
);
);
...
...
projects/app/src/pages/app/detail/components/AdEdit/Header.tsx
View file @
41115a96
...
@@ -62,7 +62,7 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({
...
@@ -62,7 +62,7 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({
});
});
if
(
unconnected
)
{
if
(
unconnected
)
{
const
msg
=
`【
${
item
.
name
}
】存在未填或未连接参数`
;
const
msg
=
`【
${
t
(
item
.
name
)
}
】存在未填或未连接参数`
;
toast
({
toast
({
status
:
'warning'
,
status
:
'warning'
,
...
@@ -72,7 +72,7 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({
...
@@ -72,7 +72,7 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({
}
}
}
}
return
modules
;
return
modules
;
},
[
edges
,
nodes
,
toast
]);
},
[
edges
,
nodes
,
t
,
t
oast
]);
const
{
mutate
:
onclickSave
,
isLoading
}
=
useRequest
({
const
{
mutate
:
onclickSave
,
isLoading
}
=
useRequest
({
mutationFn
:
async
(
modules
:
ModuleItemType
[])
=>
{
mutationFn
:
async
(
modules
:
ModuleItemType
[])
=>
{
...
...
projects/app/src/pages/app/detail/components/SimpleEdit/index.tsx
View file @
41115a96
...
@@ -337,9 +337,8 @@ function ConfigForm({
...
@@ -337,9 +337,8 @@ function ConfigForm({
bg=
{
'myWhite.400'
}
bg=
{
'myWhite.400'
}
rows=
{
5
}
rows=
{
5
}
placeholder=
{
chatNodeSystemPromptTip
}
placeholder=
{
chatNodeSystemPromptTip
}
showSetModalModeIcon
defaultValue=
{
getValues
(
'aiSettings.systemPrompt'
)
}
value=
{
getValues
(
'aiSettings.systemPrompt'
)
}
onBlur=
{
(
e
)
=>
{
onChange=
{
(
e
)
=>
{
setValue
(
'aiSettings.systemPrompt'
,
e
.
target
.
value
||
''
);
setValue
(
'aiSettings.systemPrompt'
,
e
.
target
.
value
||
''
);
setRefresh
(
!
refresh
);
setRefresh
(
!
refresh
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment