-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sap-features-hub): add pre-installation form step5
ref: MANAGER-15979 Signed-off-by: Paul Dickerson <[email protected]>
- Loading branch information
Paul Dickerson
committed
Jan 24, 2025
1 parent
0f90a4f
commit 000674f
Showing
13 changed files
with
244 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/manager/apps/sap-features-hub/src/components/Form/ToggleField.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { | ||
OdsFormField, | ||
OdsText, | ||
OdsToggle, | ||
OdsTooltip, | ||
} from '@ovhcloud/ods-components/react'; | ||
import { OdsToggleChangeEvent } from '@ovhcloud/ods-components'; | ||
import { FormKey } from '@/types/form.type'; | ||
|
||
export type ToggleFieldProps = { | ||
name: FormKey; | ||
checked: boolean; | ||
onOdsChange: (e: OdsToggleChangeEvent) => void; | ||
label?: string; | ||
tooltip?: string; | ||
}; | ||
|
||
export const ToggleField = ({ | ||
name, | ||
checked, | ||
onOdsChange, | ||
label, | ||
tooltip, | ||
}: ToggleFieldProps) => { | ||
return ( | ||
<OdsFormField | ||
key={name} | ||
className="w-full max-w-md flex flex-row items-center gap-x-2" | ||
> | ||
{label && ( | ||
<label htmlFor={`${name}-toggle`} slot="label"> | ||
<OdsText>{label}</OdsText> | ||
</label> | ||
)} | ||
<OdsToggle | ||
id={`${name}-toggle`} | ||
name={name} | ||
value={checked} | ||
onOdsChange={onOdsChange} | ||
className="ml-auto" | ||
/> | ||
{tooltip && ( | ||
<OdsTooltip triggerId={`${name}-toggle`}>{tooltip}</OdsTooltip> | ||
)} | ||
</OdsFormField> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...ps/sap-features-hub/src/pages/installation/stepOSConfig/InstallationStepOSConfig.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { OdsToggleChangeEvent } from '@ovhcloud/ods-components'; | ||
import { useFormSteps } from '@/hooks/formStep/useFormSteps'; | ||
import { useInstallationFormContext } from '@/context/InstallationForm.context'; | ||
import { TextField } from '@/components/Form/TextField.component'; | ||
import { getOSConfigFormData } from '@/utils/formStepData'; | ||
import FormLayout from '@/components/Form/FormLayout.component'; | ||
import { | ||
OS_LICENCE_MAX_LENGTH, | ||
OS_LICENCE_MIN_LENGTH, | ||
OS_LICENSE_PATTERN, | ||
} from './installationStepOSConfig.constants'; | ||
import { isValidDomain } from '@/utils/formValidation'; | ||
import { ToggleField } from '@/components/Form/ToggleField.component'; | ||
|
||
export default function InstallationStepOSConfig() { | ||
const { t } = useTranslation('installation'); | ||
const { previousStep, nextStep } = useFormSteps(); | ||
const { | ||
values: formValues, | ||
errors: formErrors, | ||
setValues, | ||
setErrors, | ||
} = useInstallationFormContext(); | ||
|
||
const { values, errors } = getOSConfigFormData({ | ||
values: formValues, | ||
errors: formErrors, | ||
}); | ||
|
||
const isStepValid = useMemo( | ||
() => values.domainName && !errors.domainName && !errors.osLicense, | ||
[values.domainName, errors.domainName, errors.osLicense], | ||
); | ||
|
||
const handleToggle = (e: OdsToggleChangeEvent) => { | ||
const { name, value } = e.detail; | ||
setValues((val) => ({ ...val, [name]: value })); | ||
}; | ||
|
||
return ( | ||
<FormLayout | ||
title={t('os_config_title')} | ||
subtitle={t('os_config_subtitle')} | ||
submitLabel={t('os_config_cta')} | ||
isSubmitDisabled={!isStepValid} | ||
onClickSubmit={nextStep} | ||
onClickPrevious={previousStep} | ||
> | ||
<TextField | ||
name="domainName" | ||
label={t('os_config_input_domain')} | ||
onOdsChange={(e) => { | ||
const { name, value } = e.detail; | ||
const isValid = isValidDomain(value as string); | ||
setValues((val) => ({ ...val, [name]: value })); | ||
setErrors((err) => ({ | ||
...err, | ||
[name]: isValid ? '' : t('os_config_helper_domain'), | ||
})); | ||
}} | ||
value={values.domainName} | ||
error={values.domainName && errors.domainName} | ||
placeholder="mydomain.local" | ||
helperText={t('os_config_helper_domain')} | ||
isRequired | ||
/> | ||
<TextField | ||
name="osLicense" | ||
label={t('os_config_input_suse')} | ||
onOdsChange={(e) => { | ||
const { name, value } = e.detail; | ||
const isValid = e.detail.validity?.valid; | ||
setValues((val) => ({ ...val, [name]: value })); | ||
setErrors((err) => ({ | ||
...err, | ||
[name]: !!value && !isValid ? t('os_config_helper_suse') : '', | ||
})); | ||
}} | ||
value={values.osLicense} | ||
error={values.osLicense && errors.osLicense} | ||
placeholder="123456789ABCDEFG" | ||
helperText={t('os_config_helper_suse')} | ||
pattern={OS_LICENSE_PATTERN} | ||
minlength={OS_LICENCE_MIN_LENGTH} | ||
maxlength={OS_LICENCE_MAX_LENGTH} | ||
/> | ||
<ToggleField | ||
name={'osUpdate'} | ||
checked={values.osUpdate} | ||
onOdsChange={handleToggle} | ||
label={t('os_config_toggle_update')} | ||
/> | ||
<ToggleField | ||
name={'firewallService'} | ||
checked={values.firewallService} | ||
onOdsChange={handleToggle} | ||
label={t('os_config_toggle_firewall_service')} | ||
tooltip={t('os_config_tooltip_firewall_service')} | ||
/> | ||
<ToggleField | ||
name={'firewallServer'} | ||
checked={values.firewallServer} | ||
onOdsChange={handleToggle} | ||
label={t('os_config_toggle_firewall_server')} | ||
tooltip={t('os_config_tooltip_firewall_server')} | ||
/> | ||
<ToggleField | ||
name={'firewallDatabase'} | ||
checked={values.firewallDatabase} | ||
onOdsChange={handleToggle} | ||
label={t('os_config_toggle_firewall_database')} | ||
tooltip={t('os_config_tooltip_firewall_database')} | ||
/> | ||
</FormLayout> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
...ap-features-hub/src/pages/installation/stepOSConfig/installationStepOSConfig.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const OS_LICENSE_PATTERN = /^[A-Za-z0-9]{16,32}$/.source; | ||
export const OS_LICENCE_MIN_LENGTH = 16; | ||
export const OS_LICENCE_MAX_LENGTH = 32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters