Skip to content
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

Add custom message for cell metadata upload not ready #963

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions src/components/data-management/LaunchAnalysisButton.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useCallback, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import {
Button, Tooltip, Popconfirm,
Button, Tooltip, Popconfirm, Typography, Space,
} from 'antd';
import _ from 'lodash';

Expand All @@ -12,25 +12,9 @@ import integrationTestConstants from 'utils/integrationTestConstants';

import { useAppRouter } from 'utils/AppRouteProvider';
import calculatePipelinesRerunStatus from 'utils/data-management/calculatePipelinesRerunStatus';
import { WarningOutlined } from '@ant-design/icons';

const LaunchButtonTemplate = (props) => {
const {
// eslint-disable-next-line react/prop-types
onClick, disabled, text, loading,
} = props;

return (
<Button
data-test-id={integrationTestConstants.ids.PROCESS_PROJECT_BUTTON}
type='primary'
disabled={disabled}
onClick={onClick}
loading={loading}
>
{text}
</Button>
);
};
const { Text } = Typography;

const LaunchAnalysisButton = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -127,6 +111,57 @@ const LaunchAnalysisButton = () => {
activeExperiment.cellLevelMetadata?.uploadStatus,
]);

const getAllExperimentSampleFiles = useCallback(() => (
activeExperiment.sampleIds.flatMap((sampleId) => Object.values(samples[sampleId]?.files ?? {}))
), [samples, activeExperiment?.sampleIds]);

const getAnyFileUploadFailed = useCallback(() => {
const nonErrorStatuses = [UploadStatus.UPLOADED, UploadStatus.UPLOADING];

const cellLevelUploadError = !_.isNil(activeExperiment.cellLevelMetadata)
&& !nonErrorStatuses.includes(activeExperiment.cellLevelMetadata.uploadStatus);

const sampleFileUploadError = getAllExperimentSampleFiles()
.some((sampleFile) => !nonErrorStatuses.includes(sampleFile.upload.status));

return cellLevelUploadError || sampleFileUploadError;
}, [
samples,
activeExperiment?.sampleIds,
activeExperiment.cellLevelMetadata,
]);

const LaunchButtonTemplate = (props) => {
const {
// eslint-disable-next-line react/prop-types
onClick, disabled, text, loading,
} = props;

return (
<Button
data-test-id={integrationTestConstants.ids.PROCESS_PROJECT_BUTTON}
type='primary'
disabled={disabled}
onClick={onClick}
loading={loading}
>
{
getAnyFileUploadFailed() ? (
<Space>
<Text type='danger'>
<WarningOutlined />
</Text>
{text}
</Space>
) : (
text
)
}

</Button>
);
};

const renderLaunchButton = () => {
let buttonText;

Expand All @@ -143,9 +178,12 @@ const LaunchAnalysisButton = () => {
}

if (!canLaunchAnalysis()) {
const message = !cellLevelMetadataIsReady
? 'Ensure that the cell level metadata file is uploaded correctly'
: 'Ensure that all samples are uploaded successfully and all relevant metadata is inserted.';
return (
<Tooltip
title='Ensure that all samples are uploaded successfully and all relevant metadata is inserted.'
title={message}
>
{/* disabled button inside tooltip causes tooltip to not function */}
{/* https://github.com/react-component/tooltip/issues/18#issuecomment-140078802 */}
Expand Down
Loading