Skip to content

Commit

Permalink
Enhances spo page section add with collapsibleTitle option. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkm17 committed Nov 5, 2024
1 parent f17d225 commit 4d2fa5b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/docs/cmd/spo/page/page-section-add.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ m365 spo page section add [options]

`--overlayOpacity [overlayOpacity]`
: The overlay opacity for the background. Applied only when `zoneEmphasis` is `Image` or `Gradient`. Sets `60` value if not specified.

`--collapsibleTitle [collapsibleTitle]`
: The display name of the collapsible section
```

<Global />
Expand Down
1 change: 1 addition & 0 deletions src/m365/spo/commands/page/canvasContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ interface ZoneGroupMetadata {
isExpanded: boolean;
showDividerLine: boolean;
iconAlignment: string;
displayName?: string;
}
36 changes: 36 additions & 0 deletions src/m365/spo/commands/page/page-section-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,42 @@ describe(commands.PAGE_SECTION_ADD, () => {
assert.strictEqual(data, JSON.stringify({ "CanvasContent1": "[{\"displayMode\":2,\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"sectionFactor\":12,\"layoutIndex\":1},\"emphasis\":{},\"zoneGroupMetadata\":{\"type\":1,\"isExpanded\":false,\"showDividerLine\":false,\"iconAlignment\":\"left\"}},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]" }));
});

it('adds a OneColumn section at the end to an uncustomized page with collapsible setting and section title', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).includes(`/_api/sitepages/pages/GetByUrl('sitepages/home.aspx')?$select=CanvasContent1,IsPageCheckedOutToCurrentUser`)) {
return {
"IsPageCheckedOutToCurrentUser": true,
"CanvasContent1": "[{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]"
};
}

throw 'Invalid request';
});

let data: string = '';
sinon.stub(request, 'post').callsFake(async (opts) => {
if ((opts.url as string).includes(`/_api/sitepages/pages/GetByUrl('sitepages/home.aspx')/savepage`)) {
data = JSON.stringify(opts.data);
return {};
}

throw 'Invalid request';
});

await command.action(logger, {
options:
{
pageName: 'home.aspx',
webUrl: 'https://contoso.sharepoint.com/sites/newsletter',
sectionTemplate: 'OneColumn',
isCollapsibleSection: true,
iconAlignment: 'Right',
collapsibleTitle: 'Collapsible section title'
}
});
assert.strictEqual(data, JSON.stringify({ "CanvasContent1": "[{\"displayMode\":2,\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"sectionFactor\":12,\"layoutIndex\":1},\"emphasis\":{},\"zoneGroupMetadata\":{\"type\":1,\"isExpanded\":false,\"showDividerLine\":false,\"iconAlignment\":\"right\",\"displayName\":\"Collapsible section title\"}},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]" }));
});

it('correctly handles random API error', async () => {
sinon.stub(request, 'get').callsFake(() => {
throw 'An error has occurred';
Expand Down
14 changes: 10 additions & 4 deletions src/m365/spo/commands/page/page-section-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Options extends GlobalOptions {
useLightText?: boolean;
overlayColor?: string;
overlayOpacity?: number;
collapsibleTitle?: string;
}

class SpoPageSectionAddCommand extends SpoCommand {
Expand Down Expand Up @@ -74,7 +75,8 @@ class SpoPageSectionAddCommand extends SpoCommand {
fillMode: typeof args.options.fillMode !== 'undefined',
useLightText: !!args.options.useLightText,
overlayColor: typeof args.options.overlayColor !== 'undefined',
overlayOpacity: typeof args.options.overlayOpacity !== 'undefined'
overlayOpacity: typeof args.options.overlayOpacity !== 'undefined',
collapsibleTitle: typeof args.options.collapsibleTitle !== 'undefined'
});
});
}
Expand Down Expand Up @@ -138,6 +140,9 @@ class SpoPageSectionAddCommand extends SpoCommand {
},
{
option: '--overlayOpacity [overlayOpacity]'
},
{
option: '--collapsibleTitle [collapsibleTitle]'
}
);
}
Expand Down Expand Up @@ -214,7 +219,7 @@ class SpoPageSectionAddCommand extends SpoCommand {
}

#initTypes(): void {
this.types.string = ['pageName', 'webUrl', 'sectionTemplate', 'zoneEmphasis', 'iconAlignment', 'gradientText', 'imageUrl', 'fillMode', 'overlayColor'];
this.types.string = ['pageName', 'webUrl', 'sectionTemplate', 'zoneEmphasis', 'iconAlignment', 'gradientText', 'imageUrl', 'fillMode', 'overlayColor', 'collapsibleTitle'];
this.types.boolean = ['isLayoutReflowOnTop', 'isCollapsibleSection', 'showDivider', 'isExpanded', 'useLightText'];
}

Expand Down Expand Up @@ -368,7 +373,7 @@ class SpoPageSectionAddCommand extends SpoCommand {
}

private getColumn(zoneIndex: number, sectionIndex: number, sectionFactor: number, args: CommandArgs, zoneId?: string): Control {
const { zoneEmphasis, isCollapsibleSection, isExpanded, showDivider, iconAlignment } = args.options;
const { zoneEmphasis, isCollapsibleSection, isExpanded, showDivider, iconAlignment, collapsibleTitle } = args.options;
const columnValue: Control = {
displayMode: 2,
position: {
Expand All @@ -393,7 +398,8 @@ class SpoPageSectionAddCommand extends SpoCommand {
type: 1,
isExpanded: !!isExpanded,
showDividerLine: !!showDivider,
iconAlignment: iconAlignment && iconAlignment.toLocaleLowerCase() === "right" ? "right" : "left"
iconAlignment: iconAlignment && iconAlignment.toLocaleLowerCase() === "right" ? "right" : "left",
displayName: collapsibleTitle
};
}

Expand Down

0 comments on commit 4d2fa5b

Please sign in to comment.