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

Moved object type fetching from home view to application start #283

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions cypress/integration/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("Basic e2e", function () {
// Edit saved submission
cy.get("button[type=button]").contains("Edit").click()
cy.get("input[name='descriptor.studyTitle']").should("have.value", "New title")
cy.get("input[name='descriptor.studyTitle']", { timeout: 10000 }).focus().type(" edited")
cy.get("input[name='descriptor.studyTitle']", { timeout: 10000 }).focus().type(" edited").blur()
cy.get("input[name='descriptor.studyTitle']").should("have.value", "New title edited")
cy.get("button[type=button]").contains("Update").click()
cy.get("div[role=alert]").contains("Object updated")
Expand Down Expand Up @@ -93,7 +93,9 @@ describe("Basic e2e", function () {
cy.get("select[name='analysisType.referenceAlignment.assembly']").select("Standard")
cy.get("input[name='analysisType.referenceAlignment.assembly.accessionId']").type("Standard Accession Id")
cy.get("h4").contains("Sequence").parent().children("button").click()
cy.get("input[name='analysisType.referenceAlignment.sequence[0].accessionId']").type("Sequence Standard Accession Id")
cy.get("input[name='analysisType.referenceAlignment.sequence[0].accessionId']").type(
"Sequence Standard Accession Id"
)

// Experiment
cy.get("h2").contains("Experiment Reference").parent().children("button").click()
Expand Down Expand Up @@ -136,7 +138,6 @@ describe("Basic e2e", function () {
cy.get("select[name='files[1].filetype']").select("info")
cy.get("select[name='files[1].checksumMethod']").select("SHA256")
cy.get("input[name='files[1].checksum']").type("c34045c1a1db8d1b3fca8a692198466952daae07eaf6104b4c87ed3b55b6af1b")

})
// Submit form
cy.get("button[type=submit]").contains("Submit").click()
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/errorPages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ describe("catch error codes and display corresponding error page", function () {
)
cy.visit(baseUrl)
cy.get('[alt="CSC Login"]').click()
cy.contains(".MuiAlert-message", "500 Internal Server Error")
cy.contains(".MuiAlert-message", "500 Internal Server Error", { timeout: 10000 })
})
})
5 changes: 2 additions & 3 deletions cypress/integration/objectTitles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ describe("draft and submitted objects' titles", function () {

// Edit submitted object
cy.get("button[type=button]").contains("Edit").click()
cy.get("input[name='descriptor.studyTitle']").should("have.value", "Test title")
cy.get("input[name='descriptor.studyTitle']").type(" 2").blur()
cy.get("input[name='descriptor.studyTitle']").should("have.value", "Test title").type(" 2").blur()
cy.get("input[name='descriptor.studyTitle']").should("have.value", "Test title 2")
cy.get("button[type=button]").contains("Update").click()
cy.get("button[type=button]").contains("Update", { timeout: 10000 }).click()
cy.get("div[role=alert]").contains("Object updated")

// Check the submitted object has correctly updated displayTitle
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ import "./commands"

// Alternatively you can use CommonJS syntax:
// require('./commands')

// Turn off all uncaught exception handling
Cypress.on("uncaught:exception", () => {
return false
})
44 changes: 43 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
//@flow
import React from "react"
import React, { useEffect } from "react"

import Container from "@material-ui/core/Container"
import CssBaseline from "@material-ui/core/CssBaseline"
import { makeStyles } from "@material-ui/core/styles"
import { useDispatch } from "react-redux"
import { Switch, Route, useLocation } from "react-router-dom"

import SelectedFolderDetails from "components/Home/SelectedFolderDetails"
import SubmissionFolderList from "components/Home/SubmissionFolderList"
import Nav from "components/Nav"
import { ObjectTypes } from "constants/wizardObject"
import { setObjectsArray } from "features/objectsArraySlice"
import schemaAPIService from "services/schemaAPI"
import Page401 from "views/ErrorPages/Page401"
import Page403 from "views/ErrorPages/Page403"
import Page404 from "views/ErrorPages/Page404"
Expand Down Expand Up @@ -60,6 +64,44 @@ const NavigationMenu = () => {
*/
const App = (): React$Element<typeof React.Fragment> => {
const classes = useStyles()
const dispatch = useDispatch()

// Fetch array of schemas from backend and store it in frontend
// Fetch only if the initial array is empty
// if there is any errors while fetching, it will return a manually created ObjectsArray instead
useEffect(() => {
if (location.pathname === "/" || pathsWithoutNav.indexOf(location.pathname) !== -1) return
let isMounted = true
const getSchemas = async () => {
const response = await schemaAPIService.getAllSchemas()

if (isMounted) {
if (response.ok) {
const schemas = response.data
.filter(schema => schema.title !== "Project" && schema.title !== "Submission")
.map(schema => schema.title.toLowerCase())
dispatch(setObjectsArray(schemas))
} else {
dispatch(
setObjectsArray([
ObjectTypes.study,
ObjectTypes.sample,
ObjectTypes.experiment,
ObjectTypes.run,
ObjectTypes.analysis,
ObjectTypes.dac,
ObjectTypes.policy,
ObjectTypes.dataset,
])
)
}
}
}
getSchemas()
return () => {
isMounted = false
}
}, [])

return (
<React.Fragment>
Expand Down
42 changes: 0 additions & 42 deletions src/views/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import SubmissionIndexCard from "components/Home/SubmissionIndexCard"
import UserDraftTemplates from "components/Home/UserDraftTemplates"
import WizardStatusMessageHandler from "components/NewDraftWizard/WizardForms/WizardStatusMessageHandler"
import { FolderSubmissionStatus } from "constants/wizardFolder"
import { ObjectTypes } from "constants/wizardObject"
import { WizardStatus } from "constants/wizardStatus"
import { setObjectsArray } from "features/objectsArraySlice"
import { setPublishedFolders } from "features/publishedFoldersSlice"
import { setUnpublishedFolders } from "features/unpublishedFoldersSlice"
import { fetchUserById } from "features/userSlice"
import folderAPIService from "services/folderAPI"
import schemaAPIService from "services/schemaAPI"

const useStyles = makeStyles(theme => ({
tableCard: {
Expand All @@ -36,7 +33,6 @@ const useStyles = makeStyles(theme => ({
const Home = (): React$Element<typeof Grid> => {
const dispatch = useDispatch()
const user = useSelector(state => state.user)
const objectsArray = useSelector(state => state.objectsArray)

const unpublishedFolders = useSelector(state => state.unpublishedFolders)
const publishedFolders = useSelector(state => state.publishedFolders)
Expand Down Expand Up @@ -75,44 +71,6 @@ const Home = (): React$Element<typeof Grid> => {
}
}, [])

// Fetch array of schemas from backend and store it in frontend
// Fetch only if the initial array is empty
// if there is any errors while fetching, it will return a manually created ObjectsArray instead
useEffect(() => {
if (objectsArray?.length === 0) {
let isMounted = true
const getSchemas = async () => {
const response = await schemaAPIService.getAllSchemas()

if (isMounted) {
if (response.ok) {
const schemas = response.data
.filter(schema => schema.title !== "Project" && schema.title !== "Submission")
.map(schema => schema.title.toLowerCase())
dispatch(setObjectsArray(schemas))
} else {
dispatch(
setObjectsArray([
ObjectTypes.study,
ObjectTypes.sample,
ObjectTypes.experiment,
ObjectTypes.run,
ObjectTypes.analysis,
ObjectTypes.dac,
ObjectTypes.policy,
ObjectTypes.dataset,
])
)
}
}
}
getSchemas()
return () => {
isMounted = false
}
}
}, [])

// Contains both unpublished and published folders (max. 5 items/each)
return (
<Grid container direction="column" justify="space-between" alignItems="stretch">
Expand Down