mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add default name to promptAddItem (#19439)
* Add default name to promptAddItem * Change to addItemPrompt
This commit is contained in:
@@ -40,7 +40,7 @@ import { DashboardData, PublishData, Status } from '../models/dashboardData/dash
|
|||||||
import { getPublishDatabaseSettings, launchPublishTargetOption } from '../dialogs/publishDatabaseQuickpick';
|
import { getPublishDatabaseSettings, launchPublishTargetOption } from '../dialogs/publishDatabaseQuickpick';
|
||||||
import { launchCreateAzureServerQuickPick, launchPublishToDockerContainerQuickpick } from '../dialogs/deployDatabaseQuickpick';
|
import { launchCreateAzureServerQuickPick, launchPublishToDockerContainerQuickpick } from '../dialogs/deployDatabaseQuickpick';
|
||||||
import { DeployService } from '../models/deploy/deployService';
|
import { DeployService } from '../models/deploy/deployService';
|
||||||
import { GenerateProjectFromOpenApiSpecOptions, ISqlProject, ItemType, SqlTargetPlatform } from 'sqldbproj';
|
import { AddItemOptions, GenerateProjectFromOpenApiSpecOptions, ISqlProject, ItemType, SqlTargetPlatform } from 'sqldbproj';
|
||||||
import { AutorestHelper } from '../tools/autorestHelper';
|
import { AutorestHelper } from '../tools/autorestHelper';
|
||||||
import { createNewProjectFromDatabaseWithQuickpick } from '../dialogs/createProjectFromDatabaseQuickpick';
|
import { createNewProjectFromDatabaseWithQuickpick } from '../dialogs/createProjectFromDatabaseQuickpick';
|
||||||
import { addDatabaseReferenceQuickpick } from '../dialogs/addDatabaseReferenceQuickpick';
|
import { addDatabaseReferenceQuickpick } from '../dialogs/addDatabaseReferenceQuickpick';
|
||||||
@@ -675,10 +675,11 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async addItemPromptFromNode(treeNode: dataworkspace.WorkspaceTreeItem, itemTypeName?: string): Promise<void> {
|
public async addItemPromptFromNode(treeNode: dataworkspace.WorkspaceTreeItem, itemTypeName?: string): Promise<void> {
|
||||||
await this.addItemPrompt(this.getProjectFromContext(treeNode), this.getRelativePath(treeNode.element), itemTypeName, treeNode.treeDataProvider as SqlDatabaseProjectTreeViewProvider);
|
await this.addItemPrompt(this.getProjectFromContext(treeNode), this.getRelativePath(treeNode.element), { itemType: itemTypeName }, treeNode.treeDataProvider as SqlDatabaseProjectTreeViewProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addItemPrompt(project: ISqlProject, relativePath: string, itemTypeName?: string, treeDataProvider?: SqlDatabaseProjectTreeViewProvider): Promise<void> {
|
public async addItemPrompt(project: ISqlProject, relativePath: string, options?: AddItemOptions, treeDataProvider?: SqlDatabaseProjectTreeViewProvider): Promise<void> {
|
||||||
|
let itemTypeName = options?.itemType;
|
||||||
if (!itemTypeName) {
|
if (!itemTypeName) {
|
||||||
const items: vscode.QuickPickItem[] = [];
|
const items: vscode.QuickPickItem[] = [];
|
||||||
|
|
||||||
@@ -697,7 +698,7 @@ export class ProjectsController {
|
|||||||
|
|
||||||
const itemType = templates.get(itemTypeName);
|
const itemType = templates.get(itemTypeName);
|
||||||
const absolutePathToParent = path.join(project.projectFolderPath, relativePath);
|
const absolutePathToParent = path.join(project.projectFolderPath, relativePath);
|
||||||
let itemObjectName = await this.promptForNewObjectName(itemType, project, absolutePathToParent, constants.sqlFileExtension);
|
let itemObjectName = await this.promptForNewObjectName(itemType, project, absolutePathToParent, constants.sqlFileExtension, options?.defaultName);
|
||||||
|
|
||||||
itemObjectName = itemObjectName?.trim();
|
itemObjectName = itemObjectName?.trim();
|
||||||
|
|
||||||
@@ -1340,8 +1341,8 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async promptForNewObjectName(itemType: templates.ProjectScriptType, _project: ISqlProject, folderPath: string, fileExtension?: string): Promise<string | undefined> {
|
private async promptForNewObjectName(itemType: templates.ProjectScriptType, _project: ISqlProject, folderPath: string, fileExtension?: string, defaultName?: string): Promise<string | undefined> {
|
||||||
const suggestedName = itemType.friendlyName.replace(/\s+/g, '');
|
const suggestedName = defaultName ?? itemType.friendlyName.replace(/\s+/g, '');
|
||||||
let counter: number = 0;
|
let counter: number = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ export class SqlDatabaseProjectProvider implements dataworkspace.IProjectProvide
|
|||||||
return Project.openProject(projectFilePath);
|
return Project.openProject(projectFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public promptAddItem(project: sqldbproj.ISqlProject, relativeFilePath: string, itemType?: string): Promise<void> {
|
public addItemPrompt(project: sqldbproj.ISqlProject, relativeFilePath: string, options?: sqldbproj.AddItemOptions): Promise<void> {
|
||||||
return this.projectController.addItemPrompt(project, relativeFilePath, itemType);
|
return this.projectController.addItemPrompt(project, relativeFilePath, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,12 +59,23 @@ declare module 'sqldbproj' {
|
|||||||
* Prompts the user to add a new item to the specified project
|
* Prompts the user to add a new item to the specified project
|
||||||
* @param project The project to add the item to
|
* @param project The project to add the item to
|
||||||
* @param relativeFilePath The relative path in the project where the item should be added
|
* @param relativeFilePath The relative path in the project where the item should be added
|
||||||
* @param itemType Optional - The type of item to add. If not specified the user will choose from a list of available types
|
* @param options The additional options to use
|
||||||
*/
|
*/
|
||||||
promptAddItem(project: ISqlProject, relativeFilePath: string, itemType?: string): Promise<void>;
|
addItemPrompt(project: ISqlProject, relativeFilePath: string, options?: AddItemOptions): Promise<void>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AddItemOptions {
|
||||||
|
/**
|
||||||
|
* The type of item to add. If not specified the user will choose from a list of available types
|
||||||
|
*/
|
||||||
|
itemType?: string,
|
||||||
|
/**
|
||||||
|
* The default name to display in the name prompt
|
||||||
|
*/
|
||||||
|
defaultName?: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of an item in a SQL Project
|
* The type of an item in a SQL Project
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ describe('ProjectsController', function (): void {
|
|||||||
const project = new Project('FakePath');
|
const project = new Project('FakePath');
|
||||||
|
|
||||||
should(project.files.length).equal(0);
|
should(project.files.length).equal(0);
|
||||||
await projController.addItemPrompt(new Project('FakePath'), '', ItemType.script);
|
await projController.addItemPrompt(new Project('FakePath'), '', { itemType: ItemType.script });
|
||||||
should(project.files.length).equal(0, 'Expected to return without throwing an exception or adding a file when an empty/undefined name is provided.');
|
should(project.files.length).equal(0, 'Expected to return without throwing an exception or adding a file when an empty/undefined name is provided.');
|
||||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||||
showInputBoxStub.restore();
|
showInputBoxStub.restore();
|
||||||
@@ -112,9 +112,9 @@ describe('ProjectsController', function (): void {
|
|||||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||||
|
|
||||||
should(project.files.length).equal(0, 'There should be no files');
|
should(project.files.length).equal(0, 'There should be no files');
|
||||||
await projController.addItemPrompt(project, '', ItemType.script);
|
await projController.addItemPrompt(project, '', { itemType: ItemType.script });
|
||||||
should(project.files.length).equal(1, 'File should be successfully added');
|
should(project.files.length).equal(1, 'File should be successfully added');
|
||||||
await projController.addItemPrompt(project, '', ItemType.script);
|
await projController.addItemPrompt(project, '', { itemType: ItemType.script });
|
||||||
const msg = constants.fileAlreadyExists(tableName);
|
const msg = constants.fileAlreadyExists(tableName);
|
||||||
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
||||||
should(spy.calledWith(msg)).be.true(`showErrorMessage not called with expected message '${msg}' Actual '${spy.getCall(0).args[0]}'`);
|
should(spy.calledWith(msg)).be.true(`showErrorMessage not called with expected message '${msg}' Actual '${spy.getCall(0).args[0]}'`);
|
||||||
@@ -327,13 +327,13 @@ describe('ProjectsController', function (): void {
|
|||||||
|
|
||||||
sinon.stub(vscode.window, 'showInputBox').resolves(preDeployScriptName);
|
sinon.stub(vscode.window, 'showInputBox').resolves(preDeployScriptName);
|
||||||
should(project.preDeployScripts.length).equal(0, 'There should be no pre deploy scripts');
|
should(project.preDeployScripts.length).equal(0, 'There should be no pre deploy scripts');
|
||||||
await projController.addItemPrompt(project, '', ItemType.preDeployScript);
|
await projController.addItemPrompt(project, '', { itemType: ItemType.preDeployScript });
|
||||||
should(project.preDeployScripts.length).equal(1, `Pre deploy script should be successfully added. ${project.preDeployScripts.length}, ${project.files.length}`);
|
should(project.preDeployScripts.length).equal(1, `Pre deploy script should be successfully added. ${project.preDeployScripts.length}, ${project.files.length}`);
|
||||||
|
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
sinon.stub(vscode.window, 'showInputBox').resolves(postDeployScriptName);
|
sinon.stub(vscode.window, 'showInputBox').resolves(postDeployScriptName);
|
||||||
should(project.postDeployScripts.length).equal(0, 'There should be no post deploy scripts');
|
should(project.postDeployScripts.length).equal(0, 'There should be no post deploy scripts');
|
||||||
await projController.addItemPrompt(project, '', ItemType.postDeployScript);
|
await projController.addItemPrompt(project, '', { itemType: ItemType.postDeployScript });
|
||||||
should(project.postDeployScripts.length).equal(1, 'Post deploy script should be successfully added');
|
should(project.postDeployScripts.length).equal(1, 'Post deploy script should be successfully added');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user