Skip to content

Commit

Permalink
fix(ui): auto ops validation (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalgrg519 authored Jan 19, 2023
1 parent 6f2befc commit 775e3d4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ export const AutoOpsRulesInput: FC<AutoOpsRulesInputProps> = memo(
</div>
)}
</div>
<AutoOpsRuleInput featureId={featureId} ruleIdx={ruleIdx} />
<AutoOpsRuleInput
featureId={featureId}
ruleIdx={ruleIdx}
feature={feature}
/>
</div>
);
})}
Expand All @@ -212,14 +216,15 @@ export const AutoOpsRulesInput: FC<AutoOpsRulesInputProps> = memo(
export interface AutoOpsRuleInputProps {
featureId: string;
ruleIdx: number;
feature: Feature.AsObject;
}

export const AutoOpsRuleInput: FC<AutoOpsRuleInputProps> = memo(
({ featureId, ruleIdx }) => {
({ featureId, ruleIdx, feature }) => {
const editable = useIsEditable();
const ruleName = `autoOpsRules.${ruleIdx}`;
const methods = useFormContext();
const { control } = methods;
const { control, setValue } = methods;
const rule = useWatch({
control,
name: ruleName,
Expand All @@ -233,6 +238,9 @@ export const AutoOpsRuleInput: FC<AutoOpsRuleInputProps> = memo(
render={({ field }) => (
<Select
onChange={(o: Option) => {
setValue(`autoOpsRules.${ruleIdx}.clauses`, [
createInitialClause(feature),
]);
field.onChange(o.value);
}}
options={opsTypeOptions}
Expand Down
54 changes: 35 additions & 19 deletions ui/web-v2/apps/admin/src/pages/feature/autoops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,49 @@ export const FeatureAutoOpsPage: FC<FeatureAutoOpsPageProps> = memo(
data.autoOpsRules
);

Promise.all([
new Promise(() => {
createAutoOpsRuleCommands.forEach(async (command) => {
await dispatch(
const promises = [];

createAutoOpsRuleCommands.forEach((command) => {
promises.push(
new Promise((resolve) => {
dispatch(
createAutoOpsRule({
environmentNamespace: currentEnvironment.namespace,
command: command,
})
);
});
}),
new Promise(() => {
deleteAutoOpsRuleIds.forEach(async (id) => {
await dispatch(
).then((res) => {
resolve(res);
});
})
);
});

deleteAutoOpsRuleIds.forEach((id) => {
promises.push(
new Promise((resolve) => {
dispatch(
deleteAutoOpsRule({
environmentNamespace: currentEnvironment.namespace,
id: id,
})
);
});
}),
new Promise(() => {
updateAutoOpsRuleParams.forEach(async (param) => {
await dispatch(updateAutoOpsRule(param));
});
}),
]).then(() => {
).then((res) => {
resolve(res);
});
})
);
});

updateAutoOpsRuleParams.forEach((param) => {
promises.push(
new Promise((resolve) => {
dispatch(updateAutoOpsRule(param)).then((res) => {
resolve(res);
});
})
);
});

Promise.all(promises).then((res) => {
dispatch(
listAutoOpsRules({
featureId: featureId,
Expand Down

0 comments on commit 775e3d4

Please sign in to comment.