Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Enhanced Tree view #94

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 14 commits into from
Feb 2, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor fixes
  • Loading branch information
Vigilans committed Jan 23, 2019
commit 21723feb15e0459800f997b6d7d10caa65d3097c
41 changes: 20 additions & 21 deletions src/leetCodeExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,42 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
}

const idPrefix: number = Date.now();
return {
return { // element.id -> parent node name, element.name -> node name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we save parent node name into element.id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some field to store the parent node name when it is not problem node...since in previous commits you simply set node.id and node.name the same value, I decided to reuse the id field to represent some other value.

The reasons for the necessity of parent node name are:

  1. We should be able to retrieve data from the LeetCodeTreeDataProvider.treeData.
  2. One problem will now be added as LeetCodeNode at least 3 times(in Difficulty, Tag and Company), we should be able to distinguish them, hence the following naming rule:
id: `${idPrefix}.${element.id}.${element.name}`,

(idPrefix = Date.now() just returns same value throughout initialization process)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a filed in the LeetCodeNode called 'parentName' to store the parent node info.

label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
id: `${idPrefix}.${element.id}`,
id: `${idPrefix}.${element.id}.${element.name}`,
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
contextValue: element.isProblem ? "problem" : "difficulty",
contextValue: element.isProblem ? "problem" : element.id.toLowerCase(),
iconPath: this.parseIconPathFromProblemState(element),
};
}

public getChildren(element?: LeetCodeNode | undefined): vscode.ProviderResult<LeetCodeNode[]> {
if (!leetCodeManager.getUser()) {
return [
new LeetCodeNode(
Object.assign(list.IProblemDefault, {
id: "notSignIn",
name: "Sign in to LeetCode",
}),
false,
),
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
id: "notSignIn",
name: "Sign in to LeetCode",
}), false),
];
}
if (!element) { // Root view
return new Promise(async (resolve: (res: LeetCodeNode[]) => void): Promise<void> => {
await this.getProblemData();
resolve([
new LeetCodeNode(Object.assign(list.IProblemDefault, {
const nodes = [
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
id: "Root",
name: "Difficulty",
}), false),
new LeetCodeNode(Object.assign(list.IProblemDefault, {
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
id: "Root",
name: "Tag",
}), false),
new LeetCodeNode(Object.assign(list.IProblemDefault, {
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
id: "Root",
name: "Company",
}), false)
]);
}), false),
]
resolve(nodes);
});
} else {
switch (element.name) { // First-level
Expand All @@ -134,12 +132,13 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
["Company", problem.companies]
] as [Category, string[]][];
for (const [parent, children] of categories) {
for (const subCategory of children) {
for (let subCategory of children) {
// TODO: rectify sub category name here
const problems = this.treeData[parent].get(subCategory);
if (problems) {
problems.push(problem);
} else {
this.treeData.Difficulty.set(subCategory, [problem]);
this.treeData[parent].set(subCategory, [problem]);
}
}
}
Expand All @@ -160,10 +159,10 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
}

private composeCategoryNodes(node: LeetCodeNode): LeetCodeNode[] {
const parent = node.id as Category;
const parent = node.name as Category;
const categoryNodes = Array.from(this.treeData[parent].keys()).map(subCategory =>
new LeetCodeNode(Object.assign(list.IProblemDefault, {
id: node.name,
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
id: parent,
name: subCategory,
}), false)
);
Expand Down