Skip to content

Commit 3e3e056

Browse files
nicodecleyreAdam-it
authored andcommitted
🚀 Add 'Set Form Customizer' command to the SharePoint Framework Toolkit
1 parent e09e726 commit 3e3e056

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@
466466
"category": "SharePoint Framework Toolkit",
467467
"icon": "$(sync)"
468468
},
469+
{
470+
"command": "spfx-toolkit.setFormCustomizer",
471+
"title": "Set Form Customizer",
472+
"category": "SharePoint Framework Toolkit",
473+
"icon": "$(file-code)"
474+
},
469475
{
470476
"command": "spfx-toolkit.showMoreActions",
471477
"title": "...",

src/constants/Commands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ export const Commands = {
6060
enableAppCatalogApp: `${EXTENSION_NAME}.enableAppCatalogApp`,
6161
disableAppCatalogApp: `${EXTENSION_NAME}.disableAppCatalogApp`,
6262
upgradeAppCatalogApp: `${EXTENSION_NAME}.upgradeAppCatalogApp`,
63-
showMoreActions: `${EXTENSION_NAME}.showMoreActions`
63+
showMoreActions: `${EXTENSION_NAME}.showMoreActions`,
64+
65+
// Set form customizer
66+
setFormCustomizer: `${EXTENSION_NAME}.setFormCustomizer`
6467
};

src/panels/CommandPanel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export class CommandPanel {
311311
actionCommands.push(new ActionTreeItem('Add new component', '', { name: 'add', custom: false }, undefined, Commands.addToProject));
312312
actionCommands.push(new ActionTreeItem('Scaffold CI/CD Workflow', '', { name: 'rocket', custom: false }, undefined, Commands.pipeline));
313313
actionCommands.push(new ActionTreeItem('View samples', '', { name: 'library', custom: false }, undefined, Commands.samplesGallery));
314+
actionCommands.push(new ActionTreeItem('Set Form Customizer', '', { name: 'checklist', custom: false }, undefined, Commands.setFormCustomizer));
314315

315316
window.registerTreeDataProvider('pnp-view-actions', new ActionTreeDataProvider(actionCommands));
316317
}

src/services/actions/CliActions.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export class CliActions {
6969
subscriptions.push(
7070
commands.registerCommand(Commands.upgradeAppCatalogApp, CliActions.upgradeAppCatalogApp)
7171
);
72+
subscriptions.push(
73+
commands.registerCommand(Commands.setFormCustomizer, CliActions.setFormCustomizer)
74+
);
7275
}
7376

7477
/**
@@ -920,4 +923,90 @@ export class CliActions {
920923
Notifications.error(`${fileName}.tour file not found in path ${path.join(wsFolder.uri.fsPath, '.tours')}. Cannot start Code Tour.`);
921924
}
922925
}
926+
927+
/**
928+
* Sets the form customizer for a content type on a list.
929+
*/
930+
public static async setFormCustomizer() {
931+
const siteUrl = await window.showInputBox({
932+
prompt: 'Enter the site URL',
933+
ignoreFocusOut: true,
934+
validateInput: (value) => value ? undefined : 'Site URL is required'
935+
});
936+
937+
if (!siteUrl) {
938+
return;
939+
}
940+
941+
const listTitle = await window.showInputBox({
942+
prompt: 'Enter the list title',
943+
ignoreFocusOut: true,
944+
validateInput: (value) => value ? undefined : 'List title is required'
945+
});
946+
947+
if (!listTitle) {
948+
return;
949+
}
950+
951+
const contentType = await window.showInputBox({
952+
prompt: 'Enter the Content Type name',
953+
ignoreFocusOut: true,
954+
validateInput: (value) => value ? undefined : 'Content Type name is required'
955+
});
956+
957+
if (!contentType) {
958+
return;
959+
}
960+
961+
const editFormClientSideComponentId = await window.showInputBox({
962+
prompt: 'Enter the Edit form customizer (leave empty to skip)',
963+
ignoreFocusOut: true
964+
});
965+
966+
const newFormClientSideComponentId = await window.showInputBox({
967+
prompt: 'Enter the New form customizer (leave empty to skip)',
968+
ignoreFocusOut: true
969+
});
970+
971+
const displayFormClientSideComponentId = await window.showInputBox({
972+
prompt: 'Enter the View form customizer (leave empty to skip)',
973+
ignoreFocusOut: true
974+
});
975+
976+
const commandOptions: any = {
977+
webUrl: siteUrl,
978+
listTitle: listTitle,
979+
name: contentType
980+
};
981+
982+
if (editFormClientSideComponentId) {
983+
commandOptions.EditFormClientSideComponentId = editFormClientSideComponentId;
984+
}
985+
986+
if (newFormClientSideComponentId ) {
987+
commandOptions.newFormCustomizer = newFormClientSideComponentId ;
988+
}
989+
990+
if (displayFormClientSideComponentId) {
991+
commandOptions.DisplayFormClientSideComponentId = displayFormClientSideComponentId;
992+
}
993+
994+
await window.withProgress({
995+
location: ProgressLocation.Notification,
996+
title: 'Setting form customizer...',
997+
cancellable: true
998+
}, async (progress: Progress<{ message?: string; increment?: number }>) => {
999+
try {
1000+
const result = await CliExecuter.execute('spo contenttype set', 'json', commandOptions);
1001+
if (result.stderr) {
1002+
Notifications.error(result.stderr);
1003+
} else {
1004+
Notifications.info('Form customizer set successfully.');
1005+
}
1006+
} catch (e: any) {
1007+
const message = e?.error?.message;
1008+
Notifications.error(message);
1009+
}
1010+
});
1011+
}
9231012
}

0 commit comments

Comments
 (0)