-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
replace consecutive identical logs with single log having count #123
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = formatActionData; | ||
|
||
var _isEqual = require('lodash/isEqual'); | ||
|
||
var _isEqual2 = _interopRequireDefault(_isEqual); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function getLastElem(arr) { | ||
return arr[arr.length - 1]; | ||
} | ||
|
||
/** | ||
* Takes an array and checks consecutive arrays. If they are same then replaces | ||
* consecutive identical objects (refers to .data of each object) with single | ||
* object and sets the count in the object to the number of identical consecutive | ||
* objects. | ||
* | ||
* @param actions An array of all the actions | ||
* @returns {Array} | ||
*/ | ||
function formatActionData(actions) { | ||
var formatted = []; | ||
actions.forEach(function (action, i) { | ||
if (i === 0 || !(0, _isEqual2.default)(action.data, getLastElem(formatted).data) || !action.data) { | ||
formatted.push({ | ||
data: action.data, | ||
count: action.count || 1, | ||
id: formatted.length + 1 | ||
}); | ||
} else { | ||
var lastElem = getLastElem(formatted); | ||
lastElem.count += action.count || 1; | ||
} | ||
}); | ||
return formatted; | ||
} |
File renamed without changes.
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
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
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ const btnStyle = { | |
class ActionLogger extends Component { | ||
|
||
getActionData() { | ||
// const actions = formatActionData(this.props.actions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this. |
||
return this.props.actions | ||
.map((action) => { | ||
return (<Foldable key={action.id} action={action} />); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { describe, it } = global; | ||
import { expect } from 'chai'; | ||
import formatActionData from '../formatActionData'; | ||
|
||
describe('formatActionData', function () { | ||
it('should not show consecutive arrays having same data', function () { | ||
const actions = [{ | ||
data: { | ||
name: 'hello', | ||
args: 'world', | ||
}, | ||
}, { | ||
data: { | ||
name: 'hello', | ||
args: 'world', | ||
}, | ||
}]; | ||
const expected = [{ | ||
data: { | ||
name: 'hello', | ||
args: 'world', | ||
}, | ||
count: 2, | ||
id: 1, | ||
}]; | ||
expect(formatActionData(actions).length).to.equal(1); | ||
expect(formatActionData(actions)).to.deep.equal(expected); | ||
}); | ||
|
||
it('should not show consecutive arrays having same data', function () { | ||
const actions = [{ | ||
data: { | ||
name: 'hello', | ||
args: 'world1', | ||
}, | ||
}, { | ||
data: { | ||
name: 'hello', | ||
args: 'world2', | ||
}, | ||
}]; | ||
const expected = [{ | ||
data: { | ||
name: 'hello', | ||
args: 'world1', | ||
}, | ||
count: 1, | ||
id: 1, | ||
}, { | ||
data: { | ||
name: 'hello', | ||
args: 'world2', | ||
}, | ||
count: 1, | ||
id: 2, | ||
}]; | ||
expect(formatActionData(actions).length).to.equal(2); | ||
expect(formatActionData(actions)).to.deep.equal(expected); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's increase this to 10.