Skip to content

Commit

Permalink
CQ-4343453 Exclude forms core components if cloud (#949)
Browse files Browse the repository at this point in the history
* CQ-4343453 Exclude forms core components if cloud

* CQ-4343453 include sdk api for cloud

* CQ-4343453 minor changes

Co-authored-by: barshatr <barshatr@adobe.com>
  • Loading branch information
barshat7 and barshatr authored Jun 21, 2022
1 parent ae17264 commit 2a4c967
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/main/archetype/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
</embedded>
#end
#end
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion == "cloud" )
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion != "cloud" )
<embedded>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-apps</artifactId>
Expand Down Expand Up @@ -397,7 +397,7 @@
<type>zip</type>
</dependency>
#end
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion == "cloud" )
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion != "cloud" )
<!-- AEM Forms Dependencies -->
<dependency>
<groupId>com.adobe.aem</groupId>
Expand Down
4 changes: 3 additions & 1 deletion src/main/archetype/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,18 @@ Import-Package: javax.annotation;version=0.0.0,*
#end
#end

#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion == "cloud" )
#if ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y")
<!-- AEM Forms Dependencies -->
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>aem-forms-sdk-api</artifactId>
</dependency>
#if ($aemVersion != "cloud")
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-core</artifactId>
</dependency>
#end
#end
<!-- Testing -->
<dependency>
Expand Down
24 changes: 13 additions & 11 deletions src/main/archetype/ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<artifactId>core-cif-components-apps</artifactId>
</dependency>
#end
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion == "cloud" )
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion != "cloud" )
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-apps</artifactId>
Expand Down Expand Up @@ -334,21 +334,23 @@ Require-Capability: osgi.extender;filter:="(&(osgi.extender=sling.scripting)(ver
</dependency>
#end
#end
#if ( ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y") and $aemVersion == "cloud")
#if ($includeForms == "y" or $includeFormsenrollment == "y" or $includeFormscommunications == "y" or $includeFormsheadless == "y")
<!-- AEM Forms Dependencies -->
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>aem-forms-sdk-api</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-apps</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-core</artifactId>
</dependency>
#if ($aemVersion != "cloud")
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-apps</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-core</artifactId>
</dependency>
#end
#end
<!-- HTL dependencies needed for the HTL Maven Plugin source code generation -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
cq:lastModifiedBy="admin"
cq:templateType="/conf/${appId}/settings/wcm/template-types/af-page-v2"
jcr:primaryType="cq:PageContent"
jcr:title="${appId} - Blank With Core Components"
jcr:title="Blank With Core Components"
status="enabled"/>
</jcr:root>
30 changes: 25 additions & 5 deletions src/main/archetype/ui.frontend.react.forms.af/src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import ReactDOM from "react-dom";
//@ts-ignore
import {Provider as Spectrum3Provider, defaultTheme} from '@adobe/react-spectrum'

const base64url = (s: any) => {
var to64url = btoa(s);
// Replace non-url compatible chars with base64url standard chars and remove leading =
return to64url.replace(/\+/g, '_').replace(/\//g, '-').replace(/=+${symbol_dollar}/g, '');
}


export const getId = () => {
let id = ""
if (!process.env.FORMPATH) {
debugger;
const parent = document.querySelector(".cmp-formcontainer")
id = parent.getAttribute("data-form-id")
} else {
id = base64url(process.env.FORMPATH)
}
return id;
}

const getForm = async (id: string) => {
const resp = await fetch(`/adobe/forms/af/v1/${symbol_dollar}{id}`)
Expand All @@ -14,21 +32,23 @@ const getForm = async (id: string) => {
}

const Form = (props: any) => {
const {id} = props;
const [form, setForm] = useState("")
const [state, setState] = useEditorEvents()
const fetchForm = async () => {
const json:any = await getForm(id);
setForm(JSON.stringify(json.afModelDefinition))
let id = getId();
if (id) {
const json:any = await getForm(id);
setForm(JSON.stringify(json.afModelDefinition))
}
}
useEffect(() => {
fetchForm()
}, [state]);
if (form != "") {
const element = document.querySelector(".cmp-formcontainer__content")
const retVal = (<Spectrum3Provider theme={defaultTheme}>
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} />
</Spectrum3Provider>)
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} />
</Spectrum3Provider>)
return ReactDOM.createPortal(retVal, element)
}
return null
Expand Down
21 changes: 1 addition & 20 deletions src/main/archetype/ui.frontend.react.forms.af/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@ import ReactDOM from 'react-dom';
// @ts-ignore
import AForm from './Form'

const base64url = (s: any) => {
var to64url = btoa(s);
// Replace non-url compatible chars with base64url standard chars and remove leading =
return to64url.replace(/\+/g, '_').replace(/\//g, '-').replace(/=+${symbol_dollar}/g, '');
}


const getId = () => {
let id = ""
if (!process.env.FORMPATH) {
const parent = document.querySelector(".cmp-formcontainer")
id = parent.getAttribute("data-form-id")
} else {
id = base64url(process.env.FORMPATH)
}
return id;
}


window.onload = async () => {
let div = document.getElementById("form-app");
if (!div) {
Expand All @@ -30,7 +11,7 @@ window.onload = async () => {
document.body.appendChild(div)
}
ReactDOM.render(
<AForm id={getId()}/>,
<AForm/>,
div
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ module.exports = {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
//sourceMapFilename: `forms-react-components/resources/[name].map[ext]` uncomment for debugging
//sourceMapFilename: `clientlib-forms-react/resources/[name].map[ext]` // uncomment for debugging
}
};

0 comments on commit 2a4c967

Please sign in to comment.