1
1
import { useState , useRef , useEffect , useCallback , useMemo } from 'react' ;
2
2
3
3
import Form , { getDefaultRegistry } from '@rjsf/core' ;
4
- import type { FieldProps } from '@rjsf/utils' ;
4
+ import type { FieldProps , RJSFSchema } from '@rjsf/utils' ;
5
5
import validator from '@rjsf/validator-ajv8' ;
6
+ import type { GeoJsonProperties , Geometry } from 'geojson' ;
6
7
import type { JSONSchema7 } from 'json-schema' ;
7
8
import { omit , head , max as fnMax , min as fnMin , isNil } from 'lodash' ;
8
9
import { useTranslation } from 'react-i18next' ;
@@ -34,7 +35,13 @@ import HelpModal from './HelpModal';
34
35
import { LinearMetadataTooltip } from './tooltip' ;
35
36
import 'common/IntervalsDataViz/style.scss' ;
36
37
37
- const IntervalEditorComponent = ( props : FieldProps ) => {
38
+ export type FormContext = {
39
+ geometry : Geometry ;
40
+ length : number ;
41
+ isCreation : boolean ;
42
+ } ;
43
+
44
+ const IntervalEditorComponent = ( props : FieldProps < GeoJsonProperties , RJSFSchema , FormContext > ) => {
38
45
const { name, formContext, formData, schema, onChange, registry } = props ;
39
46
const { openModal, closeModal } = useModal ( ) ;
40
47
const { t } = useTranslation ( ) ;
@@ -59,10 +66,10 @@ const IntervalEditorComponent = (props: FieldProps) => {
59
66
60
67
// Get the distance of the geometry
61
68
const distance = useMemo ( ( ) => {
62
- if ( ! isNil ( formContext . length ) ) {
69
+ if ( ! isNil ( formContext ? .length ) ) {
63
70
return formContext . length ;
64
71
}
65
- if ( formContext . geometry ?. type === 'LineString' ) {
72
+ if ( formContext ? .geometry ?. type === 'LineString' ) {
66
73
return getLineStringDistance ( formContext . geometry ) ;
67
74
}
68
75
return 0 ;
@@ -414,16 +421,16 @@ const IntervalEditorComponent = (props: FieldProps) => {
414
421
) ;
415
422
} ;
416
423
417
- export const FormComponent = ( props : FieldProps ) => {
424
+ export const FormComponent = ( props : FieldProps < GeoJsonProperties , RJSFSchema , FormContext > ) => {
418
425
const { name, formContext, schema, registry } = props ;
419
426
const Fields = getDefaultRegistry ( ) . fields ;
420
427
421
428
// Get the distance of the geometry
422
429
const distance = useMemo ( ( ) => {
423
- if ( ! isNil ( formContext . length ) ) {
424
- return formContext . length ! ;
430
+ if ( ! isNil ( formContext ? .length ) ) {
431
+ return formContext . length ;
425
432
}
426
- if ( formContext . geometry ?. type === 'LineString' ) {
433
+ if ( formContext ? .geometry ?. type === 'LineString' ) {
427
434
return getLineStringDistance ( formContext . geometry ) ;
428
435
}
429
436
return 0 ;
0 commit comments