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:
Lucy Zhang
2020-11-12 10:44:34 -08:00
committed by GitHub
parent 468119caa4
commit 32a6385fef
5 changed files with 38 additions and 6 deletions

View File

@@ -1024,4 +1024,20 @@ suite('Cell Model', function (): void {
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);
});
});

View File

@@ -39,6 +39,7 @@ export class CellModel extends Disposable implements ICellModel {
private _cellType: nb.CellType;
private _source: string | string[];
private _language: string;
private _savedConnectionName: string | undefined;
private _cellGuid: string;
private _future: FutureInternal;
private _outputs: nb.ICellOutput[] = [];
@@ -55,10 +56,10 @@ export class CellModel extends Disposable implements ICellModel {
private _cellUri: URI;
private _connectionManagementService: IConnectionManagementService;
private _stdInHandler: nb.MessageHandler<nb.IStdinMessage>;
private _metadata: { language?: string; tags?: string[]; cellGuid?: string; };
private _onCellLoaded = new Emitter<string>();
private _loaded: boolean;
private _stdInVisible: boolean;
private _metadata: nb.ICellMetadata;
private _isCollapsed: boolean;
private _onCollapseStateChanged = new Emitter<boolean>();
private _modelContentChangedEvent: IModelContentChangedEvent;
@@ -272,6 +273,10 @@ export class CellModel extends Disposable implements ICellModel {
return this._options.notebook.language;
}
public get savedConnectionName(): string | undefined {
return this._savedConnectionName;
}
public get cellGuid(): string {
return this._cellGuid;
}
@@ -804,6 +809,9 @@ export class CellModel extends Disposable implements ICellModel {
cellJson.metadata.tags = metadata.tags;
cellJson.outputs = this._outputs;
cellJson.execution_count = this.executionCount ? this.executionCount : null;
if (this._configurationService?.getValue('notebook.saveConnectionName')) {
metadata.connection_name = this._savedConnectionName;
}
}
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.setLanguageFromContents(cell);
this._savedConnectionName = this._metadata.connection_name;
if (cell.outputs) {
for (let output of cell.outputs) {
// For now, we're assuming it's OK to save these as-is with no modification

View File

@@ -499,6 +499,7 @@ export interface ICellModel {
readonly onCellMarkdownModeChanged: Event<boolean>;
sendChangeToNotebook(change: NotebookChangeType): void;
cellSourceChanged: boolean;
readonly savedConnectionName: string | undefined;
}
export interface IModelFactory {