Skip to content

Commit

Permalink
save intervention policy when one is not selected (#4734)
Browse files Browse the repository at this point in the history
Co-authored-by: Cole Blanchard <[email protected]>
Co-authored-by: Cole Blanchard <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent a5b2cb2 commit 382a04f
Showing 1 changed file with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,27 @@ const selectedPolicy = ref<InterventionPolicy | null>(null);
const newDescription = ref('');
const descriptionTextareaRef = ref<ComponentPublicInstance<typeof Textarea> | null>(null);
const isEditingDescription = ref(false);
const isSaveDisabled = computed(
() =>
knobs.value.transientInterventionPolicy.id !== selectedPolicy.value?.id ||
isInterventionPoliciesEqual(knobs.value.transientInterventionPolicy, selectedPolicy.value) ||
!isInterventionPoliciesValuesEqual(knobs.value.transientInterventionPolicy, selectedPolicy.value)
);
const isSaveDisabled = computed(() => {
// Extract the selected and transient policies
const transientPolicy = knobs.value.transientInterventionPolicy;
const transientPolicyId = transientPolicy.id;
// Check if the selected policy exists
const hasSelectedPolicy = !!selectedPolicy.value;
// Check if the IDs of the transient and selected policies differ
const isPolicyIdDifferent = transientPolicyId !== selectedPolicyId.value?.id;
// Check if the policies themselves are equal
const arePoliciesEqual = isInterventionPoliciesEqual(transientPolicy, selectedPolicy.value);
// Check if the policy values are equal
const arePolicyValuesEqual = isInterventionPoliciesValuesEqual(transientPolicy, selectedPolicy.value);
// Disable save if either the policy ID is different, the policies are equal,
// or the policy values are not equal
return hasSelectedPolicy && (isPolicyIdDifferent || arePoliciesEqual || !arePolicyValuesEqual);
});
const parameterOptions = computed(() => {
if (!model.value) return [];
Expand Down Expand Up @@ -391,13 +406,20 @@ const onSaveAsInterventionPolicy = (data: InterventionPolicy) => {
const onSaveInterventionPolicy = async () => {
const policy = cloneDeep(knobs.value.transientInterventionPolicy);
const data = await updateInterventionPolicy(policy);
if (!data) {
logger.error('Failed to save intervention policy');
return;
let data;
if (!selectedPolicy.value) {
// create a new policy when there is no selected policy
showSaveModal.value = true;
} else {
// update the existing policy when there is a selected policy
data = await updateInterventionPolicy(policy);
if (!data) {
logger.error('Failed to save intervention policy');
return;
}
initialize();
useProjects().refresh();
}
initialize();
useProjects().refresh();
};
watch(
Expand Down

0 comments on commit 382a04f

Please sign in to comment.