-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend) Support LIST, STRUCT type in RuntimeConfig parameters #7991
Changes from 1 commit
f6a4169
643b23e
e5d0d68
a5a8fc0
5e91dff
2faedf8
ca71e50
b53aa87
de688f5
91a8f77
4a4225e
d7628d8
91fc887
29b452e
aeec427
65a8c80
1375a73
3edc791
d8412a8
f61293e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const strParam = screen.getByLabelText('strParam - STRING'); | ||
fireEvent.change(strParam, { target: { value: 'new string' } }); | ||
|
@@ -155,7 +155,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const boolParam = screen.getByDisplayValue('true'); | ||
fireEvent.change(boolParam, { target: { value: 'false' } }); | ||
|
@@ -178,7 +178,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const boolParam = screen.getByLabelText('boolParam - BOOLEAN'); | ||
fireEvent.change(boolParam, { target: { value: 'true' } }); | ||
|
@@ -201,7 +201,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const boolParam = screen.getByLabelText('boolParam - BOOLEAN'); | ||
fireEvent.change(boolParam, { target: { value: 'True' } }); | ||
|
@@ -225,7 +225,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const intParam = screen.getByDisplayValue('123'); | ||
fireEvent.change(intParam, { target: { value: '456' } }); | ||
|
@@ -248,7 +248,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const intParam = screen.getByLabelText('intParam - NUMBER_INTEGER'); | ||
fireEvent.change(intParam, { target: { value: '789' } }); | ||
|
@@ -271,7 +271,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const intParam = screen.getByLabelText('intParam - NUMBER_INTEGER'); | ||
fireEvent.change(intParam, { target: { value: '7.89' } }); | ||
|
@@ -281,6 +281,53 @@ describe('NewRunParametersV2', () => { | |
}); | ||
}); | ||
|
||
it('test convertInput function for double type with default value', () => { | ||
const handleParameterChangeSpy = jest.fn(); | ||
const props = { | ||
titleMessage: 'default Title', | ||
pipelineRoot: 'defalut pipelineRoot', | ||
specParameters: { | ||
doubleParam: { | ||
parameterType: ParameterType_ParameterTypeEnum.NUMBER_DOUBLE, | ||
defaultValue: 1.23, | ||
}, | ||
}, | ||
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const doubleParam = screen.getByDisplayValue('1.23'); | ||
fireEvent.change(doubleParam, { target: { value: '4.56' } }); | ||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
doubleParam: 4.56, | ||
}); | ||
}); | ||
|
||
it('test convertInput function for double type without default value', () => { | ||
const handleParameterChangeSpy = jest.fn(); | ||
const props = { | ||
titleMessage: 'default Title', | ||
pipelineRoot: 'defalut pipelineRoot', | ||
specParameters: { | ||
doubleParam: { | ||
parameterType: ParameterType_ParameterTypeEnum.NUMBER_DOUBLE, | ||
}, | ||
}, | ||
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const doubleParam = screen.getByLabelText('doubleParam - NUMBER_DOUBLE'); | ||
fireEvent.change(doubleParam, { target: { value: '7.89' } }); | ||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
doubleParam: 7.89, | ||
}); | ||
}); | ||
|
||
it('test convertInput function for LIST type with default value', () => { | ||
const handleParameterChangeSpy = jest.fn(); | ||
const props = { | ||
|
@@ -295,14 +342,15 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const listParam = screen.getByDisplayValue('[1,2,3]'); | ||
fireEvent.change(listParam, { target: { value: '[4,5,6]' } }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we check the screen now has [4,5,6]?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for all cases below. |
||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
listParam: [4, 5, 6], | ||
}); | ||
expect(screen.getByDisplayValue('[4,5,6]')); | ||
}); | ||
|
||
it('test convertInput function for LIST type without default value', () => { | ||
|
@@ -318,14 +366,15 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const listParam = screen.getByLabelText('listParam - LIST'); | ||
fireEvent.change(listParam, { target: { value: '[4,5,6]' } }); | ||
zijianjoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
listParam: [4, 5, 6], | ||
}); | ||
expect(screen.getByDisplayValue('[4,5,6]')); | ||
}); | ||
|
||
it('test convertInput function for LIST type with invalid input (invalid JSON form)', () => { | ||
|
@@ -341,7 +390,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const listParam = screen.getByLabelText('listParam - LIST'); | ||
fireEvent.change(listParam, { target: { value: '[4,5,6' } }); | ||
|
@@ -365,14 +414,15 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const structParam = screen.getByDisplayValue('{"A":1,"B":2}'); | ||
fireEvent.change(structParam, { target: { value: '{"C":3,"D":4}' } }); | ||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
structParam: { C: 3, D: 4 }, | ||
}); | ||
expect(screen.getByDisplayValue('{"C":3,"D":4}')); | ||
}); | ||
|
||
it('test convertInput function for STRUCT type without default value', () => { | ||
|
@@ -388,14 +438,15 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const structParam = screen.getByLabelText('structParam - STRUCT'); | ||
fireEvent.change(structParam, { target: { value: '{"A":1,"B":2}' } }); | ||
expect(handleParameterChangeSpy).toHaveBeenCalledTimes(1); | ||
expect(handleParameterChangeSpy).toHaveBeenLastCalledWith({ | ||
structParam: { A: 1, B: 2 }, | ||
}); | ||
expect(screen.getByDisplayValue('{"A":1,"B":2}')); | ||
zijianjoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('test convertInput function for STRUCT type with invalid input (invalid JSON form)', () => { | ||
|
@@ -411,7 +462,7 @@ describe('NewRunParametersV2', () => { | |
handlePipelineRootChange: jest.fn(), | ||
handleParameterChange: handleParameterChangeSpy, | ||
}; | ||
render(<NewRunParametersV2 {...props}></NewRunParametersV2>); | ||
render(<NewRunParametersV2 {...props} />); | ||
|
||
const structParam = screen.getByLabelText('structParam - STRUCT'); | ||
fireEvent.change(structParam, { target: { value: '"A":1,"B":2' } }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,11 @@ function convertInput(paramStr: string, paramType: ParameterType_ParameterTypeEn | |
return Number(paramStr); | ||
} | ||
return null; | ||
case ParameterType_ParameterTypeEnum.NUMBER_DOUBLE: | ||
if (!Number.isNaN(Number(paramStr))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Is it necessary to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think so. The input of isNaN() should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
return Number(paramStr); | ||
} | ||
return null; | ||
case ParameterType_ParameterTypeEnum.LIST: | ||
case ParameterType_ParameterTypeEnum.STRUCT: | ||
try { | ||
|
@@ -104,6 +109,7 @@ function NewRunParametersV2(props: NewRunParametersProps) { | |
break; | ||
case ParameterType_ParameterTypeEnum.BOOLEAN: | ||
case ParameterType_ParameterTypeEnum.NUMBER_INTEGER: | ||
zijianjoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case ParameterType_ParameterTypeEnum.NUMBER_DOUBLE: | ||
defaultValStr = props.specParameters[key].defaultValue.toString(); | ||
break; | ||
default: | ||
|
@@ -234,6 +240,7 @@ class ParamEditor extends React.Component<ParamEditorProps, ParamEditorState> { | |
case ParameterType_ParameterTypeEnum.STRING: | ||
case ParameterType_ParameterTypeEnum.BOOLEAN: | ||
case ParameterType_ParameterTypeEnum.NUMBER_INTEGER: | ||
zijianjoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case ParameterType_ParameterTypeEnum.NUMBER_DOUBLE: | ||
isJson = false; | ||
break; | ||
default: | ||
|
@@ -273,7 +280,6 @@ class ParamEditor extends React.Component<ParamEditorProps, ParamEditorState> { | |
} | ||
|
||
// TODO(zijianjoy): JSON format needs to be struct or list type. | ||
// const displayValue = JSON.parse(param.value?.string_value || ''); | ||
if (this.state.isEditorOpen) { | ||
onChange(JSON.stringify(displayValue) || ''); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new tests: Please also check for the existence of display value 4.56. Just like we mentioned in https://github.com/kubeflow/pipelines/pull/7991/files#r916159217