From 1b83a24ea41a8257303028814e47dd364d282528 Mon Sep 17 00:00:00 2001 From: Lyon Lu Date: Tue, 15 Oct 2024 07:39:50 +0800 Subject: [PATCH 1/6] msgpack idl supporting Signed-off-by: Lyon Lu --- package.json | 1 + .../LaunchFormComponents/StructInput.tsx | 14 +++++++++++++- .../oss-console/src/components/Literals/helpers.ts | 8 ++++++++ yarn.lock | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) 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 ? ( Date: Thu, 17 Oct 2024 00:31:57 +0800 Subject: [PATCH 2/6] code review fix Signed-off-by: Lyon Lu --- .../LaunchFormComponents/StructInput.tsx | 11 ----------- .../Launch/LaunchForm/inputHelpers/struct.ts | 19 ++++++++++++++++++- .../src/components/Literals/helpers.ts | 9 ++++++++- 3 files changed, 26 insertions(+), 13 deletions(-) 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 49ecdee76..b000604b4 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx +++ b/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx @@ -61,7 +61,6 @@ export const StructInput: FC = (props) => { typeDefinition: { literalType }, value = '', hasCollectionParent, - initialValue, } = props; const { jsonFormRenderable, parsedJson } = useMemo(() => { @@ -101,16 +100,6 @@ 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 ? ( ): Protobuf.IStruct { return { fields }; } +function parseBinary(binary: Core.IBinary): string { + if (!binary.value) { + throw new Error('Binary value is empty'); + } + + if (binary.tag === 'msgpack') { + return JSON.stringify(msgpack.decode(binary.value)); + } + + // unsupported binary type, it might be temporary + return ''; +} + function fromLiteral(literal: Core.ILiteral): InputValue { - const structValue = extractLiteralWithCheck(literal, structPath); + if (literal.scalar?.binary) { + return parseBinary(literal.scalar.binary); + } + const structValue = extractLiteralWithCheck(literal, structPath); const finalValue = formatParameterValues(InputType.Struct, protobufStructToObject(structValue)); return finalValue; } diff --git a/packages/oss-console/src/components/Literals/helpers.ts b/packages/oss-console/src/components/Literals/helpers.ts index 931b23ab4..c847fefb6 100644 --- a/packages/oss-console/src/components/Literals/helpers.ts +++ b/packages/oss-console/src/components/Literals/helpers.ts @@ -80,7 +80,14 @@ function processBinary(binary?: Core.IBinary | null) { return 'invalid binary'; } - if (tag === 'msgpack' && binary.value) { + if (!binary.value) { + return { + tag: `${tag}`, + value: '(empty)', + }; + } + + if (tag === 'msgpack') { return { tag: 'msgpack', value: msgpack.decode(binary.value), From 7b873aea0c97c80298b12ab97fe37be53fcf33c6 Mon Sep 17 00:00:00 2001 From: Lyon Lu Date: Fri, 18 Oct 2024 03:22:26 +0800 Subject: [PATCH 3/6] fix test Signed-off-by: Lyon Lu --- script/test/jest-setup.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/script/test/jest-setup.ts b/script/test/jest-setup.ts index 7b0828bfa..9e7e2d759 100644 --- a/script/test/jest-setup.ts +++ b/script/test/jest-setup.ts @@ -1 +1,5 @@ import '@testing-library/jest-dom'; + +import { TextEncoder, TextDecoder } from 'util'; + +Object.assign(global, { TextDecoder, TextEncoder }); From 116ebb3c66d897e42f846d1eebe89777ee03dde4 Mon Sep 17 00:00:00 2001 From: Lyon Lu Date: Fri, 18 Oct 2024 04:23:17 +0800 Subject: [PATCH 4/6] fix test and error display Signed-off-by: Lyon Lu --- .../src/components/Literals/helpers.ts | 3 ++- .../helpers/genScalarBinaryTestCase.mock.ts | 26 ++++++++++++++----- packages/oss-console/src/test/setupTests.ts | 3 +++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/oss-console/src/components/Literals/helpers.ts b/packages/oss-console/src/components/Literals/helpers.ts index c847fefb6..0aa25bd49 100644 --- a/packages/oss-console/src/components/Literals/helpers.ts +++ b/packages/oss-console/src/components/Literals/helpers.ts @@ -95,7 +95,8 @@ function processBinary(binary?: Core.IBinary | null) { } return { - tag: `${tag} (binary data not shown)`, + tag: `${tag}`, + value: "(unsupported tag type)", }; } diff --git a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts index f2452e202..966f21189 100644 --- a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts +++ b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts @@ -1,15 +1,29 @@ import Core from '@clients/common/flyteidl/core'; +import { encode } from '@msgpack/msgpack'; import { TestCaseList } from '../types'; +const testJson = { + test1: 1, + test2: '2', + test3: true, +}; + const scalarBinaryTestCases: TestCaseList = { - WITH_VAL: { - value: { value: new Uint8Array(), tag: 'tag1' }, - expected: { result_var: { tag: 'tag1 (binary data not shown)' } }, + NORMAL_MSGPACK: { + value: { value: encode(testJson), tag: 'msgpack' }, + expected: { result_var: { tag: 'msgpack', value: testJson } }, }, - INT_WITH_SMALL_LOW: { - value: { tag: 'tag2' }, - expected: { result_var: { tag: 'tag2 (binary data not shown)' } }, + UNSUPPORTED_TAG: { + value: { tag: 'tag2', value: new Uint8Array([1, 2, 3, 4]) }, + expected: { result_var: { + tag: "tag2", + value: "(unsupported tag type)", + }}, }, + EMPTY_VALUE: { + value: { tag: 'msgpack' }, + expected: { result_var: { tag: 'msgpack', value: "(empty)" } }, + } }; export default scalarBinaryTestCases; diff --git a/packages/oss-console/src/test/setupTests.ts b/packages/oss-console/src/test/setupTests.ts index 808b7d01d..a12789316 100644 --- a/packages/oss-console/src/test/setupTests.ts +++ b/packages/oss-console/src/test/setupTests.ts @@ -1,4 +1,7 @@ import '@testing-library/jest-dom'; +import { TextEncoder, TextDecoder } from 'util'; + +Object.assign(global, { TextDecoder, TextEncoder }); jest.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({ prism: {}, From 2823361a847868bbb6ebb5a41943cb1ea335b6b2 Mon Sep 17 00:00:00 2001 From: Lyon Lu Date: Fri, 18 Oct 2024 04:54:03 +0800 Subject: [PATCH 5/6] display update Signed-off-by: Lyon Lu --- packages/oss-console/src/components/Literals/helpers.ts | 2 +- .../test/helpers/genScalarBinaryTestCase.mock.ts | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/oss-console/src/components/Literals/helpers.ts b/packages/oss-console/src/components/Literals/helpers.ts index 0aa25bd49..435d67bea 100644 --- a/packages/oss-console/src/components/Literals/helpers.ts +++ b/packages/oss-console/src/components/Literals/helpers.ts @@ -96,7 +96,7 @@ function processBinary(binary?: Core.IBinary | null) { return { tag: `${tag}`, - value: "(unsupported tag type)", + value: "(binary data now shown)", }; } diff --git a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts index 966f21189..6131f007c 100644 --- a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts +++ b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts @@ -13,12 +13,9 @@ const scalarBinaryTestCases: TestCaseList = { value: { value: encode(testJson), tag: 'msgpack' }, expected: { result_var: { tag: 'msgpack', value: testJson } }, }, - UNSUPPORTED_TAG: { - value: { tag: 'tag2', value: new Uint8Array([1, 2, 3, 4]) }, - expected: { result_var: { - tag: "tag2", - value: "(unsupported tag type)", - }}, + WITH_VAL: { + value: { value: new Uint8Array(), tag: 'tag1' }, + expected: { result_var: { tag: 'tag1', value: '(binary data now shown)' } }, }, EMPTY_VALUE: { value: { tag: 'msgpack' }, From 49ea75f6f850764dc3a4b91cb90158ad51c7ea5b Mon Sep 17 00:00:00 2001 From: Carina Ursu Date: Thu, 17 Oct 2024 15:56:05 -0500 Subject: [PATCH 6/6] typo Signed-off-by: Carina Ursu --- packages/oss-console/src/components/Literals/helpers.ts | 2 +- .../Literals/test/helpers/genScalarBinaryTestCase.mock.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/oss-console/src/components/Literals/helpers.ts b/packages/oss-console/src/components/Literals/helpers.ts index 435d67bea..12b7f6ba0 100644 --- a/packages/oss-console/src/components/Literals/helpers.ts +++ b/packages/oss-console/src/components/Literals/helpers.ts @@ -96,7 +96,7 @@ function processBinary(binary?: Core.IBinary | null) { return { tag: `${tag}`, - value: "(binary data now shown)", + value: "(binary data not shown)", }; } diff --git a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts index 6131f007c..a40470242 100644 --- a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts +++ b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts @@ -15,12 +15,12 @@ const scalarBinaryTestCases: TestCaseList = { }, WITH_VAL: { value: { value: new Uint8Array(), tag: 'tag1' }, - expected: { result_var: { tag: 'tag1', value: '(binary data now shown)' } }, + expected: { result_var: { tag: 'tag1', value: '(binary data not shown)' } }, }, EMPTY_VALUE: { value: { tag: 'msgpack' }, - expected: { result_var: { tag: 'msgpack', value: "(empty)" } }, - } + expected: { result_var: { tag: 'msgpack', value: '(empty)' } }, + }, }; export default scalarBinaryTestCases;