Conversation
|
The code both in the logScanned and template introduces duplication. |
lenzai
left a comment
There was a problem hiding this comment.
there s a bug
cannot accept code duplication
|
@lenzai should be better now. I removed that bug you found as well as the duplicated code. I also added links to item's row in the spreadsheet, should an edit be desired. |
lenzai
left a comment
There was a problem hiding this comment.
seems that we are in rabbit hole of moving around more and more information. (i.e. increasing coupling and thus technical debt) in order to just print the perfect logging message.
Logging is supposed to help debugging the application.
Increasing complexity sooner or later will create bugs or at least increase maintenance cost.
| .sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)), | ||
| matches: searchDatabase(req.query, allItems).sort((a, b) => | ||
| (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)), | ||
| }); |
There was a problem hiding this comment.
this is noise, refrain from doing cosmetic changes.
There was a problem hiding this comment.
you may understand why if you try the git blame command
googleSpreadsheet.js
Outdated
| o[lab[i]] = val[i]; | ||
| } | ||
| o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index; | ||
| return o; |
There was a problem hiding this comment.
potential security issue in leaking spreadsheet link to front end
hard coded value is pretty bad.
There was a problem hiding this comment.
agree, why do we need a cellRef here ?
There was a problem hiding this comment.
Not a necessary addition but, I thought having a link to any troublesome item's place in the spreadsheet would be useful for whoever has to edit it.
There was a problem hiding this comment.
that is a fair concern, and actually you can argue that google spreadsheet retrains access rights to the priviledged users.
on further development we may need a better strategy for that spreadsheet bug fixing.
All that said I still approve that pull request
app.js
Outdated
| return; | ||
| } | ||
| function logScanned(uuid, matches) { | ||
| let allMatches = matches; |
There was a problem hiding this comment.
Probably not the right way to deal with it but, this in particular was to avoid linter errors.
views/recent.ejs
Outdated
| : <br/> | ||
| <a href="/<%- allScans[i].uuid %>"><%- allScans[i].uuid %></a> | ||
| <% if (!allScans[i].fixture) { %> | ||
| <a href="<%- allScans[i].link %>" style="color: <%- allScans[i].status === 'fixed' ? 'orange' : 'red' %>">Missing Details!</a> |
There was a problem hiding this comment.
it makes sense to edit style inline here because all we want is to change a color.
but it makes the job of a designer who only knows css more difficult.
consider just giving a style class (class=fixed or class=broken) and edit that style in the css file
googleSpreadsheet.js
Outdated
| o[lab[i]] = val[i]; | ||
| } | ||
| o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index; | ||
| return o; |
There was a problem hiding this comment.
agree, why do we need a cellRef here ?
|
great job! |
|
@lenzai I thought the logging here was for whoever is editing the spreadsheets not whoever is debugging the code, even if both groups can use the logs. |
|
@Spazcool, yes it's for the content editors mostly which needs to "debug" data. Some reference concept: It's quite difficult to discuss remotely, without either dictating you step by step what to do or just publishing revised code myself. If above links inspire you, feel free to discuss or commit further. Otherwise, we can have a pair programming session in January. PS: So far, most of the code reviews by @mpsido were published through a mobile phone... I think I fixed that today. |
|
Pushed some simplifications on that code |
lenzai
left a comment
There was a problem hiding this comment.
not a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)
renaming is thoughtful
introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown
lenzai
left a comment
There was a problem hiding this comment.
some steps towards less complexity ( improved encapsulation and naming)
some off topic changes
introducing multiple bugs
see code comments for details
app.js
Outdated
| if (matches.length >= 1) { | ||
| console.log(`Too much matches for uuid ${req.params.uuid} length = ${matches.length}`); | ||
| } | ||
| matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems) |
There was a problem hiding this comment.
Perhaps amateur questions, but why remove the hard URL and how else do we get a link to work?
| .sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)); | ||
| qrList.forEach(item => item.qr = qr.imageSync('http://url.coderbunker.com/' + item.uuid, { type: 'svg' })); | ||
| qrList.forEach(item => item.qr = qr.imageSync(item.uuid, { type: 'svg' })); | ||
| res.render('qrList', { matches: qrList }); |
There was a problem hiding this comment.
break behaviour , it should be / instead of
Besides, it's off topic with the current branch
There was a problem hiding this comment.
I'll fix that, in which case it won't work ? I need to reproduce it so that I ensure the change will fix that case
There was a problem hiding this comment.
if current page is not root folder then it will assume the uuid is a subfolder
| o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index; | ||
| return o; | ||
| return formatedRow; | ||
| } |
There was a problem hiding this comment.
not a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)
There was a problem hiding this comment.
and now the template for http:///recent display irrelevant links to home page.
| // map function transforms a list into another list using the given lambda function | ||
| const formatedRows = response.values.map(row => spreadsheetValuesToObject(row, columns)); | ||
| return callback(formatedRows); | ||
| }); |
There was a problem hiding this comment.
introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown
There was a problem hiding this comment.
I actually meant to break into two steps for better readability,
All the things where nested into one line of code that was a headache to read
There was a problem hiding this comment.
Extracting local variable is usually bad design.
Extracting subfunction is fine (while inlining others maybe)
There was a problem hiding this comment.
I don't understand what "Extracting subfunction" means.
If javascript is smart (and I assume it is), formatedRows is passed by reference.
It does improve readbility don't you think so ?
There was a problem hiding this comment.
- extracting sub function https://refactoring.com/catalog/extractMethod.html
- removing local variables https://refactoring.com/catalog/inlineTemp.html
| allMatches[0].double = true; | ||
|
|
||
| const duplicatedItem = item; | ||
|
|
There was a problem hiding this comment.
duplicatedItem is redundant with item we don't need 2 names for 1 thing.
There was a problem hiding this comment.
I don't know if item is a reference or a copy.
I wanted to ensure it is a copy because I am writing in it.
There was a problem hiding this comment.
I don't think this is creating any copy.
There was a problem hiding this comment.
I need to recheck that, but if that is a reference, then I need the local variable
| <ul class='recent-list'> | ||
| <% for (var i = 0; i < allScans.length; i++) { %> | ||
| <% for (let item of allScans.values()) { %> | ||
| <li> |
There was a problem hiding this comment.
@mpsido nice! Are there other areas in the code where this rewrite should be applied?
There was a problem hiding this comment.
Everywhere there is a for loop ;) if you don't care about the index then you can use for..in or for..of.
See the MSDN documentation to understand the difference ;)
|
|
||
| const allScans = []; | ||
| const allScans = new Map(); | ||
|
|
There was a problem hiding this comment.
Because I want to avoid repetitions in the "recent" page.
I want to add one by one unique items on that page
There was a problem hiding this comment.
This is not the way to handle changes and features. We create an issue, discuss it and push it.
Hidding secret features in unrelated commits is not appropriate decision workflow and distracting for code review
|
@lenzai what are the introduced bugs you are talking about ? |
|
Closing this pull request |
|
shall we merge it and close the associated issue ? |
|
@lenzai what do you think we should do with this PR |
|
Kudos, SonarCloud Quality Gate passed!
|

REFACTOR: logScanned to catch doubled UUIDs & render doubles on template