Add Sorting Log by Time
Summary: This is a discussion on Github about reversing log. This diff tries to do that. Changelog: Add ability to reverse log by time Reviewed By: mweststrate Differential Revision: D22047276 fbshipit-source-id: 6100a5ca40db223d1989be2746c7190cce7ffc53
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f5a8e929c0
commit
993249ed86
@@ -12,9 +12,11 @@ import {
|
|||||||
TableColumnOrder,
|
TableColumnOrder,
|
||||||
TableColumnSizes,
|
TableColumnSizes,
|
||||||
TableColumns,
|
TableColumns,
|
||||||
|
TableRowSortOrder,
|
||||||
Props as PluginProps,
|
Props as PluginProps,
|
||||||
BaseAction,
|
BaseAction,
|
||||||
DeviceLogEntry,
|
DeviceLogEntry,
|
||||||
|
produce,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import {Counter} from './LogWatcher';
|
import {Counter} from './LogWatcher';
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ type BaseState = {
|
|||||||
type AdditionalState = {
|
type AdditionalState = {
|
||||||
readonly highlightedRows: ReadonlySet<string>;
|
readonly highlightedRows: ReadonlySet<string>;
|
||||||
readonly counters: ReadonlyArray<Counter>;
|
readonly counters: ReadonlyArray<Counter>;
|
||||||
|
readonly timeDirection: 'up' | 'down';
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = BaseState & AdditionalState;
|
type State = BaseState & AdditionalState;
|
||||||
@@ -104,6 +107,7 @@ const COLUMNS = {
|
|||||||
},
|
},
|
||||||
time: {
|
time: {
|
||||||
value: 'Time',
|
value: 'Time',
|
||||||
|
sortable: true,
|
||||||
},
|
},
|
||||||
pid: {
|
pid: {
|
||||||
value: 'PID',
|
value: 'PID',
|
||||||
@@ -262,6 +266,7 @@ export function addEntriesToState(
|
|||||||
entries: [],
|
entries: [],
|
||||||
key2entry: {},
|
key2entry: {},
|
||||||
} as const,
|
} as const,
|
||||||
|
addDirection: 'up' | 'down' = 'up',
|
||||||
): BaseState {
|
): BaseState {
|
||||||
const rows = [...state.rows];
|
const rows = [...state.rows];
|
||||||
const entries = [...state.entries];
|
const entries = [...state.entries];
|
||||||
@@ -280,7 +285,7 @@ export function addEntriesToState(
|
|||||||
previousEntry = state.entries[state.entries.length - 1].entry;
|
previousEntry = state.entries[state.entries.length - 1].entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRowIfNeeded(rows, row, entry, previousEntry);
|
addRowIfNeeded(rows, row, entry, previousEntry, addDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -295,8 +300,14 @@ export function addRowIfNeeded(
|
|||||||
row: TableBodyRow,
|
row: TableBodyRow,
|
||||||
entry: DeviceLogEntry,
|
entry: DeviceLogEntry,
|
||||||
previousEntry: DeviceLogEntry | null,
|
previousEntry: DeviceLogEntry | null,
|
||||||
|
addDirection: 'up' | 'down' = 'up',
|
||||||
) {
|
) {
|
||||||
const previousRow = rows.length > 0 ? rows[rows.length - 1] : null;
|
const previousRow =
|
||||||
|
rows.length > 0
|
||||||
|
? addDirection === 'up'
|
||||||
|
? rows[rows.length - 1]
|
||||||
|
: rows[0]
|
||||||
|
: null;
|
||||||
if (
|
if (
|
||||||
previousRow &&
|
previousRow &&
|
||||||
previousEntry &&
|
previousEntry &&
|
||||||
@@ -316,7 +327,11 @@ export function addRowIfNeeded(
|
|||||||
<LogCount backgroundColor={type.color}>{count}</LogCount>
|
<LogCount backgroundColor={type.color}>{count}</LogCount>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
rows.push(row);
|
if (addDirection === 'up') {
|
||||||
|
rows.push(row);
|
||||||
|
} else {
|
||||||
|
rows.unshift(row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,6 +506,7 @@ export default class LogTable extends FlipperDevicePlugin<
|
|||||||
initialState.rows,
|
initialState.rows,
|
||||||
),
|
),
|
||||||
counters: this.restoreSavedCounters(),
|
counters: this.restoreSavedCounters(),
|
||||||
|
timeDirection: 'up',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logListener = this.device.addLogListener((entry: DeviceLogEntry) => {
|
this.logListener = this.device.addLogListener((entry: DeviceLogEntry) => {
|
||||||
@@ -539,7 +555,9 @@ export default class LogTable extends FlipperDevicePlugin<
|
|||||||
const thisBatch = this.batch;
|
const thisBatch = this.batch;
|
||||||
this.batch = [];
|
this.batch = [];
|
||||||
this.queued = false;
|
this.queued = false;
|
||||||
this.setState((state) => addEntriesToState(thisBatch, state));
|
this.setState((state) =>
|
||||||
|
addEntriesToState(thisBatch, state, state.timeDirection),
|
||||||
|
);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -661,6 +679,15 @@ export default class LogTable extends FlipperDevicePlugin<
|
|||||||
stickyBottom={
|
stickyBottom={
|
||||||
!(this.props.deepLinkPayload && this.state.highlightedRows.size > 0)
|
!(this.props.deepLinkPayload && this.state.highlightedRows.size > 0)
|
||||||
}
|
}
|
||||||
|
initialSortOrder={{key: 'time', direction: 'up'}}
|
||||||
|
onSort={(order: TableRowSortOrder) =>
|
||||||
|
this.setState(
|
||||||
|
produce((prevState) => {
|
||||||
|
prevState.rows.reverse();
|
||||||
|
prevState.timeDirection = order.direction;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<DetailSidebar>{this.renderSidebar()}</DetailSidebar>
|
<DetailSidebar>{this.renderSidebar()}</DetailSidebar>
|
||||||
</LogTable.ContextMenu>
|
</LogTable.ContextMenu>
|
||||||
|
|||||||
Reference in New Issue
Block a user