This is an automated email from the ASF dual-hosted git repository.
young pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 78d1c32d4 fix(JSONInput): toObject logic (#3117)
78d1c32d4 is described below
commit 78d1c32d4b3ab90527e5e5abb21ec1b5250b2e76
Author: YYYoung <[email protected]>
AuthorDate: Fri Jun 13 16:47:14 2025 +0800
fix(JSONInput): toObject logic (#3117)
* fix(stream_routes): logic for processing data
* Revert "fix(stream_routes): logic for processing data"
This reverts commit 349512666bb772b88c54c418f50d91a30c5b5ea5.
* chore
---
src/components/form/JsonInput.tsx | 22 ++++++++++++----------
src/types/schema/apisix/stream_routes.ts | 4 ++--
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/components/form/JsonInput.tsx
b/src/components/form/JsonInput.tsx
index 3796c1139..206289eb8 100644
--- a/src/components/form/JsonInput.tsx
+++ b/src/components/form/JsonInput.tsx
@@ -15,6 +15,7 @@
* limitations under the License.
*/
import { JsonInput, type JsonInputProps } from '@mantine/core';
+import { omit } from 'rambdax';
import { useMemo } from 'react';
import {
type FieldValues,
@@ -24,19 +25,20 @@ import {
import { genControllerProps } from './util';
-export type FormItemJsonInputProps<T extends FieldValues> =
- UseControllerProps<T> &
- JsonInputProps & {
- toObject?: boolean;
- };
+export type FormItemJsonInputProps<T extends FieldValues> =
UseControllerProps<T> &
+ JsonInputProps & {
+ toObject?: boolean;
+ objValue?: unknown;
+ };
export const FormItemJsonInput = <T extends FieldValues>(
props: FormItemJsonInputProps<T>
) => {
+ const { objValue = {} } = props;
const {
controllerProps,
restProps: { toObject, ...restProps },
- } = genControllerProps(props, props.toObject ? {} : '');
+ } = genControllerProps(props, props.toObject ? objValue : '');
const {
field: { value: rawVal, onChange: fOnChange, ...restField },
fieldState,
@@ -45,9 +47,9 @@ export const FormItemJsonInput = <T extends FieldValues>(
if (!toObject) return rawVal;
if (typeof rawVal === 'string') return rawVal;
const val = JSON.stringify(rawVal, null, 2);
- if (val === '{}') return '';
+ if (val === JSON.stringify(objValue)) return '';
return val;
- }, [rawVal, toObject]);
+ }, [rawVal, toObject, objValue]);
return (
<JsonInput
@@ -59,7 +61,7 @@ export const FormItemJsonInput = <T extends FieldValues>(
try {
res = JSON.parse(val);
} catch {
- res = val.length === 0 ? {} : val;
+ res = val.length === 0 ? objValue : val;
}
}
fOnChange(res);
@@ -69,7 +71,7 @@ export const FormItemJsonInput = <T extends FieldValues>(
autosize
resize="vertical"
{...restField}
- {...restProps}
+ {...omit(['objValue'], restProps)}
/>
);
};
diff --git a/src/types/schema/apisix/stream_routes.ts
b/src/types/schema/apisix/stream_routes.ts
index fcea623b5..77757abe0 100644
--- a/src/types/schema/apisix/stream_routes.ts
+++ b/src/types/schema/apisix/stream_routes.ts
@@ -28,8 +28,8 @@ const StreamRouteProtocolLoggerItem = z.object({
const StreamRouteProtocol = z.object({
name: z.string(),
superior_id: z.string(),
- conf: z.object({}),
- logger: z.array(StreamRouteProtocolLoggerItem),
+ conf: z.object({}).optional(),
+ logger: z.array(StreamRouteProtocolLoggerItem).optional(),
});
const StreamRoute = z