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

Feature/231 create dataset boilerplate #251

Merged
merged 34 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69327f6
initial commit for boilerplate
Dec 5, 2023
f402382
Added basic tests
Dec 5, 2023
6a9cdce
updating tests
Dec 12, 2023
c384768
update route for Create Dataset
Dec 12, 2023
8d1049f
fixed suggested items from code review. Added better component tests
Dec 13, 2023
c003229
Merge branch 'develop' into feature/231-create-dataset-boilerplate
Dec 14, 2023
54ae319
Merge branch 'develop' into feature/231-create-dataset-boilerplate
Dec 14, 2023
4332efd
Merge branch 'feature/231-create-dataset-boilerplate' of https://gith…
Dec 14, 2023
5f4eb87
removed data-cy attributes from elements
Dec 15, 2023
d0c9af4
updated some file locations
Dec 20, 2023
fcb983e
Added comments and some placeholders
Dec 21, 2023
7f860cf
Created new tests, renamed and relocated use-case file, made updates …
Jan 4, 2024
45578bf
removed comments, changed names for build error
Jan 4, 2024
97acbe9
change Cypress version
Jan 5, 2024
4da6060
removing comments and redundant code from createDataset files
Jan 5, 2024
1a3dd8a
renamed Forms directory
Jan 5, 2024
bdc6e93
updated RequiredFieldText to use translation
Jan 5, 2024
59a8dbb
merge with develop
Jan 8, 2024
e96981e
fix for e2e test condition failing
Jan 8, 2024
3908945
Router changes from Melina, strict type checking
Jan 9, 2024
ea8466d
Refactored form component, added dedicated provider and context methods
Jan 12, 2024
6cb09b3
Merge branch 'develop' into feature/231-create-dataset-boilerplate
Jan 12, 2024
be5388c
changing story
Jan 12, 2024
e4507a0
Update router enums
Jan 12, 2024
ebc2b36
update story to reflect removed attributes on form
Jan 18, 2024
bc14953
re-added required attr to match spec after testing
Jan 18, 2024
4740a0c
merge from develop
Jan 19, 2024
25cca4f
update file import
Jan 22, 2024
b695feb
recast function declarations for components
Jan 22, 2024
4c717f3
relocate files to re-align with current best-practices
Jan 23, 2024
609afd4
renaming use cases to align with prev code
Jan 23, 2024
99b99f5
updated imports in Storybook
Jan 26, 2024
6de18a3
Removed redundant factory function, updated formatting in router
Jan 29, 2024
6d184d7
Add isLoading considerations, add event handler for Cancel btn
Jan 29, 2024
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
16 changes: 16 additions & 0 deletions public/locales/en/createDataset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"pageTitle": "Create Dataset",
"metadataTip": {
"title": "Metadata Tip",
"content": "After adding the dataset, click the Edit Dataset button to add more metadata."
},
"datasetForm": {
"title": "Title"
},
"datasetFormStates": {
"submitting": "Form Submitting",
"submissionSuccess": "Form submission successful"
},
"saveButton": "Save Dataset",
"cancelButton": "Cancel"
}
17 changes: 16 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
import { createBrowserRouter, RouterProvider, useRouteError } from 'react-router-dom'
import { HelloDataverse } from './sections/hello-dataverse/HelloDataverse'
import { Layout } from './sections/layout/Layout'
import { Route } from './sections/Route.enum'
import { DatasetFactory } from './sections/dataset/DatasetFactory'
import { PageNotFound } from './sections/page-not-found/PageNotFound'
import { CreateDataset } from './views/create-dataset/CreateDataset'

