Skip to content

Commit

Permalink
Refactor ISV configuration with platform-specific adjustments and UI …
Browse files Browse the repository at this point in the history
…improvements
  • Loading branch information
ziyang-lin-404 committed Jan 31, 2025
1 parent 041e376 commit d0c5720
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 75 deletions.
70 changes: 38 additions & 32 deletions src/react/ISV/components/ISVConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ const NameField = ({
<Select
id={fieldName}
onChange={(value) => {
const roleArn = options.find(
(option) => option.name === value,
).preferredAssumableRoleArn;
onChange(value);
if (getIAMUsersMutation) {
const roleArn = options.find(
(option) => option.name === value,
).preferredAssumableRoleArn;
getIAMUsersMutation.mutate(roleArn);
}
onChange(value);
}}
value={value}
placeholder={`Select existing ${
Expand Down Expand Up @@ -269,16 +269,13 @@ export const ISVConfiguration = () => {
setConfig(data);
next({
...data,
capacityBytes: getCapacityBytes(
data.buckets[0].capacity,
data.buckets[0].capacityUnit,
),
enableImmutableBackup:
application === VEEAM_BACKUP_REPLICATION_XML_VALUE ||
application === VEEAM_OFFICE_365_V8
? data.enableImmutableBackup
: false,
generateKey: data.generateKey,
// capacityBytes: getCapacityBytes(
// data.buckets[0].capacity,
// data.buckets[0].capacityUnit,
// ),
enableImmutableBackup: isImmutableBackupEnabled(data.application)
? data.enableImmutableBackup
: false,
});
};

Expand Down Expand Up @@ -370,7 +367,8 @@ export const ISVConfiguration = () => {
type="button"
variant="outline"
onClick={() => {
setSkip(true);
console.log(methods.getValues());
// setSkip(true);
}}
label="Skip Use case configuration"
/>
Expand Down Expand Up @@ -399,24 +397,28 @@ export const ISVConfiguration = () => {
platform={platform}
type={accountNameType}
fieldType="account"
getIAMUsersMutation={getIAMUsersMutation}
getIAMUsersMutation={
platform.id === 'commvault' ? null : getIAMUsersMutation
}
/>

{accountNameType === 'existing' && accountName && (
<Accordion title="Advanced settings" id="advanced-settings">
<NameField
register={register}
control={control}
errors={errors}
isExist={isIAMUserExist}
status={IAMUsersStatus}
options={IAMUsers}
platform={platform}
type={IAMUserNameType}
fieldType="iamUser"
/>
</Accordion>
)}
{accountNameType === 'existing' &&
accountName &&
(platform.id === 'veeam' || platform.id === 'veeam-vbo') && (
<Accordion title="Advanced settings" id="advanced-settings">
<NameField
register={register}
control={control}
errors={errors}
isExist={isIAMUserExist}
status={IAMUsersStatus}
options={IAMUsers}
platform={platform}
type={IAMUserNameType}
fieldType="iamUser"
/>
</Accordion>
)}

{platform.id === 'veeam-vbo' && renderVeeamApplication()}

Expand All @@ -432,7 +434,11 @@ export const ISVConfiguration = () => {
{isImmutableBackupEnabled(config.application) && (
<FormGroup
id={FORM_FIELDS.ENABLE_IMMUTABLE_BACKUP}
label="Immutable backup"
label={
platform.fieldOverrides.find(
(field) => field.name === FORM_FIELDS.ENABLE_IMMUTABLE_BACKUP,
).label
}
help="It enables object-lock on the bucket which means backups will be permanent and unchangeable."
helpErrorPosition="bottom"
labelHelpTooltip={
Expand Down
2 changes: 0 additions & 2 deletions src/react/ISV/components/ISVSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export const ISVSteps = () => {
buckets: [{ name: '', tag: id }],
application: getApplication(),
accountNameType: 'create',
IAMUserNameType: 'create',
generateKey: false,
}));

const platform = useMemo(() => {
Expand Down
26 changes: 0 additions & 26 deletions src/react/ISV/modules/commvault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ export const Commvault: ISVPlatformConfig = {
placeholder: 'Enter account name',
tooltip: <AccountTooltip />,
},
{
name: 'application',
label: 'COMMVAULT application',
placeholder: 'Select COMMVAULT application',
tooltip: (
<ul>
<ListItem>
Choose the COMMVAULT application you're setting up.
</ListItem>
<ListItem>
Features such as Immutable Backup and Max Repository Capacity (that
provides notification via Smart Object Storage API) are only
supported in COMMVAULT, and not in COMMVAULT.
</ListItem>
</ul>
),
},
{
name: 'bucketName',
label: 'Bucket name',
Expand All @@ -115,15 +98,6 @@ export const Commvault: ISVPlatformConfig = {
accountName: accountNameValidationSchema,
accountNameType: Joi.string().required(),
enableImmutableBackup: Joi.boolean().default(true),
bucketPrefix: Joi.string()
.label('Bucket Prefix')
.min(3)
.pattern(/^[a-z0-9.-]+$/)
.max(61)
.messages({
'string.empty':
'Choose a prefix for your buckets or set up values on the bucket level',
}),
buckets: Joi.array().items(
Joi.object({
name: bucketNameValidationSchema.custom((value, helpers) => {
Expand Down
45 changes: 30 additions & 15 deletions src/react/ui-elements/PartnerApp/BucketField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ type BucketFieldProps = {
platform?: string;
};

type BucketField = {
name: string;
tag?: string;
};

type FormValues = {
buckets: BucketField[];
bucketNumber?: number;
};

const BucketField = (fieldOverrides: BucketFieldProps) => {
const { bucketNameTooltip = defaultBucketNameTooltip, platform } =
fieldOverrides;
Expand All @@ -95,13 +105,28 @@ const BucketField = (fieldOverrides: BucketFieldProps) => {
register,
control,
formState: { errors },
} = useFormContext();
} = useFormContext<FormValues>();

const { fields, append, remove } = useFieldArray({
const { fields, append, remove, replace } = useFieldArray({
name: 'buckets',
control,
});

useEffect(() => {
if (fields.length === 0) {
append({
name: '',
tag: platform,
});
} else {
const updatedFields = fields.map((field) => ({
name: field.name,
tag: platform,
}));
replace(updatedFields);
}
}, [platform, fields.length]);

const handleBucketNumberChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newNumber = e.target.valueAsNumber;

Expand All @@ -116,23 +141,13 @@ const BucketField = (fieldOverrides: BucketFieldProps) => {
remove(i);
}
} else if (newNumber > fields.length) {
for (let i = fields.length; i < newNumber; i++) {
append({
name: '',
tag: platform,
});
}
}
};

useEffect(() => {
if (fields.length === 0) {
append({
const newFields = Array(newNumber - fields.length).fill({
name: '',
tag: platform,
});
append(newFields);
}
}, []);
};

const bucketNamePlaceholder = `${platform}-bucket-name`;

Expand Down

0 comments on commit d0c5720

Please sign in to comment.