Skip to content

Commit

Permalink
[frontend] fix entity link and occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
SouadHadjiat committed Oct 6, 2023
1 parent f70f0e1 commit 6841080
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { hexToRGB, itemColor } from '../../../utils/Colors';
import ItemMarkings from '../../../components/ItemMarkings';
import { getFileUri } from '../../../utils/utils';
import { resolveLink } from '../../../utils/Entity';
import useGranted, { KNOWLEDGE_KNGETEXPORT, KNOWLEDGE_KNUPLOAD } from '../../../utils/hooks/useGranted';

const useStyles = makeStyles<Theme>((theme) => ({
item: {
Expand Down Expand Up @@ -52,6 +53,11 @@ const SearchIndexedFileLineComponent: FunctionComponent<SearchIndexedFileLineCom
}) => {
const classes = useStyles();
const { fd, t } = useFormatter();
let entityLink = node.entity ? `${resolveLink(node.entity.entity_type)}/${node.entity.id}` : '';
const isGrantedToFiles = useGranted([KNOWLEDGE_KNUPLOAD, KNOWLEDGE_KNGETEXPORT]);
if (entityLink && isGrantedToFiles) {
entityLink = entityLink.concat('/files')
}
return (
<ListItem
classes={{ root: classes.item }}
Expand Down Expand Up @@ -80,14 +86,14 @@ const SearchIndexedFileLineComponent: FunctionComponent<SearchIndexedFileLineCom
{fd(node.uploaded_at)}
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.occurrences.width }}
className={classes.bodyItem}
style={{ width: dataColumns.occurrences.width }}
>
{node.searchOccurrences}
{(node.searchOccurrences && node.searchOccurrences > 99) ? '99+' : node.searchOccurrences}
</div>
<div
className={classes.bodyItem}
style={{ width: dataColumns.entity_type.width }}
className={classes.bodyItem}
style={{ width: dataColumns.entity_type.width }}
>
{node.entity && (
<Chip
Expand All @@ -106,7 +112,7 @@ const SearchIndexedFileLineComponent: FunctionComponent<SearchIndexedFileLineCom
style={{ width: dataColumns.entity_name.width }}
>
{node.entity && (
<Link to={`${resolveLink(node.entity.entity_type)}/${node.entity.id}/files`}>
<Link to={entityLink}>
<span>{node.entity?.representative.main}</span>
</Link>
)}
Expand Down

0 comments on commit 6841080

Please sign in to comment.