Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ export const render = (
): string => {
const templateBuffer = readFileSync(`${__dirname}/${templateName}.hbs`);
const template = compile(templateBuffer.toString());
const getFieldName = (value: any) => (value.DataFieldName ? value.DataFieldName : value.Id);
const getFieldName = (value: FormObject.Control) => {
if (value.DataFieldName)
return value.DataFieldName;
if (value.ClassId && value.ClassId.toLowerCase() !== '06375649-c143-495e-a496-c962e5b4488e') {
return value.Id;
}

if (value.Parameters && value.Parameters.$values.some(parameter => parameter.Name === 'UClientUniqueName')) {
return value.Parameters.$values.find(parameter => parameter.Name === 'UClientUniqueName')?.Value;
}
return "Timeline"
};
registerHelper('formtype', (value) => (value === 2 ? 'main' : 'quickcreate'));
// eslint-disable-next-line no-confusing-arrow
registerHelper(
Expand Down Expand Up @@ -83,7 +94,7 @@ export const render = (
});
});
});
controls.sort((a, b) => getFieldName(a).localeCompare(getFieldName(b)));
controls.sort((a, b) => getFieldName(a)?.localeCompare(getFieldName(b) || '') || 0);
return controls;
});
registerHelper('sectionCollector', (formdata: FormObject.Tab) => {
Expand All @@ -106,7 +117,7 @@ export const render = (
}
});
});
cells.sort((a, b) => getFieldName(a.Control).localeCompare(getFieldName(b.Control)));
cells.sort((a, b) => getFieldName(a.Control)?.localeCompare(getFieldName(b.Control) || '') || 0);
return cells;
});
const formObj: FormObject.Form = data.formjson ? JSON.parse(data.formjson) : null;
Expand Down
7 changes: 7 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,12 @@ namespace FormObject {
DataFieldName: string;
Id: string;
ClassId: string;
Parameters?: {
$values:
{
Name: string,
Value: string,
}[]
},
}
}
49 changes: 41 additions & 8 deletions tests/__snapshots__/renderer.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,39 @@ declare namespace Xrm.Ext.Entities {
"
`;

exports[`renderer tests render tests should return valid type declaration for Early-Bound form with Timeline control 1`] = `
"// This file was generated with XrmTypesGen
// GitHub: https://github.com/OliverFlint/XrmTypesGen

declare namespace Xrm.Ext.Forms.albxm_MultiSwitchTest.main {
/**
* Entity/Table Name: \`albxm_MultiSwitchTest\`
*
* Form Type: \`main\`
*
* Form Name: \`Information\`
*/
interface Information
extends Xrm.EarlyBound.Form<Ext.Entities.albxm_MultiSwitchTest> {
albxm_coloredoption: \\"albxm_ColoredOption\\";
albxm_name: \\"albxm_Name\\";
Timeline: Xrm.Controls.TimelineWall;
Timeline_Again: Xrm.Controls.TimelineWall;

\\".Tabs\\": {
\\"\\": {
\\"\\":
| \\"albxm_coloredoption\\"
| \\"albxm_name\\"
| \\"Timeline\\"
| \\"Timeline_Again\\";
};
};
}
}
"
`;

exports[`renderer tests render tests should return valid type declaration for Early-Bound main form 1`] = `
"// This file was generated with XrmTypesGen
// GitHub: https://github.com/OliverFlint/XrmTypesGen
Expand Down Expand Up @@ -1432,7 +1465,6 @@ declare namespace Xrm.Ext.Forms.Contact.main {
managerphone: \\"ManagerPhone\\";
middlename: \\"MiddleName\\";
mobilephone: \\"MobilePhone\\";
notescontrol: Xrm.Controls.TimelineWall;
originatingleadid: \\"OriginatingLeadId\\";
ownerid: \\"OwnerId\\";
parentcustomerid: \\"ParentCustomerId\\";
Expand All @@ -1447,6 +1479,7 @@ declare namespace Xrm.Ext.Forms.Contact.main {
spousesname: \\"SpousesName\\";
telephone1: \\"Telephone1\\";
telephone2: \\"Telephone2\\";
Timeline: Xrm.Controls.TimelineWall;
transactioncurrencyid: \\"TransactionCurrencyId\\";
WebResource_RecordWall: Xrm.Controls.IframeControl;

Expand Down Expand Up @@ -1525,7 +1558,7 @@ declare namespace Xrm.Ext.Forms.Contact.main {
};
\\"notes and activities\\": {
activities: \\"contactactivitiesgrid\\";
notes: \\"notescontrol\\";
notes: \\"Timeline\\";
};
tab_recordwall: {
tab_recordwall_section_1: \\"WebResource_RecordWall\\";
Expand Down Expand Up @@ -2417,11 +2450,11 @@ declare namespace Xrm {
controlName: \\"contactactivitiesgrid\\"
): Xrm.Controls.GridControl;
/**
* Gets the \`notescontrol\` control.
* Gets the \`Timeline\` control.
*
* @returns \`Xrm.Controls.TimelineWall\`.
*/
getControl(controlName: \\"notescontrol\\"): Xrm.Controls.TimelineWall;
getControl(controlName: \\"Timeline\\"): Xrm.Controls.TimelineWall;
/**
* Gets the \`WebResource_RecordWall\` control.
*
Expand Down Expand Up @@ -2788,11 +2821,11 @@ declare namespace Xrm {
*/
get(controlName: \\"contactactivitiesgrid\\"): Xrm.Controls.GridControl;
/**
* Gets the \`notescontrol\` control.
* Gets the \`Timeline\` control.
*
* @returns \`Xrm.Controls.TimelineWall\`.
*/
get(controlName: \\"notescontrol\\"): Xrm.Controls.TimelineWall;
get(controlName: \\"Timeline\\"): Xrm.Controls.TimelineWall;
/**
* Gets the \`WebResource_RecordWall\` control.
*
Expand Down Expand Up @@ -3778,11 +3811,11 @@ declare namespace Xrm {
};
type notesSectionControls = Xrm.Collection.ItemCollection<Xrm.Controls.Control> & {
/**
* Gets the \`notescontrol\` control.
* Gets the \`Timeline\` control.
*
* @returns \`Xrm.Controls.TimelineWall\`.
*/
get(controlname: \\"notescontrol\\"): Xrm.Controls.TimelineWall;
get(controlname: \\"Timeline\\"): Xrm.Controls.TimelineWall;
};
type tab_recordwall_section_1SectionControls = Xrm.Collection.ItemCollection<Xrm.Controls.Control> & {
/**
Expand Down
10 changes: 10 additions & 0 deletions tests/data/albxm_multiswitchtest.information.form.json

Large diffs are not rendered by default.

Loading