mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Notebooks: Save cell connection name in cell metadata (#13208)
* save connection info in notebook metadata * update attachTo dropdown based on saved alias * add setting for saving connection (default=false) * save/read cell connection name to/from metadata * get started on toggling multi connection mode * add activeConnection property to cell model * add changeContext method for cell * add comments * add unit test for reading connection name * save connection mode in metadata * clean up code * address PR comments
This commit is contained in:
12
src/sql/azdata.d.ts
vendored
12
src/sql/azdata.d.ts
vendored
@@ -4688,17 +4688,19 @@ declare module 'azdata' {
|
|||||||
export interface ICellContents {
|
export interface ICellContents {
|
||||||
cell_type: CellType;
|
cell_type: CellType;
|
||||||
source: string | string[];
|
source: string | string[];
|
||||||
metadata?: {
|
metadata?: ICellMetadata;
|
||||||
language?: string;
|
|
||||||
tags?: string[];
|
|
||||||
azdata_cell_guid?: string;
|
|
||||||
};
|
|
||||||
execution_count?: number;
|
execution_count?: number;
|
||||||
outputs?: ICellOutput[];
|
outputs?: ICellOutput[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CellType = 'code' | 'markdown' | 'raw';
|
export type CellType = 'code' | 'markdown' | 'raw';
|
||||||
|
|
||||||
|
export interface ICellMetadata {
|
||||||
|
language?: string;
|
||||||
|
tags?: string[];
|
||||||
|
azdata_cell_guid?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICellOutput {
|
export interface ICellOutput {
|
||||||
output_type: OutputTypeName;
|
output_type: OutputTypeName;
|
||||||
metadata?: ICellOutputMetadata;
|
metadata?: ICellOutputMetadata;
|
||||||
|
|||||||
4
src/sql/azdata.proposed.d.ts
vendored
4
src/sql/azdata.proposed.d.ts
vendored
@@ -81,6 +81,10 @@ declare module 'azdata' {
|
|||||||
export interface INotebookMetadata {
|
export interface INotebookMetadata {
|
||||||
connection_name?: string;
|
connection_name?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICellMetadata {
|
||||||
|
connection_name?: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SqlDbType = 'BigInt' | 'Binary' | 'Bit' | 'Char' | 'DateTime' | 'Decimal'
|
export type SqlDbType = 'BigInt' | 'Binary' | 'Bit' | 'Char' | 'DateTime' | 'Decimal'
|
||||||
|
|||||||
@@ -1024,4 +1024,20 @@ suite('Cell Model', function (): void {
|
|||||||
assert(!isEditMode);
|
assert(!isEditMode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should read connection name from notebook metadata', async function () {
|
||||||
|
const connectionName = 'connectionName';
|
||||||
|
let notebookModel = new NotebookModelStub({
|
||||||
|
name: '',
|
||||||
|
version: '',
|
||||||
|
mimetype: ''
|
||||||
|
});
|
||||||
|
let contents: nb.ICellContents = {
|
||||||
|
cell_type: CellTypes.Code,
|
||||||
|
source: '',
|
||||||
|
metadata: { connection_name: connectionName }
|
||||||
|
};
|
||||||
|
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||||
|
assert.equal(model.savedConnectionName, connectionName);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
private _cellType: nb.CellType;
|
private _cellType: nb.CellType;
|
||||||
private _source: string | string[];
|
private _source: string | string[];
|
||||||
private _language: string;
|
private _language: string;
|
||||||
|
private _savedConnectionName: string | undefined;
|
||||||
private _cellGuid: string;
|
private _cellGuid: string;
|
||||||
private _future: FutureInternal;
|
private _future: FutureInternal;
|
||||||
private _outputs: nb.ICellOutput[] = [];
|
private _outputs: nb.ICellOutput[] = [];
|
||||||
@@ -55,10 +56,10 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
private _cellUri: URI;
|
private _cellUri: URI;
|
||||||
private _connectionManagementService: IConnectionManagementService;
|
private _connectionManagementService: IConnectionManagementService;
|
||||||
private _stdInHandler: nb.MessageHandler<nb.IStdinMessage>;
|
private _stdInHandler: nb.MessageHandler<nb.IStdinMessage>;
|
||||||
private _metadata: { language?: string; tags?: string[]; cellGuid?: string; };
|
|
||||||
private _onCellLoaded = new Emitter<string>();
|
private _onCellLoaded = new Emitter<string>();
|
||||||
private _loaded: boolean;
|
private _loaded: boolean;
|
||||||
private _stdInVisible: boolean;
|
private _stdInVisible: boolean;
|
||||||
|
private _metadata: nb.ICellMetadata;
|
||||||
private _isCollapsed: boolean;
|
private _isCollapsed: boolean;
|
||||||
private _onCollapseStateChanged = new Emitter<boolean>();
|
private _onCollapseStateChanged = new Emitter<boolean>();
|
||||||
private _modelContentChangedEvent: IModelContentChangedEvent;
|
private _modelContentChangedEvent: IModelContentChangedEvent;
|
||||||
@@ -272,6 +273,10 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
return this._options.notebook.language;
|
return this._options.notebook.language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get savedConnectionName(): string | undefined {
|
||||||
|
return this._savedConnectionName;
|
||||||
|
}
|
||||||
|
|
||||||
public get cellGuid(): string {
|
public get cellGuid(): string {
|
||||||
return this._cellGuid;
|
return this._cellGuid;
|
||||||
}
|
}
|
||||||
@@ -804,6 +809,9 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
cellJson.metadata.tags = metadata.tags;
|
cellJson.metadata.tags = metadata.tags;
|
||||||
cellJson.outputs = this._outputs;
|
cellJson.outputs = this._outputs;
|
||||||
cellJson.execution_count = this.executionCount ? this.executionCount : null;
|
cellJson.execution_count = this.executionCount ? this.executionCount : null;
|
||||||
|
if (this._configurationService?.getValue('notebook.saveConnectionName')) {
|
||||||
|
metadata.connection_name = this._savedConnectionName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cellJson as nb.ICellContents;
|
return cellJson as nb.ICellContents;
|
||||||
}
|
}
|
||||||
@@ -828,6 +836,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
|
|
||||||
this._cellGuid = cell.metadata && cell.metadata.azdata_cell_guid ? cell.metadata.azdata_cell_guid : generateUuid();
|
this._cellGuid = cell.metadata && cell.metadata.azdata_cell_guid ? cell.metadata.azdata_cell_guid : generateUuid();
|
||||||
this.setLanguageFromContents(cell);
|
this.setLanguageFromContents(cell);
|
||||||
|
this._savedConnectionName = this._metadata.connection_name;
|
||||||
if (cell.outputs) {
|
if (cell.outputs) {
|
||||||
for (let output of cell.outputs) {
|
for (let output of cell.outputs) {
|
||||||
// For now, we're assuming it's OK to save these as-is with no modification
|
// For now, we're assuming it's OK to save these as-is with no modification
|
||||||
|
|||||||
@@ -499,6 +499,7 @@ export interface ICellModel {
|
|||||||
readonly onCellMarkdownModeChanged: Event<boolean>;
|
readonly onCellMarkdownModeChanged: Event<boolean>;
|
||||||
sendChangeToNotebook(change: NotebookChangeType): void;
|
sendChangeToNotebook(change: NotebookChangeType): void;
|
||||||
cellSourceChanged: boolean;
|
cellSourceChanged: boolean;
|
||||||
|
readonly savedConnectionName: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IModelFactory {
|
export interface IModelFactory {
|
||||||
|
|||||||
Reference in New Issue
Block a user