Skip to content

Feature/migrate fbw to reactquery#334

Merged
germanferrero merged 24 commits into
libremesh:developfrom
selankon:feature/migrate-fbw-to-reactquery
Mar 10, 2022
Merged

Feature/migrate fbw to reactquery#334
germanferrero merged 24 commits into
libremesh:developfrom
selankon:feature/migrate-fbw-to-reactquery

Conversation

@selankon
Copy link
Copy Markdown
Collaborator

@selankon selankon commented Feb 14, 2022

Migrate to React Query library instead of use the old redux system

Copy link
Copy Markdown
Contributor

@germanferrero germanferrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@selankon great work! I've add some comments you may want to address :)

Comment thread plugins/lime-plugin-fbw/src/FbwApi.js Outdated
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 });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lime-fbw set_network endpoint doesn't expect a network attribute in the body. Is this something intentional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
			});
		}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code to be deleted

Comment thread plugins/lime-plugin-fbw/src/FbwApi.js Outdated
@@ -1,13 +1,13 @@
import api from 'utils/uhttpd.service';
import { from } from 'rxjs';
// import { from } from 'rxjs';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code to be deleted

toggleForm('setting')();
},
onError: () => {
setStatus('error')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid using:

const [status, setStatus] = useState()

And take it directly from:
const [setNetwork, { isError: isSetNetworkError}] = useSetNetwork()
and
const [searchNetworks, { isError: isSeachNetworkError}] = useSearchNetworks()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And on isSeachNetworkError and isSetNetworkError I have to do setStatus('error')?

Also, what about the onSuccess result? Its ok as is now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = '' }) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@selankon selankon force-pushed the feature/migrate-fbw-to-reactquery branch from a1b2fab to 48fbc47 Compare March 1, 2022 14:36
Copy link
Copy Markdown
Contributor

@germanferrero germanferrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks @selankon !! 🎉 😄

@selankon
Copy link
Copy Markdown
Collaborator Author

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?

➜ npx eslint .

limeapp/lime-app/plugins/lime-plugin-changeNode/src/changeNodePage.js
  62:41  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/plugins/lime-plugin-fbw/src/FbwPage.spec.js
  61:9  error  Expect must have a corresponding matcher call  jest/valid-expect
  68:9  error  Expect must have a corresponding matcher call  jest/valid-expect

limeapp/lime-app/plugins/lime-plugin-metrics/src/metricsPage.js
  154:4  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/plugins/lime-plugin-pirania/src/screens/voucherList.js
  68:7  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/plugins/lime-plugin-rx/src/rxPage.js
  126:8  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/src/components/app.js
  35:5  error  Missing "key" prop for element in iterator  react/jsx-key
  43:5  error  Missing "key" prop for element in iterator  react/jsx-key
  53:5  error  Missing "key" prop for element in iterator  react/jsx-key
  64:5  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/src/components/tabs/index.js
  7:5  error  Missing "key" prop for element in iterator  react/jsx-key

limeapp/lime-app/src/utils/app.context.js
  3:1  error  'preact' import is duplicated  no-duplicate-imports

✖ 12 problems (12 errors, 0 warnings)

@germanferrero germanferrero merged commit ae5cce7 into libremesh:develop Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants