vscode-viva icon indicating copy to clipboard operation
vscode-viva copied to clipboard

💡 [Feature]: Improve code base to move some of the window prompts logic to separate util methods

Open Adam-it opened this issue 9 months ago • 1 comments

🎯 Aim of the feature

Since we started adding more and more advanced functionalities to SPFx Toolkit I noticed our code base have some duplicated logic we could try to move to some util methods and reuse. I think a good candidate to refactor are the window.showInputBox parts were we prompt the user for additional info to run a CLI command. In this case we usually provide context to select data and validate if it was provided and if not we cancel. Some good candidates to refactor

const owner: string | undefined = await window.showInputBox({
      prompt: 'Enter the email address of the tenant admin (owner)',
      ignoreFocusOut: true,
      validateInput: (value) => value ? undefined : 'Owner email is required',
    });
    if (!owner) {
      Notifications.error('Owner email is required to create a Tenant App Catalog.');
      return;
    }

or for sure this one

const relativeUrl = await window.showInputBox({
      prompt: 'Enter the relative URL of the site',
      ignoreFocusOut: true,
      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 (relativeUrl === undefined) {
      Notifications.warning('No site URL provided. Setting form customizer aborted.');
      return;
    }

📷 Images (if possible) with expected result

No response

🤔 Additional remarks or comments

lets leave this on hold until we merge this PR #440

Adam-it avatar Apr 11 '25 07:04 Adam-it

the initila PR got merged. We may start working on it

Adam-it avatar Jun 05 '25 00:06 Adam-it