Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Refactor Graph.defaultProps.id code into function #381

Merged
merged 11 commits into from
Nov 21, 2018

Conversation

valentijnnieman
Copy link
Contributor

The code for generating a random id in the Graph component's defaultProps was inline - causing trouble for R component generation. This PR factors the code out into it's own function, so that it is a little bit neater.

Copy link
Contributor

@rpkyle rpkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did the trick, package build was seamless; thanks for sharing these edits!

.toString(36)
.substring(2, 7),
/* eslint-enable no-magic-numbers */
id: generateId(),
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about multiple graphs in the same page? As-is they will all have the same id. Similar to when this was added to the dash-table.

@@ -69,6 +69,19 @@ export default class PlotlyGraph extends Component {
super(props);
this.bindEvents = this.bindEvents.bind(this);
this._hasPlotted = false;

this.props.id = this.props.id ? this.props.id : this.generateId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. A component should never override its props.

If using state, setProps or another approach brakes tests, maybe we need to dig and find if that is correct or incorrect behavior from either the test or sub-components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's wrong.

However, seeing as the test do indeed break, I'm not sure how to go from here. There are no sub-components, and the tests seem correct. Any help would be appreciated!

JSON.stringify(this.props.style) !== JSON.stringify(nextProps.style)
);
}

componentWillReceiveProps(nextProps) {
const idChanged = this.props.id !== nextProps.id;
const idChanged = this.state.id !== nextProps.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we pull the id from the state everywhere now, shouldn't we update the state to the new props.id value?

@chriddyp
Copy link
Member

Does the current code cause duplicate IDs (since it's in defaultProps instead of in runtime?). If so, then maybe this PR will fix #379?

@Marc-Andre-Rivet
Copy link
Contributor

@chriddyp You're right. @valentijnnieman There's a id: generatedId() again in graphDefaultProps, when it tries to validate at const id = props.id ? props.id : generateId(); won't it pick up that default and defeat the purpose of the check?

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above

@valentijnnieman
Copy link
Contributor Author

Does the current code cause duplicate IDs (since it's in defaultProps instead of in runtime?). If so, then maybe this PR will fix #379?

It does create duplicate IDs, although I'm not sure if that will fix #379, since the examples given there set the id of the graphs explicitly.

@valentijnnieman valentijnnieman merged commit d361ac3 into master Nov 21, 2018
@alexcjohnson alexcjohnson deleted the graph_default_id branch August 14, 2019 02:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants