-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since the addition of the HarvestBanner we can configure a konnector from the banner but in order to do that, we need to add the harvest route component. It's been a bit of a struggle, because of the Routes. But Celestin found the answer: When we `useLocation` from a component, if this component is used on the parent route, then its navigation will be based of this route, not the closest. Before, if we did: navigate('./harvest') from the DriveView component, even if the route matched /folder/:folderId, the result was: /folder/harvest and not /folder/:folderId/harvest This is why we changed the route definition. We also remove the need of /folder/file/:fileid since this is not needed anymore because now even if the folder is not defined (aka root dir) we redirect to /folder/root.dir/file/:fileid Since we import Harvestroutes, we need to install leaflet for now...
- Loading branch information
Showing
5 changed files
with
1,338 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
import { useParams, useNavigate } from 'react-router-dom' | ||
|
||
import { useQuery } from 'cozy-client' | ||
import { Routes } from 'cozy-harvest-lib' | ||
import datacardOptions from 'cozy-harvest-lib/dist/datacards/datacardOptions' | ||
|
||
import { | ||
buildTriggersQueryByKonnectorSlug, | ||
buildKonnectorsQueryById | ||
} from 'drive/web/modules/queries' | ||
|
||
const HarvestRoutes = () => { | ||
const { konnectorSlug } = useParams() | ||
const navigate = useNavigate() | ||
|
||
const queryTriggers = buildTriggersQueryByKonnectorSlug( | ||
konnectorSlug, | ||
Boolean(konnectorSlug) | ||
) | ||
const { data: triggers } = useQuery( | ||
queryTriggers.definition, | ||
queryTriggers.options | ||
) | ||
const trigger = triggers?.[0] | ||
|
||
const queryKonnector = buildKonnectorsQueryById( | ||
`io.cozy.konnectors/${konnectorSlug}`, | ||
Boolean(trigger) | ||
) | ||
const { data: konnectors } = useQuery( | ||
queryKonnector.definition, | ||
queryKonnector.options | ||
) | ||
const konnector = konnectors?.[0] | ||
|
||
const konnectorWithTriggers = konnector | ||
? { ...konnector, triggers: { data: triggers } } | ||
: undefined | ||
|
||
const onDismiss = () => navigate('..') | ||
|
||
return ( | ||
<Routes | ||
konnector={konnectorWithTriggers} | ||
konnectorSlug={konnectorSlug} | ||
datacardOptions={datacardOptions} | ||
onSuccess={onDismiss} | ||
onDismiss={onDismiss} | ||
konnectorRoot={`harvest/${konnectorSlug}`} | ||
/> | ||
) | ||
} | ||
|
||
export default HarvestRoutes |
Oops, something went wrong.