Skip to content

Commit

Permalink
added new utils for details
Browse files Browse the repository at this point in the history
  • Loading branch information
mohas22 authored and mohas22 committed Nov 5, 2024
1 parent fe71b47 commit 9e36409
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
27 changes: 1 addition & 26 deletions src/components/designSystemExtension/DetailsFields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,7 @@ class DetailsFields extends LitElement {

getFieldsHtml(arFields): any {
const arFHtml: any[] = [];
const fields: any[] = [];
arFields?.forEach(field => {
const thePConn = field.getPConnect();
const theCompType = thePConn.getComponentName().toLowerCase();
if (theCompType === 'reference') {
const configObj = thePConn.getReferencedView();
configObj.config.readOnly = true;
configObj.config.displayMode = 'DISPLAY_ONLY';
const propToUse = { ...thePConn.getInheritedProps() };
configObj.config.label = propToUse?.label;
const loadedPConn = thePConn.getReferencedViewPConnect(true).getPConnect();
const data = {
type: theCompType,
pConn: loadedPConn
};
fields.push(data);
} else {
const data = {
type: theCompType,
config: thePConn.getConfigProps()
};
fields.push(data);
}
});

for (const field of fields) {
for (const field of arFields) {
if (field?.type === 'reference') {
arFHtml.push(html`
<div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/templates/details/Details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../../../Region';
import { detailsStyles } from './details-styles';

import '../../../designSystemExtension/DetailsFields';
import { getDetailsFieldArray } from '../../../../helpers/details-utils';

interface DetailsProps {
// If any, enter additional props that only exist on this component
Expand Down Expand Up @@ -66,7 +67,7 @@ class Details extends DetailsTemplateBase {
this.arFields = [];
const pKid = kid.getPConnect();
const fields = pKid.getChildren();
this.arFields.push(...fields);
this.arFields = getDetailsFieldArray(fields);
}

this.requestUpdate();
Expand Down
5 changes: 3 additions & 2 deletions src/components/templates/details/DetailsTwoColumn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../../../Region';
import { detailsTwoColumnStyles } from './details-two-column-styles';

import '../../../designSystemExtension/DetailsFields';
import { getDetailsFieldArray } from '../../../../helpers/details-utils';

@customElement('details-two-column-component')
class DetailsTwoColumn extends DetailsTemplateBase {
Expand Down Expand Up @@ -58,9 +59,9 @@ class DetailsTwoColumn extends DetailsTemplateBase {
const pKid = kid.getPConnect();
const fields = pKid.getChildren();
if (this.children.indexOf(kid) == 0) {
this.arFields = fields;
this.arFields = getDetailsFieldArray(fields);
} else {
this.arFields2 = fields;
this.arFields2 = getDetailsFieldArray(fields);
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/helpers/details-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function getDetailsFieldArray(arFields) {
const fields: any[] = [];
arFields?.forEach(field => {
const thePConn = field.getPConnect();
const theCompType = thePConn.getComponentName().toLowerCase();
if (theCompType === 'reference') {
const configObj = thePConn.getReferencedView();
configObj.config.readOnly = true;
configObj.config.displayMode = 'DISPLAY_ONLY';
const propToUse = { ...thePConn.getInheritedProps() };
configObj.config.label = propToUse?.label;
const loadedPConn = thePConn.getReferencedViewPConnect(true).getPConnect();
const data = {
type: theCompType,
pConn: loadedPConn
};
fields.push(data);
} else {
const data = {
type: theCompType,
config: thePConn.getConfigProps()
};
fields.push(data);
}
});
return fields;
}

0 comments on commit 9e36409

Please sign in to comment.