Skip to content

Commit

Permalink
fix review points
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Kumar committed Nov 14, 2024
1 parent a552faf commit 7c4dae9
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.Map;

import com.adobe.cq.forms.core.components.models.form.FieldType;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
Expand All @@ -43,31 +44,34 @@
public class ReviewImpl extends AbstractBaseImpl implements Review {

private static final String LINKED_PANEL_PROPERTY = "fd:linkedPanels";
private static final String EDIT_ACTION_PROPERTY = "fd:editAction";
private static final String EDIT_ACTION_PROPERTY = "fd:editModeAction";

@JsonIgnore
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "linkedPanels")
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fd:linkedPanels")
@Nullable
private String[] linkedPanels;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fd:editModeAction")
@Nullable
private String editModeAction;

public String[] getLinkedPanels() {
return linkedPanels != null ? Arrays.copyOf(linkedPanels, linkedPanels.length) : new String[] {};
}

@JsonIgnore
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "editAction")
@Nullable
private String editAction;
public String getEditModeAction() {
return editModeAction;
}

public String getEditAction() {
return editAction;
@Override
public String getFieldType() {
return super.getFieldType(FieldType.PLAIN_TEXT);
}

@Override
public @NotNull Map<String, Object> getProperties() {
Map<String, Object> customProperties = super.getProperties();
customProperties.put(LINKED_PANEL_PROPERTY, getLinkedPanels());
customProperties.put(EDIT_ACTION_PROPERTY, getEditAction());
customProperties.put(EDIT_ACTION_PROPERTY, getEditModeAction());
return customProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,40 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt
if (resourceResolver != null) {
Resource componentInstance = resourceResolver.getResource(componentInstancePath);
Resource formInstance = ComponentUtils.getFormContainer(componentInstance);
FormContainer formContainer = formInstance.adaptTo(FormContainer.class);
List<Base> panelList = (List<Base>) getPanels(formContainer);
List<Base> panels = panelList.stream().filter(x -> "panel".equals(x.getFieldType())).collect(Collectors.toList());
for (Base panel : panels) {
String name = panel != null ? panel.getName() : "";
String title = "";
if (panel != null) {
Label label = panel.getLabel();
if (label != null) {
String value = label.getValue();
if (value != null) {
title = value;
if (formInstance != null) {
FormContainer formContainer = formInstance.adaptTo(FormContainer.class);
List<Base> panelList = (List<Base>) getMultipleChildPanels(formContainer);
List<Base> panels = panelList.stream().filter(x -> "panel".equals(x.getFieldType())).collect(Collectors.toList());
for (Base panel : panels) {
String name = panel != null ? panel.getName() : "";
String title = "";
if (panel != null) {
Label label = panel.getLabel();
if (label != null) {
String value = label.getValue();
if (value != null) {
title = value;
}
}
}
}
if (name != null && title != null) {
resources.add(getResourceForDropdownDisplay(resourceResolver, title, name));
if (name != null && title != null) {
resources.add(getResourceForDropdownDisplay(resourceResolver, title, name));
}
}
}
}
SimpleDataSource actionTypeDataSource = new SimpleDataSource(resources.iterator());
request.setAttribute(DataSource.class.getName(), actionTypeDataSource);
}

private List<? extends ComponentExporter> getPanels(FormComponent formContainer) {
/**
* Retrieves a list of child panels that have at least two siblings.
* If a panel has fewer than two siblings, it will not be included in the returned list.
*
* @param formContainer the top-level form container
* @return a list of panels with at least two siblings
*/
private List<? extends ComponentExporter> getMultipleChildPanels(FormComponent formContainer) {
while (formContainer instanceof Container && ((Container) formContainer).getItems().size() == 1) {
formContainer = (FormComponent) ((Container) formContainer).getItems().get(0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2023 Adobe
~ Copyright 2024 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -16,15 +16,28 @@
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.ConsumerType;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* Defines the {@code Review} Sling Model used for the {@code /apps/core/fd/components/form/review} component.
*
* @since com.adobe.cq.forms.core.components.models 2.1.0
* @since com.adobe.cq.forms.core.components.models 5.9.5
*/
@ConsumerType
public interface Review extends Base {

/**
* @return an array of linked panels to be reviewed on the review page. Each linked panel is the name of a panel that is linked to the
* review page.
* @since com.adobe.cq.forms.core.components.models.form 5.9.5
*/
@JsonIgnore
String[] getLinkedPanels();

String getEditAction();
/**
* @return the edit mode action, which indicates whether edit button is visible on the review page at field, panel, both, or none
* @since com.adobe.cq.forms.core.components.models.form 5.9.5
*/
@JsonIgnore
String getEditModeAction();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </p>
*/

@Version("5.9.5")
@Version("5.9.6")
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ void setUp() throws Exception {
@Test
void testGetEditAction() {
Review review = Utils.getComponentUnderTest(PATH_REVIEW, ReviewImpl.class, context);
assertEquals("field", review.getEditAction());
assertEquals("field", review.getEditModeAction());
}

@Test
public void testGetLinkedPanelsWithNonNullArray() throws IOException {
Review review = Utils.getComponentUnderTest(PATH_REVIEW, ReviewImpl.class, context);
String[] linkedPanels = review.getLinkedPanels();
String[] expectedLinkedPanels = context.resourceResolver().getResource(PATH_REVIEW).getValueMap().get("linkedPanels",
String[] expectedLinkedPanels = context.resourceResolver().getResource(PATH_REVIEW).getValueMap().get("fd:linkedPanels",
String[].class);
assertNotNull(expectedLinkedPanels);
assertArrayEquals(expectedLinkedPanels, linkedPanels);
Expand All @@ -73,7 +73,7 @@ void testGetProperties() {
Review review = Utils.getComponentUnderTest(PATH_REVIEW, ReviewImpl.class, context);
Map<String, Object> properties = review.getProperties();
assertEquals("/apps/formcontainer/wizard/panel2/review", properties.get("fd:path"));
assertEquals("field", properties.get("editAction"));
assertEquals("field", properties.get("fd:editModeAction"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"name": "item_2",
"sling:resourceType": "core/fd/components/form/panelcontainer/v1/panelcontainer",
"review": {
"editAction": "field",
"fd:editModeAction": "field",
"fieldType": "plain-text",
"hideTitle": "false",
"jcr:primaryType": "nt:unstructured",
Expand Down Expand Up @@ -69,7 +69,7 @@
"name": "item_2",
"sling:resourceType": "core/fd/components/form/panelcontainer/v1/panelcontainer",
"review": {
"editAction": "field",
"fd:editModeAction": "field",
"fieldType": "plain-text",
"hideTitle": "false",
"jcr:primaryType": "nt:unstructured",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"fd:linkedPanels": [
"item_1"
],
"fd:editAction": "field"
"fd:editModeAction": "field"
},
"linkedPanels": [
"fd:linkedPanels": [
"item_1"
],
"editAction": "field"
"fd:editModeAction": "field"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="review"
fieldType="plain-text"
editAction="panel"
fd:editModeAction="panel"
/>
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@
jcr:primaryType="nt:unstructured"
jcr:title="review"
sling:resourceType="forms-components-examples/components/form/review"
editAction="field"
fd:editModeAction="field"
fieldType="plain-text"
hideTitle="false"
linkedPanels="tab1_id"
fd:linkedPanels="tab1_id"
name="review1724402878089"/>
<submit
jcr:created="{Date}2024-08-23T14:18:03.480+05:30"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
jcr:primaryType="nt:unstructured"
jcr:title="review"
sling:resourceType="forms-components-examples/components/form/review"
editAction="panel"
fd:editModeAction="panel"
fieldType="plain-text"
hideTitle="false"
name="review1724402878089"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ The following properties are written to JCR for this Form Review component and a
1. `./jcr:title` - defines the label to use for this field
2. `./hideTitle` - if set to `true`, the label of this field will be hidden
3. `./name` - defines the name of the field, which will be submitted with the form data
3. `./linkedPanels` - defines linked panels for reviewing the panel. If no panel is linked, the component will review the entire form.
3. `./editAction` - defines the edit action for editing the fields, panels, field & panel, or none
3. `./fd:linkedPanels` - defines linked panels for reviewing the panel. If no panel is linked, the component will review the entire form.
3. `./fd:editModeAction` - defines the edit action for editing the fields, panels, field & panel, or none
## Client Libraries
The component provides a `core.forms.components.review.v1.runtime` client library category that contains the Javascript runtime for the component.
It should be added to a relevant site client library using the `embed` property.
Expand All @@ -44,11 +44,16 @@ JavaScript handling for dialog interaction. It is already included by its edit d
```
BLOCK cmp-adaptiveform-review
ELEMENT cmp-adaptiveform-review__container
ELEMENT cmp-adaptiveform-review__panel
MODIFIER cmp-adaptiveform-review__panel--repeatable
ELEMENT cmp-adaptiveform-review__label-containe
ELEMENT cmp-adaptiveform-review__field
ELEMENT cmp-adaptiveform-review__label
ELEMENT cmp-adaptiveform-review__value
ELEMENT cmp-adaptiveform-review__edit-button
ELEMENT cmp-adaptiveform-review__panel
MODIFIER cmp-adaptiveform-review__panel--repeatable
ELEMENT cmp-adaptiveform-review__label-containe
ELEMENT cmp-adaptiveform-review__label
ELEMENT cmp-adaptiveform-review__edit-button
ELEMENT cmp-adaptiveform-review__value
ELEMENT cmp-adaptiveform-review__field
ELEMENT cmp-adaptiveform-review__label
ELEMENT cmp-adaptiveform-review__value
ELEMENT cmp-adaptiveform-review__edit-button
ELEMENT cmp-adaptiveform-review__text
ELEMENT cmp-adaptiveform-review__label
```
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
text="Hide title"
uncheckedValue="false"
value="true" />
<editAction
<editModeAction
jcr:primaryType="nt:unstructured"
sling:orderBefore="customText"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
granite:class="cmp-adaptiveform-review__editaction"
fieldLabel="Enable edit actions for"
name="./editAction"
fieldLabel="Enable edit mode actions for"
name="./fd:editModeAction"
value="field">
<items jcr:primaryType="nt:unstructured">
<field
Expand All @@ -95,7 +95,7 @@
text="None"
value="none" />
</items>
</editAction>
</editModeAction>
<linkedPanels
jcr:primaryType="nt:unstructured"
granite:class="cmp-adaptiveform-review__linkedPanels"
Expand All @@ -104,7 +104,7 @@
fieldLabel="Link panels"
multiple="true"
value="string[]"
name="./linkedPanels"
name="./fd:linkedPanels"
>
<datasource
jcr:primaryType="nt:unstructured"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Review"
fieldType="plain-text"/>
/>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static bemBlock = 'cmp-adaptiveform-review';
static templateAttribute = 'data-cmp-review';
static DATA_ATTRIBUTE_VISIBLE = 'data-cmp-visible';
static hideFieldFromReview = ['button', 'plain-text', 'captcha', 'image'];
static selectors = {
self: "[data-" + this.NS + '-is="' + this.IS + '"]',
container: `.${Review.bemBlock}__container`,
Expand Down Expand Up @@ -90,7 +91,7 @@
}

static addAccessibilityAttributes(element, item) {
const container = element.querySelector('[' + Review.templateAttribute + '-container]');
const container = element.querySelector('div');
const label = element.querySelector('[' + Review.templateAttribute + '-label]');
const value = element.querySelector('[' + Review.templateAttribute + '-value]');
const editButton = element.querySelector('[' + Review.templateAttribute + '-editButton]');
Expand Down Expand Up @@ -217,7 +218,8 @@
const currentFragment = document.createDocumentFragment();
items.filter(item => item.visible !== false && item.fieldType && item[':type']).forEach(item => {
if (Review.isRepeatable(item)) {
const repeatablePanel = this.#renderReviewFields(item.items);
const repeatableItems = this.getModel().form.getElement(item.id).getState();
const repeatablePanel = this.#renderReviewFields(repeatableItems.items);
if (Review.hasChild(repeatablePanel)) {
currentFragment.appendChild(repeatablePanel);
}
Expand All @@ -241,7 +243,7 @@
}
currentFragment.appendChild(cloneNode);
}
} else if (item.fieldType !== 'button' && item.fieldType !== 'plain-text' && !item[':type'].endsWith('review')) {
} else if (!Review.hideFieldFromReview.includes(item.fieldType) && !item[':type'].endsWith('review')) {
Review.renderValue(cloneNode, item);
Review.addAccessibilityAttributes(cloneNode, item);
currentFragment.appendChild(cloneNode);
Expand All @@ -261,7 +263,7 @@

// return all top lavel panels if author has not linked any panel
#getAllPanels() {
let state = this.formContainer._model.getState();
let state = this.getModel().form.getState();
while (state?.items?.length === 1) {
state = state.items[0];
}
Expand All @@ -271,7 +273,7 @@
// return linked panels if author has linked any panel
#getLinkedPanels(linkedPanels) {
let queue = [], result = [];
let state = this.formContainer._model.getState();
let state = this.getModel().form.getState();
queue.push(state);
while (queue.length && linkedPanels.length) {
const items = Array.isArray(queue[0]) ? queue[0] : [queue[0]];
Expand Down Expand Up @@ -303,10 +305,10 @@
}
}
#isVisibleEditButton(fieldType) {
let editAction = this._model?._jsonModel?.properties?.editAction;
if (editAction === 'both' ||
(editAction === 'panel' && fieldType === 'panel') ||
(editAction === 'field' && fieldType !== 'panel')) {
let editModeAction = this._model?._jsonModel?.properties?.['fd:editModeAction'];
if (editModeAction === 'both' ||
(editModeAction === 'panel' && fieldType === 'panel') ||
(editModeAction === 'field' && fieldType !== 'panel')) {
return true;
}
return false;
Expand Down
Loading

0 comments on commit 7c4dae9

Please sign in to comment.