From 42669cd160f7360e6f47fd8078910fde7a3ed9ff Mon Sep 17 00:00:00 2001 From: Brian Litwin Date: Thu, 21 Feb 2019 14:27:18 -0500 Subject: [PATCH] PagerankTable: Replace topLevelFilter with NodeType in props (#1103) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The motivation for this change is to make it easier to access the selected Node's `name` prop for #576, in which we plan to show a Card displaying summary stats for the selected node. With only the `topLevelFilter` available, it's trickier than it needs to be to find out a node type's `name`. Test Plan: * Yarn test passes. * Visual/Manual inspection of table doesn't surface any issues. * Updated `it("filter defaults to defaultNodeFilter if available")` to `it("selectedNodeType defaults to defaultNodeType if available")`. * Verified that the above new test is failable in several ways by mangling the tests to test for the wrong node type and mangling the code to set the wrong node type. * Since we factored out 'topLevelFilter' and 'defaultNodeFilter', running `git grep -i topLevelFilter` and `git grep -i defaultNodeFilter` turns up empty, just to make sure those terms aren't hanging around to confuse anybody in the future. * I don't think changing the `prop` parameter warrants any additional tests, as the current tests verify that the prop is passed in correctly. This was at @decentralion's suggestion, following the Contributing Guideline's Kent Beck quote of making the easy change to make the change we were originally after (#576) easier. 🙌 --- src/explorer/App.js | 3 +- src/explorer/pagerankTable/Table.js | 36 ++++++++++-------------- src/explorer/pagerankTable/Table.test.js | 32 +++++++++++---------- src/plugins/github/declaration.js | 2 +- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/explorer/App.js b/src/explorer/App.js index 703d874..c3191e8 100644 --- a/src/explorer/App.js +++ b/src/explorer/App.js @@ -20,6 +20,7 @@ import { initialState, } from "./state"; import {StaticExplorerAdapterSet} from "./adapters/explorerAdapterSet"; +import {userNodeType} from "../plugins/github/declaration"; const credOverviewUrl = "https://discuss.sourcecred.io/t/a-gentle-introduction-to-cred/20"; @@ -91,7 +92,7 @@ export function createApp( const pnd = appState.pagerankNodeDecomposition; pagerankTable = ( diff --git a/src/explorer/pagerankTable/Table.js b/src/explorer/pagerankTable/Table.js index d11cc2f..57be461 100644 --- a/src/explorer/pagerankTable/Table.js +++ b/src/explorer/pagerankTable/Table.js @@ -4,15 +4,16 @@ import React from "react"; import sortBy from "lodash.sortby"; import * as NullUtil from "../../util/null"; -import {type NodeAddressT, NodeAddress} from "../../core/graph"; +import {NodeAddress} from "../../core/graph"; import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition"; import {DynamicExplorerAdapterSet} from "../adapters/explorerAdapterSet"; import type {DynamicExplorerAdapter} from "../adapters/explorerAdapter"; import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration"; import type {WeightedTypes} from "../../analysis/weights"; import {WeightConfig} from "../weights/WeightConfig"; - import {NodeRowList} from "./Node"; +import {type NodeType} from "../../analysis/types"; +import {fallbackNodeType} from "../../analysis/fallbackDeclaration"; type PagerankTableProps = {| +pnd: PagerankNodeDecomposition, @@ -20,10 +21,10 @@ type PagerankTableProps = {| +weightedTypes: WeightedTypes, +onWeightedTypesChange: (WeightedTypes) => void, +maxEntriesPerList: number, - +defaultNodeFilter: ?NodeAddressT, + +defaultNodeType: ?NodeType, |}; type PagerankTableState = {| - topLevelFilter: NodeAddressT, + selectedNodeType: NodeType, showWeightConfig: boolean, |}; export class PagerankTable extends React.PureComponent< @@ -32,20 +33,11 @@ export class PagerankTable extends React.PureComponent< > { constructor(props: PagerankTableProps): void { super(); - const {defaultNodeFilter, adapters} = props; - if (defaultNodeFilter != null) { - const nodeTypes = adapters.static().nodeTypes(); - if (!nodeTypes.some((x) => x.prefix === defaultNodeFilter)) { - throw new Error( - `invalid defaultNodeFilter ${defaultNodeFilter}: doesn't match any type` - ); - } - } - const topLevelFilter = NullUtil.orElse( - props.defaultNodeFilter, - NodeAddress.empty + const selectedNodeType = NullUtil.orElse( + props.defaultNodeType, + fallbackNodeType ); - this.state = {topLevelFilter, showWeightConfig: false}; + this.state = {selectedNodeType, showWeightConfig: false}; } renderConfigurationRow() { @@ -116,9 +108,11 @@ export class PagerankTable extends React.PureComponent<