-
Notifications
You must be signed in to change notification settings - Fork 36
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 panel #2294
Merged
Merged
Add expiration panel #2294
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
18cd43d
feat: Update `cozy-client` to 34.4.0
PolariTOON 7705cae
feat: Add an `ExpirationAnnotation` component
PolariTOON 763790d
feat: Add expiration annotations to date qualifications
PolariTOON 36d019d
feat: Add an `ExpirationAlert` component
PolariTOON 2afb445
feat: Add the expiration alert to the qualification block
PolariTOON 27fff18
fix: Require `file` prop in `Qualification`
PolariTOON a12d0d8
docs: Add an example of a file with many panel blocks in the viewer
PolariTOON File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Add an
ExpirationAlert
component
- Loading branch information
commit 36d019d33655aa8ce2f81a2187b5e1d0f6ac0ef4
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { useClient, models } from 'cozy-client' | ||
|
||
import Alert from '../../Alert' | ||
import Button from '../../Buttons' | ||
import Link from '../../Link' | ||
import Typography from '../../Typography' | ||
import { withViewerLocales } from '../hoc/withViewerLocales' | ||
import { useI18n } from '../../I18n' | ||
import { formatLocallyDistanceToNow } from '../../I18n/format' | ||
|
||
const FILES_DOCTYPE = 'io.cozy.files' | ||
|
||
const { computeExpirationDate, computeExpirationNoticeLink } = models.paper | ||
|
||
const ExpirationAlert = ({ file }) => { | ||
const { t } = useI18n() | ||
const client = useClient() | ||
const [isBusy, setIsBusy] = useState(false) | ||
|
||
const handleClose = async () => { | ||
setIsBusy(true) | ||
await client.collection(FILES_DOCTYPE).updateMetadataAttribute(file.id, { | ||
...file.metadata, | ||
hideExpirationAlert: true | ||
}) | ||
setIsBusy(false) | ||
} | ||
|
||
const expirationDate = computeExpirationDate(file) | ||
const expirationNoticeLink = computeExpirationNoticeLink(file) | ||
|
||
return ( | ||
<Alert | ||
severity="warning" | ||
block | ||
action={ | ||
<Button | ||
color="warning" | ||
variant="text" | ||
size="small" | ||
busy={isBusy} | ||
label={t('Viewer.panel.expiration.dismiss')} | ||
onClick={handleClose} | ||
/> | ||
} | ||
className="u-mt-1 u-mh-1" | ||
> | ||
<Typography component="span" variant="inherit"> | ||
<Typography component="span" variant="inherit"> | ||
{t('Viewer.panel.expiration.description', { | ||
duration: formatLocallyDistanceToNow(expirationDate) | ||
})} | ||
</Typography> | ||
{expirationNoticeLink && ( | ||
<> | ||
<Typography component="span" variant="inherit"> | ||
{' : '} | ||
</Typography> | ||
<Link | ||
href={expirationNoticeLink} | ||
rel="noreferrer" | ||
target="_blank" | ||
className="u-warning" | ||
> | ||
{new URL(expirationNoticeLink).hostname} | ||
</Link> | ||
</> | ||
)} | ||
</Typography> | ||
</Alert> | ||
) | ||
} | ||
|
||
ExpirationAlert.propTypes = { | ||
file: PropTypes.object.isRequired | ||
} | ||
|
||
export default withViewerLocales(ExpirationAlert) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
à voir si on a n'a pas déjà des constantes quelque part, ici ou dans cozy-client...
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.
Je ne vois pas d'endroit en particulier d'où il serait exporté, mais si un tel endroit n'existe pas, il faut avouer que ça serait sans doute bien de tout y centraliser plutôt que de redéfinir les constantes à chaque fois dans chaque lib / app.
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.
N'allait pas trop loin dans la mutualisation, y a des trucs qui font sens, d'autres non. Le KISS impose de temps en temps de dupliquer du code, et y a rien de mal à ça. Importer une constante depuis un autre package qui définit déjà une autre constante (car on peut considérer
io.cozy.files
comme une constante déjà), ça n'a que très très peu d'intérêt. Voir aucun en fait ? 🤔