Feature/migrate fbw to reactquery#334
Conversation
germanferrero
left a comment
There was a problem hiding this comment.
@selankon great work! I've add some comments you may want to address :)
| export const setNetwork = (api, { file, hostname }) => | ||
| api.call('lime-fbw', 'set_network', { file, hostname }); | ||
| export const setNetwork = ({ file, hostname, network }) => | ||
| api.call('lime-fbw', 'set_network', { file, hostname, network }); |
There was a problem hiding this comment.
The lime-fbw set_network endpoint doesn't expect a network attribute in the body. Is this something intentional?
There was a problem hiding this comment.
Well, when setNetwork is called, on the original code, it pass a param called network. See: Scan.js
if (state.apname && isValidHostname(state.hostname, true)) {
setNetwork({
file: state.file,
hostname: state.hostname,
network: state.community
});
}There was a problem hiding this comment.
Ah, ok! The backend is not using it anyway, we can remove it :)
| import Toast from 'components/toast'; | ||
| import { isValidHostname, slugify } from 'utils/isValidHostname'; | ||
| import { showNotification } from '../../../../src/store/actions'; | ||
| // import { showNotification } from '../../../../src/store/actions'; |
There was a problem hiding this comment.
commented code to be deleted
| @@ -1,13 +1,13 @@ | |||
| import api from 'utils/uhttpd.service'; | |||
| import { from } from 'rxjs'; | |||
| // import { from } from 'rxjs'; | |||
There was a problem hiding this comment.
commented code to be deleted
| toggleForm('setting')(); | ||
| }, | ||
| onError: () => { | ||
| setStatus('error') |
There was a problem hiding this comment.
You can avoid using:
const [status, setStatus] = useState()
And take it directly from:
const [setNetwork, { isError: isSetNetworkError}] = useSetNetwork()
and
const [searchNetworks, { isError: isSeachNetworkError}] = useSearchNetworks()
There was a problem hiding this comment.
And on isSeachNetworkError and isSetNetworkError I have to do setStatus('error')?
Also, what about the onSuccess result? Its ok as is now?
There was a problem hiding this comment.
isSeachNetworkError and isSetNetworkError are booleans you can use directly in your conditional rendering.
onSuccess callback looks god!
| const [status, setStatus] = useState() | ||
|
|
||
| const [searchNetworks, { isLoading: isSubmitting}] = useSearchNetworks({ | ||
| onSuccess: (payload) => { |
There was a problem hiding this comment.
Hmm, the previous code doesn't help... But it would make much more sense to have a query called useGetNetworks to do the "GET action" and the mutation called useSearchNetworks to do the "POST action".
Then you would use something like this to obtain the networks.
const { data: networks, isLoading } = useGetNetworks();
(this query can right now call search_networks endpoint with rescan:false parameter).
And useSearchNetworks would do call setQueryData on the useGetNetworks on success. That would make the component re-render and update networks.
In this way, you also avoid using useState for something that it's backend state, rather than frontend state.
| }); | ||
|
|
||
| export default connect(mapStateToProps, mapDispatchToProps)(Scan); | ||
| const getApName = ({ ap = '', file = '' }) => { |
There was a problem hiding this comment.
It's okey to do this hear, but just to give you options:
This data enrichment could also be done at query level.
You can check the "useAssocList" query to checkout what I mean.
a1b2fab to
48fbc47
Compare
…twork Migrate fbw: test expectedHost/expectedNetwork handling
Expected string ends in "."
germanferrero
left a comment
There was a problem hiding this comment.
Great work, thanks @selankon !! 🎉 😄
|
Hi @germanferrero I merged from develop and applied eslint rules but I faced that there are some files not involving to FBW that need lintern revisions. Cold we step forward with this PR? |
Migrate to React Query library instead of use the old redux system