Allow expanding/hiding the WeightConfig (#511)

The WeightConfig is a power user feature. Now that we're building a
public-facing demo out of the Cred Explorer, it will be better to hide
the weight configuration by default.

This commit adds a button for showing/hiding the weight configuration.
The weights are still propagated correctly regardless of whether the
weight config is shown.

Test plan:
- Ensure that the site loads with weights hidden by default.
- Ensure that clicking the button causes the weight config to display.
- Ensure that PageRank loads and displays correctly with the weights
hidden.
- Ensure that changes to the weight config still propagate to PageRank
(with weights hidden or not hidden).
This commit is contained in:
Dandelion Mané 2018-07-23 14:05:06 -07:00 committed by GitHub
parent 9a356f88a1
commit 943d04cc70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 17 deletions

View File

@ -25,7 +25,6 @@ type Props = {
onChange: (EdgeEvaluator) => void,
};
// The key should be an EdgeAddressT, but a Flow bug prevents this.
type EdgeWeights = Map<EdgeAddressT, UserEdgeWeight>;
type UserEdgeWeight = {|+logWeight: number, +directionality: number|};
const EDGE_WEIGHTS_KEY = "edgeWeights";
@ -60,6 +59,7 @@ const defaultNodeWeights = (): NodeWeights =>
type State = {
edgeWeights: EdgeWeights,
nodeWeights: NodeWeights,
expanded: boolean,
};
export class WeightConfig extends React.Component<Props, State> {
@ -68,6 +68,7 @@ export class WeightConfig extends React.Component<Props, State> {
this.state = {
edgeWeights: defaultEdgeWeights(),
nodeWeights: defaultNodeWeights(),
expanded: false,
};
}
@ -90,23 +91,39 @@ export class WeightConfig extends React.Component<Props, State> {
}
render() {
const {expanded} = this.state;
return (
<div
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "space-between",
}}
>
<EdgeConfig
edgeWeights={this.state.edgeWeights}
onChange={(ew) => this.setState({edgeWeights: ew}, () => this.fire())}
/>
<NodeConfig
nodeWeights={this.state.nodeWeights}
onChange={(nw) => this.setState({nodeWeights: nw}, () => this.fire())}
/>
</div>
<React.Fragment>
<button
onClick={() => {
this.setState(({expanded}) => ({expanded: !expanded}));
}}
>
{expanded ? "Hide weight configuration" : "Show weight configuration"}
</button>
{expanded && (
<div
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "space-between",
}}
>
<EdgeConfig
edgeWeights={this.state.edgeWeights}
onChange={(ew) =>
this.setState({edgeWeights: ew}, () => this.fire())
}
/>
<NodeConfig
nodeWeights={this.state.nodeWeights}
onChange={(nw) =>
this.setState({nodeWeights: nw}, () => this.fire())
}
/>
</div>
)}
</React.Fragment>
);
}