Skip to content

Commit

Permalink
[front: editLog] do not display empty arrays #463
Browse files Browse the repository at this point in the history
  • Loading branch information
t8g committed Sep 28, 2017
1 parent 789d6c0 commit 4767b33
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/src/app/isari-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ export class IsariDataService {
}

formatWithRefs(obj) {
if (typeof obj === 'string') return Observable.of(obj);
if (typeof obj === 'string' || typeof obj === 'number') return Observable.of(obj);
if (obj.value && obj.ref) return this.getForeignLabel(obj.ref, obj.value).map(x => x[0].value);

const format = (o, refs, level = 0) => {
if (isArray(o) && o.length === 0) return "?";
if (isArray(o) && o.length === 0) return "[]";
if (isArray(o)) {
return o.some(isPlainObject)
? o.map(oo => format(oo, refs, level)).join("\n")
Expand All @@ -207,8 +207,9 @@ export class IsariDataService {

return Object.keys(o)
.reduce((s, k) => {
if (isArray(o[k]) && !o[k].length) return s; // bypass empty array #463
s += `${' '.repeat(level)}${k} : `;
if (typeof o[k] === 'string') s += o[k];
if (typeof o[k] === 'string' || typeof o[k] === 'number') s += o[k];
// replace ref with label from async call (refs)
else if (o[k].ref && o[k].value) s += o[k].value.length === 0 ? '[]' : (refs[o[k].value] || '?');
else s += format(o[k], refs, level + 1);
Expand Down

0 comments on commit 4767b33

Please sign in to comment.