supporting sql built-in extensions (#890)

* supporting sql built-in extensions
This commit is contained in:
Leila Lali
2018-03-12 11:02:47 -07:00
committed by GitHub
parent e79e3bdf1d
commit 66f39fd3eb
5 changed files with 74 additions and 6 deletions

View File

@@ -156,6 +156,8 @@ class Query {
get sortBy(): number { return this.state.sortBy; }
get sortOrder(): number { return this.state.sortOrder; }
get flags(): number { return this.state.flags; }
// {{SQL CARBON EDIT}}
get criteria(): ICriterium[] { return this.state.criteria ? this.state.criteria : []; }
withPage(pageNumber: number, pageSize: number = this.state.pageSize): Query {
return new Query(assign({}, this.state, { pageNumber, pageSize }));
@@ -439,6 +441,30 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
});
}
// {{SQL CARBON EDIT}}
/**
* The result of querying the gallery returns all the extensions because it's only reading a static file.
* So this method should apply all the filters and return the actual result
* @param query
* @param galleryExtensions
*/
private createQueryResult(query: Query, galleryExtensions: IRawGalleryExtension[]): { galleryExtensions: IRawGalleryExtension[], total: number; } {
let filteredExtensions = galleryExtensions;
if (query.criteria) {
const ids = query.criteria.filter(x => x.filterType === FilterType.ExtensionId).map(v => v.value.toLocaleLowerCase());
if (ids && ids.length > 0) {
filteredExtensions = filteredExtensions.filter(e => e.extensionId && ids.includes(e.extensionId.toLocaleLowerCase()));
}
const names = query.criteria.filter(x => x.filterType === FilterType.ExtensionName).map(v => v.value.toLocaleLowerCase());
if (names && names.length > 0) {
filteredExtensions = filteredExtensions.filter(e => e.extensionName && e.publisher.publisherName && names.includes(`${e.publisher.publisherName.toLocaleLowerCase()}.${e.extensionName.toLocaleLowerCase()}`));
}
}
let actualTotal = filteredExtensions.length;
return { galleryExtensions: filteredExtensions, total: actualTotal };
}
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
return this.commonHeadersPromise.then(commonHeaders => {
const data = JSON.stringify(query.raw);
@@ -467,7 +493,10 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0];
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0;
return { galleryExtensions, total };
// {{SQL CARBON EDIT}}
let filteredExtensionsResult = this.createQueryResult(query, galleryExtensions);
return { galleryExtensions: filteredExtensionsResult.galleryExtensions, total: filteredExtensionsResult.total };
});
});
});

View File

@@ -28,6 +28,8 @@ export interface IProductConfiguration {
controlUrl: string;
};
extensionTips: { [id: string]: string; };
// {{SQL CARBON EDIT}}
recommendedExtensions: string[];
extensionImportantTips: { [id: string]: { name: string; pattern: string; }; };
exeBasedExtensionTips: { [id: string]: any; };
extensionKeywords: { [extension: string]: string[]; };

View File

@@ -41,6 +41,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
_serviceBrand: any;
private _fileBasedRecommendations: { [id: string]: number; } = Object.create(null);
// {{SQL CARBON EDIT}}
private _recommendations: string[] = Object.create(null);
private _exeBasedRecommendations: { [id: string]: string; } = Object.create(null);
private _availableRecommendations: { [pattern: string]: string[] } = Object.create(null);
private importantRecommendations: { [id: string]: { name: string; pattern: string; } } = Object.create(null);
@@ -83,6 +85,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
let output: { [id: string]: string; } = Object.create(null);
Object.keys(this._fileBasedRecommendations).forEach(x => output[x.toLowerCase()] = localize('fileBasedRecommendation', "This extension is recommended based on the files you recently opened."));
this._allWorkspaceRecommendedExtensions.forEach(x => output[x.toLowerCase()] = localize('workspaceRecommendation', "This extension is recommended by users of the current workspace."));
// {{SQL CARBON EDIT}}
this._recommendations.forEach(x => output[x.toLowerCase()] = localize('defaultRecommendations', "This extension is recommended by Sql Ops Studio."));
forEach(this._exeBasedRecommendations, entry => output[entry.key.toLowerCase()] = localize('exeBasedRecommendation', "This extension is recommended because you have {0} installed.", entry.value));
return output;
}
@@ -150,7 +154,9 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
}
getOtherRecommendations(): string[] {
return Object.keys(this._exeBasedRecommendations);
// {{SQL CARBON EDIT}}
let recommendations = Object.keys(this._exeBasedRecommendations);
return recommendations.concat(this._recommendations);
}
@@ -161,6 +167,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
private _suggestTips() {
const extensionTips = product.extensionTips;
// {{SQL CARBON EDIT}}
this._recommendations = product.recommendedExtensions;
if (!extensionTips) {
return;
}