-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add expiration helpers #1274
Add expiration helpers #1274
Conversation
d536b79
to
d611451
Compare
return true | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should start coding differently, something more declarative instead of having those imperative if
... We should only rely on a configuration file and the code will do the rest:
const config = [
'frenchNationalCard: {
'isExpiring': true,
'expiringCondition': file => ....
}
]
Like that there is no need to update the code if we want to add a new paper, change expiring condition or else. We just have to edit this config. If we think even further this config can be a json file served directly by the cozy. Like that even the PO will be able to edit by him/herself the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original approach was indeed to declare everything in a JSON (see paperDefinitions
in the first commit, that is later removed), but we discussed extensively between devs and decided to move away from a declarative coding since the conditions to determine if a given paper expires and how to compute their expiration and notice dates are already very different.
For each relevant paper, the expiring condition is different because we use different attributes and not as many. Moreover the way we compute dates is also already different, with different fallback behavior and default delays. Making something purely declarative and thus generic would need many parameters and add noise in my opinion. As you first suggested it is easier to define dedicated methods for each paper anyway, so at this point i don't really see the benefit to define either a very complex JSON config that won't really be extensible in practice or methods instead of functions.
Note that we also discussed this with the PO and confirmed that were was no need for them to be able to edit themselves a config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we discussed extensively between devs and decided to move away from a declarative coding
Attention à ne pas mélanger tous les sujets. A mon sens lors de nos échanges nous n'avons pas exclu spécifiquement le fait du faire du déclaratif de manière absolu. Là dessus, par défaut, perso je suis pas fermé.
Maintenant le fait que ce soit facile ou pas, et pertinent ou non (ce que tu évoques), et la modif via un PO (dont on a parlé aussi) sont d'autres points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we discussed extensively between devs and decided to move away from a declarative coding since the conditions to determine if a given paper expires and how to compute their expiration and notice dates are already very different.
I don't buy this argument. Each entry of the config has its own conditions and expiration methods. This is totally normal.
Since you discussed that extensively, do you have a written conclusion to share?
We have a few declarative instructions in Drive & Harvest for this kind of stuff and this is very powerful, useful and help us a lot with the maintenance and scalability.
Note that we also discussed this with the PO and confirmed that were was no need for them to be able to edit themselves a config.
As for today. Not in the future.
In my opinion this kind of development is much more better in a declarative form and the config is much more readable than having a lot of if / else condition. Also, creating this "magical function" is maybe a bit harder but not so much, and writing test for it it's pretty easy.
To go further, I really don't like the fact to publish a new Cozy Client version each time we add a qualification label and now every time we add an expiration to something. Having a declarative way of doing it will give us the opportunity to have a better solution for that.
I understand that this is not the path you chose, I'll not block this PR for that, but next time please add me in the thinking loop either by creating a SEC and putting other in the loop.
return 'https://www.service-public.fr/particuliers/vosdroits/F1029' | ||
} | ||
return null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Those code should be inside the config.
d611451
to
8f6cc27
Compare
exemple de déclaratif :
|
8f6cc27
to
300685f
Compare
c0f1780
to
8fe24c3
Compare
Some of the changes since the latest review:
I also opened an alternate PR with a final refactor at #1281 that could land instead of this one, or separately afterwards. |
@@ -170,6 +171,11 @@ import { QueryDefinition } from './queries/dsl' | |||
* @property {object} [schema] - the schema used by prosemirror (with notes and marks serialized as arrays to preserve the order). | |||
* @property {string} [title] - the initial title of the note (that will also be used for the file name) | |||
* @property {number} [version] - Number of a note | |||
* @property {Qualification} [qualification] - Qualification of the file | |||
* @property {string} [country] - Country of the paper | |||
* @property {string} [expirationDate] - Expiration date of the paper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String? Are-you sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expiration date is currently set by the user in an date field in Mes Papiers and stored as is in the metadata. So yes this is a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe we should update the doc? https://github.com/cozy/cozy-doctypes/blob/4c8913dfe8ccba9ab80fd5b656a389d828120127/docs/io.cozy.files_metadata.md?plain=1#L132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware of this document. I have no strong opinion. I mean, this is a date, indeed, but formatted as a string. So for the purpose of type checking in JSDOC this is a string (unless we want to narrow it with template literal types), but conceptually this is a date, so that's not wrong to describe it like this in the documentation you pointed to.
* @property {Qualification} [qualification] - Qualification of the file | ||
* @property {string} [country] - Country of the paper | ||
* @property {string} [expirationDate] - Expiration date of the paper | ||
* @property {string} [referencedDate] - Reference date of the paper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference date is also provided by the user as a string.
Can you squash few commits please? I think it's not useful here to have the refactor between I think having 3 commits can be great:
|
8fe24c3
to
a6b74bd
Compare
I added a description for each helper to clarify what they do, and imported |
packages/cozy-client/package.json
Outdated
@@ -51,7 +52,7 @@ | |||
"cozy-flags": "2.10.2", | |||
"cozy-logger": "1.7.0", | |||
"cozy-ui": "48.0.0", | |||
"date-fns": "2.27.0", | |||
"date-fns": "2.29.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Vu qu'on l'ajoute en dep, aucune raison de la garder en devDep
|
||
/** | ||
* @typedef {import("../types").IOCozyFile} IOCozyFile | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
This extracts and rewrites expiration helpers from `mespapiers` that will be used directly in `cozy-ui`, `cozy-mespapiers-lib` and also `mespapiers`. This avoids using `paperDefinitions` as a config. It may not be generic enough in the future and we don't have any need for that right now. This also removes the need to pass a `dateLabel` argument to these helpers. This also adds new helpers, one giving the notice link if available, and two other for comparing dates. This also removes the default notice period, meaning that papers won't be considered as expiring if the user has not set any notice period and that the alert won't appear and no notification will be sent.
a6b74bd
to
b6722a3
Compare
Since the cozy-client upgrade to 34.7.1 date-fns is a needed dep for a few of its models. But we don't need them in Drive for now and we have a few issues with the tree shaking of cozy-client. (see cozy/cozy-client#1274) So the workaround is to force the resolution to date-fns 1 which is required by drive, in order to not duplicate the package. We should not have issue with that. When we'll upgrade date-fns to v2 in drive & ui, then, we'll be able to remove this line.
In order to enhance the cozy-client tree shaking, we should avoind importing * and exporting. We had an issue with this PR #1274 because this PR adds date-fns v2 as dep, but even if the consuming app doesn't use the concerned model it was imported. BREAKING CHANGE: You can not use import { models } from cozy-client ... models.files.func() You have to change it to: import { func } from cozy-client/dist/models/files
Since the cozy-client upgrade to 34.7.1 date-fns is a needed dep for a few of its models. But we don't need them in Drive for now and we have a few issues with the tree shaking of cozy-client. (see cozy/cozy-client#1274) So the workaround is to force the resolution to date-fns 1 which is required by drive, in order to not duplicate the package. We should not have issue with that. When we'll upgrade date-fns to v2 in drive & ui, then, we'll be able to remove this line.
This extracts and reimplements many helpers from
mespapiers
that were initially implemented in cozy/mespapiers#329 and also add new ones.The rationale behind this change is to be able to use these helpers in the viewer (
cozy-ui
and thus alsomespapiers
andcozy-drive
) and alsocozy-mespapiers-lib
, instead of only be able to use them formespapiers
services.