From ca77f5b00a0ccdc5ca285e05f6715aba0d59a200 Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Thu, 2 Aug 2018 13:42:18 +0300 Subject: [PATCH 1/3] feat(step-by-step): add `groupPriority` to sort components within a group #303 Also bumping the Grid in Ignite UI for Angular back on top of the group --- lib/BaseComponent.ts | 1 + lib/BaseProjectLibrary.ts | 5 ++++- lib/MultiTemplateComponent.ts | 1 + lib/types/Component.d.ts | 9 +++++++-- spec/unit/BaseProjectLibrary-spec.ts | 18 ++++++++++++++++++ templates/angular/igx-ts/grid/index.ts | 1 + 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/BaseComponent.ts b/lib/BaseComponent.ts index 5432cf8a0..1cafb433a 100644 --- a/lib/BaseComponent.ts +++ b/lib/BaseComponent.ts @@ -5,6 +5,7 @@ export class BaseComponent implements Component { public templates: Template[]; public name: string; public group: string; + public groupPriority = 0; private basePath: string = __dirname; /** diff --git a/lib/BaseProjectLibrary.ts b/lib/BaseProjectLibrary.ts index 1096b1555..ff269e05c 100644 --- a/lib/BaseProjectLibrary.ts +++ b/lib/BaseProjectLibrary.ts @@ -99,6 +99,7 @@ export class BaseProjectLibrary implements ProjectLibrary { const component: Component = { group: template.controlGroup, + groupPriority: 0, name: newComponent, templates: [] }; @@ -145,7 +146,9 @@ export class BaseProjectLibrary implements ProjectLibrary { } public getComponentNamesByGroup(group: string): string[] { - return this.components.filter(x => x.group === group).map(x => x.name); + return this.components.filter(x => x.group === group) + .sort((a, b) => b.groupPriority - a.groupPriority) + .map(x => x.name); } /** diff --git a/lib/MultiTemplateComponent.ts b/lib/MultiTemplateComponent.ts index 5d03f5fa3..9123f90d0 100644 --- a/lib/MultiTemplateComponent.ts +++ b/lib/MultiTemplateComponent.ts @@ -1,6 +1,7 @@ export abstract class MultiTemplateComponent implements Component { public name: string; public group: string; + public groupPriority = 0; get templates(): T[] { // TODO: prop-full diff --git a/lib/types/Component.d.ts b/lib/types/Component.d.ts index 012e10c17..203bf63d8 100644 --- a/lib/types/Component.d.ts +++ b/lib/types/Component.d.ts @@ -2,10 +2,15 @@ * A set of Templates for a common component */ interface Component { - /** Name of the parent group, e.g. Data Visualization */ - group: string; /** Component name, e.g. Pie Chart or Grid */ name: string; + /** Name of the parent group, e.g. Data Visualization */ + group: string; + /** + * Controls the position of the component within the group. + * Step by step mode lists components with higher values first. + */ + groupPriority: number; templates: Template[]; } diff --git a/spec/unit/BaseProjectLibrary-spec.ts b/spec/unit/BaseProjectLibrary-spec.ts index 1097a27b5..2a97d4bc6 100644 --- a/spec/unit/BaseProjectLibrary-spec.ts +++ b/spec/unit/BaseProjectLibrary-spec.ts @@ -273,6 +273,24 @@ describe("Unit - Base project library ", () => { done(); }); + it("should sort component in a group based on priority", async done => { + spyOnProperty(BaseProjectLibrary.prototype, "components").and.returnValue([ + { name: "Component1", group: "commonGroup", groupPriority: 1 }, + { name: "Component2", group: "commonGroup", groupPriority: 20 }, + { name: "Component3", group: "commonGroup", groupPriority: 13 }, + { name: "Component4", group: "commonGroup", groupPriority: 4 }, + { name: "Component5", group: "commonGroup", groupPriority: -4 }, + { name: "Component6", group: "commonGroup", groupPriority: 0 }, + { name: "Component7", group: "commonGroup", groupPriority: 0 } + ] as Component[]); + + const library = new BaseProjectLibrary(__dirname); + expect(library.getComponentNamesByGroup("commonGroup")).toEqual( + ["Component2", "Component3", "Component4", "Component1", "Component6", "Component7", "Component5"] + ); + done(); + }); + it("gets correct project", async done => { spyOn(Util, "getDirectoryNames").and.returnValues(["chart", "combo", "grid"]); diff --git a/templates/angular/igx-ts/grid/index.ts b/templates/angular/igx-ts/grid/index.ts index 526a6f227..c3156911e 100644 --- a/templates/angular/igx-ts/grid/index.ts +++ b/templates/angular/igx-ts/grid/index.ts @@ -9,6 +9,7 @@ class IgxGridComponent extends BaseComponent { super(__dirname); this.name = "Grid"; this.group = "Grids & Lists"; + this.groupPriority = 10; } } module.exports = new IgxGridComponent(); From 3d368d9adb06fc71c2e536dff4e5b65ef7e3caae Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Thu, 2 Aug 2018 17:27:35 +0300 Subject: [PATCH 2/3] fix(step-by-step, igx): select Grids & Lists group by default --- lib/PromptSession.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PromptSession.ts b/lib/PromptSession.ts index 8b1fb66e5..9832342ad 100644 --- a/lib/PromptSession.ts +++ b/lib/PromptSession.ts @@ -209,7 +209,7 @@ export class PromptSession { const groups = projectLibrary.getComponentGroups(); const groupRes: string = await this.getUserInput({ choices: groups, - default: groups.find(x => x === "Data Grids") || groups[0], + default: groups.find(x => x.includes("Grids")) || groups[0], message: "Choose a group:", name: "componentGroup", type: "list" From 76aa019f299eac85cd3f60857c31c74076016f53 Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Thu, 2 Aug 2018 18:16:46 +0300 Subject: [PATCH 3/3] fix(step-by-step): add an end separator for longer lists --- lib/PromptSession.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/PromptSession.ts b/lib/PromptSession.ts index 9832342ad..b568be234 100644 --- a/lib/PromptSession.ts +++ b/lib/PromptSession.ts @@ -159,6 +159,10 @@ export class PromptSession { newArray.push(new inquirer.Separator()); } } + if (array.length > 4) { + // additional separator after last item for lists that wrap around + newArray.push(new inquirer.Separator(new Array(15).join("="))); + } return newArray; }