Skip to content

Commit

Permalink
pipeline bugfixes; redirect to project after publishing (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosenb authored Jun 16, 2024
1 parent 5e4793e commit 99ba743
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function useCheckFilesForAssociation(

const hasAssociatedEnities = useMemo(() => {
if (!data) return false;
// Type Other can move associated files since associations are reset in the pipeline.
if (data.baseProject.value.projectType === 'other') return false;
const associatedFiles: string[] = [];
data?.entities.forEach((entity) => {
entity.value.fileObjs?.forEach((fo) => associatedFiles.push(fo.path));
Expand Down
1 change: 1 addition & 0 deletions client/modules/_hooks/src/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './useNotifications';
export { notifyContext, useNotifyContext } from './useNotifyContext';
9 changes: 9 additions & 0 deletions client/modules/_hooks/src/notifications/useNotifyContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React, { useContext } from 'react';
import { NotificationInstance } from 'antd/es/notification/interface';

export const notifyContext = React.createContext<{
notifyApi?: NotificationInstance;
contextHolder?: React.ReactElement;
}>({});

export const useNotifyContext = () => useContext(notifyContext);
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
useAmendProject,
useNotifyContext,
usePublishProject,
useVersionProject,
} from '@client/hooks';
import { Button, Checkbox, Input, Modal } from 'antd';
import { Button, Checkbox, Input, Modal, Tag } from 'antd';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';

export const PipelinePublishModal: React.FC<{
projectId: string;
Expand All @@ -28,17 +30,34 @@ export const PipelinePublishModal: React.FC<{
const { mutate: publishMutation } = usePublishProject();
const { mutate: amendMutation } = useAmendProject();
const { mutate: versionMutation } = useVersionProject();
const navigate = useNavigate();
const { notifyApi } = useNotifyContext();
const successCallback = () => {
navigate(`/projects/${projectId}`);
notifyApi?.open({
type: 'success',
message: '',
description: 'Your publication request has been submitted',
placement: 'bottomLeft',
});
};

const doPublish = () => {
switch (operation) {
case 'publish':
publishMutation({ projectId, entityUuids });
publishMutation(
{ projectId, entityUuids },
{ onSuccess: successCallback }
);
break;
case 'amend':
amendMutation({ projectId });
amendMutation({ projectId }, { onSuccess: successCallback });
break;
case 'version':
versionMutation({ projectId, entityUuids, versionInfo });
versionMutation(
{ projectId, entityUuids, versionInfo },
{ onSuccess: successCallback }
);
break;
}
};
Expand Down Expand Up @@ -73,31 +92,67 @@ export const PipelinePublishModal: React.FC<{
width="60%"
open={isModalOpen}
footer={() => (
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<span>
<Checkbox
id="publication-agreement-checkbox"
checked={publishingAgreement}
onChange={(e) => setPublishingAgreement(e.target.checked)}
/>
<label htmlFor="publication-agreement-checkbox">
&nbsp;I agree
</label>
</span>
<Button
disabled={!canPublish}
onClick={doPublish}
type="primary"
className="success-button"
<div>
{operation === 'version' && (
<div style={{ textAlign: 'start', margin: '10px 0px' }}>
{' '}
<label
htmlFor="version-info-input"
style={{ display: 'flex', alignItems: 'center' }}
>
Version Changes&nbsp;
<Tag
color="#d9534f"
style={{
borderRadius: '2.7px',
lineHeight: 1,
paddingInline: 0,
padding: '0.2em 0.4em 0.3em',
fontSize: '75%',
}}
>
Required
</Tag>
</label>{' '}
<div>
Specify what files you are adding, removing, or replacing, and
why these changes are needed. This will be displayed to those
viewing your publication, so be detailed and formal in your
explanation.
</div>
<Input.TextArea
autoSize={{ minRows: 3 }}
onChange={(e) => setVersionInfo(e.target.value)}
id="version-info-input"
/>
</div>
)}
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
{publishButtonText[operation]}
</Button>
<span>
<Checkbox
id="publication-agreement-checkbox"
checked={publishingAgreement}
onChange={(e) => setPublishingAgreement(e.target.checked)}
/>
<label htmlFor="publication-agreement-checkbox">
&nbsp;I agree
</label>
</span>
<Button
disabled={!canPublish}
onClick={doPublish}
type="primary"
className="success-button"
>
{publishButtonText[operation]}
</Button>
</div>
</div>
)}
onCancel={handleCancel}
Expand Down Expand Up @@ -356,24 +411,6 @@ export const PipelinePublishModal: React.FC<{
issues that may arise from the publication.
</p>
</div>
{operation === 'version' && (
<>
{' '}
<label htmlFor="version-info-input">
Version Changes (required)
</label>{' '}
<div>
Specify what files you are adding, removing, or replacing, and why
these changes are needed. This will be displayed to those viewing
your publication, so be detailed and formal in your explanation.
</div>
<Input.TextArea
autoSize={{ minRows: 3 }}
onChange={(e) => setVersionInfo(e.target.value)}
id="version-info-input"
/>
</>
)}
</Modal>
</>
);
Expand Down
51 changes: 28 additions & 23 deletions client/src/datafiles/layouts/DataFilesBaseLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { Layout } from 'antd';
import { Layout, notification } from 'antd';
import { AddFileFolder, DatafilesSideNav } from '@client/datafiles';
import { useAuthenticatedUser } from '@client/hooks';
import { useAuthenticatedUser, notifyContext } from '@client/hooks';

const { Sider } = Layout;

Expand All @@ -13,28 +13,33 @@ const DataFilesRoot: React.FC = () => {
: '/tapis/designsafe.storage.community';
const { pathname } = useLocation();

const [notifyApi, contextHolder] = notification.useNotification();

return (
<Layout
hasSider
style={{
backgroundColor: 'transparent',
gap: '20px',
paddingLeft: '20px',
paddingRight: '20px',
//overflowX: 'auto',
//overflowY: 'hidden',
}}
>
<Sider width={200} theme="light" breakpoint="md" collapsedWidth={0}>
<h1 className="headline headline-research" id="headline-data-depot">
<span className="hl hl-research">Data Depot</span>
</h1>
<AddFileFolder />
<DatafilesSideNav />
</Sider>
{pathname === '/' && <Navigate to={defaultPath} replace></Navigate>}
<Outlet />
</Layout>
<notifyContext.Provider value={{ notifyApi, contextHolder }}>
{contextHolder}
<Layout
hasSider
style={{
backgroundColor: 'transparent',
gap: '20px',
paddingLeft: '20px',
paddingRight: '20px',
//overflowX: 'auto',
//overflowY: 'hidden',
}}
>
<Sider width={200} theme="light" breakpoint="md" collapsedWidth={0}>
<h1 className="headline headline-research" id="headline-data-depot">
<span className="hl hl-research">Data Depot</span>
</h1>
<AddFileFolder />
<DatafilesSideNav />
</Sider>
{pathname === '/' && <Navigate to={defaultPath} replace></Navigate>}
<Outlet />
</Layout>
</notifyContext.Provider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def publish_project(
pub_tree.nodes[node]["value"]["dois"] = [doi]

if not settings.DEBUG:
copy_publication_files(path_mapping, project_id)
copy_publication_files(path_mapping, project_id, version=version)
for doi in new_dois:
publish_datacite_doi(doi)

Expand Down

0 comments on commit 99ba743

Please sign in to comment.