Unify `RecursiveTables` abstraction (#343)
Summary: A `RecursiveTable` shows the tree-view from a single node; a `RecursiveTables` shows multiple `RecursiveTable`s, and is used both in the recursion and at the top level. This is useful because we’ll want to make changes to both entry points, for things like pagination. In particular, this makes #342 nicer. Test Plan: Note that the behavior is unchanged. Then, apply ```diff diff --git a/src/v1/app/credExplorer/pagerankTable.js b/src/v1/app/credExplorer/pagerankTable.js index 624bd71..e343e95 100644 --- a/src/v1/app/credExplorer/pagerankTable.js +++ b/src/v1/app/credExplorer/pagerankTable.js @@ -220,6 +220,7 @@ class RecursiveTables extends React.Component<RecursiveTablesProps> { const y = pagerankResult.get(b).probability; return y - x; }) + .slice(0, 10) .map((address) => ( <RecursiveTable depth={depth} ``` and note that (a) the root view has only ten entries, and (b) any expanded subview also has only ten entries. wchargin-branch: recursive-tables
This commit is contained in:
parent
222c334027
commit
910e4fc831
|
@ -111,21 +111,16 @@ export class PagerankTable extends React.Component<Props, State> {
|
|||
throw new Error("Impossible.");
|
||||
}
|
||||
const {graph, pagerankResult} = this.props;
|
||||
const nodesByScore = graph
|
||||
const addresses = graph
|
||||
.nodes()
|
||||
.slice()
|
||||
.map((node) => node.address)
|
||||
.filter(
|
||||
(n) =>
|
||||
(address) =>
|
||||
this.state.topLevelFilter
|
||||
? n.address.pluginName === this.state.topLevelFilter.pluginName &&
|
||||
n.address.type === this.state.topLevelFilter.type
|
||||
? address.pluginName === this.state.topLevelFilter.pluginName &&
|
||||
address.type === this.state.topLevelFilter.type
|
||||
: true
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const x = pagerankResult.get(a.address).probability;
|
||||
const y = pagerankResult.get(b.address).probability;
|
||||
return y - x;
|
||||
});
|
||||
);
|
||||
return (
|
||||
<table style={{borderCollapse: "collapse"}}>
|
||||
<thead>
|
||||
|
@ -136,15 +131,12 @@ export class PagerankTable extends React.Component<Props, State> {
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{nodesByScore.map((node) => (
|
||||
<RecursiveTable
|
||||
depth={0}
|
||||
address={node.address}
|
||||
graph={graph}
|
||||
pagerankResult={pagerankResult}
|
||||
key={stringify(node.address)}
|
||||
/>
|
||||
))}
|
||||
<RecursiveTables
|
||||
addresses={addresses}
|
||||
graph={graph}
|
||||
pagerankResult={pagerankResult}
|
||||
depth={0}
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
|
@ -200,16 +192,37 @@ class RecursiveTable extends React.Component<RTProps, RTState> {
|
|||
graph.neighborhood(address).forEach(({neighbor}) => {
|
||||
neighborMap.add({address: neighbor});
|
||||
});
|
||||
return neighborMap
|
||||
.getAll()
|
||||
return (
|
||||
<RecursiveTables
|
||||
addresses={neighborMap.getAll().map(({address}) => address)}
|
||||
graph={graph}
|
||||
pagerankResult={pagerankResult}
|
||||
depth={depth + 1}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
type RecursiveTablesProps = {|
|
||||
+addresses: $ReadOnlyArray<Address>,
|
||||
+graph: Graph,
|
||||
+pagerankResult: PagerankResult,
|
||||
+depth: number,
|
||||
|};
|
||||
|
||||
class RecursiveTables extends React.Component<RecursiveTablesProps> {
|
||||
render() {
|
||||
const {addresses, graph, pagerankResult, depth} = this.props;
|
||||
return addresses
|
||||
.slice()
|
||||
.sort((a, b) => {
|
||||
const x = pagerankResult.get(a.address).probability;
|
||||
const y = pagerankResult.get(b.address).probability;
|
||||
const x = pagerankResult.get(a).probability;
|
||||
const y = pagerankResult.get(b).probability;
|
||||
return y - x;
|
||||
})
|
||||
.map(({address}) => (
|
||||
.map((address) => (
|
||||
<RecursiveTable
|
||||
depth={depth + 1}
|
||||
depth={depth}
|
||||
address={address}
|
||||
graph={graph}
|
||||
pagerankResult={pagerankResult}
|
||||
|
|
Loading…
Reference in New Issue