@@ -15,6 +15,7 @@ import { ErrMessage } from './InputStyles';
1515import InputSwitcher from './InputSwitcher' ;
1616import { useSettings } from '../../helpers/AppSettings' ;
1717import toast from 'react-hot-toast' ;
18+ import { Column , Row } from '../Row' ;
1819
1920interface ValueFormProps {
2021 // Maybe pass Value instead of Resource?
@@ -55,6 +56,25 @@ export function ValueForm({
5556 const [ err , setErr ] = useState < Error | undefined > ( undefined ) ;
5657 const haveAgent = agent !== undefined ;
5758
59+ function handleCancel ( ) {
60+ setErr ( undefined ) ;
61+ setEditMode ( false ) ;
62+ // Should this maybe also remove the edits to the resource?
63+ // https://github.com/atomicdata-dev/atomic-data-browser/issues/36
64+ }
65+
66+ async function handleSave ( ) {
67+ try {
68+ await resource . save ( store ) ;
69+ setEditMode ( false ) ;
70+ toast . success ( 'Resource saved' ) ;
71+ } catch ( e ) {
72+ setErr ( e ) ;
73+ setEditMode ( true ) ;
74+ toast . error ( 'Could not save resource...' ) ;
75+ }
76+ }
77+
5878 if ( value === undefined ) {
5979 return null ;
6080 }
@@ -78,48 +98,33 @@ export function ValueForm({
7898 ) ;
7999 }
80100
81- function handleCancel ( ) {
82- setErr ( undefined ) ;
83- setEditMode ( false ) ;
84- // Should this maybe also remove the edits to the resource?
85- // https://github.com/atomicdata-dev/atomic-data-browser/issues/36
86- }
87-
88- async function handleSave ( ) {
89- try {
90- await resource . save ( store ) ;
91- setEditMode ( false ) ;
92- toast . success ( 'Resource saved' ) ;
93- } catch ( e ) {
94- setErr ( e ) ;
95- setEditMode ( true ) ;
96- toast . error ( 'Could not save resource...' ) ;
97- }
98- }
99-
100101 return (
101102 < ValueFormWrapper >
102- < InputSwitcher
103- data-test = { `input-${ property . subject } ` }
104- resource = { resource }
105- property = { property }
106- autoFocus
107- />
108- { err && < ErrMessage > { err . message } </ ErrMessage > }
109- < Button
110- disabled = { ! haveAgent }
111- title = {
112- haveAgent
113- ? 'Save the edits'
114- : 'You cannot save - there is no Agent set. Go to settings.'
115- }
116- onClick = { handleSave }
117- >
118- save
119- </ Button >
120- < Button subtle onClick = { handleCancel } >
121- cancel
122- </ Button >
103+ < Column gap = '0.5rem' >
104+ < InputSwitcher
105+ data-test = { `input-${ property . subject } ` }
106+ resource = { resource }
107+ property = { property }
108+ autoFocus
109+ />
110+ { err && < ErrMessage > { err . message } </ ErrMessage > }
111+ < Row gap = '0.5rem' >
112+ < Button subtle onClick = { handleCancel } >
113+ cancel
114+ </ Button >
115+ < Button
116+ disabled = { ! haveAgent }
117+ title = {
118+ haveAgent
119+ ? 'Save the edits'
120+ : 'You cannot save - there is no Agent set. Go to settings.'
121+ }
122+ onClick = { handleSave }
123+ >
124+ save
125+ </ Button >
126+ </ Row >
127+ </ Column >
123128 </ ValueFormWrapper >
124129 ) ;
125130}
0 commit comments