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

Modal Component #1135

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ private FormConstants() {
/** The resource type for terms and conditions v1 */
public static final String RT_FD_FORM_TERMS_AND_CONDITIONS_V1 = RT_FD_FORM_PREFIX + "termsandconditions/v1/termsandconditions";

/** The resource type for modal v1 */
public static final String RT_FD_FORM_MODAL_V1 = RT_FD_FORM_PREFIX + "modal/v1/modal";

public static final String FORM_FIELD_TYPE = "form";

public static final String REQ_ATTR_FORMCONTAINER_PATH = "formContainerPath";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public String getDefault() {
return defaultValue;
}

@JsonIgnore
s1mahanty marked this conversation as resolved.
Show resolved Hide resolved
@Override
public String getButtonType() {
return buttonType;
Expand Down Expand Up @@ -114,6 +115,11 @@ public Map<String, Object> getProperties() {
return properties;
}

@Override
s1mahanty marked this conversation as resolved.
Show resolved Hide resolved
public Type getType() {
return null;
}

@Override
@NotNull
protected FormComponentData getComponentData() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.cq.forms.core.components.internal.models.v1.form;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.Modal;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = { Modal.class,
ComponentExporter.class },
resourceType = { FormConstants.RT_FD_FORM_MODAL_V1 })

@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class ModalImpl extends PanelImpl implements Modal {
s1mahanty marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.ConsumerType;

/**
* Defines the form {@code Modal} Sling Model used for the
* {@code /apps/core/fd/components/form/modal/v1/modal} component.
*
* @since com.adobe.cq.forms.core.components.models.form 4.7.0
*/
@ConsumerType
public interface Modal extends Container, ContainerConstraint, Base {
s1mahanty marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.forms.core.components.internal.models.v1.form;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.apache.sling.api.resource.Resource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;

import com.adobe.cq.export.json.SlingModelFilter;
import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.Modal;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.wcm.api.NameConstants;
import com.day.cq.wcm.msm.api.MSMNameConstants;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

import static org.junit.Assert.assertEquals;

@ExtendWith(AemContextExtension.class)
public class ModalImplTest {

private static final String BASE = "/form/modal";
private static final String CONTENT_ROOT = "/content";

private static final String PATH_MODAL = CONTENT_ROOT + "/modal";

private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
public void setUp() {
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);

context.registerService(SlingModelFilter.class, new SlingModelFilter() {

private final Set<String> IGNORED_NODE_NAMES = new HashSet<String>() {
{
add(NameConstants.NN_RESPONSIVE_CONFIG);
add(MSMNameConstants.NT_LIVE_SYNC_CONFIG);
add("cq:annotations");
}
};

@Override
public Map<String, Object> filterProperties(Map<String, Object> map) {
return map;
}

@Override
public Iterable<Resource> filterChildResources(Iterable<Resource> childResources) {
return StreamSupport
.stream(childResources.spliterator(), false)
.filter(r -> !IGNORED_NODE_NAMES.contains(r.getName()))
.collect(Collectors.toList());
}
});
}

@Test
void testExportedType() {
Modal modal = Utils.getComponentUnderTest(PATH_MODAL, Modal.class, context);
assertEquals(FormConstants.RT_FD_FORM_MODAL_V1, modal.getExportedType());
Modal modalMock = Mockito.mock(Modal.class);
Mockito.when(modalMock.getExportedType()).thenCallRealMethod();
assertEquals("", modalMock.getExportedType());
}

@Test
void testJSONExport() throws Exception {
Modal modal = Utils.getComponentUnderTest(PATH_MODAL, Modal.class, context);
Utils.testJSONExport(modal, Utils.getTestExporterJSONPath(BASE, PATH_MODAL));
}
}
98 changes: 98 additions & 0 deletions bundles/af-core/src/test/resources/form/modal/exporter-modal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"id": "modal-3f8ac07b1d",
"fieldType": "panel",
"name": "modal1711016014566",
"label": {
"value": "Modal"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:dor": {
"dorExclusion": false,
"dorExcludeTitle": false,
"dorExcludeDescription": false
},
"fd:path": "/content/modal"
},
":itemsOrder": [
"panelcontainer",
"button"
],
":items": {
"panelcontainer": {
"id": "panelcontainer-bc5563a2b9",
"fieldType": "panel",
"name": "panelcontainer",
"label": {
"value": "Panel"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:dor": {
"dorExclusion": false,
"dorExcludeTitle": false,
"dorExcludeDescription": false
},
"fd:path": "/content/modal/panelcontainer"
},
":itemsOrder": [
"datepicker"
],
":items": {
"datepicker": {
"id": "datepicker-43f0efd69b",
"fieldType": "date-input",
"name": "datepicker1711461935572",
"type": "string",
"label": {
"value": "Date Input"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/modal/panelcontainer/datepicker"
},
"format": "date",
":type": "core/fd/components/form/datepicker/v1/datepicker"
}
},
":type": "core/fd/components/form/panelcontainer/v1/panelcontainer"
},
"button": {
"id": "button-1605226465",
"fieldType": "button",
"name": "button1711016014673",
"properties": {
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/modal/button",
"fd:buttonType": "button"
},
"label": {
"value": "Open Modal"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":type": "core/fd/components/form/button/v1/button"
}
},
":type": "core/fd/components/form/modal/v1/modal"
}
30 changes: 30 additions & 0 deletions bundles/af-core/src/test/resources/form/modal/test-content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"modal": {
"jcr:primaryType": "nt:unstructured",
"fieldType": "panel",
"jcr:title": "Modal",
"name": "modal1711016014566",
"sling:resourceType": "core/fd/components/form/modal/v1/modal",
"panelcontainer": {
"jcr:primaryType": "nt:unstructured",
"fieldType": "panel",
"jcr:title": "Panel",
"name": "panelcontainer",
"sling:resourceType": "core/fd/components/form/panelcontainer/v1/panelcontainer",
"datepicker" : {
"jcr:primaryType": "nt:unstructured",
"fieldType": "date-input",
"jcr:title": "Date Input",
"name": "datepicker1711461935572",
"sling:resourceType": "core/fd/components/form/datepicker/v1/datepicker"
}
},
"button" : {
"jcr:primaryType": "nt:unstructured",
"fieldType": "button",
"jcr:title": "Open Modal",
"name": "button1711016014673",
"sling:resourceType": "core/fd/components/form/button/v1/button"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
jcr:primaryType="nt:unstructured"
jcr:title="Button"
fieldType="button"
dorExclusion="true"/>
dorExclusion="true"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Adaptive Form Modal"
jcr:description="Add an interactive button for opening a panel container in dialog."
sling:resourceSuperType="core/fd/components/form/modal/v1/modal"
componentGroup="Core Components Examples - Adaptive Form"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Modal"
fieldType="panel">
<panelcontainer
fieldType="panel"
jcr:primaryType="nt:unstructured"
jcr:title="Panel"
sling:resourceType="core/fd/components/form/panelcontainer/v1/panelcontainer"
name="panelcontainer">
<fd:rules
jcr:primaryType="nt:unstructured"
validationStatus="valid"
visible="false()"/>
<fd:events
jcr:primaryType="nt:unstructured"/>
</panelcontainer>
<button
fieldType="button"
jcr:primaryType="nt:unstructured"
jcr:title="Open Modal"
sling:resourceType="core/fd/components/form/button/v1/button">
<fd:rules
jcr:primaryType="nt:unstructured"
validationStatus="valid"/>

<fd:events
jcr:primaryType="nt:unstructured"
click="dispatchEvent(panelcontainer, 'custom:setProperty', {visible : true()})"/>

</button>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
jcr:primaryType="sling:Folder"
lcFolder="{Long}0"
type="lcFolder"/>
Loading