-
Notifications
You must be signed in to change notification settings - Fork 22
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
[BIOMAGE-1273] Refactor ProjectDetails component #458
Merged
Merged
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e8f4518
some refactors
StefanBabukov 58c090e
move samples table to separate component
StefanBabukov c26ea16
changes
StefanBabukov a0da69c
changes
StefanBabukov 5d12627
refactor
StefanBabukov c1088a1
remove moved functions
StefanBabukov 2e6a589
merge
StefanBabukov 24db14e
merge
StefanBabukov ec9ed05
fix
StefanBabukov d063b2e
comment fixes
StefanBabukov 59306f1
comment fixes
StefanBabukov 49f84be
comment fix
StefanBabukov ee7f292
refactors
StefanBabukov 70813e5
merge conflicts
StefanBabukov b19623a
add more tests
StefanBabukov ae0a974
change
StefanBabukov f9a0f12
Merge branch 'master' into rework-project-details
StefanBabukov 38dcf8f
changes
StefanBabukov f8cf171
Merge branch 'rework-project-details' of https://github.com/biomage-l…
StefanBabukov ecb4e78
move download to util func
StefanBabukov 51fdbff
fixes
StefanBabukov 1ede5ec
Merge branch 'master' into rework-project-details
StefanBabukov a1c07ea
samples analysed also depends on the experimentSettings
StefanBabukov ac9c5c0
Merge branch 'rework-project-details' of https://github.com/biomage-l…
StefanBabukov 9d0fd62
remove package lock
StefanBabukov c75f030
actually idk if it should be there - its in master
StefanBabukov f8c855e
fix
StefanBabukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/__test__/redux/actions/projects/deleteMetadataTrack.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__test__/redux/actions/projects/updateMetadataTrack.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
import React, { useEffect } from 'react'; | ||
import _ from 'lodash'; | ||
import { | ||
Menu, Tooltip, Dropdown, Button, | ||
} from 'antd'; | ||
|
||
import { useSelector, useDispatch } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { saveAs } from 'file-saver'; | ||
import downloadTypes from 'utils/data-management/downloadTypes'; | ||
import { getFromApiExpectOK } from 'utils/getDataExpectOK'; | ||
import pushNotificationMessage from 'utils/pushNotificationMessage'; | ||
import endUserMessages from 'utils/endUserMessages'; | ||
import pipelineStatus from '../../utils/pipelineStatusValues'; | ||
import { exportQCParameters, filterQCParameters } from '../../utils/data-management/exportQCParameters'; | ||
import { loadBackendStatus } from '../../redux/actions/backendStatus/index'; | ||
|
||
const DownloadData = (props) => { | ||
const { | ||
activeProjectUuid, | ||
} = props; | ||
const dispatch = useDispatch(); | ||
const activeProject = useSelector((state) => state.projects[activeProjectUuid]); | ||
const experimentSettings = useSelector((state) => state.experimentSettings); | ||
const backendStatus = useSelector((state) => state.backendStatus); | ||
const samples = useSelector((state) => state.samples); | ||
const projects = useSelector((state) => state.projects); | ||
|
||
// Change if we have more than one experiment per project | ||
const experimentId = activeProject?.experiments[0]; | ||
|
||
useEffect(() => { | ||
if (experimentId) { | ||
dispatch(loadBackendStatus(experimentId)); | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, [activeProject]); | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const pipelineHasRun = () => ( | ||
experimentId | ||
&& (backendStatus[experimentId]?.status.pipeline?.status === pipelineStatus.SUCCEEDED) | ||
|
||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
const gem2sHasRun = () => ( | ||
experimentId | ||
&& (backendStatus[experimentId]?.status?.gem2s?.status === pipelineStatus.SUCCEEDED) | ||
); | ||
|
||
const allSamplesAnalysed = () => { | ||
// Returns true only if there is at least one sample in the currently active | ||
// project AND all samples in the project have been analysed. | ||
if (!activeProject?.samples?.length) { | ||
return false; | ||
} | ||
const steps = Object.values(_.omit(experimentSettings?.processing, ['meta'])); | ||
|
||
return steps.length > 0 | ||
// eslint-disable-next-line no-prototype-builtins | ||
&& activeProject?.samples?.every((s) => steps[0].hasOwnProperty(s)); | ||
}; | ||
|
||
const downloadExperimentData = async (type) => { | ||
try { | ||
if (!experimentId) throw new Error('No experimentId specified'); | ||
if (!Object.values(downloadTypes).includes(type)) throw new Error('Invalid download type'); | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const { signedUrl } = await getFromApiExpectOK(`/v1/experiments/${experimentId}/download/${type}`); | ||
const link = document.createElement('a'); | ||
link.style.display = 'none'; | ||
link.href = signedUrl; | ||
|
||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
setTimeout(() => { | ||
URL.revokeObjectURL(link.href); | ||
link.parentNode.removeChild(link); | ||
}, 0); | ||
} catch (e) { | ||
pushNotificationMessage('error', endUserMessages.ERROR_DOWNLOADING_DATA); | ||
} | ||
}; | ||
|
||
return ( | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Dropdown | ||
overlay={() => ( | ||
<Menu> | ||
<Menu.Item | ||
key='download-raw-seurat' | ||
disabled={!gem2sHasRun()} | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick={() => { | ||
downloadExperimentData(downloadTypes.RAW_SEURAT_OBJECT); | ||
}} | ||
> | ||
<Tooltip | ||
title={ | ||
gem2sHasRun() | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? 'Samples have been merged' | ||
: 'Launch analysis to merge samples' | ||
} | ||
placement='left' | ||
> | ||
Raw Seurat object (.rds) | ||
</Tooltip> | ||
</Menu.Item> | ||
<Menu.Item | ||
key='download-processed-seurat' | ||
disabled={ | ||
!pipelineHasRun() | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
onClick={() => { | ||
// Change if we have more than one experiment per project | ||
downloadExperimentData(downloadTypes.PROCESSED_SEURAT_OBJECT); | ||
}} | ||
> | ||
<Tooltip | ||
title={ | ||
pipelineHasRun(activeProject?.experiments[0]) | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? 'With Data Processing filters and settings applied' | ||
: 'Launch analysis to process data' | ||
} | ||
placement='left' | ||
> | ||
Processed Seurat object (.rds) | ||
</Tooltip> | ||
</Menu.Item> | ||
<Menu.Item | ||
disabled={!allSamplesAnalysed()} | ||
StefanBabukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
key='download-processing-settings' | ||
onClick={() => { | ||
const config = _.omit(experimentSettings.processing, ['meta']); | ||
const filteredConfig = filterQCParameters(config, activeProject.samples, samples); | ||
const blob = exportQCParameters(filteredConfig); | ||
saveAs(blob, `${activeProjectUuid.split('-')[0]}_settings.txt`); | ||
}} | ||
> | ||
{ | ||
allSamplesAnalysed() | ||
? 'Data Processing settings (.txt)' | ||
: ( | ||
<Tooltip title='One or more of your samples has yet to be analysed' placement='left'> | ||
Data Processing settings (.txt) | ||
</Tooltip> | ||
) | ||
} | ||
</Menu.Item> | ||
</Menu> | ||
)} | ||
trigger={['click']} | ||
placement='bottomRight' | ||
disabled={ | ||
projects.ids.length === 0 | ||
|| activeProject?.samples?.length === 0 | ||
} | ||
> | ||
<Button> | ||
Download | ||
</Button> | ||
</Dropdown> | ||
|
||
); | ||
}; | ||
|
||
DownloadData.propTypes = { | ||
activeProjectUuid: PropTypes.string.isRequired, | ||
}; | ||
export default React.memo(DownloadData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any unit tests for this component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add them as part of your next PR