From 3c7c6e2e20fbe38c296190edf6e38952f9d2295f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3jcik?= Date: Thu, 2 Jan 2025 00:41:39 +0100 Subject: [PATCH] fixup --- package.json | 3 +-- src/panels/CommandPanel.ts | 2 +- src/services/actions/CliActions.ts | 39 +++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f33a983..f0fc5c9 100644 --- a/package.json +++ b/package.json @@ -469,8 +469,7 @@ { "command": "spfx-toolkit.setFormCustomizer", "title": "Set Form Customizer", - "category": "SharePoint Framework Toolkit", - "icon": "$(file-code)" + "category": "SharePoint Framework Toolkit" }, { "command": "spfx-toolkit.showMoreActions", diff --git a/src/panels/CommandPanel.ts b/src/panels/CommandPanel.ts index 6554335..b2635c6 100644 --- a/src/panels/CommandPanel.ts +++ b/src/panels/CommandPanel.ts @@ -310,8 +310,8 @@ export class CommandPanel { actionCommands.push(new ActionTreeItem('Add new component', '', { name: 'add', custom: false }, undefined, Commands.addToProject)); actionCommands.push(new ActionTreeItem('Scaffold CI/CD Workflow', '', { name: 'rocket', custom: false }, undefined, Commands.pipeline)); - actionCommands.push(new ActionTreeItem('View samples', '', { name: 'library', custom: false }, undefined, Commands.samplesGallery)); actionCommands.push(new ActionTreeItem('Set Form Customizer', '', { name: 'checklist', custom: false }, undefined, Commands.setFormCustomizer)); + actionCommands.push(new ActionTreeItem('View samples', '', { name: 'library', custom: false }, undefined, Commands.samplesGallery)); window.registerTreeDataProvider('pnp-view-actions', new ActionTreeDataProvider(actionCommands)); } diff --git a/src/services/actions/CliActions.ts b/src/services/actions/CliActions.ts index 1debfe9..6922d9e 100644 --- a/src/services/actions/CliActions.ts +++ b/src/services/actions/CliActions.ts @@ -928,16 +928,35 @@ export class CliActions { * Sets the form customizer for a content type on a list. */ public static async setFormCustomizer() { - const siteUrl = await window.showInputBox({ - prompt: 'Enter the site URL', + const relativeUrl = await window.showInputBox({ + prompt: 'Enter the relative URL of the site', ignoreFocusOut: true, - validateInput: (value) => value ? undefined : 'Site URL is required' + placeHolder: 'e.g., sites/sales', + validateInput: (input) => { + if (!input) { + return 'site URL is required'; + } + + const trimmedInput = input.trim(); + + if (trimmedInput.startsWith('https://')) { + return 'Please provide a relative URL, not an absolute URL.'; + } + if (trimmedInput.startsWith('/')) { + return 'Please provide a relative URL without a leading slash.'; + } + + return undefined; + } }); - if (!siteUrl) { + if (relativeUrl === undefined) { + Notifications.warning('No site URL provided. Setting form customizer aborted.'); return; } + const siteUrl = `${EnvironmentInformation.tenantUrl}/${relativeUrl.trim()}`; + const listTitle = await window.showInputBox({ prompt: 'Enter the list title', ignoreFocusOut: true, @@ -945,6 +964,7 @@ export class CliActions { }); if (!listTitle) { + Notifications.warning('No list title provided. Setting form customizer aborted.'); return; } @@ -955,21 +975,22 @@ export class CliActions { }); if (!contentType) { + Notifications.warning('No content type name provided. Setting form customizer aborted.'); return; } const editFormClientSideComponentId = await window.showInputBox({ - prompt: 'Enter the Edit form customizer (leave empty to skip)', + prompt: 'Enter the Edit form customizer ID (leave empty to skip)', ignoreFocusOut: true }); - const newFormClientSideComponentId = await window.showInputBox({ - prompt: 'Enter the New form customizer (leave empty to skip)', + const newFormClientSideComponentId = await window.showInputBox({ + prompt: 'Enter the New form customizer ID (leave empty to skip)', ignoreFocusOut: true }); const displayFormClientSideComponentId = await window.showInputBox({ - prompt: 'Enter the View form customizer (leave empty to skip)', + prompt: 'Enter the View form customizer ID (leave empty to skip)', ignoreFocusOut: true }); @@ -984,7 +1005,7 @@ export class CliActions { } if (newFormClientSideComponentId ) { - commandOptions.newFormCustomizer = newFormClientSideComponentId ; + commandOptions.NewFormClientSideComponentId = newFormClientSideComponentId ; } if (displayFormClientSideComponentId) {