Skip to content
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

Add groupPriority to sort components within a group #331

Merged
merged 4 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/BaseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/BaseProjectLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class BaseProjectLibrary implements ProjectLibrary {

const component: Component = {
group: template.controlGroup,
groupPriority: 0,
name: newComponent,
templates: []
};
Expand Down Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/MultiTemplateComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export abstract class MultiTemplateComponent<T extends Template> implements Component {
public name: string;
public group: string;
public groupPriority = 0;

get templates(): T[] {
// TODO: prop-full
Expand Down
6 changes: 5 additions & 1 deletion lib/PromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -209,7 +213,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"
Expand Down
9 changes: 7 additions & 2 deletions lib/types/Component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
18 changes: 18 additions & 0 deletions spec/unit/BaseProjectLibrary-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

Expand Down
1 change: 1 addition & 0 deletions templates/angular/igx-ts/grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class IgxGridComponent extends BaseComponent {
super(__dirname);
this.name = "Grid";
this.group = "Grids & Lists";
this.groupPriority = 10;
}
}
module.exports = new IgxGridComponent();