Skip to content

Commit

Permalink
Merge pull request #17 from dhis2/DHIS2-5853/remove-logger-truncation
Browse files Browse the repository at this point in the history
fix(logger): remove logger truncation
  • Loading branch information
Birkbjo authored Feb 1, 2019
2 parents 7d497e7 + d46b354 commit 2f2775d
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 197 deletions.
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** @format */

module.exports = {
printWidth: 80,
tabWidth: 4,
Expand All @@ -9,10 +7,12 @@ module.exports = {
trailingComma: 'es5',
bracketSpacing: true,
jsxBracketSameLine: false,
jsxSingleQuote: false,
arrowParens: 'avoid',
rangeStart: 0,
rangeEnd: Infinity,
proseWrap: 'preserve',
requirePragma: false,
insertPragma: false,
endOfLine: 'lf',
}
4 changes: 2 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2018-11-26T09:55:48.645Z\n"
"PO-Revision-Date: 2018-11-26T09:55:48.645Z\n"
"POT-Creation-Date: 2019-02-01T15:53:30.758Z\n"
"PO-Revision-Date: 2019-02-01T15:53:30.758Z\n"

msgid "user is not logged in"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
]
},
"devDependencies": {
"@dhis2/code-style": "^1.5.0",
"@dhis2/code-style": "^1.7.1",
"babel-eslint": "^10.0.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"enzyme": "^3.3.0",
Expand Down
12 changes: 5 additions & 7 deletions src/components/FormBase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export class FormBase extends React.Component {

getFormState() {
const values = {}
this.fields
.map(f => f.name)
.forEach(name => {
if (name) {
values[name] = getFieldValue(this.state[name])
}
})
this.fields.map(f => f.name).forEach(name => {
if (name) {
values[name] = getFieldValue(this.state[name])
}
})
return values
}

Expand Down
44 changes: 29 additions & 15 deletions src/components/Logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function ArrowDownIcon({ onClick }) {
function Message({ date, type, text }) {
return (
<div className={s.message}>
<div className={s.date}>{date}</div>
<div className={s.date}>{date || '--:--'}</div>
<div className={s.type}>{type}</div>
<div className={s.contents}>
<div className={s.text}>{text}</div>
Expand Down Expand Up @@ -190,13 +190,27 @@ export class Logger extends React.Component {
)
}

getDate(p, prevDateHH, prevDate) {
let date = moment(p.d).format('YYYY-MM-DD HH:mm:ss')
/**
*
* @param {*} msg the log message
* @param {*} prevDateHH previous message moment-date formatted with hrs (used to truncate)
* @param {*} prevDate previous message moment-date
* @param {*} truncate whether to truncate the timestamp, so that the returned
* date is formatted without the parts of previous date (upto mm:ss)
*/
getDate(msg, prevDateHH, prevDate, truncate = false) {
if (!msg.d) {
return null
}
let date = moment(msg.d).format('YYYY-MM-DD HH:mm:ss')

if (moment(p.d).format('YYYY-MM-DD HH') === prevDateHH) {
date = moment(p.d).format('mm:ss')
} else if (moment(p.d).format('YYYY-MM-DD') === prevDate) {
date = moment(p.d).format('HH:mm:ss')
if (truncate && moment(msg.d).format('YYYY-MM-DD HH') === prevDateHH) {
date = moment(msg.d).format('mm:ss')
} else if (
truncate &&
moment(msg.d).format('YYYY-MM-DD') === prevDate
) {
date = moment(msg.d).format('HH:mm:ss')
}

return date
Expand All @@ -206,19 +220,19 @@ export class Logger extends React.Component {
let prevType, prevDate, prevDateHH
prevType = prevDate = prevDateHH = ''

return this.state.list.map(p => {
const type = p.type === prevType ? '' : p.type
const date = this.getDate(p, prevDateHH, prevDate)
return this.state.list.map(msg => {
const type = msg.type === prevType ? '' : msg.type
const date = this.getDate(msg, prevDateHH, prevDate)

prevType = p.type
prevDate = moment(p.d).format('YYYY-MM-DD')
prevDateHH = moment(p.d).format('YYYY-MM-DD HH')
prevType = msg.type
prevDate = moment(msg.d).format('YYYY-MM-DD')
prevDateHH = moment(msg.d).format('YYYY-MM-DD HH')
return (
<Message
key={`msg-${p.id}`}
key={`msg-${msg.id}`}
date={date}
type={type}
text={p.text}
text={msg.text}
/>
)
})
Expand Down
6 changes: 3 additions & 3 deletions src/components/Tree/__tests__/Tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Tree', () => {
wrapper.setProps({ list, selected })
expect(
wrapper.containsAllMatchingElements([
<div style={{ minWidth: 0 }} />,
<div style={{ minWidth: 7 }} />,
<div>+</div>,
<div>1</div>,
])
Expand All @@ -47,11 +47,11 @@ describe('Tree', () => {
wrapper.setProps({ list, selected })
expect(
wrapper.containsAllMatchingElements([
<div style={{ minWidth: 0 }} />,
<div style={{ minWidth: 7 }} />,
<div>+</div>,
<div>1</div>,

<div style={{ minWidth: 0 }} />,
<div style={{ minWidth: 7 }} />,
<div>+</div>,
<div>2</div>,
])
Expand Down
2 changes: 1 addition & 1 deletion src/pages/import/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function logStats(stats, type) {
const { created, updated, deleted, ignored, total } = stats
eventEmitter.emit('log', {
id: new Date().getTime(),
d: new Date(),
d: null,
type: `INFO - ${CATEGORY_2_LABEL[type]}`,
text: `Created: ${created}, Updated: ${updated}, Deleted: ${deleted}, Ignored: ${ignored}, Total: ${total}`,
})
Expand Down
Loading

0 comments on commit 2f2775d

Please sign in to comment.