mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
fix(console): fix code edtior set undefined value bug (#5499)
fix the code editor set undefined value bug
This commit is contained in:
parent
abb2c9f649
commit
e95a04619b
3 changed files with 8 additions and 5 deletions
|
@ -155,7 +155,8 @@ function MonacoCodeEditor({
|
||||||
path={activeModel.name}
|
path={activeModel.name}
|
||||||
theme="logto-dark"
|
theme="logto-dark"
|
||||||
options={defaultOptions}
|
options={defaultOptions}
|
||||||
value={value ?? activeModel.defaultValue}
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- empty string is falsy
|
||||||
|
value={value || activeModel.defaultValue}
|
||||||
beforeMount={handleEditorWillMount}
|
beforeMount={handleEditorWillMount}
|
||||||
onMount={handleEditorDidMount}
|
onMount={handleEditorDidMount}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|
|
@ -57,11 +57,12 @@ function ScriptSection() {
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
// If the value is the same as the default code and the original form script value is undefined, reset the value to undefined as well
|
// If the value is the same as the default code and the original form script value is undefined, reset the value to undefined as well
|
||||||
if (newValue === activeModel.defaultValue && !defaultValues?.script) {
|
if (newValue === activeModel.defaultValue && !defaultValues?.script) {
|
||||||
onChange();
|
onChange('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange(newValue);
|
// Input value should not be undefined for react-hook-form @see https://react-hook-form.com/docs/usecontroller/controller
|
||||||
|
onChange(newValue ?? '');
|
||||||
}}
|
}}
|
||||||
onMountHandler={onMountHandler}
|
onMountHandler={onMountHandler}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -31,7 +31,7 @@ export const formatResponseDataToFormData = <T extends LogtoJwtTokenPath>(
|
||||||
: ClientCredentialsJwtCustomizer
|
: ClientCredentialsJwtCustomizer
|
||||||
): JwtClaimsFormType => {
|
): JwtClaimsFormType => {
|
||||||
return {
|
return {
|
||||||
script: data?.script,
|
script: data?.script ?? '', // React-hook-form won't mutate the value if it's undefined
|
||||||
tokenType,
|
tokenType,
|
||||||
environmentVariables: formatEnvVariablesResponseToFormData(data?.envVars) ?? [
|
environmentVariables: formatEnvVariablesResponseToFormData(data?.envVars) ?? [
|
||||||
{ key: '', value: '' },
|
{ key: '', value: '' },
|
||||||
|
@ -71,7 +71,8 @@ const formatSampleCodeStringToJson = (sampleCode?: string) => {
|
||||||
|
|
||||||
export const formatFormDataToRequestData = (data: JwtClaimsFormType) => {
|
export const formatFormDataToRequestData = (data: JwtClaimsFormType) => {
|
||||||
return {
|
return {
|
||||||
script: data.script,
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- parse empty string as undefined
|
||||||
|
script: data.script || undefined,
|
||||||
envVars: formatEnvVariablesFormData(data.environmentVariables),
|
envVars: formatEnvVariablesFormData(data.environmentVariables),
|
||||||
tokenSample: formatSampleCodeStringToJson(data.testSample?.tokenSample),
|
tokenSample: formatSampleCodeStringToJson(data.testSample?.tokenSample),
|
||||||
// Technically, contextSample is always undefined for client credentials token type
|
// Technically, contextSample is always undefined for client credentials token type
|
||||||
|
|
Loading…
Reference in a new issue