diff --git a/package.json b/package.json index e11218f62..1b79b153b 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "dependencies": { "@commitlint/cli": "^17.3.0", "@commitlint/config-conventional": "^17.3.0", + "@msgpack/msgpack": "^3.0.0-beta2", "@semantic-release/changelog": "^5.0.1", "@semantic-release/commit-analyzer": "^8.0.1", "@semantic-release/exec": "^6.0.3", diff --git a/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx b/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx index 208d39086..49ecdee76 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx +++ b/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx @@ -1,7 +1,8 @@ -import React, { FC, useCallback, useMemo, useState } from 'react'; +import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'; import { Form } from '@rjsf/mui'; import validator from '@rjsf/validator-ajv8'; import styled from '@mui/system/styled'; +import * as msgpack from '@msgpack/msgpack'; import { InputProps } from '../types'; import { protobufValueToPrimitive, PrimitiveType } from '../inputHelpers/struct'; import { StyledCard } from './StyledCard'; @@ -60,6 +61,7 @@ export const StructInput: FC = (props) => { typeDefinition: { literalType }, value = '', hasCollectionParent, + initialValue, } = props; const { jsonFormRenderable, parsedJson } = useMemo(() => { @@ -99,6 +101,16 @@ export const StructInput: FC = (props) => { setParamData(formData); }, []); + useEffect(() => { + if (!jsonFormRenderable && initialValue) { + const value = initialValue.scalar?.binary?.value; + if (value) { + const parsedValue = msgpack.decode(value); + onChange(JSON.stringify(parsedValue)); + } + } + }, [jsonFormRenderable, initialValue]); + return jsonFormRenderable ? (