mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
enable table designer for table script in sql database project (#19237)
* add 'open in designer' to context menu of tables in sql projects * fix tests * Address comments * enable table designer for sql database proj * update label and issues on init * vbump sts * use promisified fs * pr comments Co-authored-by: Alan Ren <alanren@microsoft.com>
This commit is contained in:
@@ -245,10 +245,20 @@ export class Project implements ISqlProject {
|
||||
|
||||
// create a FileProjectEntry for each file
|
||||
const fileEntries: FileProjectEntry[] = [];
|
||||
filesSet.forEach(f => {
|
||||
for (let f of Array.from(filesSet.values())) {
|
||||
const typeEntry = entriesWithType.find(e => e.relativePath === f);
|
||||
fileEntries.push(this.createFileProjectEntry(f, EntryType.File, typeEntry ? typeEntry.typeAttribute : undefined));
|
||||
});
|
||||
let containsCreateTableStatement;
|
||||
|
||||
// read file to check if it has a "Create Table" statement
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(f));
|
||||
|
||||
if (await utils.exists(fullPath)) {
|
||||
const fileContents = await fs.readFile(fullPath);
|
||||
containsCreateTableStatement = fileContents.toString().toLowerCase().includes('create table');
|
||||
}
|
||||
|
||||
fileEntries.push(this.createFileProjectEntry(f, EntryType.File, typeEntry ? typeEntry.typeAttribute : undefined, containsCreateTableStatement));
|
||||
}
|
||||
|
||||
return fileEntries;
|
||||
}
|
||||
@@ -1078,13 +1088,14 @@ export class Project implements ISqlProject {
|
||||
return this.getCollectionProjectPropertyValue(constants.DatabaseSource);
|
||||
}
|
||||
|
||||
public createFileProjectEntry(relativePath: string, entryType: EntryType, sqlObjectType?: string): FileProjectEntry {
|
||||
public createFileProjectEntry(relativePath: string, entryType: EntryType, sqlObjectType?: string, containsCreateTableStatement?: boolean): FileProjectEntry {
|
||||
let platformSafeRelativePath = utils.getPlatformSafeFileEntryPath(relativePath);
|
||||
return new FileProjectEntry(
|
||||
Uri.file(path.join(this.projectFolderPath, platformSafeRelativePath)),
|
||||
utils.convertSlashesForSqlProj(relativePath),
|
||||
entryType,
|
||||
sqlObjectType);
|
||||
sqlObjectType,
|
||||
containsCreateTableStatement);
|
||||
}
|
||||
|
||||
private findOrCreateItemGroup(containedTag?: string, prePostScriptExist?: { scriptExist: boolean; }): Element {
|
||||
|
||||
@@ -27,12 +27,14 @@ export class FileProjectEntry extends ProjectEntry implements IFileProjectEntry
|
||||
fsUri: Uri;
|
||||
relativePath: string;
|
||||
sqlObjectType: string | undefined;
|
||||
containsCreateTableStatement: boolean | undefined;
|
||||
|
||||
constructor(uri: Uri, relativePath: string, entryType: EntryType, sqlObjectType?: string) {
|
||||
constructor(uri: Uri, relativePath: string, entryType: EntryType, sqlObjectType?: string, containsCreateTableStatement?: boolean) {
|
||||
super(entryType);
|
||||
this.fsUri = uri;
|
||||
this.relativePath = relativePath;
|
||||
this.sqlObjectType = sqlObjectType;
|
||||
this.containsCreateTableStatement = containsCreateTableStatement;
|
||||
}
|
||||
|
||||
public override toString(): string {
|
||||
|
||||
@@ -80,6 +80,15 @@ export class ExternalStreamingJobFileNode extends FileNode {
|
||||
}
|
||||
}
|
||||
|
||||
export class TableFileNode extends FileNode {
|
||||
public override get treeItem(): vscode.TreeItem {
|
||||
const treeItem = super.treeItem;
|
||||
treeItem.contextValue = DatabaseProjectItemType.table;
|
||||
|
||||
return treeItem;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two folder/file tree nodes so that folders come before files, then alphabetically
|
||||
* @param a a folder or file tree node
|
||||
|
||||
@@ -80,6 +80,8 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
||||
case EntryType.File:
|
||||
if (entry.sqlObjectType === ExternalStreamingJob) {
|
||||
newNode = new fileTree.ExternalStreamingJobFileNode(entry.fsUri, parentNode);
|
||||
} else if (entry.containsCreateTableStatement) {
|
||||
newNode = new fileTree.TableFileNode(entry.fsUri, parentNode);
|
||||
}
|
||||
else {
|
||||
newNode = new fileTree.FileNode(entry.fsUri, parentNode);
|
||||
|
||||
Reference in New Issue
Block a user