Skip to content

Commit

Permalink
Merge pull request #538 from NASA-IMPACT/develop
Browse files Browse the repository at this point in the history
Production deployment
  • Loading branch information
sunu authored Aug 30, 2023
2 parents 2d30968 + 90c2911 commit 8df03c5
Show file tree
Hide file tree
Showing 27 changed files with 727 additions and 411 deletions.
23 changes: 17 additions & 6 deletions app/assets/scripts/components/common/confirmation-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,25 @@ export const confirmationDeleteControls = createBinaryControlsRenderer({
* track of. Useful to know what confirmation we're working with.
*/
export const confirmDeleteDocumentVersion = async (name, version) => {
return showConfirmationPrompt({
title: 'Delete this document version?',
content: (
let title = 'Delete this document version?';
let content = (
<p>
The version <strong>{version}</strong> of document <strong>{name}</strong>{' '}
will be deleted.
</p>
);
if (version === 'v1.0') {
title = 'Delete this document?';
content = (
<p>
The version <strong>{version}</strong> of document{' '}
<strong>{name}</strong> will be deleted.
The document <strong>{name}</strong> will be{' '}
<strong>permanently deleted</strong>. Do you want to proceed?
</p>
),
);
}
return showConfirmationPrompt({
title,
content,
renderControls: confirmationDeleteControls
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DocumentCommentsButton from '../documents/document-comment-button';
import { documentView } from '../../utils/url-creator';
import { computeAtbdVersion } from '../../context/atbds-list';
import getDocumentIdKey from '../documents/get-document-id-key';
import { resolveTitle } from '../../utils/common';

function DocumentDashboardEntry(props) {
const { atbd, onDocumentAction } = props;
Expand Down Expand Up @@ -77,7 +78,7 @@ function DocumentDashboardEntry(props) {
to={documentView(atbd, lastVersion.version)}
title={`View ${atbd.title}`}
>
{atbd.title}
{resolveTitle(atbd.title)}
</Link>
</DocumentEntryTitle>
<DocumentEntryNav role='navigation'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ export default function DocumentActionsMenu(props) {
<MenuItemReasonDisabled
{...props}
// A document can only be deleted:
// - By a curator
// - By the owner when in draft
// - By the owner or curator when in draft
// Whether or not it is the owner is checked by the rules. Here we check the
// status to be able to show a message because disabling it in the rules
// would remove the button.
isDisabled={!isCurator && !isDraftEquivalent(atbdVersion)}
tipMessage='It is not possible to delete document that is not in Draft'
isDisabled={!isDraftEquivalent(atbdVersion)}
tipMessage='It is not possible to delete documents that are not in Draft.'
/>
)
};
Expand Down
3 changes: 2 additions & 1 deletion app/assets/scripts/components/documents/document-headline.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DateButton } from '../common/date';
import { CollaboratorsMenu } from './collaborators-menu';
import DocumentCommentsButton from './document-comment-button';

import { resolveTitle } from '../../utils/common';
import { Can, useContextualAbility } from '../../a11n';
import { useUser } from '../../context/user';
import { documentEdit, documentView } from '../../utils/url-creator';
Expand Down Expand Up @@ -105,7 +106,7 @@ export default function DocumentHeadline(props) {
<InpageHeadHgroup>
<TruncatedInpageTitle>
<Link to={documentView(atbd, version)} title={`View ${title}`}>
{title}
{resolveTitle(title)}
</Link>
</TruncatedInpageTitle>
<InpageHeadNav role='navigation'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import getDocumentIdKey from '../get-document-id-key';
import { computeAtbdVersion } from '../../../context/atbds-list';
import { SafeReadEditor } from '../../slate';
import { truncateSlateObject } from '../../slate/plugins/common/text-utils';
import { resolveTitle } from '../../../utils/common';

const getDropChange = (label) => (isOpen) =>
isOpen &&
Expand Down Expand Up @@ -63,7 +64,7 @@ function DocumentHubEntry(props) {
<CardHeader>
<CardHeadline>
<CardHgroup>
<CardTitle>{atbd.title}</CardTitle>
<CardTitle>{resolveTitle(atbd.title)}</CardTitle>
<CardToolbar>
{atbd.document_type === 'PDF' && (
<BsFilePdf title='PDF type document' />
Expand Down
17 changes: 15 additions & 2 deletions app/assets/scripts/components/documents/new-atbd-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { glsp } from '@devseed-ui/theme-provider';

import FormInfoTip from '../common/forms/form-info-tooltip';
import { useDocumentCreate } from '../documents/single-edit/use-document-create';
import { resolveTitle } from '../../utils/common';
import { formString } from '../../utils/strings';

const StyledFormInput = styled(FormInput)`
width: 100%;
Expand Down Expand Up @@ -65,7 +67,12 @@ function NewATBDModal(props) {
content={
<ModalContent>
<FormGroup>
<FormLabel htmlFor='atbd-title'>ATBD Title</FormLabel>
<FormLabel htmlFor='atbd-title'>
ATBD Title{' '}
<FormInfoTip
title={formString('identifying_information.title')}
/>
</FormLabel>
<StyledFormInput
id='atbd-title'
type='text'
Expand All @@ -74,9 +81,15 @@ function NewATBDModal(props) {
onChange={handleTitleInputChange}
autoFocus
/>
<h4>Preview: {resolveTitle(title)}</h4>
</FormGroup>
<FormGroup>
<FormLabel htmlFor='atbd-alias'>Alias</FormLabel>
<FormLabel htmlFor='atbd-alias'>
Alias{' '}
<FormInfoTip
title={formString('identifying_information.alias')}
/>
</FormLabel>
<StyledFormInput
id='atbd-alias'
type='text'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import RecoverToast from './recover-toast';

export function LocalStore({ atbd }) {
const isInitialized = useRef();
const toastId = useRef();
const toastId = useRef(null);
const { values, setValues, dirty } = useFormikContext();
const { step } = useParams();

const stepId = step || 'identifying_information';
const [isOutDated, setIsOutDated] = useState(false);

const removeToast = useCallback(() => {
toast.dismiss(toastId.current);
toastId.current = null;
if (toastId.current !== null) {
toast.dismiss(toastId.current);
toastId.current = null;
}
}, []);

const recoverData = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DOCUMENT_SECTIONS = [
{ id: 'version_description', label: 'Version Information' },
{ id: 'citation', label: 'Citation' },
{ id: 'contacts', label: 'Contacts' },
{ id: 'reviewer_info', label: 'Reviewer Information' },
{ id: 'attachment', label: 'Attachment' },
{ id: 'introduction', label: 'Introduction' },
{ id: 'context_background', label: 'Context / Background' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React, { useCallback, useEffect } from 'react';
import T from 'prop-types';
import set from 'lodash.set';
import { Formik, Form as FormikForm } from 'formik';
import get from 'lodash.get';
import { FieldArray, Formik, Form as FormikForm } from 'formik';
import { Form } from '@devseed-ui/form';
import { GlobalLoading } from '@devseed-ui/global-loading';
import { glsp } from '@devseed-ui/theme-provider';
import styled from 'styled-components';

import { Inpage, InpageBody } from '../../../../styles/inpage';
import {
FormBlock,
FormBlockHeading,
FormSectionNotes
} from '../../../../styles/form-block';
import { FormikSectionFieldset } from '../../../common/forms/section-fieldset';
import {
FormikSectionFieldset,
SectionFieldset
} from '../../../common/forms/section-fieldset';
import ContactsList from './contacts-list';
import { Link } from '../../../../styles/clean/link';

Expand All @@ -23,6 +29,17 @@ import { getDocumentSectionLabel } from '../sections';
import { documentEdit } from '../../../../utils/url-creator';
import { LocalStore } from '../local-store';
import { FormikUnloadPrompt } from '../../../common/unload-prompt';
import { FormikInputText } from '../../../common/forms/input-text';
import { DeletableFieldset } from '../../../common/forms/deletable-fieldset';
import { FieldMultiItem } from '../../../common/forms/field-multi-item';

const emptyAffiliation = '';

const BasicInfoSection = styled.div`
display: grid;
grid-gap: ${glsp()};
grid-template-columns: 1fr 1fr;
`;

export default function StepContacts(props) {
const { renderInpageHeader, renderFormFooter, atbd, id, version, step } =
Expand Down Expand Up @@ -131,6 +148,58 @@ export default function StepContacts(props) {
</FormSectionNotes>
<ContactsList contactsList={contacts.data} />
</FormikSectionFieldset>
<SectionFieldset
label={getDocumentSectionLabel('reviewer_info')}
>
<BasicInfoSection>
<FormikInputText
id='reviewer_info.first_name'
name='reviewer_info.first_name'
label='First name'
/>
<FormikInputText
id='reviewer_info.last_name'
name='reviewer_info.last_name'
label='Last name'
/>
<FormikInputText
id='reviewer_info.email'
name='reviewer_info.email'
label='Email'
/>
</BasicInfoSection>
<FieldArray
name='reviewer_info.affiliations'
render={({ remove, push, form, name: affFieldName }) => {
const fieldValues = get(form.values, affFieldName) || [];
return (
<FieldMultiItem
id={affFieldName}
label='Affiliations relevant to this document'
emptyMessage='There are no affiliations. You can start by adding one.'
onAddClick={() => push(emptyAffiliation)}
>
{fieldValues.map((field, index) => (
<DeletableFieldset
/* eslint-disable-next-line react/no-array-index-key */
key={index}
id={`${affFieldName}-${index}`}
label={`Entry #${index + 1}`}
onDeleteClick={() => remove(index)}
>
<FormikInputText
id={`${affFieldName}-${index}`}
name={`${affFieldName}.${index}`}
label='Name'
labelHint='(required)'
/>
</DeletableFieldset>
))}
</FieldMultiItem>
);
}}
/>
</SectionFieldset>
{renderFormFooter()}
</Form>
</FormBlock>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react';
import T from 'prop-types';
import set from 'lodash.set';
import { Formik, Form as FormikForm } from 'formik';
import { Formik, Form as FormikForm, useField } from 'formik';
import { Form, FormHelperMessage } from '@devseed-ui/form';

import { Inpage, InpageBody } from '../../../styles/inpage';
Expand All @@ -27,6 +27,13 @@ import { isPublished } from '../status';
import { LocalStore } from './local-store';
import { FormikUnloadPrompt } from '../../common/unload-prompt';
import RichTextContex2Formik from './rich-text-ctx-formik';
import { resolveTitle } from '../../../utils/common';

function TitlePreview() {
const [{ value }] = useField('title');

return <h4>Preview: {resolveTitle(value)}</h4>;
}

export default function StepIdentifyingInformation(props) {
const { renderInpageHeader, renderFormFooter, atbd, id, version, step } =
Expand Down Expand Up @@ -100,6 +107,7 @@ export default function StepIdentifyingInformation(props) {
name='title'
label='ATBD Title'
description={formString('identifying_information.title')}
helper={<TitlePreview />}
/>
<FieldAtbdAlias disabled={hasAnyVersionPublished} />
</SectionFieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const fields = [
label: 'Authors',
helper: (
<FormHelperMessage>
Separate values with <em>and</em> (e.g., John Doe <em>and</em> Jane
Doe).
Separate last name and first names with a comma, and authors with{' '}
<em>and</em> (e.g., Doe, John <em>and</em> Doe, Jane).
</FormHelperMessage>
)
},
Expand Down
3 changes: 2 additions & 1 deletion app/assets/scripts/components/documents/single-edit/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const STEP_IDENTIFYING_INFORMATION = {

const STEP_CONTACTS = {
id: 'contacts',
label: 'Contact Information',
label: 'Contact and Reviewer Information',
StepComponent: StepContacts,
getInitialValues: (atbd) => {
return getValuesFromObj(atbd, {
Expand All @@ -58,6 +58,7 @@ const STEP_CONTACTS = {
// affiliations: []
// }
],
reviewer_info: atbd?.reviewer_info,
sections_completed: {
contacts: 'incomplete'
}
Expand Down
Loading

0 comments on commit 8df03c5

Please sign in to comment.