Fix/prev next links issue (#10523)

* intital test code

* added tests

* remove commented code

* fix for failing tests

* reuse exported enum

* changes to address comments

* add back onVisibility highlight

* port highlight fix from Chris

* fix tests
This commit is contained in:
Maddy
2020-06-12 18:42:17 -07:00
committed by GitHub
parent c9569d8573
commit 26a00696d4
11 changed files with 138 additions and 74 deletions

View File

@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { Directive, Inject, HostListener, Input } from '@angular/core';
import { URI } from 'vs/base/common/uri';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { onUnexpectedError } from 'vs/base/common/errors';

View File

@@ -55,7 +55,6 @@ import { CodeCellComponent } from 'sql/workbench/contrib/notebook/browser/cellVi
import { TextCellComponent } from 'sql/workbench/contrib/notebook/browser/cellViews/textCell.component';
import { NotebookInput } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
import { IColorTheme } from 'vs/platform/theme/common/themeService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -105,7 +104,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
@Inject(ICapabilitiesService) private capabilitiesService: ICapabilitiesService,
@Inject(ITextFileService) private textFileService: ITextFileService,
@Inject(ILogService) private readonly logService: ILogService,
@Inject(ICommandService) private commandService: ICommandService,
@Inject(IAdsTelemetryService) private adstelemetryService: IAdsTelemetryService,
@Inject(IConfigurationService) private _configurationService: IConfigurationService
) {
@@ -516,8 +514,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
this._navProvider = this.notebookService.getNavigationProvider(this._notebookParams.notebookUri);
if (this.contextKeyService.getContextKeyValue('bookOpened') && this._navProvider) {
// If there's a book opened but the current notebook isn't part of the book, this is a no-op
this.commandService.executeCommand('notebook.command.revealInBooksViewlet', this._notebookParams.notebookUri, false);
this._navProvider.getNavigation(this._notebookParams.notebookUri).then(result => {
this.navigationResult = result;
this.addButton(localize('previousButtonLabel', "< Previous"),

View File

@@ -16,6 +16,7 @@ import { INotebookService } from 'sql/workbench/services/notebook/browser/notebo
import { Emitter } from 'vs/base/common/event';
import { Registry } from 'vs/platform/registry/common/platform';
import { NotebookProviderRegistration, INotebookProviderRegistry, Extensions } from 'sql/workbench/services/notebook/common/notebookRegistry';
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
suite('Notebook Service Tests', function (): void {
let notebookService: INotebookService;
@@ -31,6 +32,7 @@ suite('Notebook Service Tests', function (): void {
const extensionService = new TestExtensionService();
const fileService = new TestFileService();
const logService = new NullLogService();
const contextService = new MockContextKeyService();
const queryManagementService = new NBTestQueryManagementService();
const instantiationService = new TestInstantiationService();
@@ -47,7 +49,7 @@ suite('Notebook Service Tests', function (): void {
instantiationService.stub(IExtensionManagementService, 'onDidUninstallExtension', didUninstallEvent.event);
const extensionManagementService = instantiationService.get(IExtensionManagementService);
notebookService = new NotebookService(lifecycleService, storageService, extensionService, extensionManagementService, instantiationService, fileService, logService, queryManagementService);
notebookService = new NotebookService(lifecycleService, storageService, extensionService, extensionManagementService, instantiationService, fileService, logService, queryManagementService, contextService);
});
test('Validate default properties on create', async function (): Promise<void> {

View File

@@ -34,6 +34,16 @@ export interface ILanguageMagic {
executionTarget?: string;
}
/**
* Valid navigation providers.
*/
export enum NavigationProviders {
NotebooksNavigator = 'BookNavigator.Notebooks',
ProvidedBooksNavigator = 'BookNavigator.ProvidedBooks'
}
export const unsavedBooksContextKey = 'unsavedBooks';
export interface INotebookService {
_serviceBrand: undefined;

View File

@@ -10,7 +10,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import {
INotebookService, INotebookManager, INotebookProvider,
DEFAULT_NOTEBOOK_FILETYPE, INotebookEditor, SQL_NOTEBOOK_PROVIDER, INavigationProvider, ILanguageMagic
DEFAULT_NOTEBOOK_FILETYPE, INotebookEditor, SQL_NOTEBOOK_PROVIDER, INavigationProvider, ILanguageMagic, NavigationProviders, unsavedBooksContextKey
} from 'sql/workbench/services/notebook/browser/notebookService';
import { RenderMimeRegistry } from 'sql/workbench/services/notebook/browser/outputs/registry';
import { standardRendererFactories } from 'sql/workbench/services/notebook/browser/outputs/factories';
@@ -36,6 +36,7 @@ import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contr
import { find, firstIndex } from 'vs/base/common/arrays';
import { onUnexpectedError } from 'vs/base/common/errors';
import { notebookConstants } from 'sql/workbench/services/notebook/browser/interfaces';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export interface NotebookProviderProperties {
provider: string;
@@ -115,7 +116,8 @@ export class NotebookService extends Disposable implements INotebookService {
@IInstantiationService private _instantiationService: IInstantiationService,
@IFileService private readonly _fileService: IFileService,
@ILogService private readonly _logService: ILogService,
@IQueryManagementService private readonly _queryManagementService: IQueryManagementService
@IQueryManagementService private readonly _queryManagementService: IQueryManagementService,
@IContextKeyService private contextKeyService: IContextKeyService,
) {
super();
this._providersMemento = new Memento('notebookProviders', this._storageService);
@@ -220,7 +222,11 @@ export class NotebookService extends Disposable implements INotebookService {
}
getNavigationProvider(): INavigationProvider {
let provider = this._navigationProviders.size > 0 ? this._navigationProviders.values().next().value : undefined;
let provider;
if (this._navigationProviders.size > 0) {
const providerName = this.contextKeyService.getContextKeyValue(unsavedBooksContextKey) ? NavigationProviders.ProvidedBooksNavigator : NavigationProviders.NotebooksNavigator;
provider = this._navigationProviders.get(providerName);
}
return provider;
}