Skip to content

Commit

Permalink
feat(step-by-step): add groupPriority to sort components within a g…
Browse files Browse the repository at this point in the history
…roup #303

Also bumping the Grid in Ignite UI for Angular back on top of the group
  • Loading branch information
damyanpetev committed Aug 2, 2018
1 parent e082538 commit ca77f5b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
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
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();

0 comments on commit ca77f5b

Please sign in to comment.