@@ -4,22 +4,16 @@ import {
44 useCollectionPlugins ,
55 WidgetRenderer
66} from '@stac-manager/data-core' ;
7- import {
8- Box ,
9- Button ,
10- Flex ,
11- Heading ,
12- Tab ,
13- TabList ,
14- TabPanel ,
15- TabPanels ,
16- Tabs
17- } from '@chakra-ui/react' ;
7+ import { Box , Button , ButtonGroup , Flex , Heading } from '@chakra-ui/react' ;
188import { Formik , FormikHelpers } from 'formik' ;
199import { WidgetJSON } from '@stac-manager/data-widgets' ;
20- import { CollecticonTickSmall } from '@devseed-ui/collecticons-chakra' ;
10+ import {
11+ CollecticonCode ,
12+ CollecticonTickSmall
13+ } from '@devseed-ui/collecticons-chakra' ;
2114
2215import { InnerPageHeaderSticky } from '$components/InnerPageHeader' ;
16+ import { CollecticonForm } from '$components/icons/form' ;
2317
2418type FormView = 'fields' | 'json' ;
2519
@@ -88,52 +82,60 @@ export function EditForm(props: {
8882 </ >
8983 }
9084 />
91- < Tabs
92- isLazy
93- variant = 'enclosed'
94- index = { view === 'fields' ? 0 : 1 }
95- onChange = { ( i ) => {
96- setView ( [ 'fields' , 'json' ] [ i ] as FormView ) ;
97- setStacData (
98- view === 'json' ? values . jsonData : toOutData ( values )
99- ) ;
100- } }
101- >
102- < TabList >
103- < Tab bg = 'base.50a' > FORM</ Tab >
104- < Tab > JSON</ Tab >
105- </ TabList >
106- < TabPanels >
107- < TabPanel p = { 0 } display = 'flex' flexFlow = 'column' gap = { 4 } >
108- { view === 'fields' &&
109- plugins . map ( ( pl ) => (
110- < PluginBox key = { pl . name } plugin = { pl } >
111- { ( { field } ) => (
112- < Box
113- p = '16'
114- borderRadius = 'lg'
115- bg = 'base.50a'
116- display = 'flex'
117- flexDir = 'column'
118- gap = { 8 }
119- >
120- < Heading size = 'sm' > { pl . name } </ Heading >
121- < WidgetRenderer pointer = '' field = { field } />
122- </ Box >
123- ) }
124- </ PluginBox >
125- ) ) }
126- </ TabPanel >
127- < TabPanel p = { 0 } pt = { 4 } >
128- { view === 'json' && (
129- < WidgetJSON
130- field = { { type : 'json' , label : 'Json Document' } }
131- pointer = 'jsonData'
132- />
133- ) }
134- </ TabPanel >
135- </ TabPanels >
136- </ Tabs >
85+ < Flex alignItems = 'center' justifyContent = 'space-between' p = { 4 } >
86+ < Heading size = 'md' > { initialData ? 'Edit' : 'New' } </ Heading >
87+
88+ < ButtonGroup isAttached variant = 'outline' size = 'sm' >
89+ < Button
90+ aria-label = 'Edit Form'
91+ leftIcon = { < CollecticonForm /> }
92+ onClick = { ( ) => {
93+ setView ( 'fields' ) ;
94+ setStacData ( values . jsonData ) ;
95+ } }
96+ isActive = { view === 'fields' }
97+ >
98+ Form
99+ </ Button >
100+ < Button
101+ aria-label = 'Edit JSON'
102+ leftIcon = { < CollecticonCode /> }
103+ onClick = { ( ) => {
104+ setView ( 'json' ) ;
105+ setStacData ( toOutData ( values ) ) ;
106+ } }
107+ isActive = { view === 'json' }
108+ >
109+ JSON
110+ </ Button >
111+ </ ButtonGroup >
112+ </ Flex >
113+ < Flex flexFlow = 'column' gap = { 4 } >
114+ { view === 'fields' ? (
115+ plugins . map ( ( pl ) => (
116+ < PluginBox key = { pl . name } plugin = { pl } >
117+ { ( { field } ) => (
118+ < Box
119+ p = '16'
120+ borderRadius = 'lg'
121+ bg = 'base.50a'
122+ display = 'flex'
123+ flexDir = 'column'
124+ gap = { 8 }
125+ >
126+ < Heading size = 'sm' > { pl . name } </ Heading >
127+ < WidgetRenderer pointer = '' field = { field } />
128+ </ Box >
129+ ) }
130+ </ PluginBox >
131+ ) )
132+ ) : (
133+ < WidgetJSON
134+ field = { { type : 'json' , label : 'Json Document' } }
135+ pointer = 'jsonData'
136+ />
137+ ) }
138+ </ Flex >
137139 </ Flex >
138140 ) }
139141 </ Formik >
0 commit comments