mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -05:00
Add validation for new file names for sql projects (#21601)
* Add validation for new file names for sql projects * Addres comments and add validation for new project dialog * Address comments * Address comments on test * Fix tests * Remove extra error messages and rename file * Address comments * Fix tests * Add test file back
This commit is contained in:
@@ -15,6 +15,7 @@ import { IconPathHelper } from '../common/iconHelper';
|
||||
import { defaultProjectSaveLocation } from '../common/projectLocationHelper';
|
||||
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
|
||||
import { WorkspaceService } from '../services/workspaceService';
|
||||
import { isValidBasename, isValidBasenameErrorMessage } from '../common/pathUtilsHelper';
|
||||
|
||||
class NewProjectDialogModel {
|
||||
projectTypeId: string = '';
|
||||
@@ -174,16 +175,25 @@ export class NewProjectDialog extends DialogBase {
|
||||
}
|
||||
}));
|
||||
|
||||
const projectNameTextBox = view.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: constants.ProjectNameTitle,
|
||||
placeHolder: constants.ProjectNamePlaceholder,
|
||||
required: true,
|
||||
width: constants.DefaultInputWidth
|
||||
}).component();
|
||||
const projectNameTextBox = view.modelBuilder.inputBox().withValidation(
|
||||
component => isValidBasename(component.value)
|
||||
)
|
||||
.withProps({
|
||||
ariaLabel: constants.ProjectNameTitle,
|
||||
placeHolder: constants.ProjectNamePlaceholder,
|
||||
required: true,
|
||||
width: constants.DefaultInputWidth
|
||||
}).component();
|
||||
|
||||
this.register(projectNameTextBox.onTextChanged(() => {
|
||||
this.model.name = projectNameTextBox.value!;
|
||||
return projectNameTextBox.updateProperty('title', projectNameTextBox.value);
|
||||
this.register(projectNameTextBox.onTextChanged(text => {
|
||||
const errorMessage = isValidBasenameErrorMessage(text);
|
||||
if (errorMessage) {
|
||||
// Set validation error message if project name is invalid
|
||||
return void projectNameTextBox.updateProperty('validationErrorMessage', errorMessage);
|
||||
} else {
|
||||
this.model.name = projectNameTextBox.value!;
|
||||
return projectNameTextBox.updateProperty('title', projectNameTextBox.value);
|
||||
}
|
||||
}));
|
||||
|
||||
const locationTextBox = view.modelBuilder.inputBox().withProps({
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as constants from '../common/constants';
|
||||
import { directoryExist, showInfoMessageWithLearnMoreLink } from '../common/utils';
|
||||
import { defaultProjectSaveLocation } from '../common/projectLocationHelper';
|
||||
import { WorkspaceService } from '../services/workspaceService';
|
||||
import { isValidBasename, isValidBasenameErrorMessage } from '../common/pathUtilsHelper';
|
||||
|
||||
/**
|
||||
* Create flow for a New Project using only VS Code-native APIs such as QuickPick
|
||||
@@ -39,7 +40,7 @@ export async function createNewProjectWithQuickpick(workspaceService: WorkspaceS
|
||||
{
|
||||
title: constants.EnterProjectName,
|
||||
validateInput: (value) => {
|
||||
return value ? undefined : constants.NameCannotBeEmpty;
|
||||
return isValidBasename(value) ? undefined : isValidBasenameErrorMessage(value);
|
||||
},
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user