Skip to content

Commit

Permalink
Merge pull request opendatahub-io#2927 from Gkrumbach07/bug/RHOAIENG-…
Browse files Browse the repository at this point in the history
…7678-dashboard-converts-pipeline-params-from-floats-to

update double params to be fixed at 1
  • Loading branch information
openshift-merge-bot[bot] authored Jun 21, 2024
2 parents 15db599 + 75e082b commit 2cafeff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('Pipeline create runs', () => {
},
double_param: {
parameterType: InputDefinitionParameterType.DOUBLE,
defaultValue: 0.1,
defaultValue: 7.0,
description: 'Some double helper text',
isOptional: true,
},
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Pipeline create runs', () => {
paramsSection.findParamById('string_param').should('have.value', 'String default value');
cy.findByTestId('string_param-helper-text').should('have.text', 'Some string helper text');

paramsSection.findParamById('double_param').should('have.value', '0.1');
paramsSection.findParamById('double_param').should('have.value', '7.0');
cy.findByTestId('double_param-form-group').should('not.have.text', '*', { exact: false });
cy.findByTestId('double_param-helper-text').should('have.text', 'Some double helper text');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextInput } from '@patternfly/react-core';
import React from 'react';
import React, { useRef } from 'react';
import NumberInputWrapper from '~/components/NumberInputWrapper';
import { InputParamProps } from './types';

Expand All @@ -15,16 +15,24 @@ export const NumberInputParam: React.FC<NumberInputParamProps> = ({
const [value, setValue] = React.useState<number | ''>(
inputProps.value !== '' ? Number(inputProps.value) : '',
);
const isDefault = useRef(true);

if (isFloat) {
// if the default value is a whole number, display it as x.0
const displayValue =
typeof value === 'number' && Number.isInteger(value) && isDefault.current
? value.toFixed(1)
: value;

return (
<TextInput
{...inputProps}
data-testid={inputProps.id}
type="number"
step={0.1}
value={value}
value={displayValue}
onChange={(event, newValue) => {
isDefault.current = false;
setValue(typeof newValue === 'string' ? parseFloat(newValue) : newValue);
onChange(event, newValue);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const SelectedNodeInputOutputTab: React.FC<SelectedNodeInputOutputTabProps> = ({

switch (type) {
case InputDefinitionParameterType.DOUBLE:
return numberValue && Number.isInteger(numberValue)
? numberValue.toFixed(1)
: numberValue;
case InputDefinitionParameterType.INTEGER:
return numberValue;
case InputDefinitionParameterType.BOOLEAN:
Expand Down

0 comments on commit 2cafeff

Please sign in to comment.