CE-1068 - add RELOAD_WIDGET action, and targetWidget to FieldRules

This commit is contained in:
2024-04-30 10:18:13 -05:00
parent 8dc8ae0b6d
commit 65aaf4fce1
5 changed files with 99 additions and 10 deletions

View File

@ -133,6 +133,17 @@ public class MaterialDashboardTableMetaData extends QSupplementalTableMetaData
validateListOfFieldNames(tableMetaData, defaultQuickFilterFieldNames, qInstanceValidator, prefix + "defaultQuickFilterFieldNames: ");
for(FieldRule fieldRule : CollectionUtils.nonNullList(fieldRules))
{
validateFieldRule(qInstance, tableMetaData, qInstanceValidator, fieldRule, prefix);
}
}
/*******************************************************************************
**
*******************************************************************************/
static void validateFieldRule(QInstance qInstance, QTableMetaData tableMetaData, QInstanceValidator qInstanceValidator, FieldRule fieldRule, String prefix)
{
qInstanceValidator.assertCondition(fieldRule.getTrigger() != null, prefix + "has a fieldRule without a trigger");
qInstanceValidator.assertCondition(fieldRule.getAction() != null, prefix + "has a fieldRule without an action");
@ -142,10 +153,18 @@ public class MaterialDashboardTableMetaData extends QSupplementalTableMetaData
qInstanceValidator.assertNoException(() -> tableMetaData.getField(fieldRule.getSourceField()), prefix + "has a fieldRule with an unrecognized sourceField: " + fieldRule.getSourceField());
}
if(qInstanceValidator.assertCondition(StringUtils.hasContent(fieldRule.getTargetField()), prefix + "has a fieldRule without a targetField"))
if(StringUtils.hasContent(fieldRule.getTargetField()))
{
qInstanceValidator.assertNoException(() -> tableMetaData.getField(fieldRule.getTargetField()), prefix + "has a fieldRule with an unrecognized targetField: " + fieldRule.getTargetField());
}
if(StringUtils.hasContent(fieldRule.getTargetWidget()))
{
if(qInstanceValidator.assertCondition(qInstance.getWidget(fieldRule.getTargetWidget()) != null, prefix + "has a widgetRule with an unrecognized targetWidget: " + fieldRule.getTargetWidget()))
{
qInstanceValidator.assertCondition(CollectionUtils.nonNullList(tableMetaData.getSections()).stream().anyMatch(s -> fieldRule.getTargetWidget().equals(s.getWidgetName())),
prefix + "has a widgetRule with a targetWidget which is not used in any sections on the table");
}
}
}

View File

@ -38,6 +38,8 @@ public class FieldRule implements Serializable
private FieldRuleAction action;
private String targetField;
private String targetWidget;
/*******************************************************************************
@ -162,4 +164,35 @@ public class FieldRule implements Serializable
return (this);
}
/*******************************************************************************
** Getter for targetWidget
*******************************************************************************/
public String getTargetWidget()
{
return (this.targetWidget);
}
/*******************************************************************************
** Setter for targetWidget
*******************************************************************************/
public void setTargetWidget(String targetWidget)
{
this.targetWidget = targetWidget;
}
/*******************************************************************************
** Fluent setter for targetWidget
*******************************************************************************/
public FieldRule withTargetWidget(String targetWidget)
{
this.targetWidget = targetWidget;
return (this);
}
}

View File

@ -27,5 +27,6 @@ package com.kingsrook.qqq.frontend.materialdashboard.model.metadata.fieldrules;
*******************************************************************************/
public enum FieldRuleAction
{
CLEAR_TARGET_FIELD
CLEAR_TARGET_FIELD,
RELOAD_WIDGET
}

View File

@ -29,6 +29,7 @@ export interface FieldRule
sourceField: string;
action: FieldRuleAction;
targetField: string;
targetWidget: string;
}
@ -46,5 +47,6 @@ export enum FieldRuleTrigger
*******************************************************************************/
export enum FieldRuleAction
{
CLEAR_TARGET_FIELD = "CLEAR_TARGET_FIELD"
CLEAR_TARGET_FIELD = "CLEAR_TARGET_FIELD",
RELOAD_WIDGET = "RELOAD_WIDGET"
}

View File

@ -29,6 +29,9 @@ import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.frontend.materialdashboard.junit.BaseTest;
import com.kingsrook.qqq.frontend.materialdashboard.junit.TestUtils;
import com.kingsrook.qqq.frontend.materialdashboard.model.metadata.fieldrules.FieldRule;
import com.kingsrook.qqq.frontend.materialdashboard.model.metadata.fieldrules.FieldRuleAction;
import com.kingsrook.qqq.frontend.materialdashboard.model.metadata.fieldrules.FieldRuleTrigger;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -76,6 +79,37 @@ class MaterialDashboardTableMetaDataTest extends BaseTest
assertValidationFailureReasons(qInstance -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).withSupplementalMetaData(new MaterialDashboardTableMetaData().withDefaultQuickFilterFieldNames(List.of("firstName", "lastName", "firstName"))),
"duplicated field name: firstName");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testValidateFieldRules()
{
assertValidationFailureReasons(qInstance -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).withSupplementalMetaData(new MaterialDashboardTableMetaData().withFieldRule(new FieldRule())),
"without an action",
"without a trigger",
"without a sourceField");
assertValidationFailureReasons(qInstance -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).withSupplementalMetaData(new MaterialDashboardTableMetaData().withFieldRule(new FieldRule()
.withTrigger(FieldRuleTrigger.ON_CHANGE)
.withAction(FieldRuleAction.CLEAR_TARGET_FIELD)
.withSourceField("notAField")
.withTargetField("alsoNotAField")
)),
"unrecognized sourceField: notAField",
"unrecognized targetField: alsoNotAField");
assertValidationFailureReasons(qInstance -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).withSupplementalMetaData(new MaterialDashboardTableMetaData().withFieldRule(new FieldRule()
.withTrigger(FieldRuleTrigger.ON_CHANGE)
.withAction(FieldRuleAction.RELOAD_WIDGET)
.withSourceField("id")
.withTargetWidget("notAWidget")
)),
"unrecognized targetWidget: notAWidget");
}