mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
setting selected db name in drop down to current connection db name (#11912)
This commit is contained in:
@@ -35,6 +35,14 @@ export abstract class SqlPackageManageProviderBase {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns database name as current location
|
||||||
|
*/
|
||||||
|
public async getCurrentLocation(): Promise<string | undefined> {
|
||||||
|
let connection = await this.getCurrentConnection();
|
||||||
|
return connection?.databaseName;
|
||||||
|
}
|
||||||
|
|
||||||
protected async getCurrentConnection(): Promise<azdata.connection.ConnectionProfile> {
|
protected async getCurrentConnection(): Promise<azdata.connection.ConnectionProfile> {
|
||||||
return await this._apiWrapper.getCurrentConnection();
|
return await this._apiWrapper.getCurrentConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,11 @@ export interface IPackageManageProvider {
|
|||||||
*/
|
*/
|
||||||
getLocations(): Promise<IPackageLocation[]>;
|
getLocations(): Promise<IPackageLocation[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current location
|
||||||
|
*/
|
||||||
|
getCurrentLocation(): Promise<string | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Package Overview
|
* Returns Package Overview
|
||||||
* @param packageName package name
|
* @param packageName package name
|
||||||
|
|||||||
@@ -170,16 +170,18 @@ export class InstalledPackagesTab {
|
|||||||
component = view.modelBuilder.text().withProperties({
|
component = view.modelBuilder.text().withProperties({
|
||||||
value: locations[0].displayName
|
value: locations[0].displayName
|
||||||
}).component();
|
}).component();
|
||||||
} else if (locations) {
|
} else if (locations && locations.length > 1) {
|
||||||
let dropdownValues = locations.map(x => {
|
let dropdownValues = locations.map(x => {
|
||||||
return {
|
return {
|
||||||
name: x.name,
|
name: x.name,
|
||||||
displayName: x.displayName
|
displayName: x.displayName
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const currentLocation = await dialog.model.getCurrentLocation();
|
||||||
|
const selectedLocation = dropdownValues.find(x => x.name === currentLocation);
|
||||||
let locationDropDown = view.modelBuilder.dropDown().withProperties({
|
let locationDropDown = view.modelBuilder.dropDown().withProperties({
|
||||||
values: dropdownValues,
|
values: dropdownValues,
|
||||||
value: dropdownValues[0]
|
value: selectedLocation || dropdownValues[0]
|
||||||
}).component();
|
}).component();
|
||||||
|
|
||||||
locationDropDown.onValueChanged(async () => {
|
locationDropDown.onValueChanged(async () => {
|
||||||
|
|||||||
@@ -213,8 +213,10 @@ export class ManagePackagesDialogModel {
|
|||||||
* Changes the current location
|
* Changes the current location
|
||||||
*/
|
*/
|
||||||
public changeLocation(location: string): void {
|
public changeLocation(location: string): void {
|
||||||
|
if (location) {
|
||||||
this._currentLocation = location;
|
this._currentLocation = location;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs given packages using current provider
|
* Installs given packages using current provider
|
||||||
@@ -240,6 +242,19 @@ export class ManagePackagesDialogModel {
|
|||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current location for current provider
|
||||||
|
*/
|
||||||
|
public async getCurrentLocation(): Promise<string | undefined> {
|
||||||
|
if (!this._currentLocation) {
|
||||||
|
let provider = this.currentPackageManageProvider;
|
||||||
|
if (provider) {
|
||||||
|
return await provider.getCurrentLocation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.resolve(this._currentLocation);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UnInstalls given packages using current provider
|
* UnInstalls given packages using current provider
|
||||||
* @param packages Packages to install
|
* @param packages Packages to install
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ export class LocalCondaPackageManageProvider implements IPackageManageProvider {
|
|||||||
return this.jupyterInstallation.installCondaPackages(packages, useMinVersion);
|
return this.jupyterInstallation.installCondaPackages(packages, useMinVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current location
|
||||||
|
*/
|
||||||
|
public async getCurrentLocation(): Promise<string | undefined> {
|
||||||
|
return Promise.resolve(constants.localhostName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uninstalls given packages
|
* Uninstalls given packages
|
||||||
* @param packages Packages to uninstall
|
* @param packages Packages to uninstall
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ export class LocalPipPackageManageProvider implements IPackageManageProvider {
|
|||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current location
|
||||||
|
*/
|
||||||
|
public async getCurrentLocation(): Promise<string | undefined> {
|
||||||
|
return Promise.resolve(constants.localhostName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns location title
|
* Returns location title
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -138,6 +138,34 @@ describe('Manage Packages', () => {
|
|||||||
should.equal(model.jupyterInstallation, jupyterServerInstallation);
|
should.equal(model.jupyterInstallation, jupyterServerInstallation);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('CurrentLocation should return provider current location if specified', async function (): Promise<void> {
|
||||||
|
let testContext1 = createContext();
|
||||||
|
testContext1.provider.providerId = 'providerId1';
|
||||||
|
testContext1.provider.packageTarget = {
|
||||||
|
location: 'location1',
|
||||||
|
packageType: 'package-type1'
|
||||||
|
};
|
||||||
|
|
||||||
|
let testContext2 = createContext();
|
||||||
|
testContext2.provider.providerId = 'providerId2';
|
||||||
|
testContext2.provider.packageTarget = {
|
||||||
|
location: 'location1',
|
||||||
|
packageType: 'package-type2'
|
||||||
|
};
|
||||||
|
let providers = new Map<string, IPackageManageProvider>();
|
||||||
|
providers.set(testContext1.provider.providerId, createProvider(testContext1));
|
||||||
|
providers.set(testContext2.provider.providerId, createProvider(testContext2));
|
||||||
|
|
||||||
|
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, undefined);
|
||||||
|
|
||||||
|
await model.init();
|
||||||
|
let actual = await model.getCurrentLocation();
|
||||||
|
should.equal(actual, 'location2');
|
||||||
|
model.changeLocation('location1');
|
||||||
|
actual = await model.getCurrentLocation();
|
||||||
|
should.equal(actual, 'location1');
|
||||||
|
});
|
||||||
|
|
||||||
it('Should create a cache for multiple providers successfully', async function (): Promise<void> {
|
it('Should create a cache for multiple providers successfully', async function (): Promise<void> {
|
||||||
let testContext1 = createContext();
|
let testContext1 = createContext();
|
||||||
testContext1.provider.providerId = 'providerId1';
|
testContext1.provider.providerId = 'providerId1';
|
||||||
@@ -413,7 +441,8 @@ describe('Manage Packages', () => {
|
|||||||
packageType: 'package-type'
|
packageType: 'package-type'
|
||||||
},
|
},
|
||||||
canUseProvider: () => { return Promise.resolve(true); },
|
canUseProvider: () => { return Promise.resolve(true); },
|
||||||
getLocations: () => { return Promise.resolve([{displayName: 'location-title', name: 'location'}]); },
|
getLocations: () => { return Promise.resolve([{ displayName: 'location-title', name: 'location' }, { displayName: 'location2-title', name: 'location2' }]); },
|
||||||
|
getCurrentLocation: () => { return Promise.resolve('location2'); },
|
||||||
installPackages: () => { return Promise.resolve(); },
|
installPackages: () => { return Promise.resolve(); },
|
||||||
uninstallPackages: (packages: IPackageDetails[]) => { return Promise.resolve(); },
|
uninstallPackages: (packages: IPackageDetails[]) => { return Promise.resolve(); },
|
||||||
listPackages: () => { return Promise.resolve([]); },
|
listPackages: () => { return Promise.resolve([]); },
|
||||||
@@ -426,6 +455,7 @@ describe('Manage Packages', () => {
|
|||||||
let mockProvider = TypeMoq.Mock.ofType(LocalPipPackageManageProvider);
|
let mockProvider = TypeMoq.Mock.ofType(LocalPipPackageManageProvider);
|
||||||
mockProvider.setup(x => x.canUseProvider()).returns(() => testContext.provider.canUseProvider());
|
mockProvider.setup(x => x.canUseProvider()).returns(() => testContext.provider.canUseProvider());
|
||||||
mockProvider.setup(x => x.getLocations()).returns(() => testContext.provider.getLocations());
|
mockProvider.setup(x => x.getLocations()).returns(() => testContext.provider.getLocations());
|
||||||
|
mockProvider.setup(x => x.getCurrentLocation()).returns(() => testContext.provider.getCurrentLocation());
|
||||||
mockProvider.setup(x => x.installPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages, useMinVersion) => testContext.provider.installPackages(packages, useMinVersion));
|
mockProvider.setup(x => x.installPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages, useMinVersion) => testContext.provider.installPackages(packages, useMinVersion));
|
||||||
mockProvider.setup(x => x.uninstallPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages) => testContext.provider.uninstallPackages(packages));
|
mockProvider.setup(x => x.uninstallPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages) => testContext.provider.uninstallPackages(packages));
|
||||||
mockProvider.setup(x => x.listPackages(TypeMoq.It.isAny())).returns(() => testContext.provider.listPackages());
|
mockProvider.setup(x => x.listPackages(TypeMoq.It.isAny())).returns(() => testContext.provider.listPackages());
|
||||||
|
|||||||
5
extensions/notebook/src/types.d.ts
vendored
5
extensions/notebook/src/types.d.ts
vendored
@@ -138,6 +138,11 @@ export interface IPackageManageProvider {
|
|||||||
*/
|
*/
|
||||||
getLocations(): Promise<IPackageLocation[]>;
|
getLocations(): Promise<IPackageLocation[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current location
|
||||||
|
*/
|
||||||
|
getCurrentLocation(): Promise<string | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Package Overview
|
* Returns Package Overview
|
||||||
* @param packageName package name
|
* @param packageName package name
|
||||||
|
|||||||
Reference in New Issue
Block a user