Skip to content

SCSS and Legend Panel #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions src/components/containers/Section.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import CogMenu from './CogMenu';
import SubPanel from './SubPanel';
import React, {Component, cloneElement} from 'react';
import PropTypes from 'prop-types';
import {bem, icon} from '../../lib';
import {icon} from '../../lib';
import unpackPlotProps from '../../lib/unpackPlotProps';

const classNames = {
section: bem('section'),
sectionHeading: bem('section', 'heading'),
sectionCogMenu: `${bem('section', 'cog-menu')} ${icon('cog')}`,
};

function childIsVisible(child) {
return Boolean((child.props.plotProps || {}).isVisible);
}
Expand All @@ -19,7 +13,7 @@ class Section extends Component {
super(props, context);

this.children = null;
this.cogMenu = null;
this.subPanel = null;

this.processAndSetChildren(context);
}
Expand All @@ -35,48 +29,43 @@ class Section extends Component {
}

const attrChildren = [];
let cogMenu = null;
let subPanel = null;

for (let i = 0; i < children.length; i++) {
let child = children[i];
if (!child) {
continue;
}
if (child.type === CogMenu) {
// Process the first cogMenu. Ignore the rest.
if (cogMenu) {
if (child.type === SubPanel) {
// Process the first subPanel. Ignore the rest.
if (subPanel) {
continue;
}
cogMenu = child;
subPanel = child;
continue;
}

let isAttr = !!child.props.attr;
let plotProps = isAttr
? unpackPlotProps(child.props, context, child.constructor)
: {};
: {isVisible: true};
let childProps = Object.assign({plotProps}, child.props);
childProps.key = i;

attrChildren.push(cloneElement(child, childProps, child.children));
attrChildren.push(cloneElement(child, childProps));
}

this.children = attrChildren.length ? attrChildren : null;
this.cogMenu = cogMenu;
this.subPanel = subPanel;
}

render() {
const hasVisibleChildren = this.children.some(childIsVisible);

return hasVisibleChildren ? (
<div className={classNames.section}>
<div className={classNames.sectionHeading}>
<div className="section">
<div className="section__heading">
{this.props.name}
{this.cogMenu ? (
<span>
<i className={classNames.sectionCogMenu} />
</span>
) : null}
{this.subPanel}
</div>
{this.children}
</div>
Expand Down
20 changes: 19 additions & 1 deletion src/components/containers/__tests__/Section-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Section from '../Section';
import {Flaglist, Numeric} from '../../fields';
import {Flaglist, Info, Numeric} from '../../fields';
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
import {connectTraceToPlot} from '../../../lib';
import {mount} from 'enzyme';
Expand Down Expand Up @@ -47,6 +47,24 @@ describe('Section', () => {
).toBe(false);
});

fit('is visible if it contains any non attr children', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want this behavior? Seems kinda like you wouldn't want <Info> to be enough to invoke display, or maybe sometimes you do but not always?

⚠️ committed fit ⚠️ (you probably fixed this later... but at least in plotly.js we have a syntax test checking for fit et al in all test files)

Copy link
Member Author

Choose a reason for hiding this comment

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

yep I did catch that one. And yep we have the same test in the workspace. I'll make an issue for that right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

#57

Hmmm yeh I could see skipping <Info> actually. But not <MenuPanel>? Unless you interrogate the <Section>s inside <MenuPanel> ... but that would take some serious gymnastics...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah right, that's your caveat above. It might be worth thinking a bit about whether there really are any cases where only the <MenuPanel> exists to make a <Section> visible. If that's really "advanced settings" we might be able to argue that if none of the basics for that section exist, there's never a case where the advanced would be needed?

I'm not sure if any similar argument works for <Panel>. Would be worthwhile looking for a concrete example.

Copy link
Member Author

Choose a reason for hiding this comment

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

True I'll add this to an issue and deal with it once I have some breathing room

Copy link
Member Author

Choose a reason for hiding this comment

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

#58

const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<Section name="test-section">
<Info>INFO</Info>
</Section>
</TestEditor>
).find('[name="test-section"]');

expect(wrapper.children().length).toBe(1);
expect(wrapper.find(Info).exists()).toBe(true);
expect(wrapper.find(Info).text()).toBe('INFO');
});

it('is not visible if it contains no visible children', () => {
// pull and hole are not scatter attrs. Section should not show.
const wrapper = mount(
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/Info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Field from './Field';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import {bem} from '../../lib';

export default class Info extends Component {
render() {
Expand Down