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

DnD with breadcrumbs #1836

Merged
merged 25 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0bcb2ee
readcrum refs and active colors
tanmoyAtb Dec 22, 2021
edd2942
lingui extract
actions-user Dec 25, 2021
910fc8c
breadcrumb component
tanmoyAtb Dec 25, 2021
045301b
Merge branch 'feat/tanmoy-breadcrumbs-as-dropzone-1772' of github.com…
tanmoyAtb Dec 25, 2021
9eaee7f
added breadcrumbs
tanmoyAtb Dec 25, 2021
8da8d57
colors
tanmoyAtb Dec 25, 2021
7e5212c
Merge branch 'dev' into feat/tanmoy-breadcrumbs-as-dropzone-1772
Tbaut Jan 3, 2022
a05c58b
removed logs
tanmoyAtb Jan 3, 2022
03736e0
Merge branch 'dev' into feat/tanmoy-breadcrumbs-as-dropzone-1772
Tbaut Jan 4, 2022
8d6afa9
merged
tanmoyAtb Jan 5, 2022
e4d184a
drag source hook update
tanmoyAtb Jan 5, 2022
432996b
removing crumb on latest folder
tanmoyAtb Jan 6, 2022
543c7fe
wip
tanmoyAtb Jan 6, 2022
c6f8167
ref system update
tanmoyAtb Jan 6, 2022
548d5c3
Update packages/common-components/src/Breadcrumb/Breadcrumb.tsx
tanmoyAtb Jan 6, 2022
15ee292
Update packages/files-ui/src/Utils/pathUtils.ts
tanmoyAtb Jan 6, 2022
c8d996e
Update packages/common-components/src/Breadcrumb/Breadcrumb.tsx
tanmoyAtb Jan 6, 2022
903eb7b
ternaries and logic
tanmoyAtb Jan 6, 2022
5b936d0
Merge branch 'dev' into feat/tanmoy-breadcrumbs-as-dropzone-1772
tanmoyAtb Jan 7, 2022
ed89b80
added classname generator
tanmoyAtb Jan 7, 2022
b1d5d55
Merge branch 'dev' into feat/tanmoy-breadcrumbs-as-dropzone-1772
Tbaut Jan 7, 2022
57d91bd
breadcrumb component
tanmoyAtb Jan 8, 2022
312c52a
resolved
tanmoyAtb Jan 8, 2022
2c0191c
comments
tanmoyAtb Jan 8, 2022
85b543f
Update packages/files-ui/src/Components/Modules/FileBrowsers/views/Fi…
tanmoyAtb Jan 10, 2022
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
92 changes: 57 additions & 35 deletions packages/common-components/src/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import { MenuDropdown } from "../MenuDropdown"

export type Crumb = {
text: string
path?: string
onClick?: () => void
forwardedRef?: React.Ref<HTMLDivElement>
active?: boolean
component?: React.ReactElement | null
}

export type BreadcrumbProps = {
crumbs?: Crumb[]
homeOnClick?: () => void
hideHome?: boolean
homeRef?: React.Ref<HTMLDivElement>
homeActive?: boolean
className?: string
showDropDown?: boolean
}
Expand All @@ -36,6 +42,7 @@ const useStyles = makeStyles(
},
home: {
height: 16,
width: "fit-content",
margin: "3px 0",
"& > svg": {
display: "block",
Expand Down Expand Up @@ -79,40 +86,65 @@ const useStyles = makeStyles(
textOverflow: "ellipsis"
},
menuTitle: {
padding: `0px ${constants.generalUnit}px 0px 0px`
padding: `0px ${constants.generalUnit * 1.5}px 0px ${constants.generalUnit * 0.5}px`
},
menuIcon: {
width: 12,
height: 12,
"& svg": {
height: 12,
width: 12
width: 12,
fill: palette.additional["gray"][9]
}
},
wrapper: {
border: "1px solid transparent",
padding: `0 ${constants.generalUnit * 0.5}px`,
"&.active": {
borderColor: palette.primary.main
}
},
fullWidth: {
width: "100%"
}
})
)

