Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dynamic widgets in Forms #2287

Merged
merged 1 commit into from Sep 1, 2023
Merged

Conversation

pcdavid
Copy link
Member

@pcdavid pcdavid commented Aug 21, 2023

No description provided.


VariableManager idVariableManager = variableManager.createChild();
idVariableManager.put(FormComponent.TARGET_OBJECT_ID, buttonDescription.getTargetObjectIdProvider().apply(variableManager));
idVariableManager.put(FormComponent.TARGET_OBJECT_ID, buttonDescription.getTargetObjectIdProvider().apply(variableManager));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate lines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 38 to 56

/**
* The name of the variable used to store the id of widget's description in the {@link VariableManager} for a widget
* to compute its own id.
*/
public static final String CONTROL_DESCRIPTION_ID = "controlDescriptionId";

/**
* The name of the variable used to store the id of widget's description in the {@link VariableManager} for a widget
* to compute its own id.
*/
public static final String TARGET_OBJECT_ID = "targetObjectId";

/**
* The name of the variable used to store the id of widget's description in the {@link VariableManager} for a widget
* to compute its own id.
*/
public static final String WIDGET_LABEL = "widgetLabel";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same comment for the three variables

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 91 to 103
List<Element> children = candidates.stream().map(candidate -> {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(VariableManager.SELF, candidate);
childVariableManager.put(FormComponent.PARENT_ELEMENT_ID, id);
return childVariableManager;
}).flatMap(childVariableManager -> pageDescriptions.stream().filter(pageDescription -> pageDescription.getCanCreatePredicate().test(childVariableManager)).map(pageDescription -> {
PageComponentProps pageComponentProps = new PageComponentProps(childVariableManager, pageDescription, this.props.getWidgetDescriptors());
return new Element(PageComponent.class, pageComponentProps);
})).toList();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation doesn't seem right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


private Function<VariableManager, Boolean> predicate;

private AbstractWidgetDescription widgetDescription;
private List<AbstractControlDescription> childrenDescription;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ForDescription, it's named controlDescriptions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,214 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New file, should be only 2023

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,201 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New file, should be only 2023

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In this first version, we will only support the same case as in EEF desktop, namely widgets inside a _Group_.
All these four elements (For, If, Groups, Flexbox) behave as containers for an arbitrary number sub-elements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number of

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


* `iterationExpression`: an AQL expression to be evaluated when rendering the form, which should return a collection of (arbitrary) elements;
* `iterator`: a (fixed) variable name.

It will also _contain_ an arbitrary number if _DynamicIf_, which has a `predicateExpression` attribute and a `control: ControlDescription[1]` containment reference.
The semantics of the element is that it's children element will be rendered once for every element in the collection returned by `iterationExpression`, in order.
For each value _V_ returned by `iterationExpression`, all the children are rendered in a context where _V_ is bound to a variable named as specified buy _iterator_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buy -> by

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

CHANGELOG.adoc Outdated
Existing FormDescription documents will need to be modified to load correctly, and any custom widget's metamodel will need to be regenerated using the new `form.ecore` version as reference.
See [ADR-107] _Add support for dynamic and conditional widgets in Forms_ for the details of the changes.
Also, all widget descriptions now have a `Function<VariableManager, String> targetObjectIdProvider`, needed to compute the widget instance's id.
The new `targetObjectIdProvider` is required to be non-null, so any code which programatically builds core Form Descriptions (not View-based ones), needs to pass a non-null provider.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

programatically -> programmatically

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Bug: #2236
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
@pcdavid pcdavid merged commit 0135956 into master Sep 1, 2023
4 checks passed
@pcdavid pcdavid deleted the pcd/enh/dynamic-widgets branch September 1, 2023 13:30
@pcdavid pcdavid linked an issue Sep 1, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add initial support for EEF's DynamicFor/If to Forms
2 participants