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

Show users at the top of shared folders browser #1388

Merged
merged 14 commits into from
Aug 4, 2021
53 changes: 0 additions & 53 deletions packages/files-ui/src/Components/Elements/SharedUser.tsx

This file was deleted.

72 changes: 72 additions & 0 deletions packages/files-ui/src/Components/Elements/SharedUsers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { useCallback, useMemo } from "react"
import { makeStyles, createStyles, useThemeSwitcher } from "@chainsafe/common-theme"
import UserBubble from "./UserBubble"
import { BucketUser } from "@chainsafe/files-api-client"
import { BucketKeyPermission } from "../../Contexts/FilesContext"

const useStyles = makeStyles(() => {
return createStyles({
root: {
display: "flex"
}
})
})
interface Props {
bucket: BucketKeyPermission
}

const SharedUsers = ({ bucket }: Props) => {
const classes = useStyles()
const { desktop } = useThemeSwitcher()
const { owners, readers, writers } = bucket

const getUserIds = useCallback((users?: BucketUser[]): string[] => {
if(!users) return []

return users.reduce((acc: string[], user): string[] => {
return user.uuid ? [...acc, user.uuid] : acc
}, [] as string[])
}, [])

const userIds = useMemo(() =>
[
...getUserIds(owners),
...getUserIds(readers),
...getUserIds(writers)
],
[owners, readers, writers, getUserIds])

if (!userIds.length) {
return null
}

if (!desktop) {
return <div className={classes.root}>
<UserBubble
text={`+${userIds.length}`}
tooltip={userIds}
/>
</div>
}

return (
<div className={classes.root}>
<UserBubble
tooltip={userIds[0]}
/>
{userIds.length > 2 && (
<UserBubble
text={`+${userIds.length - 1}`}
tooltip={userIds.slice(0, -1)}
/>
)}
{userIds.length === 2 && (
<UserBubble
tooltip={userIds[1]}
/>
)}
</div>
)
}

export default SharedUsers
4 changes: 1 addition & 3 deletions packages/files-ui/src/Components/Elements/UserBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ const useStyles = makeStyles(({ zIndex, animation, constants, palette }: CSFThem
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
left: "50%",
top: "-20px",
bottom: constants.generalUnit * 5 + 5, //bubble height + the 5 from the triangle in &:after
position: "absolute",
transform: "translate(-50%, -50%)",
zIndex: zIndex?.layer1,
transitionDuration: `${animation.transform}ms`,
opacity: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import {
UserShareSvg
} from "@chainsafe/common-components"
import { CSFTheme } from "../../../../../Themes/types"
import { BucketUser } from "@chainsafe/files-api-client"
import { desktopSharedGridSettings, mobileSharedGridSettings } from "../../SharedFoldersOverview"
import SharedUsers from "../../../../Elements/SharedUser"
import SharedUsers from "../../../../Elements/SharedUsers"
import { t, Trans } from "@lingui/macro"
import { Form, FormikProvider, useFormik } from "formik"
import clsx from "clsx"
Expand Down Expand Up @@ -200,14 +199,6 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS
click(e)
}

const getUserIds = (users: BucketUser[]): string[] => {
return users.reduce((acc: string[], user): string[] => {
return user.uuid ? [...acc, user.uuid] : acc
}, [] as string[])
}

const userIds = [...getUserIds(bucket.owners), ...getUserIds(bucket.readers), ...getUserIds(bucket.writers)]

const formik = useFormik({
initialValues:{
fileName: name
Expand Down Expand Up @@ -284,7 +275,7 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS
align="left"
className={classes.sharedUser}
>
<SharedUsers sharedUsers={userIds}/>
<SharedUsers bucket={bucket}/>
</TableCell>
{desktop &&
<TableCell align="left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { DragPreviewLayer } from "./DragPreviewLayer"
import { useFileBrowser } from "../../../../Contexts/FileBrowserContext"
import ReportFileModal from "../ReportFileModal"
import CopyToSharedFolderModal from "../CopyToSharedFolderModal"
import SharedUsers from "../../../Elements/SharedUsers"

const baseOperations: FileOperation[] = ["download", "info", "preview"]
const readerOperations: FileOperation[] = [...baseOperations, "report"]
Expand Down Expand Up @@ -82,7 +83,6 @@ const useStyles = makeStyles(
borderColor: palette.primary.main
}
}
// transitionDuration: `${animation.transform}ms`,
},
header: {
display: "flex",
Expand Down Expand Up @@ -276,6 +276,11 @@ const useStyles = makeStyles(
width: "20px",
height: "20px"
}
},
users: {
flex: 1,
display: "flex",
justifyContent: "flex-end"
}
})
}
Expand Down Expand Up @@ -632,6 +637,11 @@ const FilesList = ({ isShared = false }: Props) => {
>
{heading}
</Typography>
{isShared && bucket && (
<div className={classes.users}>
<SharedUsers bucket={bucket}/>
</div>
)}
<div className={classes.controls}>
{controls && desktop ? (
<>
Expand Down