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

feat: implement webapp routing #899

Conversation

acezard
Copy link
Contributor

@acezard acezard commented Aug 18, 2023

description to be completed

removed some race conditions
removed faulty redirections
cleaned state management
@acezard acezard marked this pull request as ready for review August 22, 2023 08:05
import { SharingCozyApp } from '/app/domain/sharing/models/SharingCozyApp'
import { ServiceResponse } from '/app/domain/sharing/models/SharingState'

export const fetchSharingCozyApps = {
Copy link
Member

Choose a reason for hiding this comment

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

@Crash-- can you check this part? Will this work if we request io.cozy.apps instead of the registry?

My intuition is that io.cozy.apps will only list apps that are installed on the cozy but not candidate apps that are not yet installed on the cozy. Is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, by default, Q('io.cozy.apps') will only have the source === stack https://github.com/cozy/cozy-client/blob/master/packages/cozy-stack-client/src/AppCollection.js#L55 . So you'll only request the installed applications.

Before you should have just add the registry to the source, but now, you have to make a different Query : Q('io.cozy.apps_registry') that will list the apps from the registry. cozy/cozy-client#1376

Copy link
Member

Choose a reason for hiding this comment

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

Feedback from our latest meeting: We just changed the specs to optimize development delays

  • We will start to list only installed app
  • And then list "non installed" app only after implementing mespapiers.

So for this PR, listing io.cozy.apps is expected

cc @Crash--

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I will still update index/alias)

| { type: SharingActionType.SetFlowErrored; payload: boolean }
| { type: SharingActionType.SetRecoveryState }

export interface ServiceResponse<T> {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Seems like you cannot have both result and error filled simultaneously, so I would reflect that in the type:

interface ServiceResponseOk<T> {
  result: T
}

interface ServiceResponseError {
  error: string
}

export type ServiceResponse<T> = ServiceResponseOk<T> | ServiceResponseError

Hower this would complexify a bit type checks (exemple here and here) but it ensures not type overlap is possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it would be better.

  • Updated


useEffect(() => {
let subscription: NativeEventSubscription | undefined

// If there's no client, we don't need to listen to app state changes
// because we can't lock the app anyway
if (client && !subscription) {
if (!hasExecuted.current && client && !subscription) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that if client changes (or any other array dependency) the subscription will be removed but will never register again (as hasExecuted.current is never set back to false)? Is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will double-check the lifecycle of this event listener, I didn't notice a removal that broke my appStatus change flow but it's better to be safe

src/App.js Outdated
@@ -132,7 +132,9 @@ const WrappedApp = () => {
if (client)
return (
<CozyProvider client={client}>
<Nav client={client} setClient={setClient} />
<SharingProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

No way we call that SharingProvider, like I said you yesterday. We already have a SharingProvider https://github.com/cozy/cozy-libs/blob/master/packages/cozy-sharing/src/SharingProvider.jsx that doesn't do the same thing.

accept_from_flagship?: boolean
}
slug: string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should definitly stop adding types here but adding types to cozy-client. We have the type for the konnector https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/types/types.d.ts#L47 we should add the one for the app.

This current type miss a lot of stuff. You can find the all stuff here https://github.com/cozy/cozy-doctypes/blob/master/docs/io.cozy.apps.md and there https://docs.cozy.io/en/cozy-apps-registry/#properties-meaning-reference

By the way, you should update the documentation in order to add the new stuff in there.


export const fetchSharingCozyApps = {
definition: Q('io.cozy.apps').where({
'accept_documents_from_flagship.route_to_upload': { $exists: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not add the $exists:true but instead you should index on this attribute.

https://docs.cozy.io/en/tutorials/data/advanced/#indexes-why-is-my-document-not-being-retrieved

accept_from_flagship: true
}),
options: {
as: 'io.cozy.apps/fetchSharingCozyApps'
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not call the query by the functional meaning but by what it does: https://github.com/cozy/cozy-guidelines/#naming-of-queries

pathname: '',
slug,
subDomainType: session.subDomainType,
hash: hash.replace(/^\/?#?\//, ''),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to make this replace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's to handle route_to_upload looking like that: "route_to_upload": "/#/createfromFlagshipUpload=true". I did not find a way to handle it directly with the generateWebLink(). I agree it doesn't look great overall. Probably best to remove the leading /# in the manifest. I don't think the manifest has to be aware we are using hash router anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know, actually in the manifest, we can define a few routes. Those routes are used by the server, so if you create a /test route, then the url will be : foo.mycozy.cloud/test.

I don't know if it's a good idea to use /createfromFlagship directly in the manifest, since we can think this will be related to the server.

The manifest is at the intersection between the server and the front end app.

The manifest is linked to the app, so the manifest knows about the structure of the app and knows if the app use an hash router or not.

@Ldoppea do you have a better idea?

if (client === null) return

const route = getRouteToUpload(
fetchedApps as SharingCozyApp[],
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we ok to call this getRouteToUpload with a fetchedApps equals to null because fetchStatus===loading/pending/errored ?

Copy link
Contributor Author

@acezard acezard Aug 23, 2023

Choose a reason for hiding this comment

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

In my mind yes because it defers the null check to the low-level function (it will handle null or empty array data). That way the SharingProvider (to be renamed as we said) can focus on the user flow logic without too much coupling to data handling.

we can see the check here https://github.com/cozy/cozy-flagship-app/pull/899/files#diff-01d469baef9fd23e2cab7b642078293aea5526fbacdeb12c5c58c30f3c9f16a9R23

Copy link
Contributor

Choose a reason for hiding this comment

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

if you say so, but you have to deal with the fact that the request can fail (fetchStatus===errored) somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you say so, but you have to deal with the fact that the request can fail (fetchStatus===errored) somewhere.

true, I didn't test for this scenario.

  • To update

@acezard
Copy link
Contributor Author

acezard commented Aug 30, 2023

closing for better readability, every commit can be seen on the last branch/pr: #906 (every comment remains meaningful and will be updated on the main branch)

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.

3 participants