Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better import in progress #2027

Merged
merged 4 commits into from
Mar 9, 2021
Merged

Better import in progress #2027

merged 4 commits into from
Mar 9, 2021

Conversation

flohhhh
Copy link
Contributor

@flohhhh flohhhh commented Mar 5, 2021

We want to view when an account import is in
progress on the balance page and in the settings
page. For that we activate the realtime on the jobs
when we are on one of these 2 pages otherwise we
stop it. We also want to display a notification to
the user whether it went correctly or not.

@ptbrowne
Copy link
Contributor

ptbrowne commented Mar 5, 2021

Please take the time to write a PR description :)

Copy link
Contributor

@ptbrowne ptbrowne left a comment

Choose a reason for hiding this comment

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

This looks really nice 👏 , the real blocker for me is the lack of test for the JobsContextProvider though.

I have some remarks and nits.

src/AppContainer.jsx Outdated Show resolved Hide resolved
src/ducks/balance/Balance.spec.jsx Outdated Show resolved Hide resolved
src/ducks/balance/ImportGroupPanel.jsx Show resolved Hide resolved
src/ducks/balance/ImportGroupPanel.spec.jsx Outdated Show resolved Hide resolved
src/components/JobsContext.jsx Show resolved Hide resolved
src/components/JobsContext.jsx Show resolved Hide resolved
useEffect(() => {
startJobsRealtime()
return () => stopJobsRealtime()
}, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

There is useRealtime hook that could simplify the logic, it does the start/stop/subscribe/unsubscribe for you:

https://github.com/cozy/cozy-ui/blob/db54f27493b6ba61cf41a1b48cf363b9957dd049/react/hooks/useRealtime.js

cozy-ui might not be the good place for it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think so too, it would be better in realtime lib

return (
<JobsContext.Provider
value={{
jobsInProgress
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It could be nice to prepare a bit the context value to make its consumption easier for the components below. For example, indexing the accounts or the triggers, or the connectors.

  const value = useMemo(() => ({
    inProgress: jobsInProgress,
    byAccountId: keyBy(jobsInProgress, x => x.account),
    byKonnectorSlug: keyBy(jobsInProgress, x => x.konnector),,
    byTriggerId: keyBy(jobsInProgress, x => x.trigger), // useMemo could be used 
  }, [jobsInProgress])
  return <JobsContext.Provider
    value={value}
  ...
  />

The value passed below is here memoized not to incure unnecessary renders (not sure if this is really necessary but it cannot hurt I guess) and indexed so that a component can access info easily.

@todo
Copy link

todo bot commented Mar 8, 2021

add tests for JobsContext

// @TODO add tests for JobsContext
/** Allows to subscribe to jobs and thus to know jobs in progress
*
* @param client
* @param options
* @returns jobsInProgress


This comment was generated by todo based on a TODO comment in ae5e5da in #2027. cc @cozy.

@todo
Copy link

todo bot commented Mar 8, 2021

useRealtime hook

// @TODO useRealtime hook
useEffect(() => {
startJobsRealtime()
return () => stopJobsRealtime()
}, [])


This comment was generated by todo based on a TODO comment in ae5e5da in #2027. cc @cozy.

@flohhhh flohhhh force-pushed the better-import-in-progress branch 2 times, most recently from ac31d14 to 3e6c596 Compare March 8, 2021 17:49
@todo
Copy link

todo bot commented Mar 8, 2021

use 'useQuery' instead of 'client'

// @TODO use 'useQuery' instead of 'client'
// const resp = useQuery(konnectorConn.query(slug), konnectorConn)
// const name = get(resp, 'data[0].attributes.name', '')
return (
<ListItem button disableRipple>


This comment was generated by todo based on a TODO comment in 3e6c596 in #2027. cc @cozy.

@todo
Copy link

todo bot commented Mar 8, 2021

use 'useQuery' instead of 'client'

// @TODO use 'useQuery' instead of 'client'
// const resp = useQuery(konnectorConn.query(slug), konnectorConn)
// const name = get(resp, 'data[0].attributes.name', '')
return (
<ListItem button disableRipple>


This comment was generated by todo based on a TODO comment in 02a303d in #2027. cc @cozy.

Florian Pires added 3 commits March 8, 2021 20:08
We want to view when an account import is in
progress on the balance page and in the settings
page. For that we activate the realtime on the jobs
when we are on one of these 2 pages otherwise we
stop it. We also want to display a notification to
the user whether it went correctly or not.

There are several tests which are not added yet
@todo
Copy link

todo bot commented Mar 8, 2021

use 'useQuery' instead of 'client'

// @TODO use 'useQuery' instead of 'client'
// const resp = useQuery(konnectorConn.query(slug), konnectorConn)
// const name = get(resp, 'data[0].attributes.name', '')
return (
<ListItem button disableRipple>


This comment was generated by todo based on a TODO comment in e932082 in #2027. cc @cozy.

@flohhhh flohhhh marked this pull request as ready for review March 8, 2021 19:22
Copy link
Contributor

@ptbrowne ptbrowne left a comment

Choose a reason for hiding this comment

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

Thanks !

@flohhhh flohhhh merged commit a07d8e3 into master Mar 9, 2021
@delete-merged-branch delete-merged-branch bot deleted the better-import-in-progress branch March 9, 2021 08:31
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.

None yet

2 participants