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

Bugfix/object title not updated #456

Merged
merged 3 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cypress/integration/draft.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Draft operations", function () {
cy.get("div[role=button]").contains("Fill Form").click()
cy.get("h2").contains("Would you like to save draft version of this form")
cy.get("div[role=dialog]").contains("Save").click()
cy.wait(500)
cy.get("ul[data-testid='Draft-objects']").find("li").should("have.length", 2)

// Delete a draft
Expand Down
19 changes: 18 additions & 1 deletion cypress/integration/home.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe("Home e2e", function () {
cy.get("button[type=button]").contains("Save as Draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with")

// Fill a Sample form draft
cy.clickFillForm("Sample")
cy.get("input[data-testid='title']").type("Test sample")
cy.get("button[type=button]").contains("Save as Draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with")

// Save folder and navigate to Home page
cy.get("button[type=button]").contains("Save and Exit").click()
cy.get('button[aria-label="Save a new folder and move to frontpage"]').contains("Return to homepage").click()
Expand Down Expand Up @@ -72,7 +78,18 @@ describe("Home e2e", function () {

// Navigate to home & edit submitted object
cy.findDraftFolder("Edited unpublished folder")
cy.get('button[aria-label="Edit this object"]').click()

// Edit draft Sample form
cy.get("tr[data-testid='Test sample']").within(() => cy.get('button[aria-label="Edit this object"]').click())
cy.get("input[data-testid='title']").type(" edited")
cy.get("button[type=button]").contains("Update draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft updated with")

// Navigate to home & check updated draft's new title
cy.findDraftFolder("Edited unpublished folder")
cy.get("tr[data-testid='Test sample edited']").should("be.visible")

cy.get("tr[data-testid='Second test title']").within(() => cy.get('button[aria-label="Edit this object"]').click())
cy.get("input[name='descriptor.studyTitle']").type(" edited")
cy.get("button[type=button]").contains("Update").click()
cy.get("div[role=alert]").contains("Object updated")
Expand Down
1 change: 0 additions & 1 deletion src/components/Home/SelectedFolderDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const SelectedFolderDetails = (): React$Element<typeof Grid> => {

const handleObject = async (data: any, draft: boolean, objectType: string, objectInFolder: any) => {
const service = draft ? draftAPIService : objectAPIService

const response = await service.getObjectByAccessionId(objectType, objectInFolder.accessionId)

if (response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const CancelFormDialog = ({
currentObject.accessionId || currentObject.objectId,
objectType,
currentObject.status,
submissionFolder.folderId,
submissionFolder,
currentObject.cleanedValues || currentObject,
dispatch
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { setDraftStatus, resetDraftStatus } from "features/draftStatusSlice"
import { resetFocus } from "features/focusSlice"
import { setCurrentObject, resetCurrentObject } from "features/wizardCurrentObjectSlice"
import { updateStatus } from "features/wizardStatusMessageSlice"
import { deleteObjectFromFolder, modifyObjectTags } from "features/wizardSubmissionFolderSlice"
import { deleteObjectFromFolder, replaceObjectInFolder } from "features/wizardSubmissionFolderSlice"
import objectAPIService from "services/objectAPI"
import schemaAPIService from "services/schemaAPI"
import type { FolderDetailsWithId } from "types"
import { getObjectDisplayTitle, formatDisplayObjectType } from "utils"
import { dereferenceSchema } from "utils/JSONSchemaUtils"

Expand Down Expand Up @@ -120,7 +121,7 @@ type FormContentProps = {
formSchema: any,
onSubmit: () => Promise<any>,
objectType: string,
folderId: string,
folder: FolderDetailsWithId,
currentObject: any,
}

Expand Down Expand Up @@ -194,7 +195,7 @@ const CustomCardHeader = (props: CustomCardHeaderProps) => {
/*
* Return react-hook-form based form which is rendered from schema and checked against resolver. Set default values when continuing draft
*/
const FormContent = ({ resolver, formSchema, onSubmit, objectType, folderId, currentObject }: FormContentProps) => {
const FormContent = ({ resolver, formSchema, onSubmit, objectType, folder, currentObject }: FormContentProps) => {
const classes = useStyles()
const dispatch = useDispatch()

Expand Down Expand Up @@ -331,14 +332,18 @@ const FormContent = ({ resolver, formSchema, onSubmit, objectType, folderId, cur
*/
const patchHandler = (response, cleanedValues) => {
if (response.ok) {
const index = folder.metadataObjects.findIndex(item => item.accessionId === currentObject.accessionId)
dispatch(
modifyObjectTags({
accessionId: currentObject.accessionId,
tags: {
replaceObjectInFolder(
folder.folderId,
currentObject.accessionId,
index,
{
submissionType: ObjectSubmissionTypes.form,
displayTitle: getObjectDisplayTitle(objectType, cleanedValues),
},
})
ObjectStatus.submitted
)
)
dispatch(resetDraftStatus())
dispatch(
Expand Down Expand Up @@ -371,7 +376,7 @@ const FormContent = ({ resolver, formSchema, onSubmit, objectType, folderId, cur
currentObject.accessionId || currentObject.objectId,
objectType,
currentObject.status,
folderId,
folder,
cleanedValues,
dispatch
)
Expand Down Expand Up @@ -435,7 +440,7 @@ const WizardFillObjectDetailsForm = (): React$Element<typeof Container> => {
const dispatch = useDispatch()

const objectType = useSelector(state => state.objectType)
const { folderId, metadataObjects } = useSelector(state => state.submissionFolder)
const folder = useSelector(state => state.submissionFolder)
const currentObject = useSelector(state => state.currentObject)

// States that will update in useEffect()
Expand Down Expand Up @@ -488,7 +493,7 @@ const WizardFillObjectDetailsForm = (): React$Element<typeof Container> => {
}, [objectType])

const getAccessionIds = (objectType: string) => {
const submissions = metadataObjects?.filter(obj => obj.schema.toLowerCase() === objectType)
const submissions = folder.metadataObjects?.filter(obj => obj.schema.toLowerCase() === objectType)
// Add "- Title: " to accessionId, special case DAC form: add "- Main Contact:"
const accessionIds = submissions?.map(obj =>
obj.schema === ObjectTypes.dac
Expand Down Expand Up @@ -680,7 +685,7 @@ const WizardFillObjectDetailsForm = (): React$Element<typeof Container> => {
*/
const onSubmit = async data => {
setSubmitting(true)
const response = await submitObjectHook(data, folderId, objectType, dispatch)
const response = await submitObjectHook(data, folder.folderId, objectType, dispatch)

if (response) setSubmitting(false)
}
Expand All @@ -696,9 +701,9 @@ const WizardFillObjectDetailsForm = (): React$Element<typeof Container> => {
resolver={WizardAjvResolver(states.validationSchema)}
onSubmit={onSubmit}
objectType={objectType}
folderId={folderId}
folder={folder}
currentObject={currentObject}
key={currentObject?.accessionId || folderId}
key={currentObject?.accessionId || folder.folderId}
/>
{submitting && <LinearProgress />}
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ const WizardUploadObjectXMLForm = (): React$Element<typeof Container> => {
setResponseStatus(response)
if (response.ok) {
dispatch(
replaceObjectInFolder(folderId, currentObject.accessionId, currentObject.index, {
submissionType: ObjectSubmissionTypes.xml,
fileName: fileName,
})
replaceObjectInFolder(
folderId,
currentObject.accessionId,
currentObject.index,
{
submissionType: ObjectSubmissionTypes.xml,
fileName: fileName,
},
ObjectStatus.submitted
)
)
.then(() => {
setSuccessStatus(WizardStatus.success)
Expand Down
20 changes: 12 additions & 8 deletions src/components/NewDraftWizard/WizardHooks/WizardSaveDraftHook.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
//@flow

import { ObjectStatus } from "constants/wizardObject"
import { WizardStatus } from "constants/wizardStatus"
import { resetDraftStatus } from "features/draftStatusSlice"
import { setLoading, resetLoading } from "features/loadingSlice"
import { resetCurrentObject } from "features/wizardCurrentObjectSlice"
import { updateStatus } from "features/wizardStatusMessageSlice"
import { addObjectToDrafts, modifyDraftObjectTags } from "features/wizardSubmissionFolderSlice"
import { addObjectToDrafts, replaceObjectInFolder } from "features/wizardSubmissionFolderSlice"
import draftAPIService from "services/draftAPI"
import type { FolderDetailsWithId } from "types"
import { getObjectDisplayTitle } from "utils"

const saveDraftHook = async (
accessionId?: string,
objectType: string,
objectStatus: string,
folderId: string,
folder: FolderDetailsWithId,
values: any,
dispatch: function
): any => {
const draftDisplayTitle = getObjectDisplayTitle(objectType, values)
dispatch(setLoading())
if (accessionId && objectStatus === ObjectStatus.draft) {
const response = await draftAPIService.patchFromJSON(objectType, accessionId, values)
const index = folder.drafts.findIndex(item => item.accessionId === accessionId)
if (response.ok) {
dispatch(resetDraftStatus())
dispatch(
modifyDraftObjectTags({
replaceObjectInFolder(
folder.folderId,
accessionId,
tags: {
displayTitle: draftDisplayTitle,
},
})
index,
{ displayTitle: draftDisplayTitle },
ObjectStatus.draft
)
)
dispatch(
updateStatus({
Expand Down Expand Up @@ -62,7 +66,7 @@ const saveDraftHook = async (
)
dispatch(resetDraftStatus())
dispatch(
addObjectToDrafts(folderId, {
addObjectToDrafts(folder.folderId, {
accessionId: response.data.accessionId,
schema: "draft-" + objectType,
tags: { displayTitle: draftDisplayTitle },
Expand Down
Loading