const Breadcrumb: React.FC<BreadcrumbProps> = ({
const CrumbComponent = ({ crumb }: {crumb: Crumb}) => {
const classes = useStyles()
return (
!crumb.component
? <div
ref={crumb.forwardedRef}
className={clsx(crumb.active && "active", classes.wrapper)}
>
<Typography
onClick={() => crumb.onClick && crumb.onClick()}
className={clsx(classes.crumb, crumb.onClick && "clickable")}
variant="body1"
>
{crumb.text}
</Typography>
</div>
: crumb.component
)
}

const Breadcrumb = ({
crumbs = [],
homeOnClick,
hideHome,
homeRef,
homeActive,
className,
showDropDown
}: BreadcrumbProps) => {
const classes = useStyles()

const generateFullCrumbs = (crumbs: Crumb[]) => {
return crumbs.map((item: Crumb, index: number) => (
return crumbs.map((crumb: Crumb, index: number) => (
<Fragment key={`crumb-${index}`}>
<div>
<Typography
onClick={() => (item.onClick ? item.onClick() : null)}
className={clsx(classes.crumb, item.onClick && "clickable")}
variant="body1"
>
{item.text}
</Typography>
</div>
<CrumbComponent crumb={crumb} />
{index < (crumbs.length - 1) && <div className={clsx(classes.separator)} />}
</Fragment>
))
Expand All @@ -131,14 +163,7 @@ const Breadcrumb: React.FC<BreadcrumbProps> = ({
titleText: classes.menuTitleText
}}
menuItems={crumbs.map((crumb) => ({
contents: (
<Typography
variant="body1"
onClick={() => (crumb.onClick ? crumb.onClick() : null)}
>
{crumb.text}
</Typography>
)
contents: <CrumbComponent crumb={crumb} />
}))}
/>
)
Expand All @@ -154,15 +179,7 @@ const Breadcrumb: React.FC<BreadcrumbProps> = ({
<>
{generateDropdownCrumb(dropdownCrumbs)}
<div className={clsx(classes.separator)} />
<div>
<Typography
onClick={() => (lastCrumb.onClick ? lastCrumb.onClick() : null)}
className={clsx(classes.crumb, lastCrumb.onClick && "clickable")}
variant="body1"
>
{lastCrumb.text}
</Typography>
</div>
<CrumbComponent crumb={lastCrumb} />
</>
)
}
Expand All @@ -171,11 +188,16 @@ const Breadcrumb: React.FC<BreadcrumbProps> = ({
return (
<div className={clsx(classes.root, className)}>
{!hideHome && <>
<HomeIcon
className={clsx(classes.home, homeOnClick && "clickable")}
onClick={() => (homeOnClick ? homeOnClick() : null)}
/>
<div className={clsx(classes.separator)} />
<div
ref={homeRef}
className={clsx(classes.wrapper, homeActive && "active")}
>
<HomeIcon
className={clsx(classes.home, homeOnClick && "clickable")}
onClick={() => homeOnClick && homeOnClick()}
/>
</div>
{!!crumbs.length && <div className={clsx(classes.separator)} />}
</>
}
{generateCrumbs()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const BreadcrumbStory = (): React.ReactNode => {
const crumbs = useMemo(() => ([
{
text: text("breadcrumb 2", "Level 1 Clickable"),
onClick: () => actionsData.linkClick()
onClick: () => actionsData.linkClick(),
active: boolean("breadcrumb-2-active", false)
},
{
text: "Level 2"
Expand All @@ -36,6 +37,7 @@ export const BreadcrumbStory = (): React.ReactNode => {
<>
<Breadcrumb
homeOnClick={() => actionsData.homeClicked()}
homeActive={boolean("home-active", false)}
showDropDown={boolean("show dropdown", true)}
crumbs={crumbs}
hideHome={boolean("hide home", false)}
Expand Down
2 changes: 1 addition & 1 deletion packages/common-theme/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json from "@rollup/plugin-json"
import nodePolyfills from "rollup-plugin-node-polyfills"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
import postcss from "rollup-plugin-postcss"
import copy from 'rollup-plugin-copy'
import copy from "rollup-plugin-copy"

export default {
input: "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/files-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"scripts": {
"postinstall": "yarn compile",
"start": "yarn compile && craco --max_old_space_size=4096 start",
"build": "craco --max_old_space_size=4096 --openssl-legacy-provider build ",
"build": "craco --max_old_space_size=4096 --openssl-legacy-provider build",
"sentry": "(export REACT_APP_SENTRY_RELEASE=$(sentry-cli releases propose-version); node scripts/sentry.js)",
"release": "(export REACT_APP_SENTRY_RELEASE=$(sentry-cli releases propose-version); yarn compile && yarn build && node scripts/sentry.js)",
"test": "cypress open",
Expand Down
101 changes: 54 additions & 47 deletions packages/files-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import { UserProvider } from "./Contexts/UserContext"
import { BillingProvider } from "./Contexts/BillingContext"
import { PosthogProvider } from "./Contexts/PosthogContext"
import { NotificationsProvider } from "./Contexts/NotificationsContext"
import { StylesProvider, createGenerateClassName } from "@material-ui/styles"

// making material and jss use one className generator
const generateClassName = createGenerateClassName({
productionPrefix: "c",
disableGlobal: true
})

if (
process.env.NODE_ENV === "production" &&
Expand Down Expand Up @@ -94,57 +101,57 @@ const App = () => {
), [])

return (

<ThemeSwitcher
storageKey="csf.themeKey"
themes={{ light: lightTheme, dark: darkTheme }}
>
<ErrorBoundary
fallback={fallBack}
onReset={() => window.location.reload()}
<StylesProvider generateClassName={generateClassName}>
<ThemeSwitcher
storageKey="csf.themeKey"
themes={{ light: lightTheme, dark: darkTheme }}
>
<CssBaseline />
<LanguageProvider availableLanguages={availableLanguages}>
<ToastProvider
autoDismiss
defaultPosition="bottomRight"
>
<Web3Provider
onboardConfig={onboardConfig}
checkNetwork={false}
cacheWalletSelection={canUseLocalStorage}
<ErrorBoundary
fallback={fallBack}
onReset={() => window.location.reload()}
>
<CssBaseline />
<LanguageProvider availableLanguages={availableLanguages}>
<ToastProvider
autoDismiss
defaultPosition="bottomRight"
>
<FilesApiProvider
apiUrl={apiUrl}
withLocalStorage={false}
<Web3Provider
onboardConfig={onboardConfig}
checkNetwork={false}
cacheWalletSelection={canUseLocalStorage}
>
<ThresholdKeyProvider
enableLogging={directAuthNetwork !== "mainnet"}
network={directAuthNetwork}
<FilesApiProvider
apiUrl={apiUrl}
withLocalStorage={false}
>
<NotificationsProvider>
<UserProvider>
<FilesProvider>
<BillingProvider>
<Router>
<PosthogProvider>
<AppWrapper>
<FilesRoutes />
</AppWrapper>
</PosthogProvider>
</Router>
</BillingProvider>
</FilesProvider>
</UserProvider>
</NotificationsProvider>
</ThresholdKeyProvider>
</FilesApiProvider>
</Web3Provider>
</ToastProvider>
</LanguageProvider>
</ErrorBoundary>
</ThemeSwitcher>

<ThresholdKeyProvider
enableLogging={directAuthNetwork !== "mainnet"}
network={directAuthNetwork}
>
<NotificationsProvider>
<UserProvider>
<FilesProvider>
<BillingProvider>
<Router>
<PosthogProvider>
<AppWrapper>
<FilesRoutes />
</AppWrapper>
</PosthogProvider>
</Router>
</BillingProvider>
</FilesProvider>
</UserProvider>
</NotificationsProvider>
</ThresholdKeyProvider>
</FilesApiProvider>
</Web3Provider>
</ToastProvider>
</LanguageProvider>
</ErrorBoundary>
</ThemeSwitcher>
</StylesProvider>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
extractFileBrowserPathFromURL,
getUrlSafePathWithFile,
getAbsolutePathsFromCids,
pathEndingWithSlash
pathEndingWithSlash,
joinArrayOfPaths
} from "../../../Utils/pathUtils"
import { IBulkOperations, IFileBrowserModuleProps, IFilesTableBrowserProps } from "./types"
import FilesList from "./views/FilesList"
Expand Down Expand Up @@ -145,14 +146,16 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {

// Breadcrumbs/paths
const arrayOfPaths = useMemo(() => getArrayOfPaths(currentPath), [currentPath])
const crumbs: Crumb[] = useMemo(() => arrayOfPaths.map((path, index) => ({
text: decodeURIComponent(path),
onClick: () => {
redirect(
ROUTE_LINKS.Drive(getURISafePathFromArray(arrayOfPaths.slice(0, index + 1)))
)
}
})), [arrayOfPaths, redirect])
const crumbs: Crumb[] = useMemo(() => arrayOfPaths.map((path, index) => {
return {
text: decodeURIComponent(path),
onClick: () => {
redirect(
ROUTE_LINKS.Drive(getURISafePathFromArray(arrayOfPaths.slice(0, index + 1)))
)
},
path: joinArrayOfPaths(arrayOfPaths.slice(0, index + 1))
}}), [arrayOfPaths, redirect])

const handleUploadOnDrop = useCallback(async (files: File[], fileItems: DataTransferItemList, path: string) => {
if (!bucket) return
Expand Down
Loading