Add descriptions for EdgeTypes (#1074)

* Add descriptions for EdgeTypes

* Displays edge and node description tooltip in weight configuration UI

* Update tests
This commit is contained in:
Ana Noemi 2019-01-30 15:48:22 -05:00 committed by GitHub
parent 072e2953a3
commit 1e78437f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 38 additions and 3 deletions

View File

@ -23,6 +23,8 @@ export const fallbackEdgeType: EdgeType = Object.freeze({
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: EdgeAddress.empty, prefix: EdgeAddress.empty,
description:
"The fallback EdgeType for edges which don't have any other type",
}); });
export const fallbackDeclaration: PluginDeclaration = Object.freeze({ export const fallbackDeclaration: PluginDeclaration = Object.freeze({

View File

@ -96,4 +96,7 @@ export type EdgeType = {|
// of this EdgeType. A given edge `e` is a member of the type `t` if // of this EdgeType. A given edge `e` is a member of the type `t` if
// `EdgeAddress.hasPrefix(e.address, t.prefix) == true` // `EdgeAddress.hasPrefix(e.address, t.prefix) == true`
+prefix: EdgeAddressT, +prefix: EdgeAddressT,
// The `description` property should be a human-readable string that makes
// it clear to a user what each EdgeType does
+description: string,
|}; |};

View File

@ -157,6 +157,7 @@ describe("explorer/pagerankTable/Aggregation", () => {
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: EdgeAddress.fromParts(["look", "like"]), prefix: EdgeAddress.fromParts(["look", "like"]),
description: "TODO: Add a description for this EdgeType",
}; };
function aggView(aggregation: FlatAggregation) { function aggView(aggregation: FlatAggregation) {
const el = shallow(<AggregationView aggregation={aggregation} />); const el = shallow(<AggregationView aggregation={aggregation} />);

View File

@ -66,6 +66,7 @@ describe("explorer/pagerankTable/aggregate", () => {
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: EdgeAddress.fromParts(["foo"]), prefix: EdgeAddress.fromParts(["foo"]),
description: "TODO: Add a description for this EdgeType",
}, },
bar: { bar: {
forwardName: "bars", forwardName: "bars",
@ -73,6 +74,7 @@ describe("explorer/pagerankTable/aggregate", () => {
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: EdgeAddress.fromParts(["bar"]), prefix: EdgeAddress.fromParts(["bar"]),
description: "TODO: Add a description for this EdgeType",
}, },
empty: { empty: {
forwardName: "empty", forwardName: "empty",
@ -80,6 +82,7 @@ describe("explorer/pagerankTable/aggregate", () => {
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: EdgeAddress.empty, prefix: EdgeAddress.empty,
description: "TODO: Add a description for this EdgeType",
}, },
}; };
const edgeTypesArray = [edgeTypes.foo, edgeTypes.bar]; const edgeTypesArray = [edgeTypes.foo, edgeTypes.bar];

View File

@ -15,6 +15,7 @@ export class EdgeTypeConfig extends React.Component<{
<EdgeWeightSlider <EdgeWeightSlider
name={this.props.weightedType.type.backwardName} name={this.props.weightedType.type.backwardName}
weight={this.props.weightedType.forwardWeight} weight={this.props.weightedType.forwardWeight}
description={this.props.weightedType.type.description}
onChange={(forwardWeight) => { onChange={(forwardWeight) => {
this.props.onChange({ this.props.onChange({
...this.props.weightedType, ...this.props.weightedType,
@ -25,6 +26,7 @@ export class EdgeTypeConfig extends React.Component<{
<EdgeWeightSlider <EdgeWeightSlider
name={this.props.weightedType.type.forwardName} name={this.props.weightedType.type.forwardName}
weight={this.props.weightedType.backwardWeight} weight={this.props.weightedType.backwardWeight}
description={this.props.weightedType.type.description}
onChange={(backwardWeight) => { onChange={(backwardWeight) => {
this.props.onChange({ this.props.onChange({
...this.props.weightedType, ...this.props.weightedType,
@ -57,6 +59,7 @@ export class EdgeWeightSlider extends React.Component<WeightSliderProps> {
<WeightSlider <WeightSlider
name={modifiedName} name={modifiedName}
weight={this.props.weight} weight={this.props.weight}
description={this.props.description}
onChange={this.props.onChange} onChange={this.props.onChange}
/> />
); );

View File

@ -54,7 +54,12 @@ describe("explorer/weights/EdgeTypeConfig", () => {
function example() { function example() {
const onChange = jest.fn(); const onChange = jest.fn();
const element = shallow( const element = shallow(
<EdgeWeightSlider weight={3} name="foo" onChange={onChange} /> <EdgeWeightSlider
weight={3}
name="foo"
description="Description for test slider"
onChange={onChange}
/>
); );
const weightSlider = element.find(WeightSlider); const weightSlider = element.find(WeightSlider);
return {element, onChange, weightSlider}; return {element, onChange, weightSlider};

View File

@ -13,6 +13,7 @@ export class NodeTypeConfig extends React.Component<{
<WeightSlider <WeightSlider
name={this.props.weightedType.type.name} name={this.props.weightedType.type.name}
weight={this.props.weightedType.weight} weight={this.props.weightedType.weight}
description={this.props.weightedType.type.description}
onChange={(weight) => { onChange={(weight) => {
this.props.onChange({ this.props.onChange({
...this.props.weightedType, ...this.props.weightedType,

View File

@ -6,11 +6,12 @@ export type Props = {|
+weight: number, +weight: number,
+name: React$Node, +name: React$Node,
+onChange: (number) => void, +onChange: (number) => void,
+description: string,
|}; |};
export class WeightSlider extends React.Component<Props> { export class WeightSlider extends React.Component<Props> {
render() { render() {
return ( return (
<label style={{display: "flex"}}> <label style={{display: "flex"}} title={this.props.description}>
<span style={{flexGrow: 1}}>{this.props.name}</span> <span style={{flexGrow: 1}}>{this.props.name}</span>
<input <input
type="range" type="range"

View File

@ -12,7 +12,12 @@ describe("explorer/weights/WeightSlider", () => {
function example() { function example() {
const onChange = jest.fn(); const onChange = jest.fn();
const element = shallow( const element = shallow(
<WeightSlider weight={3} name="foo" onChange={onChange} /> <WeightSlider
weight={3}
name="foo"
description="Description for test slider"
onChange={onChange}
/>
); );
return {element, onChange}; return {element, onChange};
} }

View File

@ -28,6 +28,7 @@ export const assemblesEdgeType: EdgeType = Object.freeze({
backwardName: "is assembled by", backwardName: "is assembled by",
defaultBackwardWeight: 2 ** -2, defaultBackwardWeight: 2 ** -2,
prefix: EdgeAddress.fromParts(["factorio", "assembles"]), prefix: EdgeAddress.fromParts(["factorio", "assembles"]),
description: "TODO: Add a description for this EdgeType",
}); });
export const transportsEdgeType: EdgeType = Object.freeze({ export const transportsEdgeType: EdgeType = Object.freeze({
@ -36,6 +37,7 @@ export const transportsEdgeType: EdgeType = Object.freeze({
backwardName: "is transported by", backwardName: "is transported by",
defaultBackwardWeight: 2 ** -1, defaultBackwardWeight: 2 ** -1,
prefix: EdgeAddress.fromParts(["factorio", "transports"]), prefix: EdgeAddress.fromParts(["factorio", "transports"]),
description: "TODO: Add a description for this EdgeType",
}); });
export const declaration: PluginDeclaration = Object.freeze({ export const declaration: PluginDeclaration = Object.freeze({

View File

@ -19,6 +19,7 @@ const hasParentEdgeType = Object.freeze({
prefix: E.Prefix.hasParent, prefix: E.Prefix.hasParent,
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
description: "TODO: Add a description for this EdgeType",
}); });
const nodeTypes = Object.freeze([commitNodeType]); const nodeTypes = Object.freeze([commitNodeType]);

View File

@ -76,6 +76,7 @@ const authorsEdgeType = Object.freeze({
defaultForwardWeight: 1 / 2, defaultForwardWeight: 1 / 2,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: E.Prefix.authors, prefix: E.Prefix.authors,
description: "TODO: Add a description for this EdgeType",
}); });
const hasParentEdgeType = Object.freeze({ const hasParentEdgeType = Object.freeze({
@ -84,6 +85,7 @@ const hasParentEdgeType = Object.freeze({
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1 / 4, defaultBackwardWeight: 1 / 4,
prefix: E.Prefix.hasParent, prefix: E.Prefix.hasParent,
description: "TODO: Add a description for this EdgeType",
}); });
const mergedAsEdgeType = Object.freeze({ const mergedAsEdgeType = Object.freeze({
@ -92,6 +94,7 @@ const mergedAsEdgeType = Object.freeze({
defaultForwardWeight: 1 / 2, defaultForwardWeight: 1 / 2,
defaultBackwardWeight: 1, defaultBackwardWeight: 1,
prefix: E.Prefix.mergedAs, prefix: E.Prefix.mergedAs,
description: "TODO: Add a description for this EdgeType",
}); });
const referencesEdgeType = Object.freeze({ const referencesEdgeType = Object.freeze({
@ -100,6 +103,7 @@ const referencesEdgeType = Object.freeze({
defaultForwardWeight: 1, defaultForwardWeight: 1,
defaultBackwardWeight: 1 / 16, defaultBackwardWeight: 1 / 16,
prefix: E.Prefix.references, prefix: E.Prefix.references,
description: "TODO: Add a description for this EdgeType",
}); });
const mentionsAuthorEdgeType = Object.freeze({ const mentionsAuthorEdgeType = Object.freeze({
@ -109,6 +113,7 @@ const mentionsAuthorEdgeType = Object.freeze({
// TODO(#811): Probably change this to 0 // TODO(#811): Probably change this to 0
defaultBackwardWeight: 1 / 32, defaultBackwardWeight: 1 / 32,
prefix: E.Prefix.mentionsAuthor, prefix: E.Prefix.mentionsAuthor,
description: "TODO: Add a description for this EdgeType",
}); });
const reactsHeartEdgeType = Object.freeze({ const reactsHeartEdgeType = Object.freeze({
@ -118,6 +123,7 @@ const reactsHeartEdgeType = Object.freeze({
// TODO(#811): Probably change this to 0 // TODO(#811): Probably change this to 0
defaultBackwardWeight: 1 / 32, defaultBackwardWeight: 1 / 32,
prefix: E.Prefix.reactsHeart, prefix: E.Prefix.reactsHeart,
description: "TODO: Add a description for this EdgeType",
}); });
const reactsThumbsUpEdgeType = Object.freeze({ const reactsThumbsUpEdgeType = Object.freeze({
@ -127,6 +133,7 @@ const reactsThumbsUpEdgeType = Object.freeze({
// TODO(#811): Probably change this to 0 // TODO(#811): Probably change this to 0
defaultBackwardWeight: 1 / 32, defaultBackwardWeight: 1 / 32,
prefix: E.Prefix.reactsThumbsUp, prefix: E.Prefix.reactsThumbsUp,
description: "TODO: Add a description for this EdgeType",
}); });
const reactsHoorayEdgeType = Object.freeze({ const reactsHoorayEdgeType = Object.freeze({
@ -136,6 +143,7 @@ const reactsHoorayEdgeType = Object.freeze({
// TODO(#811): Probably change this to 0 // TODO(#811): Probably change this to 0
defaultBackwardWeight: 1 / 32, defaultBackwardWeight: 1 / 32,
prefix: E.Prefix.reactsHooray, prefix: E.Prefix.reactsHooray,
description: "TODO: Add a description for this EdgeType",
}); });
const reactsRocketEdgeType = Object.freeze({ const reactsRocketEdgeType = Object.freeze({