-
Notifications
You must be signed in to change notification settings - Fork 90
feat(extension): support config-based ordering #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c78d33
feat(extension): support config based ordering and refresh view on fi…
Nemikolh 47c68d4
feat: make it possible to add a part and delete anything
Nemikolh 266fb8b
feat: make it possible to delete parts, chapters and lessons
Nemikolh 9185aeb
Merge branch 'main' into joan/config-based-ordering
Nemikolh 85be465
fix: respect the config ordering used when adding a new unit
Nemikolh 0f080fb
fix: lint issues
Nemikolh 1eefbac
Merge branch 'main' into joan/config-based-ordering
Nemikolh 043f5e6
Merge branch 'main' into joan/config-based-ordering
Nemikolh 1c12d4f
fix: code review
Nemikolh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { cmd } from '.'; | ||
import * as vscode from 'vscode'; | ||
import { Node } from '../models/Node'; | ||
import { getLessonsTreeView } from '../global-state'; | ||
|
||
export async function deleteUnit(selectedNode: Node | undefined, selectedNodes: Node[] | undefined) { | ||
let nodes: readonly Node[] = (selectedNodes ? selectedNodes : [selectedNode]).filter((node) => node !== undefined); | ||
|
||
if (nodes.length === 0) { | ||
nodes = getLessonsTreeView().selection; | ||
} | ||
|
||
for (const node of nodes) { | ||
await vscode.workspace.fs.delete(node.path, { recursive: true }); | ||
} | ||
|
||
return cmd.refresh(); | ||
} | ||
Nemikolh marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
extensions/vscode/src/commands/tutorialkit.load-tutorial.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
import * as vscode from 'vscode'; | ||
import { extContext } from '../extension'; | ||
import { LessonsTreeDataProvider, getLessonsTreeDataProvider, setLessonsTreeDataProvider } from '../views/lessonsTree'; | ||
import { LessonsTreeDataProvider } from '../views/lessonsTree'; | ||
import { setLessonsTreeDataProvider, setLessonsTreeView } from '../global-state'; | ||
|
||
export async function loadTutorial(uri: vscode.Uri) { | ||
setLessonsTreeDataProvider(new LessonsTreeDataProvider(uri, extContext)); | ||
const treeDataProvider = new LessonsTreeDataProvider(uri, extContext); | ||
|
||
extContext.subscriptions.push( | ||
vscode.window.createTreeView('tutorialkit-lessons-tree', { | ||
treeDataProvider: getLessonsTreeDataProvider(), | ||
canSelectMany: true, | ||
}), | ||
); | ||
await treeDataProvider.init(); | ||
|
||
const treeView = vscode.window.createTreeView('tutorialkit-lessons-tree', { | ||
treeDataProvider, | ||
canSelectMany: true, | ||
}); | ||
|
||
setLessonsTreeDataProvider(treeDataProvider); | ||
setLessonsTreeView(treeView); | ||
|
||
extContext.subscriptions.push(treeView, treeDataProvider); | ||
|
||
vscode.commands.executeCommand('setContext', 'tutorialkit:tree', true); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { TreeView } from 'vscode'; | ||
import type { LessonsTreeDataProvider } from './views/lessonsTree'; | ||
import type { Node } from './models/Node'; | ||
|
||
let lessonsTreeDataProvider: LessonsTreeDataProvider; | ||
let lessonsTreeView: TreeView<Node>; | ||
|
||
export function getLessonsTreeDataProvider() { | ||
return lessonsTreeDataProvider; | ||
} | ||
|
||
export function getLessonsTreeView() { | ||
return lessonsTreeView; | ||
} | ||
|
||
export function setLessonsTreeDataProvider(provider: LessonsTreeDataProvider) { | ||
lessonsTreeDataProvider = provider; | ||
} | ||
|
||
export function setLessonsTreeView(treeView: TreeView<Node>) { | ||
lessonsTreeView = treeView; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as vscode from 'vscode'; | ||
import type { TutorialSchema, PartSchema, ChapterSchema, LessonSchema } from '@tutorialkit/types'; | ||
|
||
export class Node { | ||
/** | ||
* Path to the meta.md / content.md file. | ||
*/ | ||
metadataFilePath?: vscode.Uri; | ||
|
||
/** | ||
* The metadata read from the metadata file. | ||
*/ | ||
metadata?: Metadata; | ||
|
||
/** | ||
* The number of expected children, populated on creation. | ||
* If an order is specified but more folder are found, they | ||
* are also included in that count but end up at the end of | ||
* the tree. | ||
*/ | ||
childCount: number = 0; | ||
|
||
/** | ||
* The children of that node, loaded lazily. | ||
*/ | ||
children: Node[] = []; | ||
|
||
/** | ||
* If specified, describe the order of the children. | ||
* When children are loaded, this should be used to sort | ||
* them appropriately. | ||
*/ | ||
order?: Map<string, number>; | ||
|
||
get type() { | ||
return this.metadata?.type; | ||
} | ||
|
||
get name() { | ||
if (this._customName) { | ||
return this._customName; | ||
} | ||
|
||
if (this.metadata && this.metadata.type !== 'tutorial') { | ||
return this.metadata.title; | ||
} | ||
|
||
return '<no name>'; | ||
} | ||
|
||
constructor( | ||
public folderName: string, | ||
readonly path: vscode.Uri, | ||
private _customName?: string, | ||
) {} | ||
|
||
pushChild(folderPath: string) { | ||
this.childCount += 1; | ||
|
||
if (this.order) { | ||
this.order.set(folderPath, this.order.size); | ||
|
||
switch (this.metadata?.type) { | ||
case 'chapter': { | ||
this.metadata.lessons!.push(folderPath); | ||
break; | ||
} | ||
case 'tutorial': { | ||
this.metadata.parts!.push(folderPath); | ||
break; | ||
} | ||
case 'part': { | ||
this.metadata.chapters!.push(folderPath); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export type Metadata = PartSchema | ChapterSchema | LessonSchema | TutorialSchema; | ||
|
||
export type NodeType = Metadata['type']; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed those because I don't think we should use them? @sulco what do you think?