Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
public
Mímir
Commits
dbd37c47
Commit
dbd37c47
authored
Aug 13, 2020
by
Aron Fiechter
Browse files
Handle case with no results in querySlice
Set noResultModalOpen to true, do not clear entity or anything else.
parent
a8dc7970
Changes
1
Hide whitespace changes
Inline
Side-by-side
client/src/components/navbar/querySlice.js
View file @
dbd37c47
...
...
@@ -11,6 +11,7 @@ export const querySlice = createSlice({
result
:
stubData
,
error
:
null
,
loading
:
false
,
noResultModalOpen
:
false
,
},
reducers
:
{
// Redux Toolkit allows us to write "mutating" logic in reducers. It
...
...
@@ -28,10 +29,22 @@ export const querySlice = createSlice({
setLoading
:
(
state
,
action
)
=>
{
state
.
loading
=
action
.
payload
;
},
openNoResultModal
:
(
state
)
=>
{
state
.
noResultModalOpen
=
true
;
},
closeNoResultModal
:
(
state
)
=>
{
state
.
noResultModalOpen
=
false
;
},
},
});
export
const
{
getQueryResultSuccess
,
getQueryResultFailure
,
setLoading
}
=
querySlice
.
actions
;
export
const
{
getQueryResultSuccess
,
getQueryResultFailure
,
setLoading
,
openNoResultModal
,
closeNoResultModal
,
}
=
querySlice
.
actions
;
// The function below is called a thunk and allows us to perform async logic. It
// can be dispatched like a regular action: `dispatch(performQuery(<query>))`. This
...
...
@@ -39,22 +52,27 @@ export const { getQueryResultSuccess, getQueryResultFailure, setLoading } = quer
// code can then be executed and other actions can be dispatched
export
const
performQuery
=
(
query
)
=>
async
(
dispatch
)
=>
{
dispatch
(
setLoading
(
true
));
try
{
const
data
=
await
sendQuery
(
query
);
dispatch
(
getQueryResultSuccess
(
data
));
dispatch
(
clearEntity
());
dispatch
(
resetRange
());
}
catch
(
err
)
{
dispatch
(
getQueryResultFailure
(
err
.
toString
()));
}
finally
{
dispatch
(
setLoading
(
false
));
}
return
sendQuery
(
query
)
.
then
((
data
)
=>
{
if
(
data
.
nResults
===
0
)
{
return
dispatch
(
openNoResultModal
());
}
dispatch
(
clearEntity
());
dispatch
(
resetRange
());
return
dispatch
(
getQueryResultSuccess
(
data
));
})
.
catch
((
err
)
=>
{
return
dispatch
(
getQueryResultFailure
(
err
.
toString
()));
})
.
finally
(()
=>
dispatch
(
setLoading
(
false
)));
};
export
const
selectQuery
=
(
state
)
=>
state
.
query
.
result
.
query
;
export
const
selectResult
=
(
state
)
=>
state
.
query
.
result
;
export
const
selectError
=
(
state
)
=>
state
.
query
.
error
;
export
const
selectResultsById
=
(
state
)
=>
state
.
query
.
result
?.
mapById
;
export
const
selectLoading
=
(
state
)
=>
state
.
query
.
loading
;
export
const
selectNodes
=
(
state
)
=>
state
.
query
.
result
?.
nodes
;
export
const
selectNoResultModalOpen
=
(
state
)
=>
state
.
query
.
noResultModalOpen
;
export
default
querySlice
.
reducer
;
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