From a831e05e5fd7353a5dab916868f361aa777246c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Tue, 21 May 2019 04:41:00 +0300 Subject: [PATCH] Add a WeightsFileManager (#1150) This adds a WeightsFileManager component that allows the user to save or load weights in the cred explorer. Clicking the download icon downloads the weights, clicking the upload icon uploads them. I also did a slight refactor to the FileUploader so that it no longer always provides the file upload icon, instead the instantiator passes children which act as the upload clickable. Seemed more consistent. Test plan: No tests added, but I manually tested that upload and download both work. --- CHANGELOG.md | 1 + src/explorer/App.js | 10 ++++++ src/explorer/pagerankTable/Table.js | 3 ++ src/explorer/pagerankTable/Table.test.js | 2 ++ src/explorer/pagerankTable/sharedTestUtils.js | 2 ++ src/explorer/weights/WeightsFileManager.js | 33 +++++++++++++++++++ src/util/FileUploader.js | 8 ++--- src/util/FileUploaderInspectionTest.js | 5 ++- 8 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/explorer/weights/WeightsFileManager.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e29043..b6862de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Allow the user to save or upload weight settings (#1150) - Allow tweaking weights on a per-node basis (#1143) - Add the `pagerank` command (#1114) - Add the `clear` command (#1111) diff --git a/src/explorer/App.js b/src/explorer/App.js index 8d9df53..6d30658 100644 --- a/src/explorer/App.js +++ b/src/explorer/App.js @@ -12,6 +12,7 @@ import {type NodeAddressT} from "../core/graph"; import {PagerankTable} from "./pagerankTable/Table"; import {WeightConfig} from "./weights/WeightConfig"; +import {WeightsFileManager} from "./weights/WeightsFileManager"; import {type Weights, defaultWeights} from "../analysis/weights"; import {Prefix as GithubPrefix} from "../plugins/github/nodes"; import { @@ -108,6 +109,14 @@ export function createApp( }} /> ); + const weightFileManager = ( + { + this.setState({weights}); + }} + /> + ); let pagerankTable; if (appState.type === "PAGERANK_EVALUATED") { const adapters = appState.graphWithAdapters.adapters; @@ -117,6 +126,7 @@ export function createApp( defaultNodeType={userNodeType} adapters={adapters} weightConfig={weightConfig} + weightFileManager={weightFileManager} manualWeights={this.state.weights.nodeManualWeights} onManualWeightsChange={(addr: NodeAddressT, weight: number) => this.setState(({weights}) => { diff --git a/src/explorer/pagerankTable/Table.js b/src/explorer/pagerankTable/Table.js index ea10d6b..20a5cf5 100644 --- a/src/explorer/pagerankTable/Table.js +++ b/src/explorer/pagerankTable/Table.js @@ -4,6 +4,7 @@ import React from "react"; import sortBy from "lodash.sortby"; import {WeightConfig} from "../weights/WeightConfig"; +import {WeightsFileManager} from "../weights/WeightsFileManager"; import {NodeAddress, type NodeAddressT} from "../../core/graph"; import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition"; import {DynamicExplorerAdapterSet} from "../adapters/explorerAdapterSet"; @@ -19,6 +20,7 @@ type PagerankTableProps = {| +manualWeights: Map, +onManualWeightsChange: (NodeAddressT, number) => void, +weightConfig: React$Element, + +weightFileManager: React$Element, |}; type PagerankTableState = {| selectedNodeTypePrefix: NodeAddressT, @@ -45,6 +47,7 @@ export class PagerankTable extends React.PureComponent<
{this.renderFilterSelect()} + {this.props.weightFileManager}