Skip to content

Commit 1970145

Browse files
committed
feat: render picklist values in doc template
1 parent cb2dccb commit 1970145

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

src/core/markdown/__test__/generating-custom-object-docs.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { extendExpect } from './expect-extensions';
22
import {
33
customField,
4+
customFieldPickListValues,
45
customObjectGenerator,
56
generateDocs,
67
unparsedFieldBundleFromRawString,
@@ -46,7 +47,7 @@ describe('Generates Custom Object documentation', () => {
4647
expect(result).documentationBundleHasLength(1);
4748
assertEither(result, (data) => expect(data).firstDocContains('`TestObject__c`'));
4849
});
49-
50+
5051
it('displays the Fields heading if fields are present', async () => {
5152
const customObjectBundle = unparsedObjectBundleFromRawString({
5253
rawContent: customObjectGenerator(),
@@ -64,6 +65,25 @@ describe('Generates Custom Object documentation', () => {
6465
assertEither(result, (data) => expect(data).firstDocContains('## Fields'));
6566
});
6667

68+
it('displays the pick list values name', async () => {
69+
const customObjectBundle = unparsedObjectBundleFromRawString({
70+
rawContent: customObjectGenerator(),
71+
filePath: 'src/object/TestObject__c.object-meta.xml',
72+
});
73+
74+
const customFieldBundle = unparsedFieldBundleFromRawString({
75+
rawContent: customFieldPickListValues,
76+
filePath: 'src/object/TestField__c.field-meta.xml',
77+
parentName: 'TestObject__c',
78+
});
79+
80+
const result = await generateDocs([customObjectBundle, customFieldBundle])();
81+
expect(result).documentationBundleHasLength(1);
82+
assertEither(result, (data) => expect(data).firstDocContains('* Staging'));
83+
assertEither(result, (data) => expect(data).firstDocContains('* Active'));
84+
assertEither(result, (data) => expect(data).firstDocContains('* Inactive'));
85+
});
86+
6787
it('does not display the Fields heading if no fields are present', async () => {
6888
const input = unparsedObjectBundleFromRawString({
6989
rawContent: customObjectGenerator(),

src/core/markdown/__test__/test-helpers.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,36 @@ export const customField = `
8484
<type>Url</type>
8585
<description>A URL that points to a photo</description>
8686
</CustomField>`;
87+
88+
export const customFieldPickListValues = `
89+
<?xml version="1.0" encoding="UTF-8"?>
90+
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
91+
<fullName>Status__c</fullName>
92+
<externalId>false</externalId>
93+
<label>Status</label>
94+
<required>true</required>
95+
<trackFeedHistory>false</trackFeedHistory>
96+
<description>Status</description>
97+
<type>Picklist</type>
98+
<valueSet>
99+
<restricted>true</restricted>
100+
<valueSetDefinition>
101+
<sorted>false</sorted>
102+
<value>
103+
<fullName>Staging</fullName>
104+
<default>false</default>
105+
<label>Staging</label>
106+
</value>
107+
<value>
108+
<fullName>Active</fullName>
109+
<default>false</default>
110+
<label>Active</label>
111+
</value>
112+
<value>
113+
<fullName>Inactive</fullName>
114+
<default>false</default>
115+
<label>Inactive</label>
116+
</value>
117+
</valueSetDefinition>
118+
</valueSet>
119+
</CustomField>`;

src/core/markdown/adapters/type-to-renderable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ function fieldMetadataToRenderable(
281281
description: field.description ? [field.description] : [],
282282
apiName: getApiName(field.name, config),
283283
fieldType: field.type,
284+
pickListValues: field.pickListValues
284285
};
285286
}
286287

src/core/markdown/templates/custom-object-template.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export const customObjectTemplate = `
2323
**Type**
2424
2525
*{{fieldType}}*
26+
{{#each pickListValues}}
27+
* {{this}}
28+
{{/each}}
2629
{{/if}}
2730
2831
{{#unless @last}}---{{/unless}}

src/core/reflection/sobject/reflect-custom-field-source.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function toCustomFieldMetadata(parserResult: { CustomField: unknown }): CustomFi
6666
};
6767

6868
const pickListValues =
69-
isCustomField(customField) && customField.type === 'Picklist' ? toPickListValues(customField) : [];
69+
hasType(customField) && customField.type?.toLowerCase() === 'picklist' ? toPickListValues(customField) : [];
7070
return { ...defaultValues, ...customField, type_name: 'customfield', pickListValues } as CustomFieldMetadata;
7171
}
7272

@@ -85,7 +85,7 @@ function toPickListValues(customField: object): string[] {
8585
return [];
8686
}
8787

88-
function isCustomField(customField: object): customField is CustomFieldMetadata {
88+
function hasType(customField: object): customField is CustomFieldMetadata {
8989
return (customField as CustomFieldMetadata).type != undefined;
9090
}
9191

src/core/renderables/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export type RenderableCustomField = {
189189
heading: string;
190190
apiName: string;
191191
description: RenderableContent[];
192+
pickListValues: string[];
192193
type: 'field';
193194
fieldType?: string | null;
194195
};

0 commit comments

Comments
 (0)