Skip to content

Commit

Permalink
#1497 added Path column for extended view of observations
Browse files Browse the repository at this point in the history
  • Loading branch information
matej-vavrek committed Sep 30, 2024
1 parent dedd836 commit 238b5c2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions js/components/preview/molecule/moleculeView/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import { DJANGO_CONTEXT } from '../../../../utils/djangoContext';
import { getFontColorByBackgroundColor } from '../../../../utils/colors';
import { api, METHOD } from '../../../../utils/api';
import { base_url } from '../../../routes/constants';
import { ContentCopyRounded } from '@mui/icons-material';
import { ToastContext } from '../../../toast';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -411,6 +413,7 @@ const MoleculeView = memo(
const [tagEditModalOpenNew, setTagEditModalOpenNew] = useState(tagEditorOpenObs);

const { getNglView } = useContext(NglContext);
const { toastInfo } = useContext(ToastContext);
const stage = getNglView(VIEWS.MAJOR_VIEW) && getNglView(VIEWS.MAJOR_VIEW).stage;

const isLigandOn = L;
Expand Down Expand Up @@ -465,6 +468,7 @@ const MoleculeView = memo(
const [moleculeTooltipOpen, setMoleculeTooltipOpen] = useState(false);
const [tagPopoverOpen, setTagPopoverOpen] = useState(null);
const [centroidRes, setCentroidRes] = useState('');
const [experimentalPath, setExperimentalPath] = useState('');

const moleculeImgRef = useRef(null);

Expand Down Expand Up @@ -514,6 +518,26 @@ const MoleculeView = memo(
});
}, [data.canon_site_conf]);

useEffect(() => {
api({
url: `${base_url}/api/experiments/`,
method: METHOD.GET
})
.then(resp => {
const experiment = resp.data.results.find(experiment => experiment.id === data.experiment);
if (experiment) {
setExperimentalPath(experiment.pdb_info_source_file ?? '');
} else {
console.log('there is not any matching canonSiteConf object with ' + data.experiment + ' id');
setExperimentalPath('');
}
})
.catch(err => {
console.log('error fetching experiment from experiments api', err);
setExperimentalPath('');
});
}, [data.experiment]);

useEffect(() => {
if (showExpandedView) {
setHeaderWidthsHandler(centroidRes, 'CentroidRes');
Expand Down Expand Up @@ -1134,6 +1158,11 @@ const MoleculeView = memo(
return tagTooltip;
}, [getTagType]);

const copyExperimentalPaths = async () => {
await navigator.clipboard.writeText(experimentalPath);
toastInfo('Link was copied to the clipboard', { autoHideDuration: 5000 });
};

return (
<>
<Grid
Expand Down Expand Up @@ -1503,6 +1532,13 @@ const MoleculeView = memo(
{data.longcode}
</Grid>
</Tooltip>
<Tooltip title={experimentalPath.length > 0 ? experimentalPath : 'empty path'}>
<Grid item align="center" style={{ minWidth: headerWidths.Path }}>
<IconButton color="inherit" onClick={copyExperimentalPaths} size="small">
<ContentCopyRounded fontSize="small" />
</IconButton>
</Grid>
</Tooltip>
</Grid>}
</Grid >
<SvgTooltip
Expand Down
4 changes: 4 additions & 0 deletions js/components/preview/molecule/observationsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export const ObservationsDialog = memo(
CrystalformSites: getCalculatedTagColumnWidth('CrystalformSites'),
CentroidRes: getCalculatedTagColumnWidth('CentroidRes'),
LongCode: getCalculatedTagColumnWidth('LongCode'),
Path: getCalculatedTagColumnWidth('Path')
});

/**
Expand Down Expand Up @@ -1001,6 +1002,9 @@ export const ObservationsDialog = memo(
<Grid item align="center" className={classes.headerCell} style={{ minWidth: headerWidths.LongCode }}>
LongCode
</Grid>
<Grid item align="center" className={classes.headerCell} style={{ minWidth: headerWidths.Path }}>
Path
</Grid>
</Grid>
)}
</Grid>
Expand Down

0 comments on commit 238b5c2

Please sign in to comment.