-
Notifications
You must be signed in to change notification settings - Fork 32
Add provision to recipe parameters while enrolling applicaiton #1934
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from 'react'; | ||
import { FieldLevelHelp, useCustomTranslation } from '@odf/shared'; | ||
import { LazyNameValueEditor } from '@odf/shared/utils/NameValueEditor'; | ||
import { FormGroup } from '@patternfly/react-core'; | ||
import { | ||
EnrollDiscoveredApplicationAction, | ||
EnrollDiscoveredApplicationStateType, | ||
} from '../../utils/reducer'; | ||
|
||
export const RecipeParameterInput: React.FC<RecipeParameterInputProps> = ({ | ||
dispatch, | ||
}) => { | ||
const { t } = useCustomTranslation(); | ||
const [recipeParams, setRecipeParams] = React.useState<[string, string][]>([ | ||
['', ''], | ||
]); | ||
|
||
const updateRecipeParams = ({ | ||
nameValuePairs, | ||
}: { | ||
nameValuePairs: [string, string][]; | ||
}) => { | ||
setRecipeParams(nameValuePairs); | ||
const validPairs = nameValuePairs.filter(([key]) => key.trim()); | ||
dispatch({ | ||
type: EnrollDiscoveredApplicationStateType.SET_RECIPE_PARAMETERS, | ||
payload: Object.fromEntries(validPairs.map(([k, v]) => [k.trim(), v])), | ||
}); | ||
}; | ||
|
||
return ( | ||
<FormGroup | ||
label={t('Recipe parameters')} | ||
fieldId="recipe-parameters" | ||
labelIcon={ | ||
<FieldLevelHelp> | ||
{t( | ||
'Recipe parameters are a set of named inputs that substitute the placeholders in a recipe.' | ||
)} | ||
</FieldLevelHelp> | ||
} | ||
data-test="recipe-parameters-form-group" | ||
> | ||
<LazyNameValueEditor | ||
data-test="recipe-parameters" | ||
nameValuePairs={recipeParams} | ||
updateParentData={updateRecipeParams} | ||
addString={t('Add parameter')} | ||
valueString={t('Value (optional)')} | ||
nameMaxLength={128} | ||
valueMaxLength={256} | ||
/> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
type RecipeParameterInputProps = { | ||
dispatch: React.Dispatch<EnrollDiscoveredApplicationAction>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ import { | |
} from '@odf/shared/review-and-create-step'; | ||
import { getName } from '@odf/shared/selectors'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import * as _ from 'lodash-es'; | ||
import { | ||
formatRecipeParametersForDisplay, | ||
convertToRecipeParameters, | ||
} from '../../utils/k8s-utils'; | ||
import { | ||
EnrollDiscoveredApplicationState, | ||
ProtectionMethodType, | ||
|
@@ -23,7 +28,7 @@ export const Review: React.FC<ReviewProps> = ({ state }) => { | |
const { namespace, configuration, replication } = state; | ||
const { clusterName, namespaces, name } = namespace; | ||
const { protectionMethod, recipe, resourceLabels } = configuration; | ||
const { recipeName, recipeNamespace } = recipe; | ||
const { recipeName, recipeNamespace, recipeParameters } = recipe; | ||
const { k8sResourceLabelExpressions, pvcLabelExpressions } = resourceLabels; | ||
const { drPolicy, k8sResourceReplicationInterval } = replication; | ||
|
||
|
@@ -37,6 +42,9 @@ export const Review: React.FC<ReviewProps> = ({ state }) => { | |
drPolicy.spec.schedulingInterval === '0m' | ||
? REPLICATION_DISPLAY_TEXT(t).sync | ||
: REPLICATION_DISPLAY_TEXT(t).async; | ||
const displayRecipeParameters = formatRecipeParametersForDisplay( | ||
convertToRecipeParameters(recipeParameters) | ||
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. Here, This looks redundant, I think only the whitespace trimming logic has to be common between these two functions. |
||
); | ||
const [unitVal, interval] = parseSyncInterval(k8sResourceReplicationInterval); | ||
|
||
return ( | ||
|
@@ -62,6 +70,11 @@ export const Review: React.FC<ReviewProps> = ({ state }) => { | |
<ReviewAndCreationItem label={t('Recipe namespace:')}> | ||
{recipeNamespace} | ||
</ReviewAndCreationItem> | ||
{!_.isEmpty(recipeParameters) && ( | ||
<ReviewAndCreationItem label={t('Recipe Parameters:')}> | ||
{displayRecipeParameters} | ||
</ReviewAndCreationItem> | ||
)} | ||
</> | ||
)} | ||
{protectionMethod === ProtectionMethodType.RESOURCE_LABEL && ( | ||
|
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.
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.
It is for display only, let's keep it inside the review-step.tsx file.