Skip to content

Commit

Permalink
fix(data element form views): use sticky footer only in edit view
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Aug 9, 2023
1 parent be13e5d commit e74a722
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 242 deletions.
13 changes: 11 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-07-31T11:36:19.094Z\n"
"PO-Revision-Date: 2023-07-31T11:36:19.094Z\n"
"POT-Creation-Date: 2023-08-03T09:45:13.203Z\n"
"PO-Revision-Date: 2023-08-03T09:45:13.203Z\n"

msgid "schemas"
msgstr "schemas"
Expand Down Expand Up @@ -595,6 +595,15 @@ msgstr ""
msgid "Aggregation levels"
msgstr "Aggregation levels"

msgid "Aggregation level(s)"
msgstr "Aggregation level(s)"

msgid "Custom attributes"
msgstr "Custom attributes"

msgid "Custom fields for your DHIS2 instance"
msgstr "Custom fields for your DHIS2 instance"

msgid "Selected legends"
msgstr "Selected legends"

Expand Down
15 changes: 15 additions & 0 deletions src/pages/dataElements/Edit.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.form {
background: var(--colors-white);
padding: var(--spacers-dp16);
padding-bottom: var(--spacers-dp32);
}

.formActions {
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
padding: var(--spacers-dp16);
box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
background: var(--colors-white);
}
57 changes: 52 additions & 5 deletions src/pages/dataElements/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
import { Button, ButtonStrip } from '@dhis2/ui'
import React from 'react'
import { useParams } from 'react-router-dom'
import { Form } from 'react-final-form'
import { useNavigate } from 'react-router-dom'
import classes from './Edit.module.css'
import { DataElementForm } from './form'

// @TODO(DataElements/edit): I suppose we want some of the initial values to be
// dynamic? In that case, we'd have to load them and add loading/error UIs.
const INITIAL_VALUES = {
legends: [],
domain: 'aggregate',
valueType: 'number',
aggregationType: 'sum',
}

export const Component = () => {
const { id } = useParams()
// could do it like this instead of separate new and edit routes
const isNew = id === 'new'
const navigate = useNavigate()
const onSubmit = (values: object) => {
console.log(
'@TODO(DataElements/edit): Implement onSubmit; values:',
values
)
}

return (
<Form
onSubmit={onSubmit}
initialValues={INITIAL_VALUES}
>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<div className={classes.form}>
<DataElementForm />
</div>

<div className={classes.formActions}>
<ButtonStrip>
<Button primary type="submit">
Save and close
</Button>

return <div>This is a form for dataElements</div>
<Button
onClick={() => {
alert('@TODO(Data elements/edit): Implement me!')
navigate(-1)
}}
>
Cancel
</Button>
</ButtonStrip>
</div>
</form>
)}
</Form>
)
}
7 changes: 4 additions & 3 deletions src/pages/dataElements/New.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.container {
box-sizing: border-box;
height: 100%;
.form {
background: var(--colors-white);
padding: var(--spacers-dp16);
padding-bottom: var(--spacers-dp32);
}

.formActions {
Expand Down
52 changes: 26 additions & 26 deletions src/pages/dataElements/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Button, ButtonStrip } from '@dhis2/ui'
import React from 'react'
import { Form } from 'react-final-form'
import { useNavigate } from 'react-router-dom'
import { StandardFormSection } from '../../components'
import { DataElementForm } from './form'
import classes from './New.module.css'

// @TODO(DataElements/new): I suppose we want some of the initial values to be
// dynamic? In that case, we'd have to load them and add loading/error UIs.
const INITIAL_VALUES = {
legends: [],
domain: 'aggregate',
valueType: 'number',
aggregationType: 'sum',
}

export const Component = () => {
// @TODO(DataElements/new): values dynamic or static?
const initialValues = {
legends: [],
domain: 'aggregate',
valueType: 'number',
aggregationType: 'sum',
}

const navigate = useNavigate()
const onSubmit = (values: object) => {
console.log(
Expand All @@ -26,29 +26,29 @@ export const Component = () => {
return (
<Form
onSubmit={onSubmit}
initialValues={INITIAL_VALUES}
initialValues={initialValues}
>
{({ handleSubmit }) => (
<form className={classes.container} onSubmit={handleSubmit}>
<form onSubmit={handleSubmit}>
<div className={classes.form}>
<DataElementForm />
</div>

<div className={classes.formActions}>
<ButtonStrip>
<Button primary type="submit">
Save and close
</Button>
<StandardFormSection>
<ButtonStrip>
<Button primary type="submit">
Save and close
</Button>

<Button
onClick={() => {
alert('@TODO(Data elements/New): Implement me!')
navigate(-1)
}}
>
Cancel
</Button>
</ButtonStrip>
<Button
onClick={() => {
alert('@TODO(Data elements/new): Implement me!')
navigate(-1)
}}
>
Cancel
</Button>
</ButtonStrip>
</StandardFormSection>
</div>
</form>
)}
Expand Down
67 changes: 67 additions & 0 deletions src/pages/dataElements/form/CustomAttributes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { InputFieldFF, TextAreaFieldFF } from '@dhis2/ui'
import * as React from 'react'
import { Field as FieldRFF } from 'react-final-form'
import { StandardFormSection } from '../../../components'

const inputWidth = '440px'

export function CustomAttributes({
attributes = [],
}: {
attributes?: Array<{
id: string,
displayFormName: string,
// @TODO(CustomAttributes): Implement all possible value types!
valueType: 'TEXT' | 'LONG_TEXT',
code: string,
mandatory: boolean,
}>,
}) {
return (
<>
{attributes.map((attribute) => {
const {
mandatory: required,
valueType,
displayFormName,
id,
} = attribute

// @TODO(CustomAttributes): What to use as name?
const name = `attribute.${id}`

if (valueType === 'TEXT') {
return (
<StandardFormSection key={attribute.id}>
<FieldRFF
component={InputFieldFF}
required={required}
inputWidth={inputWidth}
label={displayFormName}
name={name}
/>
</StandardFormSection>
)
}

if (valueType === 'LONG_TEXT') {
return (
<StandardFormSection key={attribute.id}>
<FieldRFF
component={TextAreaFieldFF}
required={required}
inputWidth={inputWidth}
label={displayFormName}
name={name}
/>
</StandardFormSection>
)
}

throw new Error(
`@TODO(CustomAttributes): Implement value type "${valueType}"!`
)
})}
</>
)
}
7 changes: 0 additions & 7 deletions src/pages/dataElements/form/DataElementForm.module.css

This file was deleted.

Empty file.
Loading

0 comments on commit e74a722

Please sign in to comment.