-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(data element form views): use sticky footer only in edit view
- Loading branch information
Showing
10 changed files
with
466 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"!` | ||
) | ||
})} | ||
</> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.