Skip to content

Commit

Permalink
Fixes #37612 - Fix deletion of Ansible variables from Host page
Browse files Browse the repository at this point in the history
- Use `isEqual` for deep comparison when matching variable values,
  ensuring correct behavior during variable deletion.
- Add `defaultValue` field to GraphQL mutation, for proper display
  after Ansible variable deletion.
  • Loading branch information
nofaralfasi committed Aug 5, 2024
1 parent d0d226b commit b351074
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { isEqual } from 'lodash';
import { TimesIcon, CheckIcon } from '@patternfly/react-icons';
import { sprintf, translate as __ } from 'foremanReact/common/I18n';

Expand Down Expand Up @@ -48,7 +49,7 @@ export const onCompleted = onSubmitSuccess => response => {
message: formatError(joinErrors(errors)),
});
} else {
onSubmitSuccess(overridenAnsibleVariable.currentValue.value);
onSubmitSuccess(overridenAnsibleVariable.defaultValue);
showToast({
type: 'success',
message: __('Ansible variable override was successfully deleted.'),
Expand All @@ -59,7 +60,7 @@ export const onCompleted = onSubmitSuccess => response => {
export const findOverride = (variable, hostname) =>
variable.lookupValues.nodes.find(
item =>
item.value === variable.currentValue.value &&
isEqual(item.value, variable.currentValue.value) &&
item.match === `fqdn=${hostname}`
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export const deleteMocks = [
overridenAnsibleVariable: {
__typename: 'OverridenAnsibleVariable',
id: ansibleVariableId,
defaultValue: 101,
currentValue: {
__typename: 'AnsibleVariableOverride',
element: 'os',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mutation DeleteAnsibleVariableOverride($id: ID!, $hostId: Int!, $variableId: Int
id
overridenAnsibleVariable {
id
defaultValue
currentValue {
value
element
Expand Down

0 comments on commit b351074

Please sign in to comment.