@@ -19,8 +19,9 @@ import {
19
19
} from '@/data-sources/types' ;
20
20
import { useForm , ValidationRules } from '@/hooks/useForm' ;
21
21
import { GoogleSheetsIcon , GoogleSheetsIconWithText } from '@/settings/icons/GoogleSheetsIcon' ;
22
- import { StringIdName } from '@/types/common' ;
22
+ import { NumberIdName } from '@/types/common' ;
23
23
import { SelectOption } from '@/types/input' ;
24
+ import { isPositiveIntegerString } from '@/utils/string' ;
24
25
25
26
const SERVICE_CONFIG_VERSION = 1 ;
26
27
@@ -94,7 +95,7 @@ export const GoogleSheetsSettings = ( {
94
95
} ;
95
96
96
97
const onCredentialsChange = ( nextValue : string ) => {
97
- handleOnChange ( 'credentials' , nextValue ) ;
98
+ handleOnChange ( 'credentials' , JSON . parse ( nextValue ) ) ;
98
99
} ;
99
100
100
101
const onSelectChange = (
@@ -103,15 +104,16 @@ export const GoogleSheetsSettings = ( {
103
104
) => {
104
105
if ( extra ?. event ) {
105
106
const { id } = extra . event . target ;
106
- let newValue : StringIdName | null = null ;
107
+ let newValue : NumberIdName | null = null ;
107
108
if ( id === 'spreadsheet' ) {
108
109
const selectedSpreadsheet = spreadsheets ?. find (
109
110
spreadsheet => spreadsheet . value === value
110
111
) ;
111
112
newValue = { id : value , name : selectedSpreadsheet ?. label ?? '' } ;
112
- } else if ( id === 'sheet' ) {
113
+ } else if ( id === 'sheet' && isPositiveIntegerString ( value ) ) {
114
+ const parsedValue = parseInt ( value , 10 ) ;
113
115
const selectedSheet = sheets ?. find ( sheet => sheet . value === value ) ;
114
- newValue = { id : value , name : selectedSheet ?. label ?? '' } ;
116
+ newValue = { id : parsedValue , name : selectedSheet ?. label ?? '' } ;
115
117
}
116
118
handleOnChange ( id , newValue ) ;
117
119
}
@@ -221,7 +223,7 @@ export const GoogleSheetsSettings = ( {
221
223
>
222
224
< TextareaControl
223
225
label = { __ ( 'Credentials' , 'remote-data-blocks' ) }
224
- value = { state . credentials ? JSON . stringify ( state . credentials ) : '' }
226
+ value = { state . credentials ? JSON . stringify ( state . credentials , null , 2 ) : '' }
225
227
onChange = { onCredentialsChange }
226
228
help = { credentialsHelpText }
227
229
rows = { 10 }
0 commit comments