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: Add a Badge to the first konnector folder #3312

Merged
merged 1 commit into from
Jan 30, 2025
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
1 change: 1 addition & 0 deletions src/lib/doctypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DOCTYPE_ALBUMS = 'io.cozy.photos.albums'
export const DOCTYPE_PHOTOS_SETTINGS = 'io.cozy.photos.settings'
export const DOCTYPE_APPS = 'io.cozy.apps'
export const DOCTYPE_CONTACTS = 'io.cozy.contacts'
export const DOCTYPE_KONNECTORS = 'io.cozy.konnectors'
export const DOCTYPE_CONTACTS_VERSION = 2

export const schema = {
Expand Down
81 changes: 81 additions & 0 deletions src/modules/filelist/icons/BadgeKonnector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import PropTypes from 'prop-types'
import React from 'react'

import {
getReferencedBy,
isQueryLoading,
isReferencedBy,
useQuery
} from 'cozy-client'
import AppIcon from 'cozy-ui/transpiled/react/AppIcon'
import Badge from 'cozy-ui/transpiled/react/Badge'
import { makeStyles } from 'cozy-ui/transpiled/react/styles'

import { DOCTYPE_KONNECTORS } from 'lib/doctypes'
import { buildFileByIdQuery } from 'queries'

const getKonnectorSlugFromFile = file => {
const konnector = getReferencedBy(file, DOCTYPE_KONNECTORS)[0]
if (konnector) {
return konnector.id.split('/')[1]
}
return null
}

const useStyle = makeStyles({
badge: {
backgroundColor: 'var(--white)',
JF-Cozy marked this conversation as resolved.
Show resolved Hide resolved
height: '1.5rem',
minWidth: '1.5rem',
borderRadius: '0.375rem',
border: '1px solid var(--borderMainColor)'
},
appIcon: {
width: '75%',
height: '75%'
},
anchorOriginBottomRightCircular: {
bottom: '10px'
}
})

export const BadgeKonnector = ({ file, children }) => {
const { badge, anchorOriginBottomRightCircular, appIcon } = useStyle()
const konnectorSlug = getKonnectorSlugFromFile(file)

// Check if the parent folder is a konnector folder, because if have no file in your account folder, its considered as a konnector folder
const parentFolderQuery = buildFileByIdQuery(file.dir_id)
const { data: parentFolder, ...parentQueryQueryLeft } = useQuery(
parentFolderQuery.definition,
parentFolderQuery.options
)
Merkur39 marked this conversation as resolved.
Show resolved Hide resolved
const isparentQueryLoading = isQueryLoading(parentQueryQueryLeft)
const hasKonnectorParentFolder = isReferencedBy(
parentFolder,
DOCTYPE_KONNECTORS
)

if (isparentQueryLoading || hasKonnectorParentFolder) {
return <>{children}</>
}

return (
<Badge
classes={{ badge, anchorOriginBottomRightCircular }}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
badgeContent={
<AppIcon
className={appIcon}
type="konnector"
app={{ slug: konnectorSlug }}
/>
}
>
{children}
</Badge>
)
}

BadgeKonnector.propTypes = {
file: PropTypes.object.isRequired
}
45 changes: 32 additions & 13 deletions src/modules/filelist/icons/FileThumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { models } from 'cozy-client'
import { isReferencedBy, models } from 'cozy-client'
import { isDirectory } from 'cozy-client/dist/models/file'
import { SharedBadge, SharingOwnerAvatar } from 'cozy-sharing'
import Box from 'cozy-ui/transpiled/react/Box'
Expand All @@ -13,6 +13,8 @@ import Spinner from 'cozy-ui/transpiled/react/Spinner'

import IconServer from 'assets/icons/icon-type-server.svg'
import type { File, FolderPickerEntry } from 'components/FolderPicker/types'
import { DOCTYPE_KONNECTORS } from 'lib/doctypes'
import { BadgeKonnector } from 'modules/filelist/icons/BadgeKonnector'
import FileIcon from 'modules/filelist/icons/FileIcon'
import FileIconMime from 'modules/filelist/icons/FileIconMime'
import { SharingShortcutIcon } from 'modules/filelist/icons/SharingShortcutIcon'
Expand Down Expand Up @@ -77,21 +79,38 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
const isSimpleFile =
!isSharingShortcut && !isRegularShortcut && !isInSyncFromSharing
const isFolder = isSimpleFile && isDirectory(file)
const isKonnectorFolder = isReferencedBy(file, DOCTYPE_KONNECTORS)

if (isFolder && size && size >= 48)
if (isFolder) {
if (size && size >= 48) {
return (
<Box
width={size}
height={size}
bgcolor="var(--contrastBackgroundColor)"
borderRadius={8}
display="flex"
alignItems="center"
justifyContent="center"
>
{isKonnectorFolder ? (
<BadgeKonnector file={file}>
<FileIcon file={file} size={48} isEncrypted={isEncrypted} />
</BadgeKonnector>
) : (
<FileIcon file={file} size={48} isEncrypted={isEncrypted} />
)}
</Box>
)
}
}
if (isKonnectorFolder) {
return (
<Box
width={size}
height={size}
bgcolor="var(--contrastBackgroundColor)"
borderRadius={8}
display="flex"
alignItems="center"
justifyContent="center"
>
<FileIcon file={file} size={48} isEncrypted={isEncrypted} />
</Box>
<BadgeKonnector file={file}>
<FileIcon file={file} size={size} isEncrypted={isEncrypted} />
</BadgeKonnector>
)
}

return (
<>
Expand Down
3 changes: 2 additions & 1 deletion src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ export const buildFileByIdQuery: QueryBuilder<string> = fileId => ({
options: {
as: `io.cozy.files/${fileId}`,
fetchPolicy: defaultFetchPolicy,
singleDocData: true
singleDocData: true,
enabled: !!fileId
}
})

Expand Down
Loading