Skip to content

Commit d7743cb

Browse files
committed
goodparts integration
1 parent bd00f11 commit d7743cb

File tree

7 files changed

+58
-20
lines changed

7 files changed

+58
-20
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ yarn-debug.log*
2323
yarn-error.log*
2424
dist
2525
.babelrc
26-
public
2726
style.css

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### React Step Builder is a UI-agnostic multi step interface builder.
44

5+
[![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
6+
57
## Overview
68

79
React Step Builder allows you to combine states of multiple components in one place

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@testing-library/jest-dom": "^5.11.3",
1212
"@testing-library/react": "^10.4.9",
1313
"@testing-library/react-hooks": "^3.4.1",
14+
"goodparts": "^1.3.0",
1415
"react": "^16.12.0",
1516
"react-dom": "^16.12.0",
1617
"react-scripts": "3.4.0",
@@ -29,7 +30,8 @@
2930
"start": "react-scripts start",
3031
"build": "SET NODE_ENV=production&babel src/lib --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,__snapshots__",
3132
"test": "jest --collect-coverage",
32-
"coverage": "jest --coverage --detectOpenHandles --forceExit || true"
33+
"coverage": "jest --coverage --detectOpenHandles --forceExit || true",
34+
"lint": "node_modules/.bin/goodparts src/lib --fix"
3335
},
3436
"keywords": [
3537
"step-builder",

public/index.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>React Step Builder</title>
4+
</head>
5+
<body>
6+
<div id="root"></div>
7+
</body>
8+
</html>

src/lib/.eslintrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2016,
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"modules": true,
7+
"jsx": true
8+
}
9+
}
10+
}

src/lib/StepBuilder.js

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// prettier-ignore
12
export class StepBuilder {
23
/**
34
* Main class for building the Step structure
45
*/
56

6-
constructor() {
7+
constructor () {
78
this.start = 1;
89
this.current = 1;
910
this.size = null;
@@ -13,16 +14,16 @@ export class StepBuilder {
1314
* @param {Array} steps - Array of step titles
1415
* @return {Array} Returns an array of connected steps
1516
*/
16-
build(steps) {
17+
build (steps) {
1718
this.size = steps.length;
1819

1920
return steps.map((title, order) => {
20-
var newStep = new StepNode(title);
21+
let newStep = new StepNode(title);
2122

2223
newStep.order = order + 1;
2324

24-
var prev = order === 0 ? null : newStep.order - 1;
25-
var next = order === this.size - 1 ? null : newStep.order + 1;
25+
let prev = order === 0 ? null : newStep.order - 1;
26+
let next = order === this.size - 1 ? null : newStep.order + 1;
2627

2728
newStep.nextStep = next;
2829
newStep.prevStep = prev;
@@ -32,38 +33,44 @@ export class StepBuilder {
3233
}
3334

3435
/**
35-
* Moves to the next step if there is any available, and returns the order number. If the current step is the last one, it returns the current step.
36+
* Moves to the next step if there is any available, and returns
37+
* the order number. If the current step is the last one, it returns
38+
* the current step.
3639
* @return {number} Order of the next available step
3740
*/
38-
next() {
41+
next () {
3942
this.current = this.current === this.size ? this.current : this.current + 1;
4043
return this.current;
4144
}
4245

4346
/**
44-
* Moves to the previous step if there is any available, and returns the order number. If the current step is the first one, it returns the current step.
47+
* Moves to the previous step if there is any available, and returns
48+
* the order number. If the current step is the first one, it returns
49+
* the current step.
4550
* @return {number} Order of the previous available step
4651
*/
47-
prev() {
52+
prev () {
4853
this.current = this.current === 1 ? 1 : this.current - 1;
4954
return this.current;
5055
}
5156

5257
/**
53-
* Jumps to the provided step and returns the order number. If the step is not available, returns the current step number.
58+
* Jumps to the provided step and returns the order number. If the step
59+
* is not available, returns the current step number.
5460
* @param {number} step_order The order of the step to jump to.
5561
* @return {number} Order of the jumped step
5662
*/
57-
jump(stepId) {
63+
jump (stepId) {
5864
if (stepId > 0 && stepId <= this.size) {
5965
this.current = stepId;
6066
}
6167
return this.current;
6268
}
6369
}
6470

71+
// prettier-ignore
6572
class StepNode {
66-
constructor(title) {
73+
constructor (title) {
6774
this.order = null;
6875
this.title = title;
6976
this.nextStep = null;
@@ -74,31 +81,31 @@ class StepNode {
7481
* Checks if the step is the first one in the steps list
7582
* @return {boolean}
7683
*/
77-
isFirst() {
78-
return !Boolean(this.prevStep);
84+
isFirst () {
85+
return !this.prevStep;
7986
}
8087

8188
/**
8289
* Checks if the step is the last one in the steps list
8390
* @return {boolean}
8491
*/
85-
isLast() {
86-
return !Boolean(this.nextStep);
92+
isLast () {
93+
return !this.nextStep;
8794
}
8895

8996
/**
9097
* Checks if the current step has a previous step
9198
* @return {boolean}
9299
*/
93-
hasPrev() {
100+
hasPrev () {
94101
return Boolean(this.prevStep);
95102
}
96103

97104
/**
98105
* Checks if the current step has a next step
99106
* @return {boolean}
100107
*/
101-
hasNext() {
108+
hasNext () {
102109
return Boolean(this.nextStep);
103110
}
104111
}

0 commit comments

Comments
 (0)