Skip to content

Commit

Permalink
Fix modification check for read-only form items
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed Nov 18, 2024
1 parent c387a62 commit cc0a76e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 90 deletions.
44 changes: 23 additions & 21 deletions ui/src/main/java/org/jboss/hal/ui/resource/BooleanFormItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,32 @@ boolean validate() {

@Override
boolean isModified() {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
if (ra.description.hasDefault()) {
return ra.description.get(DEFAULT).asBoolean() != switchControl.value();
} else {
return ra.value.asBoolean(false) != switchControl.value();
if (ra.readable && !ra.description.readOnly()) {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
if (ra.description.hasDefault()) {
return ra.description.get(DEFAULT).asBoolean() != switchControl.value();
} else {
return ra.value.asBoolean(false) != switchControl.value();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
return ra.expression || ra.value.asBoolean() != switchControl.value();
} else {
return true;
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
return ra.expression || ra.value.asBoolean() != switchControl.value();
} else {
return true;
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
} else {
unknownScope();
}
} else {
unknownScope();
}
return false;
}
Expand Down
84 changes: 43 additions & 41 deletions ui/src/main/java/org/jboss/hal/ui/resource/NumberFormItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,56 +340,58 @@ private RangeValidation inRange(NumericValidation numericValidation) {

@Override
boolean isModified() {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
if (allowedValuesControl != null) {
String selectedValue = allowedValuesControl.value();
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
}
} else if (minMaxControl != null) {
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(minMaxControl.value());
} else {
return !minMaxControl.value().isEmpty();
if (ra.readable && !ra.description.readOnly()) {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
if (allowedValuesControl != null) {
String selectedValue = allowedValuesControl.value();
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
}
} else if (minMaxControl != null) {
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(minMaxControl.value());
} else {
return !minMaxControl.value().isEmpty();
}
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
if (allowedValuesControl != null) {
String selectedValue = allowedValuesControl.value();
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
if (allowedValuesControl != null) {
String selectedValue = allowedValuesControl.value();
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
}
} else if (minMaxControl != null) {
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(minMaxControl.value());
} else {
return !minMaxControl.value().isEmpty();
}
}
} else if (minMaxControl != null) {
} else if (inputMode == EXPRESSION) {
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(minMaxControl.value());
return !originalValue.equals(textControlValue());
} else {
return !minMaxControl.value().isEmpty();
return !textControlValue().isEmpty();
}
}
} else if (inputMode == EXPRESSION) {
if (wasDefined) {
String originalValue = ra.value.asString();
return !originalValue.equals(textControlValue());
} else {
return !textControlValue().isEmpty();
}
} else {
unknownScope();
}
} else {
unknownScope();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static void executeOperation(AddressTemplate template, String operation)

private static ResourceForm operationForm(AddressTemplate template, Metadata metadata,
OperationDescription operationDescription) {
List<ResourceAttribute> resourceAttributes = resourceAttributes(operationDescription, __ -> true);
List<ResourceAttribute> resourceAttributes = resourceAttributes(operationDescription, notDeprecated());
ResourceForm resourceForm = new ResourceForm(template);
for (ResourceAttribute ra : resourceAttributes) {
resourceForm.addItem(formItem(template, metadata, ra,
Expand Down
54 changes: 29 additions & 25 deletions ui/src/main/java/org/jboss/hal/ui/resource/SelectFormItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ private FormSelect selectControl() {
@Override
void resetValidation() {
super.resetValidation();
selectControl.resetValidation();
if (selectControl != null) {
selectControl.resetValidation();
}
}

@Override
Expand All @@ -132,33 +134,35 @@ boolean validate() {

@Override
boolean isModified() {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
String selectedValue = selectControl.value();
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
if (ra.readable && !ra.description.readOnly()) {
if (flags.scope == NEW_RESOURCE) {
if (inputMode == NATIVE) {
String selectedValue = selectControl.value();
if (ra.description.hasDefault()) {
return !ra.description.get(DEFAULT).asString().equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
String selectedValue = selectControl.value();
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
} else if (flags.scope == EXISTING_RESOURCE) {
boolean wasDefined = ra.value.isDefined();
if (inputMode == NATIVE) {
String selectedValue = selectControl.value();
if (wasDefined) {
// modified if the original value was an expression or is different from the current user input
String originalValue = ra.value.asString();
return ra.expression || !originalValue.equals(selectedValue);
} else {
return !UNDEFINED.equals(selectedValue);
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
}
} else if (inputMode == EXPRESSION) {
return isExpressionModified();
} else {
unknownScope();
}
} else {
unknownScope();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ boolean validate() {

@Override
boolean isModified() {
// StringFormItem runs in mixed mode, so it's safe to delegate to isExpressionModified()
return isExpressionModified();
if (ra.readable && !ra.description.readOnly()) {
// StringFormItem runs in mixed mode, so it's safe to delegate to isExpressionModified()
return isExpressionModified();
}
return false;
}

@Override
Expand Down

0 comments on commit cc0a76e

Please sign in to comment.