11'use client' ;
22
3- import { useEffect , useState } from 'react' ;
4- import { useParams , useRouter } from 'next/navigation' ;
5- import LoadingPage from '@/app/[locale]/dashboard/loading' ;
63import { graphql } from '@/gql' ;
74import {
85 TypeDatasetMetadata ,
96 TypeMetadata ,
10- UpdateDatasetInput ,
11- UpdateMetadataInput ,
7+ UpdateMetadataInput
128} from '@/gql/generated/graphql' ;
139import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query' ;
10+ import { useParams , useRouter } from 'next/navigation' ;
1411import {
1512 Button ,
1613 Combobox ,
@@ -22,6 +19,7 @@ import {
2219 toast ,
2320} from 'opub-ui' ;
2421
22+ import { Loading } from '@/components/loading' ;
2523import { GraphQL } from '@/lib/api' ;
2624
2725const datasetMetadataQueryDoc : any = graphql ( `
@@ -154,72 +152,75 @@ export function EditMetadata({
154152
155153 return (
156154 < >
157- { getMetaDataListQuery ?. isLoading ? (
158- < LoadingPage />
159- ) : (
160- < Form
161- onSubmit = { ( values ) => {
162- updateMetadataMutation . mutate ( {
163- UpdateMetadataInput : {
164- dataset : id ,
165- metadata : [
166- ...Object . keys ( values )
167- . filter (
168- ( valueItem ) =>
169- valueItem !== 'description' && valueItem !== 'tags'
170- )
171- . map ( ( key ) => {
172- return {
173- id : key ,
174- value : values [ key ] || '' ,
175- } ;
176- } ) ,
177- ] ,
178- description : values . description || '' ,
179- tags : values . tags || [ ] ,
180- } ,
181- } ) ;
182- } }
183- formOptions = { {
184- resetOptions : {
185- keepValues : true ,
186- keepDirtyValues : true ,
155+ < Form
156+ onSubmit = { ( values ) => {
157+ updateMetadataMutation . mutate ( {
158+ UpdateMetadataInput : {
159+ dataset : id ,
160+ metadata : [
161+ ...Object . keys ( values )
162+ . filter (
163+ ( valueItem ) =>
164+ valueItem !== 'description' && valueItem !== 'tags'
165+ )
166+ . map ( ( key ) => {
167+ return {
168+ id : key ,
169+ value : values [ key ] || '' ,
170+ } ;
171+ } ) ,
172+ ] ,
173+ description : values . description || '' ,
174+ tags : values . tags || [ ] ,
187175 } ,
188- defaultValues : defaultValuesPrepFn (
189- getDatasetMetadata ?. data ?. datasets [ 0 ] ?. metadata
190- ) ,
191- } }
192- >
193- < >
194- < div className = "flex flex-col gap-1" >
195- < Text variant = "headingMd" > Add Metadata</ Text >
196- </ div >
197- < div className = "my-4" >
198- < Divider />
199- </ div >
176+ } ) ;
177+ } }
178+ formOptions = { {
179+ resetOptions : {
180+ keepValues : true ,
181+ keepDirtyValues : true ,
182+ } ,
183+ defaultValues : defaultValuesPrepFn (
184+ getDatasetMetadata ?. data ?. datasets [ 0 ] ?. metadata
185+ ) ,
186+ } }
187+ >
188+ < >
189+ < div className = "pt-3" >
190+ < FormLayout >
191+ < Input
192+ key = "description"
193+ multiline
194+ name = "description"
195+ label = { 'Description' }
196+ defaultValue = { getDatasetMetadata ?. data ?. datasets [ 0 ] . description }
197+ />
198+
199+ < div className = "flex flex-wrap" >
200+ < div className = "w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2" >
201+ < Combobox name = { 'tags' } list = { [ ] } label = { 'Tags' } />
202+ </ div >
203+ < div className = "w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2" > </ div >
204+ </ div >
200205
201- < div className = "pt-3" >
202- < FormLayout >
203- < Input
204- key = "description"
205- multiline
206- name = "description"
207- label = { 'Description' }
208- defaultValue = {
209- getDatasetMetadata ?. data ?. datasets [ 0 ] . description
210- }
211- />
206+ { getMetaDataListQuery . isLoading ? (
207+ < Loading />
208+ ) : getMetaDataListQuery ?. data ?. metadata ?. length > 0 ? (
209+ < >
210+ < div className = "my-4" >
211+ < Divider />
212+ </ div >
212213
213- < div className = "flex flex-wrap" >
214- < div className = "w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2" >
215- < Combobox name = { 'tags' } list = { [ ] } label = { 'Tags' } />
214+ < div className = "flex flex-col gap-1" >
215+ < Text variant = "headingMd" > Add Metadata</ Text >
216216 </ div >
217- < div className = "w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2" > </ div >
218- </ div >
219217
220- < div className = "flex flex-wrap" >
221- { getMetaDataListQuery ?. data ?. metadata ?. length > 0 ? (
222- getMetaDataListQuery ?. data ?. metadata ?. map (
218+ < div className = "my-4" >
219+ < Divider />
220+ </ div >
221+
222+ < div className = "flex flex-wrap" >
223+ { getMetaDataListQuery ?. data ?. metadata ?. map (
223224 ( metadataFormItem : TypeMetadata ) => {
224225 if ( metadataFormItem . dataType === 'STRING' ) {
225226 return (
@@ -240,117 +241,35 @@ export function EditMetadata({
240241 }
241242 return null ;
242243 }
243- )
244- ) : (
245- < > </ >
246- ) }
247- </ div >
248-
249- { /* <FormLayout.Group>
250- <Select
251- name="update_frequency"
252- label="Update Frequency"
253- helpText="How often is this dataset updated?"
254- options={[
255- { label: 'Daily', value: 'daily' },
256- { label: 'Weekly', value: 'weekly' },
257- { label: 'Monthly', value: 'monthly' },
258- { label: 'Yearly', value: 'yearly' },
259- ]}
260- placeholder="Select"
261- required
262- error="This field is required"
263- disabled={getMetaDataListQuery.isLoading}
264- />
265- <Select
266- name="language"
267- label="Language"
268- helpText="What language is this dataset in?"
269- options={[
270- { label: 'English', value: 'english' },
271- { label: 'Hindi', value: 'hindi' },
272- { label: 'Spanish', value: 'spanish' },
273- { label: 'French', value: 'french' },
274- ]}
275- placeholder="Select"
276- required
277- error="This field is required"
278- disabled={getMetaDataListQuery.isLoading}
279- />
280- </FormLayout.Group>
281-
282- <FormLayout.Group>
283- <Combobox
284- name="geo_list"
285- label="Geography"
286- // helpText="Which geography does this data belong to?"
287- placeholder="Search Locations"
288- list={[
289- {
290- label: 'India',
291- value: 'india',
292- },
293- {
294- label: 'USA',
295- value: 'usa',
296- },
297- {
298- label: 'UK',
299- value: 'uk',
300- },
301- ]}
302- displaySelected
303- required
304- error="This field is required"
305- />
306- <Combobox
307- name="tags_list"
308- label="Tags"
309- placeholder="Search Tags"
310- // helpText="Any other tags or keywords that can help people discover your dataset"
311- list={[
312- {
313- label: 'Health',
314- value: 'health',
315- },
316- {
317- label: 'Education',
318- value: 'education',
319- },
320- {
321- label: 'Agriculture',
322- value: 'agriculture',
323- },
324- ]}
325- displaySelected
326- required
327- error="This field is required"
328- />
329- </FormLayout.Group> */ }
330- </ FormLayout >
331- </ div >
332- < div className = "mt-8" >
333- < Divider />
334- </ div >
335- < div className = "mt-4 flex flex-wrap items-center justify-center gap-2" >
336- < Button
337- id = "exitAfterSave"
338- disabled
339- loading = { updateMetadataMutation . isLoading }
340- >
341- Save & Exit
342- </ Button >
343- < Button
344- id = "proceedAfterSave"
345- submit
346- loading = { updateMetadataMutation . isLoading }
347- >
348- Save & Proceed
349- </ Button >
350- </ div >
351- </ >
352- </ Form >
353- ) }
244+ ) }
245+ </ div >
246+ </ >
247+ ) : (
248+ < > </ >
249+ ) }
250+ </ FormLayout >
251+ </ div >
252+ < div className = "mt-8" >
253+ < Divider />
254+ </ div >
255+ < div className = "mt-4 flex flex-wrap items-center justify-center gap-2" >
256+ < Button
257+ id = "exitAfterSave"
258+ disabled
259+ loading = { updateMetadataMutation . isLoading }
260+ >
261+ Save & Exit
262+ </ Button >
263+ < Button
264+ id = "proceedAfterSave"
265+ submit
266+ loading = { updateMetadataMutation . isLoading }
267+ >
268+ Save & Proceed
269+ </ Button >
270+ </ div >
271+ </ >
272+ </ Form >
354273 </ >
355274 ) ;
356275}
0 commit comments