Skip to content

Commit

Permalink
Addressed the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Jan 13, 2017
1 parent f6feb56 commit 5583a5d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
6 changes: 3 additions & 3 deletions client/app/scripts/components/node-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NodeDetailsTable from './node-details/node-details-table';
import Warning from './warning';


const logError = debug('scope:error');
const log = debug('scope:node-details');

function getTruncationText(count) {
return 'This section was too long to be handled efficiently and has been truncated'
Expand Down Expand Up @@ -213,7 +213,7 @@ class NodeDetails extends React.Component {
return (
<div className="node-details-content-section" key={table.id}>
<div className="node-details-content-section-header">
{table.label.length > 0 && table.label}
{table.label && table.label.length > 0 && table.label}
{table.truncationCount > 0 && <span
className="node-details-content-section-header-warning">
<Warning text={getTruncationText(table.truncationCount)} />
Expand Down Expand Up @@ -249,7 +249,7 @@ class NodeDetails extends React.Component {
);
}

logError(`Undefined type '${table.type}' for table ${table.id}`);
log(`Undefined type '${table.type}' for table ${table.id}`);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import sortBy from 'lodash/sortBy';
import { Map as makeMap } from 'immutable';
import { sortBy } from 'lodash';

import { NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT } from '../../constants/limits';

import {
isNumber, getTableColumnsStyles, genericTableEntryKey
isNumber,
getTableColumnsStyles,
genericTableEntryKey
} from '../../utils/node-details-utils';
import NodeDetailsTableHeaders from './node-details-table-headers';
import MatchedText from '../matched-text';
Expand All @@ -31,7 +34,7 @@ export default class NodeDetailsGenericTable extends React.Component {
super(props, context);
this.state = {
limit: NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT,
sortedBy: props.columns[0].id,
sortedBy: props.columns && props.columns[0].id,
sortedDesc: true
};
this.handleLimitClick = this.handleLimitClick.bind(this);
Expand Down
4 changes: 2 additions & 2 deletions client/app/scripts/utils/node-details-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export function isPropertyList(table) {
}

export function isNumber(data) {
return data.dataType && data.dataType === 'number';
return data && data.dataType && data.dataType === 'number';
}

export function isIP(data) {
return data.dataType && data.dataType === 'ip';
return data && data.dataType && data.dataType === 'ip';
}

export function genericTableEntryKey(row, column) {
Expand Down
54 changes: 26 additions & 28 deletions report/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func WithoutPrefix(s string, prefix string) (string, bool) {

// ExtractMulticolumnTable returns the rows to build a multicolumn table from this node
func (node Node) ExtractMulticolumnTable(template TableTemplate) (rows []Row) {
rowsByID := map[string]Row{}
rowsMapByID := map[string]Row{}

// Itearate through the whole of our map to extract all the values with the key
// with the given prefix. Since multicolumn tables don't support fixed rows (yet),
Expand All @@ -82,64 +82,56 @@ func (node Node) ExtractMulticolumnTable(template TableTemplate) (rows []Row) {
ids := strings.Split(keyWithoutPrefix, TableEntryKeySeparator)
rowID, columnID := ids[0], ids[1]
// If the row with the given ID doesn't yet exist, we create an empty one.
if _, ok := rowsByID[rowID]; !ok {
rowsByID[rowID] = Row{
if _, ok := rowsMapByID[rowID]; !ok {
rowsMapByID[rowID] = Row{
ID: rowID,
Entries: map[string]string{},
}
}
// At this point, the row with that ID always exists, so we just update the value.
rowsByID[rowID].Entries[columnID] = value
rowsMapByID[rowID].Entries[columnID] = value
}
})

// Gather a sorted list of rows' IDs.
ids := make([]string, 0, len(rowsByID))
for id := range rowsByID {
ids = append(ids, id)
// Gather a list of rows.
rows = make([]Row, 0, len(rowsMapByID))
for _, row := range rowsMapByID {
rows = append(rows, row)
}
sort.Strings(ids)

// Return the rows in the sorted order.
rows = []Row{}
for _, id := range ids {
rows = append(rows, rowsByID[id])
}
// Return the rows sorted by ID.
sort.Sort(rowsByID(rows))
return rows
}

// ExtractPropertyList returns the rows to build a property list from this node
func (node Node) ExtractPropertyList(template TableTemplate) (rows []Row) {
valuesByLabel := map[string]string{}
valuesMapByLabel := map[string]string{}

// Itearate through the whole of our map to extract all the values with the key
// with the given prefix as well as the keys corresponding to the fixed table rows.
node.Latest.ForEach(func(key string, _ time.Time, value string) {
if label, ok := template.FixedRows[key]; ok {
valuesByLabel[label] = value
valuesMapByLabel[label] = value
} else if label, ok := WithoutPrefix(key, template.Prefix); ok {
valuesByLabel[label] = value
valuesMapByLabel[label] = value
}
})

// Gather a sorted list of labels.
labels := make([]string, 0, len(valuesByLabel))
for label := range valuesByLabel {
labels = append(labels, label)
}
sort.Strings(labels)

// Return the label-value formatted rows sorted by label.
rows = []Row{}
for _, label := range labels {
// Gather a label-value formatted list of rows.
rows = make([]Row, 0, len(valuesMapByLabel))
for label, value := range valuesMapByLabel {
rows = append(rows, Row{
ID: "label_" + label,
Entries: map[string]string{
"label": label,
"value": valuesByLabel[label],
"value": value,
},
})
}

// Return the rows sorted by ID.
sort.Sort(rowsByID(rows))
return rows
}

Expand Down Expand Up @@ -175,6 +167,12 @@ type Row struct {
Entries map[string]string `json:"entries"`
}

type rowsByID []Row

func (t rowsByID) Len() int { return len(t) }
func (t rowsByID) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t rowsByID) Less(i, j int) bool { return t[i].ID < t[j].ID }

// Copy returns a copy of the Row.
func (r Row) Copy() Row {
entriesCopy := make(map[string]string, len(r.Entries))
Expand Down

0 comments on commit 5583a5d

Please sign in to comment.