const router = createBrowserRouter(
[
{
path: '/',
element: <Layout />,
errorElement: <PageNotFound />,
children: [
{
path: Route.HOME,
Expand All @@ -17,13 +20,25 @@
{
path: `${Route.DATASETS}`,
element: DatasetFactory.create()
},
{
path: `${Route.CREATE}`,
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
element: <CreateDataset />
}
]
}
],
{ basename: import.meta.env.BASE_URL }
)

// Just a quick test for ensuring errorElements work correctly.
function ErrorBoundary() {

Check warning on line 35 in src/Router.tsx

View workflow job for this annotation

GitHub Actions / lint

'ErrorBoundary' is defined but never used. Allowed unused vars must match /^_/u
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
const error = useRouteError()
console.error(error)
// Uncaught ReferenceError: path is not defined
return <div>Dang!</div>
}

export function Router() {
return <RouterProvider router={router} />
}
File renamed without changes
File renamed without changes.
20 changes: 20 additions & 0 deletions src/components/Forms/RequiredFieldText/RequiredFieldText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function RequiredFieldText() {
return (
<p>
<RequiredInputSymbol />
Asterisks indicate required fields
M27Mangan marked this conversation as resolved.
Show resolved Hide resolved
</p>
)
}

// TODO: Why can't I export this object from Storybook?
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
// Needed to duplicate it on the frontend to be able to use.

const RequiredInputSymbol = () => {
return (
<span role="img" aria-label="Required input symbol" style={{ color: '#a94442' }}>
{' '}
*
</span>
)
}
4 changes: 4 additions & 0 deletions src/components/ui/SeparationLine/SeparationLine.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import styles from '/src/sections/dataset/Dataset.module.scss'
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
export function SeparationLine() {
return <div className={styles['separation-line']}></div>
}
3 changes: 2 additions & 1 deletion src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export enum Route {
SIGN_UP = '/dataverseuser.xhtml?editMode=CREATE&redirectPage=%2Fdataverse.xhtml',
LOG_IN = '/loginpage.xhtml?redirectPage=%2Fdataverse.xhtml',
LOG_OUT = '/',
DATASETS = 'datasets'
DATASETS = 'datasets',
CREATE = 'create'
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion src/sections/hello-dataverse/HelloDataverse.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";
@import "src/sections/assets/variables";
@import "src/assets/variables";

.container {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion src/sections/hello-dataverse/HelloDataverse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logo from '../assets/logo.svg'
import logo from '../../assets/logo.svg'
import styles from './HelloDataverse.module.scss'
import { Trans, useTranslation } from 'react-i18next'

Expand Down
2 changes: 1 addition & 1 deletion src/sections/layout/Layout.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "src/sections/assets/variables";
@import "src/assets/variables";

.body-container {
min-height: $body-available-height;
Expand Down
2 changes: 1 addition & 1 deletion src/sections/layout/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logo from '../../assets/logo.svg'
import logo from '../../../assets/logo.svg'
import { useTranslation } from 'react-i18next'
import { Navbar } from '@iqss/dataverse-design-system'
import { Route } from '../../Route.enum'
Expand Down
119 changes: 119 additions & 0 deletions src/views/create-dataset/CreateDataset.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { ChangeEvent, FormEvent, useEffect, useState } from 'react'
import { Alert, Button, Col, Form, Row } from '@iqss/dataverse-design-system'
import { useTranslation } from 'react-i18next'
import { useDataset } from '../../sections/dataset/DatasetContext'
import { DatasetSkeleton } from '../../sections/dataset/DatasetSkeleton'
import { useLoading } from '../../sections/loading/LoadingContext'
import styles from '/src/sections/dataset/Dataset.module.scss'
import { FormInputElement } from '@iqss/dataverse-design-system/src/lib/components/form/form-group/form-element/FormInput'
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
import { SeparationLine } from '../../components/ui/SeparationLine/SeparationLine'
import { RequiredFieldText } from '../../components/Forms/RequiredFieldText/RequiredFieldText'

/*
* TODO:
* Break out different components
* Find submit action source
* cleanup state objects and submit process
* show submitted info in console
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
*/

// See comments about https://rjsf-team.github.io/react-jsonschema-form/
// https://github.com/IQSS/dataverse-frontend/issues/231

export function CreateDataset() {
const { setIsLoading } = useLoading()
const { isLoading } = useDataset()
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
const { t } = useTranslation('createDataset')
const [submitting, setSubmitting] = useState(false)
const [submitStatus, setSubmitStatus] = useState(false)

useEffect(() => {
setIsLoading(isLoading)
}, [isLoading])
MellyGray marked this conversation as resolved.
Show resolved Hide resolved

const [state, setState] = useState({
createDatasetTitle: ''
})
MellyGray marked this conversation as resolved.
Show resolved Hide resolved

const handleCreateDatasetFieldChange = (e: ChangeEvent<FormInputElement>) => {
let value: (typeof state)[keyof typeof state] = e.target.value
if (e.target.type === 'text') {
value = e.target.value
}

setState({ ...state, [e.target.id]: value })
}

// TODO: Connect to API when ready
const handleCreateDatasetSubmit = (event: FormEvent<HTMLFormElement>) => {
setSubmitting(true)
event.preventDefault()
setTimeout(() => {
setSubmitting(false)
console.log('Form Submitted!')
setSubmitStatus(true)
}, 3000)
console.log(state)
// TODO: Callback for form submission should be here.
}

// TODO: Probably replace this with a FormSkeleton or remove entirely
if (isLoading) {
return <DatasetSkeleton />
}
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
return (
M27Mangan marked this conversation as resolved.
Show resolved Hide resolved
<article>
<header className={styles.header}>
<h1>{t('pageTitle')}</h1>
</header>
<SeparationLine />
<div className={styles.container}>
<RequiredFieldText />
{submitting && <div>Submtting Form...</div>}
<Form onSubmit={handleCreateDatasetSubmit}>
{submitStatus && <div>Form Submitted!</div>}
<Row>
<Col md={9}>
<Form.Group controlId="createDatasetTitle" required>
<Form.Group.Label>{t('datasetForm.title')}</Form.Group.Label>
<Form.Group.Input
data-cy="datasetFormInputTitle"
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
type="text"
placeholder="Dataset Title"
onChange={handleCreateDatasetFieldChange}
/>
</Form.Group>
</Col>
</Row>
<SeparationLine />
<Alert
key={1}
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
variant={'info'}
customHeading={t('metadataTip.title')}
dismissible={false}>
{t('metadataTip.content')}
</Alert>
{/* SRC: https://github.com/IQSS/dataverse/blob/develop/src/main/webapp/dataset.xhtml */}
{/* <p:commandButton id="saveBottom" styleClass="btn btn-default" value="#{DatasetPage.editMode == 'CREATE' ? bundle['file.addBtn'] : bundle.saveChanges}" rendered="#{DatasetPage.editMode == 'CREATE' or DatasetPage.editMode == 'METADATA'}"
onclick="PF('blockDatasetForm').show();"
update=":datasetForm,:messagePanel"
oncomplete="$(document).scrollTop(0);"
action="#{DatasetPage.save}"
/> */}
{/* Where is datasetSaveCommand() */}
{/* <p:remoteCommand
name="datasetSaveCommand"
action="#{DatasetPage.save()}"
update=":datasetForm,:messagePanel"
/> */}
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
<Button type="submit" data-cy="datasetFormSubmit">
{t('saveButton')}
</Button>
<Button withSpacing variant="secondary" data-cy="datasetFormCancel">
{t('cancelButton')}
</Button>
</Form>
</div>
</article>
)
}
24 changes: 24 additions & 0 deletions tests/component/views/create-dataset/CreateDataset.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CreateDataset } from '../../../../src/views/create-dataset/CreateDataset'

describe('Form component', () => {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
it('should render all form fields', () => {
cy.customMount(<CreateDataset />)
cy.get('[data-cy=datasetFormInputTitle]').should('be.visible')
cy.get('[data-cy=datasetFormSubmit]').should('be.visible')
cy.get('[data-cy=datasetFormCancel]').should('be.visible')
})

it('should submit the form with correct values', () => {
cy.customMount(<CreateDataset />)

cy.get('[data-cy=datasetFormInputTitle]').type('Test Dataset Title')

cy.get('[data-cy=datasetFormSubmit]').click()

// Wait for the form submission to complete (adjust the timeout as needed)
cy.wait(4000)

// Assert that the form was successfully submitted
cy.contains('Form Submitted!')
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
})
})
Loading