Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
19bc1aaa
Unverified
Commit
19bc1aaa
authored
Jan 09, 2024
by
Zzm0809
Committed by
GitHub
Jan 09, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix] fix datasource form state bug (#2959)
Co-authored-by:
Zzm0809
<
Zzm0809@users.noreply.github.com
>
parent
ece7d6f0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
26 deletions
+59
-26
index.tsx
.../RegCenter/DataSource/components/DataSourceList/index.tsx
+43
-25
BusinessCrud.ts
dinky-web/src/services/BusinessCrud.ts
+1
-1
init.d.ts
dinky-web/src/types/RegCenter/init.d.ts
+9
-0
state.d.ts
dinky-web/src/types/RegCenter/state.d.ts
+6
-0
No files found.
dinky-web/src/pages/RegCenter/DataSource/components/DataSourceList/index.tsx
View file @
19bc1aaa
...
@@ -37,6 +37,8 @@ import {
...
@@ -37,6 +37,8 @@ import {
import
{
PROTABLE_OPTIONS_PUBLIC
,
PRO_LIST_CARD_OPTIONS
}
from
'@/services/constants'
;
import
{
PROTABLE_OPTIONS_PUBLIC
,
PRO_LIST_CARD_OPTIONS
}
from
'@/services/constants'
;
import
{
API_CONSTANTS
}
from
'@/services/endpoints'
;
import
{
API_CONSTANTS
}
from
'@/services/endpoints'
;
import
{
DataSources
}
from
'@/types/RegCenter/data.d'
;
import
{
DataSources
}
from
'@/types/RegCenter/data.d'
;
import
{
InitDataSourceState
}
from
'@/types/RegCenter/init.d'
;
import
{
DataSourceState
}
from
'@/types/RegCenter/state.d'
;
import
{
l
}
from
'@/utils/intl'
;
import
{
l
}
from
'@/utils/intl'
;
import
{
WarningMessage
}
from
'@/utils/messages'
;
import
{
WarningMessage
}
from
'@/utils/messages'
;
import
{
import
{
...
@@ -59,10 +61,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -59,10 +61,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
/**
/**
* state
* state
*/
*/
const
[
loading
,
setLoading
]
=
React
.
useState
<
boolean
>
(
false
);
const
[
datasourceState
,
setDatasourceState
]
=
useState
<
DataSourceState
>
(
InitDataSourceState
);
const
[
modalVisible
,
setModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
detailPage
,
setDetailPage
]
=
useState
<
boolean
>
(
false
);
const
[
formValues
,
setFormValues
]
=
useState
<
Partial
<
DataSources
.
DataSource
>>
({});
const
actionRef
=
React
.
useRef
<
ActionType
>
();
const
actionRef
=
React
.
useRef
<
ActionType
>
();
const
queryDataSourceList
=
async
(
keyword
=
''
)
=>
{
const
queryDataSourceList
=
async
(
keyword
=
''
)
=>
{
...
@@ -91,10 +90,10 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -91,10 +90,10 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
* @param callback
* @param callback
*/
*/
const
executeAndCallbackRefresh
=
async
(
callback
:
()
=>
Promise
<
any
>
)
=>
{
const
executeAndCallbackRefresh
=
async
(
callback
:
()
=>
Promise
<
any
>
)
=>
{
set
Loading
(
true
);
set
DatasourceState
((
prevState
)
=>
({
...
prevState
,
loading
:
true
})
);
await
callback
();
await
callback
();
await
queryDataSourceList
();
await
queryDataSourceList
();
set
Loading
(
false
);
set
DatasourceState
((
prevState
)
=>
({
...
prevState
,
loading
:
false
})
);
};
};
/**
/**
...
@@ -161,8 +160,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -161,8 +160,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
* @param item
* @param item
*/
*/
const
editClick
=
(
item
:
DataSources
.
DataSource
)
=>
{
const
editClick
=
(
item
:
DataSources
.
DataSource
)
=>
{
setFormValues
(
item
);
setDatasourceState
((
prevState
)
=>
({
...
prevState
,
value
:
item
,
editOpen
:
true
}));
setModalVisible
(
!
modalVisible
);
};
};
/**
/**
...
@@ -176,9 +174,9 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -176,9 +174,9 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
type
:
STUDIO_MODEL
.
updateSelectDatabaseId
,
type
:
STUDIO_MODEL
.
updateSelectDatabaseId
,
payload
:
item
.
id
payload
:
item
.
id
});
});
set
FormValues
(
item
);
set
DatasourceState
((
prevState
)
=>
({
...
prevState
,
value
:
item
})
);
history
.
push
(
`/registration/datasource/detail/
${
item
.
id
}
`
);
history
.
push
(
`/registration/datasource/detail/
${
item
.
id
}
`
);
setD
etailPage
(
!
detailPage
);
setD
atasourceState
((
prevState
)
=>
({
...
prevState
,
isDetailPage
:
true
})
);
}
else
{
}
else
{
await
WarningMessage
(
l
(
'rc.ds.enter.error'
));
await
WarningMessage
(
l
(
'rc.ds.enter.error'
));
}
}
...
@@ -190,7 +188,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -190,7 +188,7 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
*/
*/
const
renderDataSourceActionButton
=
(
item
:
DataSources
.
DataSource
)
=>
{
const
renderDataSourceActionButton
=
(
item
:
DataSources
.
DataSource
)
=>
{
return
[
return
[
<
Authorized
key=
{
`${item.id}_edit`
}
path=
'/registration/datasource/
add
'
>
<
Authorized
key=
{
`${item.id}_edit`
}
path=
'/registration/datasource/
edit
'
>
<
EditBtn
key=
{
`${item.id}_edit`
}
onClick=
{
()
=>
editClick
(
item
)
}
/>
<
EditBtn
key=
{
`${item.id}_edit`
}
onClick=
{
()
=>
editClick
(
item
)
}
/>
</
Authorized
>,
</
Authorized
>,
<
Authorized
key=
{
`${item.id}_delete`
}
path=
'/registration/datasource/delete'
>
<
Authorized
key=
{
`${item.id}_delete`
}
path=
'/registration/datasource/delete'
>
...
@@ -256,21 +254,23 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -256,21 +254,23 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
* cancel all
* cancel all
*/
*/
const
cancelAll
=
()
=>
{
const
cancelAll
=
()
=>
{
setModalVisible
(
false
);
setDatasourceState
(
InitDataSourceState
);
setFormValues
({});
};
};
const
renderToolBar
=
()
=>
{
const
renderToolBar
=
()
=>
{
return
[
return
[
<
Input
.
Search
<
Input
.
Search
loading=
{
loading
}
loading=
{
datasourceState
.
loading
}
key=
{
`_search`
}
key=
{
`_search`
}
allowClear
allowClear
placeholder=
{
l
(
'rc.ds.search'
)
}
placeholder=
{
l
(
'rc.ds.search'
)
}
onSearch=
{
(
value
)
=>
queryDataSourceList
(
value
)
}
onSearch=
{
(
value
)
=>
queryDataSourceList
(
value
)
}
/>,
/>,
<
Authorized
key=
'create'
path=
'/registration/datasource/add'
>
<
Authorized
key=
'create'
path=
'/registration/datasource/add'
>
<
CreateBtn
key=
{
'CreateBtn'
}
onClick=
{
()
=>
setModalVisible
(
true
)
}
/>
<
CreateBtn
key=
{
'CreateBtn'
}
onClick=
{
()
=>
setDatasourceState
({
...
datasourceState
,
addedOpen
:
true
})
}
/>
</
Authorized
>
</
Authorized
>
];
];
};
};
...
@@ -280,12 +280,12 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -280,12 +280,12 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
*/
*/
return
(
return
(
<>
<>
{
!
detailPage
?
(
{
!
d
atasourceState
.
isD
etailPage
?
(
<>
<>
<
ProList
<
DataSources
.
DataSource
>
<
ProList
<
DataSources
.
DataSource
>
{
...
PROTABLE_OPTIONS_PUBLIC
}
{
...
PROTABLE_OPTIONS_PUBLIC
}
{
...(
PRO_LIST_CARD_OPTIONS
as
any
)
}
{
...(
PRO_LIST_CARD_OPTIONS
as
any
)
}
loading=
{
loading
}
loading=
{
datasourceState
.
loading
}
tooltip=
{
l
(
'rc.ds.enter'
)
}
tooltip=
{
l
(
'rc.ds.enter'
)
}
actionRef=
{
actionRef
}
actionRef=
{
actionRef
}
headerTitle=
{
l
(
'rc.ds.management'
)
}
headerTitle=
{
l
(
'rc.ds.management'
)
}
...
@@ -294,16 +294,34 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
...
@@ -294,16 +294,34 @@ const DataSourceTable: React.FC<connect & StateType> = (props) => {
/
>
/
>
{
/* added */
}
{
/* added */
}
<
DataSourceModal
{
datasourceState
.
addedOpen
&&
(
values=
{
formValues
}
<
DataSourceModal
visible=
{
modalVisible
}
values=
{
{}
}
onCancel=
{
cancelAll
}
visible=
{
datasourceState
.
addedOpen
}
onTest=
{
(
value
)
=>
handleTest
(
value
)
}
onCancel=
{
cancelAll
}
onSubmit=
{
(
value
)
=>
executeAndCallbackRefresh
(
async
()
=>
saveOrUpdateHandle
(
value
))
}
onTest=
{
(
value
)
=>
handleTest
(
value
)
}
/>
onSubmit=
{
(
value
)
=>
executeAndCallbackRefresh
(
async
()
=>
saveOrUpdateHandle
(
value
))
}
/>
)
}
{
/* edit mode */
}
{
datasourceState
.
editOpen
&&
(
<
DataSourceModal
values=
{
datasourceState
.
value
}
visible=
{
datasourceState
.
editOpen
}
onCancel=
{
cancelAll
}
onTest=
{
(
value
)
=>
handleTest
(
value
)
}
onSubmit=
{
(
value
)
=>
executeAndCallbackRefresh
(
async
()
=>
saveOrUpdateHandle
(
value
))
}
/>
)
}
</>
</>
) : (
) : (
<
DataSourceDetail
backClick=
{
()
=>
setDetailPage
(
false
)
}
dataSource=
{
formValues
}
/>
<
DataSourceDetail
backClick=
{
()
=>
setDatasourceState
((
prevState
)
=>
({
...
prevState
,
isDetailPage
:
false
}))
}
dataSource=
{
datasourceState
.
value
}
/>
)
}
)
}
</>
</>
);
);
...
...
dinky-web/src/services/BusinessCrud.ts
View file @
19bc1aaa
...
@@ -136,7 +136,7 @@ export const handleRemoveById = async (url: string, id: number, afterCallBack?:
...
@@ -136,7 +136,7 @@ export const handleRemoveById = async (url: string, id: number, afterCallBack?:
* @param params
* @param params
*/
*/
export
const
updateDataByParam
=
async
(
url
:
string
,
params
:
any
)
=>
{
export
const
updateDataByParam
=
async
(
url
:
string
,
params
:
any
)
=>
{
await
LoadingMessageAsync
(
l
(
'app.request.update'
));
await
LoadingMessageAsync
(
l
(
'app.request.
running'
)
+
l
(
'app.request.
update'
));
try
{
try
{
const
{
code
,
msg
}
=
await
updateDataByParams
(
url
,
{
...
params
});
const
{
code
,
msg
}
=
await
updateDataByParams
(
url
,
{
...
params
});
if
(
code
===
RESPONSE_CODE
.
SUCCESS
)
{
if
(
code
===
RESPONSE_CODE
.
SUCCESS
)
{
...
...
dinky-web/src/types/RegCenter/init.d.ts
View file @
19bc1aaa
...
@@ -26,6 +26,7 @@ import {
...
@@ -26,6 +26,7 @@ import {
BuildStepsState
,
BuildStepsState
,
ClusterConfigState
,
ClusterConfigState
,
ClusterInstanceState
,
ClusterInstanceState
,
DataSourceState
,
DocumentState
,
DocumentState
,
GitProjectState
,
GitProjectState
,
GlobalVarState
,
GlobalVarState
,
...
@@ -251,3 +252,11 @@ export const InitTemplateState: TemplateState = {
...
@@ -251,3 +252,11 @@ export const InitTemplateState: TemplateState = {
value
:
{},
value
:
{},
drawerOpen
:
false
drawerOpen
:
false
};
};
export
const
InitDataSourceState
:
DataSourceState
=
{
loading
:
false
,
addedOpen
:
false
,
editOpen
:
false
,
value
:
{},
isDetailPage
:
false
};
dinky-web/src/types/RegCenter/state.d.ts
View file @
19bc1aaa
...
@@ -22,6 +22,7 @@ import { BaseState, ContextMenuPosition } from '@/types/Public/state.d';
...
@@ -22,6 +22,7 @@ import { BaseState, ContextMenuPosition } from '@/types/Public/state.d';
import
{
import
{
Alert
,
Alert
,
Cluster
,
Cluster
,
DataSources
,
Document
,
Document
,
GitProject
,
GitProject
,
GlobalVar
,
GlobalVar
,
...
@@ -129,3 +130,8 @@ export interface TemplateState extends BaseState {
...
@@ -129,3 +130,8 @@ export interface TemplateState extends BaseState {
value
:
Partial
<
UDFTemplate
>
;
value
:
Partial
<
UDFTemplate
>
;
drawerOpen
:
boolean
;
drawerOpen
:
boolean
;
}
}
export
interface
DataSourceState
extends
BaseState
{
value
:
Partial
<
DataSources
.
DataSource
>
;
isDetailPage
:
boolean
;
}
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