Combine loadGraph and runPagerank into one button (#759)

* StateTransitionMachine.loadGraph reports success

Step one towards #586. This will enable us to chain runPagerank after
loadGraph only if the load went through successfully.

Test plan: Unit tests included.

* Add StateTransitionMachine.loadGraphAndRunPagerank

This methods combines `loadGraph` and `runPagerank` into one method
which internally chains the two method. `runPagerank` is only called if
`loadGraph` was successful.

Progress on #586.

Test plan:
The new method has attached unit tests. I implemented the unit tests via
mocking, which seemed quite convenient as the method is basically a
wrapper for chaining two other function calls.

* Combine loadGraph and runPagerank into one button

Resolves #586. The new button is called "Analyze cred".

Test plan: Unit tests, also I tested it manually.
This commit is contained in:
Dandelion Mané 2018-09-03 14:34:14 -07:00 committed by GitHub
parent 1135141054
commit 44407b5520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 53 deletions

View File

@ -1,6 +1,7 @@
# Changelog # Changelog
## [Unreleased] ## [Unreleased]
- Combine "load graph" and "run pagerank" into one button (#759)
- Store GitHub data compressed at rest, reducing space usage by 68× (#750) - Store GitHub data compressed at rest, reducing space usage by 68× (#750)
- Improve weight sliders display (#736) - Improve weight sliders display (#736)
- Separate bots from users in the UI (#720) - Separate bots from users in the UI (#720)

View File

@ -60,8 +60,6 @@ export function createApp(
render() { render() {
const {localStore} = this.props; const {localStore} = this.props;
const {appState} = this.state; const {appState} = this.state;
const subType =
appState.type === "INITIALIZED" ? appState.substate.type : null;
const loadingState = const loadingState =
appState.type === "INITIALIZED" ? appState.substate.loading : null; appState.type === "INITIALIZED" ? appState.substate.loading : null;
let pagerankTable; let pagerankTable;
@ -103,27 +101,18 @@ export function createApp(
onChange={(repo) => this.stateTransitionMachine.setRepo(repo)} onChange={(repo) => this.stateTransitionMachine.setRepo(repo)}
/> />
</div> </div>
<button
disabled={subType !== "READY_TO_LOAD_GRAPH"}
onClick={() =>
this.stateTransitionMachine.loadGraph(this.props.assets)
}
>
Load graph
</button>
<button <button
disabled={ disabled={
!( appState.type === "UNINITIALIZED" || loadingState === "LOADING"
(subType === "READY_TO_RUN_PAGERANK" || }
subType === "PAGERANK_EVALUATED") && onClick={() =>
loadingState !== "LOADING" this.stateTransitionMachine.loadGraphAndRunPagerank(
this.props.assets,
GithubPrefix.user
) )
} }
onClick={() =>
this.stateTransitionMachine.runPagerank(GithubPrefix.user)
}
> >
Run PageRank Analyze cred
</button> </button>
<WeightConfig <WeightConfig
onChange={(ee) => this.stateTransitionMachine.setEdgeEvaluator(ee)} onChange={(ee) => this.stateTransitionMachine.setEdgeEvaluator(ee)}

View File

@ -52,6 +52,7 @@ describe("app/credExplorer/App", () => {
setEdgeEvaluator, setEdgeEvaluator,
loadGraph, loadGraph,
runPagerank, runPagerank,
loadGraphAndRunPagerank,
localStore, localStore,
}; };
} }
@ -147,40 +148,21 @@ describe("app/credExplorer/App", () => {
}); });
} }
function testGraphButton(stateFn, {disabled}) { function testAnalyzeCredButton(stateFn, {disabled}) {
const adjective = disabled ? "disabled" : "working"; const adjective = disabled ? "disabled" : "working";
it(`has a ${adjective} load graph button`, () => { it(`has a ${adjective} analyze cred button`, () => {
const {el, loadGraph, setState} = example(); const {el, loadGraphAndRunPagerank, setState} = example();
setState(stateFn()); setState(stateFn());
el.update(); el.update();
const button = el.findWhere( const button = el.findWhere(
(b) => b.text() === "Load graph" && b.is("button") (b) => b.text() === "Analyze cred" && b.is("button")
); );
if (disabled) { if (disabled) {
expect(button.props().disabled).toBe(true); expect(button.props().disabled).toBe(true);
} else { } else {
expect(button.props().disabled).toBe(false); expect(button.props().disabled).toBe(false);
button.simulate("click"); button.simulate("click");
expect(loadGraph).toBeCalledTimes(1); expect(loadGraphAndRunPagerank).toBeCalledTimes(1);
}
});
}
function testPagerankButton(stateFn, {disabled}) {
const adjective = disabled ? "disabled" : "working";
it(`has a ${adjective} run PageRank button`, () => {
const {el, runPagerank, setState} = example();
setState(stateFn());
el.update();
const button = el.findWhere(
(b) => b.text() === "Run PageRank" && b.is("button")
);
if (disabled) {
expect(button.props().disabled).toBe(true);
} else {
expect(button.props().disabled).toBe(false);
button.simulate("click");
expect(runPagerank).toBeCalledTimes(1);
} }
}); });
} }
@ -225,21 +207,19 @@ describe("app/credExplorer/App", () => {
function stateTestSuite( function stateTestSuite(
suiteName, suiteName,
stateFn, stateFn,
{loadGraphDisabled, runPagerankDisabled, hasPagerankTable} {analyzeCredDisabled, hasPagerankTable}
) { ) {
describe(suiteName, () => { describe(suiteName, () => {
testWeightConfig(stateFn); testWeightConfig(stateFn);
testRepositorySelect(stateFn); testRepositorySelect(stateFn);
testGraphButton(stateFn, {disabled: loadGraphDisabled}); testAnalyzeCredButton(stateFn, {disabled: analyzeCredDisabled});
testPagerankButton(stateFn, {disabled: runPagerankDisabled});
testPagerankTable(stateFn, hasPagerankTable); testPagerankTable(stateFn, hasPagerankTable);
testLoadingIndicator(stateFn); testLoadingIndicator(stateFn);
}); });
} }
stateTestSuite("UNINITIALIZED", exampleStates.uninitialized, { stateTestSuite("UNINITIALIZED", exampleStates.uninitialized, {
loadGraphDisabled: true, analyzeCredDisabled: true,
runPagerankDisabled: true,
hasPagerankTable: false, hasPagerankTable: false,
}); });
describe("READY_TO_LOAD_GRAPH", () => { describe("READY_TO_LOAD_GRAPH", () => {
@ -248,8 +228,7 @@ describe("app/credExplorer/App", () => {
loadingState, loadingState,
exampleStates.readyToLoadGraph(loadingState), exampleStates.readyToLoadGraph(loadingState),
{ {
loadGraphDisabled: false, analyzeCredDisabled: loadingState === "LOADING",
runPagerankDisabled: true,
hasPagerankTable: false, hasPagerankTable: false,
} }
); );
@ -262,8 +241,7 @@ describe("app/credExplorer/App", () => {
loadingState, loadingState,
exampleStates.readyToRunPagerank(loadingState), exampleStates.readyToRunPagerank(loadingState),
{ {
loadGraphDisabled: true, analyzeCredDisabled: loadingState === "LOADING",
runPagerankDisabled: loadingState === "LOADING",
hasPagerankTable: false, hasPagerankTable: false,
} }
); );
@ -276,8 +254,7 @@ describe("app/credExplorer/App", () => {
loadingState, loadingState,
exampleStates.pagerankEvaluated(loadingState), exampleStates.pagerankEvaluated(loadingState),
{ {
loadGraphDisabled: true, analyzeCredDisabled: loadingState === "LOADING",
runPagerankDisabled: loadingState === "LOADING",
hasPagerankTable: true, hasPagerankTable: true,
} }
); );