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(Viewer): Support for io.cozy.bills #2636

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions assets/icons/ui/file-duotone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
"babel-preset-cozy-app": "2.0.2",
"browserslist-config-cozy": "0.4.0",
"copyfiles": "2.4.1",
"cozy-client": "^46.10.0",
"cozy-client": "^47.6.0",
"cozy-device-helper": "2.0.0",
"cozy-flags": "^2.10.1",
"cozy-harvest-lib": "^6.7.3",
"cozy-intent": "1.16.1",
"cozy-logger": "^1.9.0",
"cozy-sharing": "^3.10.0",
"cozy-stack-client": "^45.0.1",
"cozy-stack-client": "^47.4.0",
"css-loader": "0.28.11",
"cssnano": "4.1.11",
"cssnano-preset-advanced": "4.0.8",
Expand Down Expand Up @@ -181,7 +181,7 @@
"rooks": "^5.11.2"
},
"peerDependencies": {
"cozy-client": ">=45.15.0",
"cozy-client": ">=47.6.0",
"cozy-device-helper": "^2.0.0",
"cozy-harvest-lib": "^6.7.3",
"cozy-intent": ">=1.3.0",
Expand Down
10 changes: 1 addition & 9 deletions react/Icons/FileDuotone.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// Automatically created, please run `scripts/generate-svg-icon.sh assets/icons/ui/file-duotone.svg` to regenerate;
// Automatically created, please run `scripts/generate-svgr-icon.sh assets/icons/ui/file-duotone.svg` to regenerate;
import React from 'react'

function SvgFileDuotone(props) {
return (
<svg viewBox="0 0 26 32" {...props}>
<g fillRule="evenodd">
<path
d="M0 2.002C0 .896.89 0 1.997 0H19l7 7v22.996A2 2 0 0124.003 32H1.997A1.995 1.995 0 010 29.998C.048 16 0 16 0 2.002z"
fill="#FFF"
/>
<path
d="M18.5 0c-.276 0-.5.23-.5.5V8h7.5c.276 0 .5-.232.5-.5V7l-7-7h-.5z"
fill="#FFF"
/>
<path
d="M0 2.002C0 .896.89 0 1.997 0H19l7 7v22.996A2 2 0 0124.003 32H1.997A1.995 1.995 0 010 29.998C.048 16 0 16 0 2.002z"
opacity={0.242}
Expand Down
8 changes: 4 additions & 4 deletions react/QualificationGrid/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import QualificationItem from '../QualificationItem'
import { useI18n } from '../providers/I18n'
import PeopleIcon from '../Icons/People'
import TeamIcon from '../Icons/Team'
import CompanyIcon from '../Icons/Company'
import WorkIcon from '../Icons/Work'
import ChessIcon from '../Icons/Chess'
import HeartIcon from '../Icons/Heart'
import HomeIcon from '../Icons/Home'
import CarIcon from '../Icons/Car'
import CompassIcon from '../Icons/Compass'
import BankIcon from '../Icons/Bank'
import BillIcon from '../Icons/Bill'
import DotsIcon from '../Icons/Dots'
Expand All @@ -21,11 +21,11 @@ import { getThemesList } from './helpers'
const IconByName = {
people: PeopleIcon,
team: TeamIcon,
company: CompanyIcon,
work: WorkIcon,
heart: HeartIcon,
home: HomeIcon,
car: CarIcon,
compass: CompassIcon,
chess: ChessIcon,
bank: BankIcon,
bill: BillIcon,
dots: DotsIcon
Expand Down
5 changes: 3 additions & 2 deletions react/Viewer/Panel/ActionMenuWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
editPath
)
const isAppLinkLoaded = fetchStatus === 'loaded'
const isEditable = Boolean(editPath) && isEditableAttribute(name, file)

const handleCopy = async () => {
try {
Expand Down Expand Up @@ -70,7 +71,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
return (
<ActionMenuMobile
onClose={onClose}
isEditable={Boolean(editPath) && isEditableAttribute(name, file)}
isEditable={isEditable}
actions={{ handleCopy, handleEdit }}
appLink={url}
appSlug={mespapiersAppSlug}
Expand All @@ -82,7 +83,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
<ActionMenuDesktop
ref={ref}
onClose={onClose}
isEditable={Boolean(editPath) && isEditableAttribute(name, file)}
isEditable={isEditable}
actions={{ handleCopy, handleEdit }}
appLink={url}
appSlug={mespapiersAppSlug}
Expand Down
18 changes: 16 additions & 2 deletions react/Viewer/Panel/Qualification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import {
isExpiringSoon,
formatMetadataQualification,
KNOWN_BILLS_ATTRIBUTES_NAMES,
getMetadataQualificationType
} from 'cozy-client/dist/models/paper'

Expand All @@ -20,7 +21,8 @@ const ComponentFromMetadataQualificationType = {
contact: QualificationListItemContact,
date: QualificationListItemDate,
information: QualificationListItemInformation,
other: QualificationListItemOther
other: QualificationListItemOther,
bills: QualificationListItemInformation
}

const isExpirationAlertHidden = file => {
Expand Down Expand Up @@ -48,8 +50,20 @@ const Qualification = ({ file }) => {
}

const formattedMetadataQualification = useMemo(() => {
const relatedBills = file.bills?.data?.[0]

if (relatedBills) {
const formattedBillsMetadata = KNOWN_BILLS_ATTRIBUTES_NAMES.map(
attrName => ({ name: attrName, value: relatedBills[attrName] })
)

return formatMetadataQualification(metadata).concat(
formattedBillsMetadata
)
}

return formatMetadataQualification(metadata)
}, [metadata])
}, [metadata, file.bills?.data])

useEffect(() => {
actionBtnRef.current = formattedMetadataQualification.map(
Expand Down
1 change: 1 addition & 0 deletions react/Viewer/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const files = [
type: 'file',
name: 'My vehicle registration.pdf',
mime: 'application/pdf',
bills: { data: [{ amount: '500' }] },
metadata: {
carbonCopy: true,
AObtentionDate: null,
Expand Down
16 changes: 9 additions & 7 deletions react/Viewer/helpers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { models, generateWebLink } from 'cozy-client'
import { generateWebLink } from 'cozy-client'

const {
import {
isEncrypted,
isFromKonnector,
hasQualifications,
hasCertifications,
normalize
} = models.file
} from 'cozy-client/dist/models/file'

const {
import {
KNOWN_DATE_METADATA_NAMES,
KNOWN_INFORMATION_METADATA_NAMES
} = models.paper
KNOWN_INFORMATION_METADATA_NAMES,
KNOWN_BILLS_ATTRIBUTES_NAMES
} from 'cozy-client/dist/models/paper'

export const getCurrentModel = metadataName => {
if (
KNOWN_DATE_METADATA_NAMES.includes(metadataName) ||
KNOWN_INFORMATION_METADATA_NAMES.includes(metadataName)
KNOWN_INFORMATION_METADATA_NAMES.includes(metadataName) ||
KNOWN_BILLS_ATTRIBUTES_NAMES.includes(metadataName)
) {
return 'information'
}
Expand Down
2 changes: 0 additions & 2 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2697,8 +2697,6 @@ exports[`IconStack should render examples: IconStack 1`] = `
"<div data-testid=\\"mountNode\\">
<div class=\\"styles__IconStack-wrapper___10dhG optional-bg-wrapper-class\\"><svg viewBox=\\"0 0 26 32\\" class=\\"styles__icon___23x3R\\" style=\\"fill: blue;\\" width=\\"32\\" height=\\"32\\">
<g fill-rule=\\"evenodd\\">
<path d=\\"M0 2.002C0 .896.89 0 1.997 0H19l7 7v22.996A2 2 0 0124.003 32H1.997A1.995 1.995 0 010 29.998C.048 16 0 16 0 2.002z\\" fill=\\"#FFF\\"></path>
<path d=\\"M18.5 0c-.276 0-.5.23-.5.5V8h7.5c.276 0 .5-.232.5-.5V7l-7-7h-.5z\\" fill=\\"#FFF\\"></path>
<path d=\\"M0 2.002C0 .896.89 0 1.997 0H19l7 7v22.996A2 2 0 0124.003 32H1.997A1.995 1.995 0 010 29.998C.048 16 0 16 0 2.002z\\" opacity=\\"0.242\\"></path>
<path d=\\"M18.5 0c-.276 0-.5.23-.5.5V8h7.5c.276 0 .5-.232.5-.5V7l-7-7h-.5z\\"></path>
</g>
Expand Down
27 changes: 9 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6087,16 +6087,16 @@ cozy-bi-auth@0.0.23:
lodash "^4.17.20"
node-jose "^1.1.4"

cozy-client@^46.10.0:
version "46.10.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-46.10.0.tgz#7d3bb11b77ce79ec09df156d21cab19983b90d37"
integrity sha512-zS6COIbERCBgNnj37cYvj901D9osfEX0AbcnOyFw3tMzJV0nrOidbDU5sg9SLrsd7gIKhkR2w7nN/TN6eNOz4g==
cozy-client@^47.6.0:
version "47.6.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-47.6.0.tgz#ed151e75003aa3eeda657d398d18958aadaa6e1c"
integrity sha512-hBALCB//rdMg2bj3k8dVHRaYFG0CQ7vF9u58BufYuNoJFB4HKh9R/KFSXH0+wkvDjUOK4olYjoz+7xH6bZmEPQ==
dependencies:
"@cozy/minilog" "1.0.0"
"@types/jest" "^26.0.20"
"@types/lodash" "^4.14.170"
btoa "^1.2.1"
cozy-stack-client "^46.5.0"
cozy-stack-client "^47.4.0"
date-fns "2.29.3"
json-stable-stringify "^1.0.1"
lodash "^4.17.13"
Expand Down Expand Up @@ -6206,19 +6206,10 @@ cozy-sharing@^3.10.0:
react-tooltip "^3.11.1"
snarkdown "^2.0.0"

cozy-stack-client@^45.0.1:
version "45.0.1"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-45.0.1.tgz#4028aad131e40b7ba58528b39e411028bfd319d0"
integrity sha512-VWBbBdGmsnzxarQhUFUbnQZn4VxgWp98umUpSF9PexNmBTwvHG7eNH64/1GaChQjc7xhe8yggzCeQ7wyjQsq0g==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^46.5.0:
version "46.5.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-46.5.0.tgz#9c15410a4b98cfe556b5fac4dfc8ac0f0e2de763"
integrity sha512-OmspOAWGozpi7sZG1Mi9PAeNEUgi/JpCy4f3l6O2wnfKamW8x+iaZWRofJhS5rqPfpRW2XbMkJjq9Yz3xOgv0A==
cozy-stack-client@^47.4.0:
version "47.4.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-47.4.0.tgz#db58f19ecc1f3a4100d24648ca9f87a4a825b6fe"
integrity sha512-hwk//fVrM05GZmRodYTQel7tvpK+NZ6gDn1gkpYmjaLvG8hN24PskeWr5+a6iBNzlO1FtDh7qQ1/jU5vw7v6zg==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
Expand Down