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

Search results handle folders: proper PR #1994

Merged
merged 2 commits into from
Dec 17, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const Section = M.styled(M.Paper)(({ theme: t }) => ({
position: 'relative',
[t.breakpoints.down('xs')]: {
borderRadius: 0,
borderTop: `1px solid ${t.palette.divider}`,
padding: t.spacing(2),
},
[t.breakpoints.up('sm')]: {
Expand Down
65 changes: 47 additions & 18 deletions catalog/app/components/SearchResults/SearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const CrumbLink = M.styled(StyledLink)({ wordBreak: 'break-word' })

function ObjectCrumbs({ handle, showBucket = false }) {
const { urls } = NamedRoutes.use()
const isDir = handle.key.endsWith('/')

const crumbs = React.useMemo(() => {
const all = getBreadCrumbs(handle.key)
Expand All @@ -55,7 +56,9 @@ function ObjectCrumbs({ handle, showBucket = false }) {

return (
<span onCopy={copyWithoutSpaces}>
<HeaderIcon title="File">insert_drive_file</HeaderIcon>
<HeaderIcon title={isDir ? 'Directory' : 'File'}>
{isDir ? 'folder_open' : 'insert_drive_file'}
</HeaderIcon>
{crumbs.bucket && (
<>
<CrumbLink {...crumbs.bucket} />
Expand Down Expand Up @@ -85,12 +88,12 @@ function HeaderIcon(props) {
)
}

function ObjectHeader({ handle, showBucket, downloadable }) {
function ObjectHeader({ handle, showBucket, downloadable = false }) {
return (
<Heading display="flex" alignItems="center" mb={1}>
<Heading display="flex" alignItems="center" mb="0 !important">
<ObjectCrumbs {...{ handle, showBucket }} />
<M.Box flexGrow={1} />
{downloadable &&
{!!downloadable &&
AWS.Signer.withDownloadUrl(handle, (url) => (
<M.Box
alignItems="center"
Expand Down Expand Up @@ -190,7 +193,7 @@ function VersionInfo({ bucket, path, version, versions }) {
}

return (
<>
<M.Box mt={1}>
<M.Typography variant="subtitle1" className={classes.versionContainer}>
<Nowrap>
Version{' '}
Expand Down Expand Up @@ -238,7 +241,7 @@ function VersionInfo({ bucket, path, version, versions }) {
))}
</SmallerSection>
)}
</>
</M.Box>
)
}

Expand Down Expand Up @@ -458,7 +461,12 @@ function RevisionInfo({ bucket, handle, hash, comment, lastModified }) {
)
}

function ObjectHit({ showBucket, hit: { path, versions, bucket } }) {
function ObjectHit({ hit, ...props }) {
const Component = hit.path.endsWith('/') ? DirHit : FileHit
return <Component {...{ hit, ...props }} />
}

function FileHit({ showBucket, hit: { path, versions, bucket } }) {
const cfg = Config.use()
const s3 = AWS.S3.use()

Expand Down Expand Up @@ -492,6 +500,23 @@ function ObjectHit({ showBucket, hit: { path, versions, bucket } }) {
)
}

function DirHit({
showBucket,
hit: {
path,
versions: [v],
bucket,
},
}) {
const handle = { bucket, key: path }
return (
<Section>
<ObjectHeader {...{ handle, showBucket }} />
<Meta meta={v.meta} />
</Section>
)
}

function PackageHit({
showBucket,
hit: { bucket, handle, hash, lastModified, meta, tags, comment },
Expand All @@ -515,7 +540,7 @@ function PackageHit({
}

export function Hit(props) {
const Component = props.hit.type === 'object' ? ObjectHit : PackageHit
const Component = props.hit.type === 'package' ? PackageHit : ObjectHit
return <Component {...props} />
}

Expand Down Expand Up @@ -552,16 +577,20 @@ export function Hits({
)
}

export function Alt({ ...props }) {
return (
<M.Box
borderTop={{ xs: 1, sm: 0 }}
borderColor="divider"
pt={3}
px={{ xs: 2, sm: 0 }}
{...props}
/>
)
const useAltStyles = M.makeStyles((t) => ({
root: {
paddingTop: t.spacing(3),
[t.breakpoints.down('xs')]: {
borderTop: `1px solid ${t.palette.divider}`,
paddingLeft: t.spacing(2),
paddingRight: t.spacing(2),
},
},
}))

export function Alt({ className, ...props }) {
const classes = useAltStyles()
return <M.Box className={cx(className, classes.root)} {...props} />
}

export function Progress({ children }) {
Expand Down