///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools // // Copyright (C) 2013 - 2024, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// import { Box } from '@mui/material'; import { styled } from '@mui/material/styles'; import React, { useState, useEffect } from 'react'; import AccountTreeIcon from '@mui/icons-material/AccountTree'; import CommentIcon from '@mui/icons-material/Comment'; import ArrowForwardIosRoundedIcon from '@mui/icons-material/ArrowForwardIosRounded'; import { usePgAdmin } from '../../../static/js/BrowserComponent'; import usePreferences from '../../../preferences/static/js/store'; const StyledBox = styled(Box)(({theme}) => ({ position: 'absolute', bottom: 0, width: 'auto', maxWidth: '99%', zIndex: 1004, padding: '0.25rem 0.5rem', fontSize: '0.95em', color: theme.palette.background.default, backgroundColor: theme.palette.text.primary, borderTopRightRadius: theme.shape.borderRadius, '& .ObjectBreadcrumbs-row': { display: 'flex', alignItems: 'center', '& .ObjectBreadcrumbs-overflow': { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden', } }, })); export default function ObjectBreadcrumbs() { const pgAdmin = usePgAdmin(); const preferences = usePreferences().getPreferencesForModule('browser'); const [objectData, setObjectData] = useState({ path: null, description: null, }); const onItemHover = (item, _data)=>{ if(item && !_data?._type.startsWith('coll-')) { setObjectData({ path: pgAdmin.Browser.tree.getNodeDisplayPath(item, false), description: item?._metadata?.data.description }); } else { setObjectData({ path: null, description: null }); } }; useEffect(()=>{ if(preferences.breadcrumbs_enable) { pgAdmin.Browser.Events.on('pgadmin-browser:tree:hovered', onItemHover); } return ()=>{ pgAdmin.Browser.Events.off('pgadmin-browser:tree:hovered', onItemHover); }; }, [preferences.breadcrumbs_enable]); if(!objectData.path) { return <>; } return (
{ objectData.path?.reduce((res, item, i)=>( res.concat({item}, ) ), []).slice(0, -1) }
{preferences.breadcrumbs_show_comment && objectData.description &&
{objectData.description}
}
); }