Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chat-query
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
jaden
chat-query
Commits
6d7c31af
Commit
6d7c31af
authored
Jun 30, 2023
by
熊洋洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:improve code
parent
b967781b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
52 deletions
+90
-52
components/AITool/index.tsx
components/AITool/index.tsx
+1
-1
next-i18next.config.js
next-i18next.config.js
+3
-0
pages/actions/View/chatView.tsx
pages/actions/View/chatView.tsx
+82
-47
pages/actions/index.tsx
pages/actions/index.tsx
+4
-4
No files found.
components/AITool/index.tsx
View file @
6d7c31af
...
...
@@ -268,7 +268,7 @@ export function AIWrapper({
height={56}
className="overflow-hidden shadow-md simple-mode shadow-cyan-500/30"
autoFocus
onPressEnter={() => handleButtonClick()}
onPressEnter={() =>
!SendButton &&
handleButtonClick()}
value={inputValue}
onChange={value => {
const el = input.current?.dom;
...
...
next-i18next.config.js
View file @
6d7c31af
...
...
@@ -209,6 +209,9 @@ i18n.use(LanguageDetector)
'
please enter query name
'
:
'
请输入查询名称
'
,
name
:
'
名称
'
,
},
chatView
:
{
'
component display
'
:
'
组件显示
'
,
},
},
},
fallbackLng
:
'
en
'
,
...
...
pages/actions/View/chatView.tsx
View file @
6d7c31af
import
{
Button
,
Card
,
Spin
}
from
'
@arco-design/web-react
'
;
import
{
IconCode
,
IconEye
,
IconSend
}
from
'
@arco-design/web-react/icon
'
;
import
React
,
{
ReactElement
,
memo
,
useCallback
,
useRef
,
useState
}
from
'
react
'
;
import
{
LiveEditor
,
LiveError
,
LivePreview
,
LiveProvider
}
from
'
react-live-runner
'
;
import
{
IconCode
,
IconEye
,
IconRefresh
,
IconSend
,
IconSwap
}
from
'
@arco-design/web-react/icon
'
;
import
React
,
{
ReactElement
,
memo
,
useCallback
,
useMemo
,
useRef
,
useState
}
from
'
react
'
;
import
{
LiveEditor
,
LiveError
,
LivePreview
,
LiveProvider
,
useLiveContext
,
}
from
'
react-live-runner
'
;
import
*
as
styledComponents
from
'
styled-components
'
;
import
*
as
echarts
from
'
echarts
'
;
import
ReactDOM
from
'
react-dom
'
;
...
...
@@ -11,6 +17,13 @@ import useSWRMutation from 'swr/mutation';
import
getView
from
'
@/client/api/getView
'
;
import
{
nanoid
}
from
'
nanoid
'
;
import
{
get
}
from
'
lodash
'
;
import
{
useTranslation
}
from
'
react-i18next
'
;
function
Error
()
{
const
{
error
}
=
useLiveContext
();
console
.
log
(
error
,
'
error
'
);
return
<
code
>
{
error
}
</
code
>;
}
export
function
ChatView
({
defaultNode
,
...
...
@@ -21,8 +34,8 @@ export function ChatView({
})
{
const
[
showCode
,
setShowCode
]
=
useState
(
true
);
const
reqRef
=
useRef
(
nanoid
());
const
[
showTable
,
setShowTable
]
=
useState
(
false
);
const
{
trigger
,
data
,
isMutating
}
=
useSWRMutation
(
reqRef
.
current
,
(
_
,
{
arg
:
{
need
}
})
=>
{
console
.
log
(
need
);
return
getView
.
getViewComponent
({
props
,
need
,
...
...
@@ -34,39 +47,86 @@ export function ChatView({
return
(
<
Button
shape=
"circle"
icon=
{
<
IconSend
/>
}
icon=
{
data
?
<
IconRefresh
/>
:
<
IconSend
/>
}
size=
"mini"
type=
"primary"
loading=
{
isMutating
}
onClick=
{
async
()
=>
{
await
trigger
({
need
:
inputRef
.
current
.
dom
.
value
});
// inputRef.current.dom.value = ''
;
setShowTable
(
false
)
;
}
}
/>
);
},
[
isMutating
,
trigger
]
[
isMutating
,
trigger
,
setShowTable
]
);
const
example
=
get
(
data
,
'
data.code
'
);
console
.
log
(
example
,
'
isMutating
'
);
const
{
t
}
=
useTranslation
(
'
chatView
'
);
const
Live
=
useMemo
(()
=>
{
let
node
;
try
{
node
=
!
showCode
?
(
<
LiveEditor
className=
"overflow-auto min-h-[350px]"
/>
)
:
(
<
LivePreview
/>
);
}
catch
(
err
)
{
node
=
<
LiveEditor
className=
"overflow-auto min-h-[350px]"
/>;
}
return
(
<
LiveProvider
code=
{
example
}
scope=
{
{
data
:
props
,
import
:
{
react
:
React
,
'
react-dom
'
:
ReactDOM
,
'
styled-components
'
:
styledComponents
,
'
echarts-for-react
'
:
ReactECharts
,
echarts
:
{
default
:
echarts
,
echarts
:
echarts
,
...
echarts
,
},
},
}
}
>
{
node
}
<
Error
/>
</
LiveProvider
>
);
},
[
example
,
props
,
showCode
]);
return
(
<
div
>
<
AI
simpleMode=
"input"
startView=
{
3
}
inputProps=
{
{
style
:
{
width
:
400
},
height
:
36
,
className
:
'
overflow-hidden simple-mode-border mb-[20px]
'
,
prefix
:
<
span
className=
"text-[var(--pc)]"
>
组件显示
</
span
>,
autoFocus
:
false
,
}
}
SendButton=
{
SendButton
}
/>
<
div
className=
"flex justify-between items-center mb-[20px]"
>
<
AI
simpleMode=
"input"
startView=
{
3
}
inputProps=
{
{
style
:
{
width
:
400
},
height
:
36
,
className
:
'
overflow-hidden simple-mode-border
'
,
prefix
:
<
span
className=
"text-[var(--pc)]"
>
{
t
(
'
component display
'
)
}
</
span
>,
autoFocus
:
false
,
}
}
SendButton=
{
SendButton
}
messageList=
{
[]
}
setMessageList=
{
function
(
value
:
any
[])
{
return
false
;
}
}
/>
{
data
&&
(
<
Button
shape=
"circle"
onClick=
{
()
=>
setShowTable
(
!
showTable
)
}
>
<
IconSwap
/>
</
Button
>
)
}
</
div
>
<
Spin
loading=
{
isMutating
}
block
className=
"my-[20px]"
>
{
example
?
(
{
example
&&
!
showTable
?
(
<
div
>
<
div
className=
"text-[20px] absolute text-orange-200 z-[99] right-[20px]"
>
{
showCode
?
(
...
...
@@ -75,32 +135,7 @@ export function ChatView({
<
IconEye
onClick=
{
()
=>
setShowCode
(
true
)
}
/>
)
}
</
div
>
<
div
className=
"overflow-hidden"
>
<
LiveProvider
code=
{
example
}
scope=
{
{
data
:
props
,
import
:
{
react
:
React
,
'
react-dom
'
:
ReactDOM
,
'
styled-components
'
:
styledComponents
,
'
echarts-for-react
'
:
ReactECharts
,
echarts
:
{
default
:
echarts
,
echarts
:
echarts
,
...
echarts
,
},
},
}
}
>
{
!
showCode
?
(
<
LiveEditor
className=
"overflow-auto min-h-[350px]"
/>
)
:
(
<
LivePreview
/>
)
}
<
LiveError
/>
</
LiveProvider
>
</
div
>
<
div
className=
"overflow-hidden"
>
{
Live
}
</
div
>
</
div
>
)
:
(
defaultNode
||
null
...
...
pages/actions/index.tsx
View file @
6d7c31af
...
...
@@ -368,7 +368,7 @@ const MessageItemHOC = ({ setShowQueriesList, activeDb, currentModels, activeMod
})
)
}
{
size
(
sql
)
?
(
[
<>
<
FormItem
key=
"1"
>
<
Button
type=
"primary"
...
...
@@ -456,11 +456,11 @@ const MessageItemHOC = ({ setShowQueriesList, activeDb, currentModels, activeMod
{
t
(
'
run
'
)
}
</
Button
>
{
contextHolder
}
</
FormItem
>
,
</
FormItem
>
<
div
className=
"w-full"
key=
"preViewData"
>
<
DataTable
data=
{
preViewData
}
/>
</
div
>
,
]
</
div
>
</>
)
:
(
<
Empty
description=
{
t
(
'
Error in query
'
)
}
...
...
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