Skip to content

Commit

Permalink
feat: Allow click on searched file's path
Browse files Browse the repository at this point in the history
In the search, we display the folder path for files results.
It is not possible to click on it, to directly open the folder rather
than the file itself.
  • Loading branch information
paultranvan authored and cballevre committed Nov 14, 2024
1 parent 7135435 commit 13f29a9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/assistant/ResultMenu/ResultMenuContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ const SearchResult = () => {
<ResultMenuItem
key={result.id || idx}
icon={result.icon}
slug={result.slug}
primaryText={result.primary}
secondaryText={result.secondary}
secondaryUrl={result.secondaryUrl}
query={searchValue}
highlightQuery="true"
selected={
Expand Down
10 changes: 9 additions & 1 deletion src/assistant/ResultMenu/ResultMenuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import ListItem from 'cozy-ui/transpiled/react/ListItem'
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
import SuggestionItemTextHighlighted from './SuggestionItemTextHighlighted'
import SuggestionItemTextSecondary from './SuggestionItemTextSecondary'

const ResultMenuItem = ({
icon,
primaryText,
secondaryText,
secondaryUrl,
slug,
selected,
onClick,
query,
Expand All @@ -32,7 +35,12 @@ const ResultMenuItem = ({
)

const secondary = highlightQuery ? (
<SuggestionItemTextHighlighted text={secondaryText} query={query} />
<SuggestionItemTextSecondary
text={secondaryText}
query={query}
slug={slug}
url={secondaryUrl}
/>
) : (
secondaryText
)
Expand Down
46 changes: 46 additions & 0 deletions src/assistant/ResultMenu/SuggestionItemTextSecondary.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Code copied and adapted from cozy-drive
*
* See source: https://github.com/cozy/cozy-drive/blob/fbe2df67199683b23a40f476ccdacb00ee027459/src/modules/search/components/SuggestionItemTextSecondary.jsx
*/
import React from 'react'

import AppLinker from 'cozy-ui/transpiled/react/AppLinker'
import SuggestionItemTextHighlighted from './SuggestionItemTextHighlighted'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'

import styles from './styles.styl'

const SuggestionItemTextSecondary = ({ text, query, url, slug }) => {
const { isMobile } = useBreakpoints()

if (isMobile || !url) {
return <SuggestionItemTextHighlighted text={text} query={query} />
}

const app = { slug }
return (
<AppLinker app={app} href={url}>
{({ href, onClick }) => (
<a
className={styles['suggestion-item-parent-link']}
href={href}
onClick={e => {
e.stopPropagation()
if (typeof onClick == 'function') {
onClick(e)
}
}}
>
<SuggestionItemTextHighlighted
text={text}
query={query}
slug={slug}
/>
</a>
)}
</AppLinker>
)
}

export default SuggestionItemTextSecondary
7 changes: 7 additions & 0 deletions src/assistant/ResultMenu/styles.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
&-inner
max-height 16.5rem
overflow auto

.suggestion-item-parent-link
color var(--primaryTextColor)
text-decoration none

&:hover
text-decoration underline
2 changes: 2 additions & 0 deletions src/assistant/Search/useFetchResult.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const useFetchResult = searchValue => {
return {
id: r.doc._id,
icon: icon,
slug: r.slug,
secondaryUrl: r.secondaryUrl,
primary: r.title,
secondary: r.subTitle,
onClick: () => {
Expand Down

0 comments on commit 13f29a9

Please sign in to comment.