mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Create book UI (#14210)
* Add dialog for creating books * create empty book * add localized constants * add validation to dialog * reset the create book command to original * address pr comments * change error message * Init book toc manager in bookTreeView
This commit is contained in:
@@ -221,14 +221,22 @@ export class BookTocManager implements IBookTocManager {
|
||||
/**
|
||||
* Follows the same logic as the JupyterBooksCreate.ipynb. It receives a path that contains a notebooks and
|
||||
* a path where it creates the book. It copies the contents from one folder to another and creates a table of contents.
|
||||
* @param bookContentPath The path to the book folder, the basename of the path is the name of the book
|
||||
* @param contentFolder The path to the folder that contains the notebooks and markdown files to be added to the created book.
|
||||
* @param bookContentPath - The path to the book folder, the basename of the path is the name of the book
|
||||
* @param contentFolder - (Optional) The path to the folder that contains the notebooks and markdown files to be added to the created book.
|
||||
* If it's undefined then a blank notebook is attached to the book.
|
||||
*/
|
||||
public async createBook(bookContentPath: string, contentFolder: string): Promise<void> {
|
||||
await fs.promises.mkdir(bookContentPath);
|
||||
await fs.copy(contentFolder, bookContentPath);
|
||||
let filesinDir = await fs.readdir(bookContentPath);
|
||||
this.tableofContents = await this.getAllFiles([], bookContentPath, filesinDir, bookContentPath);
|
||||
public async createBook(bookContentPath: string, contentFolder?: string): Promise<void> {
|
||||
let filesinDir: string[];
|
||||
await fs.promises.mkdir(bookContentPath, { recursive: true });
|
||||
if (contentFolder) {
|
||||
await fs.copy(contentFolder, bookContentPath);
|
||||
filesinDir = await fs.readdir(bookContentPath);
|
||||
this.tableofContents = await this.getAllFiles([], bookContentPath, filesinDir, bookContentPath);
|
||||
} else {
|
||||
await fs.writeFile(path.join(bookContentPath, 'README.md'), '');
|
||||
filesinDir = ['readme.md'];
|
||||
this.tableofContents = await this.getAllFiles([], bookContentPath, filesinDir, bookContentPath);
|
||||
}
|
||||
await fs.writeFile(path.join(bookContentPath, '_config.yml'), yaml.safeDump({ title: path.basename(bookContentPath) }));
|
||||
await fs.writeFile(path.join(bookContentPath, '_toc.yml'), yaml.safeDump(this.tableofContents, { lineWidth: Infinity }));
|
||||
await vscode.commands.executeCommand('notebook.command.openNotebookFolder', bookContentPath, undefined, true);
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as constants from '../common/constants';
|
||||
import { IPrompter, IQuestion, QuestionTypes } from '../prompts/question';
|
||||
import { IPrompter } from '../prompts/question';
|
||||
import CodeAdapter from '../prompts/adapter';
|
||||
import { BookTreeItem, BookTreeItemType } from './bookTreeItem';
|
||||
import { BookModel } from './bookModel';
|
||||
@@ -16,9 +16,10 @@ import { Deferred } from '../common/promise';
|
||||
import { IBookTrustManager, BookTrustManager } from './bookTrustManager';
|
||||
import * as loc from '../common/localizedConstants';
|
||||
import * as glob from 'fast-glob';
|
||||
import { debounce, getPinnedNotebooks } from '../common/utils';
|
||||
import { debounce, getPinnedNotebooks, confirmReplace } from '../common/utils';
|
||||
import { IBookPinManager, BookPinManager } from './bookPinManager';
|
||||
import { BookTocManager, IBookTocManager, quickPickResults } from './bookTocManager';
|
||||
import { CreateBookDialog } from '../dialog/createBookDialog';
|
||||
import { getContentPath } from './bookVersionHandler';
|
||||
import { TelemetryReporter, BookTelemetryView, NbTelemetryActions } from '../telemetry';
|
||||
|
||||
@@ -52,6 +53,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
this.initialize(workspaceFolders).catch(e => console.error(e));
|
||||
this.prompter = new CodeAdapter();
|
||||
this._bookTrustManager = new BookTrustManager(this.books);
|
||||
this.bookTocManager = new BookTocManager();
|
||||
|
||||
this._extensionContext.subscriptions.push(azdata.nb.registerNavigationProvider(this));
|
||||
}
|
||||
@@ -142,10 +144,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
}
|
||||
|
||||
async createBook(bookPath: string, contentPath: string): Promise<void> {
|
||||
bookPath = path.normalize(bookPath);
|
||||
contentPath = path.normalize(contentPath);
|
||||
await this.bookTocManager.createBook(bookPath, contentPath);
|
||||
async createBook(): Promise<void> {
|
||||
const dialog = new CreateBookDialog(this.bookTocManager);
|
||||
dialog.createDialog();
|
||||
TelemetryReporter.createActionEvent(BookTelemetryView, NbTelemetryActions.CreateBook).send();
|
||||
}
|
||||
|
||||
@@ -502,7 +503,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
let destinationUri: vscode.Uri = vscode.Uri.file(path.join(pickedFolder.fsPath, path.basename(this.currentBook.bookPath)));
|
||||
if (destinationUri) {
|
||||
if (await fs.pathExists(destinationUri.fsPath)) {
|
||||
let doReplace = await this.confirmReplace();
|
||||
let doReplace = await confirmReplace(this.prompter);
|
||||
if (!doReplace) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -676,15 +677,6 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
return untitledFileName;
|
||||
}
|
||||
|
||||
//Confirmation message dialog
|
||||
private async confirmReplace(): Promise<boolean> {
|
||||
return await this.prompter.promptSingle<boolean>(<IQuestion>{
|
||||
type: QuestionTypes.confirm,
|
||||
message: loc.confirmReplace,
|
||||
default: false
|
||||
});
|
||||
}
|
||||
|
||||
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
|
||||
let result: azdata.nb.NavigationResult;
|
||||
let notebook = this.currentBook?.getNotebook(uri.fsPath);
|
||||
|
||||
Reference in New Issue
Block a user