mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 12:50:43 +00:00
CE-1068 - add RELOAD_WIDGET action, and targetWidget to FieldRules
This commit is contained in:
@ -134,17 +134,36 @@ public class MaterialDashboardTableMetaData extends QSupplementalTableMetaData
|
|||||||
|
|
||||||
for(FieldRule fieldRule : CollectionUtils.nonNullList(fieldRules))
|
for(FieldRule fieldRule : CollectionUtils.nonNullList(fieldRules))
|
||||||
{
|
{
|
||||||
qInstanceValidator.assertCondition(fieldRule.getTrigger() != null, prefix + "has a fieldRule without a trigger");
|
validateFieldRule(qInstance, tableMetaData, qInstanceValidator, fieldRule, prefix);
|
||||||
qInstanceValidator.assertCondition(fieldRule.getAction() != null, prefix + "has a fieldRule without an action");
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(qInstanceValidator.assertCondition(StringUtils.hasContent(fieldRule.getSourceField()), prefix + "has a fieldRule without a sourceField"))
|
|
||||||
{
|
|
||||||
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"))
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
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");
|
||||||
|
|
||||||
|
if(qInstanceValidator.assertCondition(StringUtils.hasContent(fieldRule.getSourceField()), prefix + "has a fieldRule without a sourceField"))
|
||||||
|
{
|
||||||
|
qInstanceValidator.assertNoException(() -> tableMetaData.getField(fieldRule.getSourceField()), prefix + "has a fieldRule with an unrecognized sourceField: " + fieldRule.getSourceField());
|
||||||
|
}
|
||||||
|
|
||||||
|
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.assertNoException(() -> tableMetaData.getField(fieldRule.getTargetField()), prefix + "has a fieldRule with an unrecognized targetField: " + fieldRule.getTargetField());
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ public class FieldRule implements Serializable
|
|||||||
private FieldRuleAction action;
|
private FieldRuleAction action;
|
||||||
private String targetField;
|
private String targetField;
|
||||||
|
|
||||||
|
private String targetWidget;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -162,4 +164,35 @@ public class FieldRule implements Serializable
|
|||||||
return (this);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,6 @@ package com.kingsrook.qqq.frontend.materialdashboard.model.metadata.fieldrules;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public enum FieldRuleAction
|
public enum FieldRuleAction
|
||||||
{
|
{
|
||||||
CLEAR_TARGET_FIELD
|
CLEAR_TARGET_FIELD,
|
||||||
|
RELOAD_WIDGET
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ export interface FieldRule
|
|||||||
sourceField: string;
|
sourceField: string;
|
||||||
action: FieldRuleAction;
|
action: FieldRuleAction;
|
||||||
targetField: string;
|
targetField: string;
|
||||||
|
targetWidget: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,5 +47,6 @@ export enum FieldRuleTrigger
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export enum FieldRuleAction
|
export enum FieldRuleAction
|
||||||
{
|
{
|
||||||
CLEAR_TARGET_FIELD = "CLEAR_TARGET_FIELD"
|
CLEAR_TARGET_FIELD = "CLEAR_TARGET_FIELD",
|
||||||
|
RELOAD_WIDGET = "RELOAD_WIDGET"
|
||||||
}
|
}
|
||||||
|
@ -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.backend.core.model.metadata.QInstance;
|
||||||
import com.kingsrook.qqq.frontend.materialdashboard.junit.BaseTest;
|
import com.kingsrook.qqq.frontend.materialdashboard.junit.BaseTest;
|
||||||
import com.kingsrook.qqq.frontend.materialdashboard.junit.TestUtils;
|
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 org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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"))),
|
assertValidationFailureReasons(qInstance -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).withSupplementalMetaData(new MaterialDashboardTableMetaData().withDefaultQuickFilterFieldNames(List.of("firstName", "lastName", "firstName"))),
|
||||||
"duplicated field name: 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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user