-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from sebgroup/develop
Release 27/Aug/2020
- Loading branch information
Showing
11 changed files
with
531 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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,46 +1,49 @@ | ||
import React from "react"; | ||
import { loremIpsum } from "lorem-ipsum"; | ||
import { randomId } from "@sebgroup/frontend-tools/dist/randomId"; | ||
import { ActionLinkItem, TableRow } from "../../src/Table/Table"; | ||
|
||
function range(len: number): Array<number> { | ||
const arr: Array<number> = []; | ||
for (let i = 0; i < len; i++) { | ||
arr.push(i); | ||
} | ||
return arr; | ||
}; | ||
const arr: Array<number> = []; | ||
for (let i = 0; i < len; i++) { | ||
arr.push(i); | ||
} | ||
return arr; | ||
} | ||
|
||
function newPerson(): object { | ||
const statusChance: number = Math.random(); | ||
return { | ||
id: parseInt(randomId("").substr(8, 4), 10), | ||
firstName: loremIpsum({ units: "words", count: 1 }), | ||
lastName: loremIpsum({ units: "words", count: 1 }), | ||
age: Math.floor(Math.random() * 30), | ||
visits: Math.floor(Math.random() * 100), | ||
progress: Math.floor(Math.random() * 100), | ||
status: | ||
statusChance > 0.66 | ||
? "relationship" | ||
: statusChance > 0.33 | ||
? "complicated" | ||
: "single", | ||
}; | ||
}; | ||
const statusChance: number = Math.random(); | ||
return { | ||
id: parseInt(randomId("").substr(8, 4), 10), | ||
firstName: loremIpsum({ units: "words", count: 1 }), | ||
lastName: loremIpsum({ units: "words", count: 1 }), | ||
age: Math.floor(Math.random() * 30), | ||
visits: Math.floor(Math.random() * 100), | ||
progress: Math.floor(Math.random() * 100), | ||
status: statusChance > 0.66 ? "relationship" : statusChance > 0.33 ? "complicated" : "single", | ||
}; | ||
} | ||
|
||
const actionLinks: Array<ActionLinkItem> = [ | ||
{ | ||
label: "Edit", | ||
onClick: (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>, selectedRow: TableRow) => {}, | ||
}, | ||
]; | ||
|
||
export default function makeData<T>(lens: Array<number>): T { | ||
const makeDataLevel: Function = (depth: number = 0): object | Function => { | ||
const len: number = lens[depth] | ||
return range(len).map((d: number) => { | ||
return { | ||
...newPerson(), | ||
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined, | ||
rowContentDetail: <p className="details"> | ||
{loremIpsum({ units: "sentences", count: 2 })} | ||
</p> | ||
} | ||
}) | ||
} | ||
export default function makeData<T>(lens: Array<number>, useRowActionColumn?: boolean): T { | ||
const makeDataLevel: Function = (depth: number = 0): object | Function => { | ||
const len: number = lens[depth]; | ||
return range(len).map((d: number) => { | ||
return { | ||
...newPerson(), | ||
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined, | ||
actionLinks: useRowActionColumn ? (d % 2 === 0 ? actionLinks : null) : null, | ||
actionButtonState: useRowActionColumn ? (d % 2 === 0 ? "disabled" : null) : null, | ||
rowContentDetail: <p className="details">{loremIpsum({ units: "sentences", count: 2 })}</p>, | ||
}; | ||
}); | ||
}; | ||
|
||
return makeDataLevel(); | ||
return makeDataLevel(); | ||
} |
This file contains 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 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
Oops, something went wrong.