Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Frontend V2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Frontend V2
Commits
b210a169
Commit
b210a169
authored
1 month ago
by
Leonardo
Browse files
Options
Downloads
Patches
Plain Diff
fix: update database error of read only property being changed
parent
7cfb3663
No related branches found
Branches containing commit
Tags
v1.121.0
Tags containing commit
1 merge request
!476
fix: update database error of read only property being changed
Pipeline
#146701
failed
1 month ago
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/management/database/useHandleDatabase.ts
+25
-19
25 additions, 19 deletions
src/lib/management/database/useHandleDatabase.ts
with
25 additions
and
19 deletions
src/lib/management/database/useHandleDatabase.ts
+
25
−
19
View file @
b210a169
import
{
wsTestDatabaseConnection
,
wsCreateState
,
wsUpdateState
,
useAuthCache
,
useAppDispatch
,
useProjects
}
from
'
../../data-access
'
;
import
{
wsTestDatabaseConnection
,
wsCreateState
,
wsUpdateState
,
useAuthCache
,
useAppDispatch
,
useProjects
,
DatabaseStatus
,
}
from
'
../../data-access
'
;
import
{
useState
}
from
'
react
'
;
import
{
addNewQuery
,
addSaveState
,
selectSaveState
,
setActiveQueryID
,
testedSaveState
}
from
'
../../data-access/store/sessionSlice
'
;
import
{
addSaveState
,
selectSaveState
,
testedSaveState
}
from
'
../../data-access/store/sessionSlice
'
;
import
{
setSchemaLoading
}
from
'
../../data-access/store/schemaSlice
'
;
import
{
PartialSaveState
,
SaveState
}
from
'
ts-common
'
;
import
{
addError
}
from
'
@/lib/data-access/store/configSlice
'
;
import
{
Button
}
from
'
@/lib/components
'
;
import
{
wsAddQuery
,
wsDeleteQuery
,
wsUpdateQuery
}
from
'
@/lib/data-access/broker
'
;
import
{
queryAllByAltText
}
from
'
@testing-library/react
'
;
import
{
wsAddQuery
,
wsUpdateQuery
}
from
'
@/lib/data-access/broker
'
;
export
type
ConnectionStatus
=
{
updating
:
boolean
;
...
...
@@ -35,22 +41,23 @@ export const useHandleDatabase = () => {
status
:
'
Testing database connection
'
,
verified
:
null
,
}));
const
newSaveStateData
=
JSON
.
parse
(
JSON
.
stringify
(
saveStateData
))
as
PartialSaveState
;
// undo readonly
const
currentProject
=
project
.
currentProject
;
if
(
currentProject
)
{
s
aveStateData
.
project
=
currentProject
;
newS
aveStateData
.
project
=
currentProject
;
}
else
{
s
aveStateData
.
project
=
null
;
newS
aveStateData
.
project
=
null
;
}
wsTestDatabaseConnection
(
s
aveStateData
.
dbConnections
?.[
0
],
data
=>
{
if
(
!
s
aveStateData
)
{
wsTestDatabaseConnection
(
newS
aveStateData
.
dbConnections
?.[
0
],
data
=>
{
if
(
!
newS
aveStateData
)
{
console
.
error
(
'
formData is null
'
);
return
;
}
if
(
s
aveStateData
.
userId
!==
authCache
.
authentication
?.
userID
&&
authCache
.
authentication
?.
userID
)
{
if
(
newS
aveStateData
.
userId
!==
authCache
.
authentication
?.
userID
&&
authCache
.
authentication
?.
userID
)
{
console
.
error
(
'
user_id is not equal to auth.userID
'
);
s
aveStateData
.
userId
=
authCache
.
authentication
.
userID
;
newS
aveStateData
.
userId
=
authCache
.
authentication
.
userID
;
}
if
(
data
&&
data
.
status
===
'
success
'
)
{
setConnectionStatus
(
prevState
=>
({
...
...
@@ -62,18 +69,17 @@ export const useHandleDatabase = () => {
dispatch
(
selectSaveState
(
undefined
));
if
(
type
===
'
add
'
||
forceAdd
)
{
// Reset query state, backend should handle creating this anew
const
data
=
JSON
.
parse
(
JSON
.
stringify
(
saveStateData
))
as
any
;
// undo readonly
const
queryStateToClone
=
JSON
.
parse
(
JSON
.
stringify
(
saveStateData
.
queryStates
??
{}));
delete
data
.
queryStates
;
const
queryStateToClone
=
JSON
.
parse
(
JSON
.
stringify
(
newSaveStateData
.
queryStates
??
{}));
delete
newSaveStateData
.
queryStates
;
wsCreateState
(
d
ata
,
async
newSaveState
=>
{
wsCreateState
(
newSaveStateD
ata
,
async
newSaveState
=>
{
if
(
!
newSaveState
)
{
dispatch
(
addError
(
'
Failed to create new save state.
'
));
return
;
}
// Only if we are adding a save state that is cloned and contains a queryState
if
(
s
aveStateData
.
queryStates
!=
null
)
{
if
(
newS
aveStateData
.
queryStates
!=
null
)
{
// Clone query state
for
(
const
i
in
queryStateToClone
.
openQueryArray
)
{
const
query
=
queryStateToClone
.
openQueryArray
[
i
];
...
...
@@ -108,7 +114,7 @@ export const useHandleDatabase = () => {
}
dispatch
(
addSaveState
(
newSaveState
));
dispatch
(
testedSaveState
(
newSaveState
.
id
));
dispatch
(
testedSaveState
(
{
saveStateID
:
newSaveState
.
id
,
status
:
DatabaseStatus
.
untested
}
));
setConnectionStatus
({
updating
:
false
,
status
:
null
,
...
...
@@ -118,9 +124,9 @@ export const useHandleDatabase = () => {
});
}
else
{
if
(
data
.
saveStateID
)
{
dispatch
(
testedSaveState
(
data
.
saveStateID
));
dispatch
(
testedSaveState
(
{
saveStateID
:
data
.
saveStateID
,
status
:
DatabaseStatus
.
untested
}
));
}
wsUpdateState
(
s
aveStateData
as
SaveState
,
updatedSaveState
=>
{
wsUpdateState
(
newS
aveStateData
as
SaveState
,
updatedSaveState
=>
{
if
(
!
updatedSaveState
)
{
dispatch
(
addError
(
'
Failed to update save state.
'
));
return
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment