Skip to content

Test section visibility #47

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 62 commits into from
Nov 13, 2017
Merged

Test section visibility #47

merged 62 commits into from
Nov 13, 2017

Conversation

bpostlethwaite
Copy link
Member

@bpostlethwaite bpostlethwaite commented Nov 4, 2017

@alexcjohnson this PR tests <Section>. During testing I realized that we presumed our UI Fields like <Numeric> always had access to traceIndex and fullTraceIndex which was only the case when they were nested within a TraceAccordion.

I factored out findFullTraceIndex from <TraceAccordion> and now each widget (via unpackPlotProps) checks its context and props for traceIndex and fullTraceIndex and will also compute fullTraceIndex if it has to. This means users should not have to worry about fullTraceIndex at all.

I built up the test fixture libs a little more. Factoring out the derefencing logic into its own function (and porting over the more robust Workspace object walkers) from Hub.js allows us to toggle between referenced and dereferenced fixtures with a config flag.

Next PR will add more robust handling of PlotSchema.

We need both traceIndex and fullTraceIndex within each field so that
unpackPlotProps can properly compute the derived plots from
fullData. Before this commit only TraceAccordion new how to generate
fullTraceIndex which meant it was difficult to test or use a data
field widget outside of the TraceAccordion.

This commit adds functionality to unpackPlotProps such that it checks
if the traceIndex is input either by context OR props and if
fullDataIndex is also passed in. If it is not it computes it using the
factored out function. This behaviour still happens in traceAccordion
as it can do the computation once for all of its children (all fields
point to the single trace)
Factor out dereferencing from Hub so it can be used elsewhere. Use
Workspace WalkObject (code copy) and accompanying tests.
@bpostlethwaite
Copy link
Member Author

bpostlethwaite commented Nov 5, 2017

wait I just thought of something. Maybe the Data Attr Fields (via connectToPlot/Section and unpackPlotProps) should expect that traceIndex and fullDataIndex come from Context. Then instead of an API that requires nesting a Data Attr Field inside a TraceAccordion or manually receiving the traceIndex Prop we can create a new wrapper component called <Trace> which takes a traceIndex and/or fullTraceIndex (it'll compute the fullTraceIndex if it isn't passed in) which will pass the indexes down as context from it onward.

This matches the proposed <Layout> wrapper so that the nested machinery knows which container to target.

<PlotlyEditor>
    <Panel name="create">
        <Trace traceIndex={0}>
            <Section name="data">
                <DataSelector attr="x" />
            </Section>
        </Trace>
    </Panel>
    <Panel name="axis">
        <Layout>
            <Axis axis="xaxis">
                <Section name="range">
                    <Toggle attr="log" />
                </Section>
            </Axis>
        </Layout>
    </Panel>
</PlotlyEditor>

(Axis stuff just pseudo API...)

So Widgets will need to be nested inside either a Layout or a Trace or they will throw an error. <TraceAccordion> will then automatically generate <Trace> wrappers for every trace in gd.data. As such <TraceAccordion> will be less magical and serve as an example on how to construct other variants of linking widgets to traces.

I think I will implement this stuff in this PR so let's hold off on the review.

New <Trace> component will inject traceIndex and fullTraceIndex into
context for child components to access. It will also eventually
configure something that will be able to discern between targeting
gd.data vs gd.layout. Probably something like "container" or "attrRoot"
@bpostlethwaite
Copy link
Member Author

Okay all that took was factoring out TracePanel from TraceAccordion.js. Now <Trace> can set the attr root as gd.data and we can create a <Layout> element that will set the attr root as gd.layout. This is nice and extensible as we will be able to create other containers that send things to frames etc. This might come in handy for simplifying how breakpoints work.

@bpostlethwaite
Copy link
Member Author

ready for review

naive direct lookups do not account for various exceptions and edge cases
we present users with "area" as "scatter + fill"
This component API uses information about which gd container it
targets to further specify handlers and data passed down to lower
level components
We may need to use an array but it will involve complexity when
working with generic updates from Layout. Remove for now until we know
we need it.
<Trace> mixed logic with structure. We aim to present a structural
component API for declaring the structure of the UI. This should be
independent of the logical connections to Plotly.js. Now we can pair
connectTraceToPlot with <Fold> or <Section> or even <Panel>
This more closely approximates the way different layers must be
linked together.
The Layout component is now whatever connectToLayout(<Container>) is
necessary

it('accepts array index notation', () => {
test(['foo', 'bar', [3], 'value'], 'foo.bar[3].value');
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure, I lifted this thing from the workspace. The walker is useful, the array notation probably not. In future incarnations I imagine we will not actually use this thing. Also the whole makeAttrsetterPath function is used in the workspace but you told me about nestedProperty({}, attrPath).path or whatever it is which makes this whole function redundant. I'll probably delete it.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Looks great, really nice tests. One question about makeAttrSetterPath behavior, unless it has some purpose I'm not seeing I'd reduce to one way of providing an array index. But I won't hold it up for that.

I really like putting traceIndex etc into context - seems like it will extend well to other item selections (maybe you already have this in other PRs even) like annotations, axes, updatemenus[ buttons]...

💃

@bpostlethwaite
Copy link
Member Author

Yup plenty more context usage ahead! I'm sorta stuck on the <Axes> API - a couple possibilities. Perhaps we can ☎️ on it soon.

@bpostlethwaite bpostlethwaite merged commit 03e69a9 into develop Nov 13, 2017
@bpostlethwaite bpostlethwaite deleted the TestSectionVisibility branch November 13, 2017 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants