Skip to content
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

NEW Edit tab click changes tab state #428

Merged

Conversation

raissanorth
Copy link
Contributor

Related issue:

Related PRs:

This is work in progress for the above issue. The related PRs connect Tabs to the redux-form store.

I would like some initial feedback on the approach taken. Since we are dispatching an action I am not sure if bubbling up the edit tab click from ElementActions to Element, saving the active tab in Element's local state and passing it down as a prop to InlineEditForm is the most elegant solution.

Outstanding work includes styling of the selected edit tab and cursor, as well as expanding the form on edit tab click.

@raissanorth raissanorth changed the title NEW Edit tab click changes tab state WIP NEW Edit tab click changes tab state Oct 3, 2018
Copy link
Contributor

@NightJar NightJar left a comment

Choose a reason for hiding this comment

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

The code looks good, although it could use a run over with a linter - there are a few extremely minor formatting issues around the place (to do with white space).

I can't help but think that this approach is a bad form of coupling though - e.g. There's no away an Element should be concerned with which tab is currently active - and even if it should be, to which Tabs component does it refer?

I feel like this is caught between a rock and a hard place in that the majority of controls we should like to affect are nested within the scaffolding component (FormBuilderLoader) - but as we discussed in person this PR is good to get a discussion going around the approach.

Perhaps there is a way to leverage the SilverStripe javascript Injector to wrap a higher order component around the Tabs component in this context, hooking it up to a redux reducer we control (as opposed to reduxform) in order to handle receiving the active tab value from an event dispatched directly to it (from wherever else that may be in hierarchy - where at the moment it's very coupled to the tree hierarchy presented in this PR).

I don't block this from a merge though, it can meet MVP and be followed up later in dealing with technical debt.

What are everyone else's thoughts?

/**
* Set the active tab
*
* @param activeTab
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing type

@@ -48,7 +48,7 @@ class ElementList extends Component {
}

return blocks.map((element) => (
<div>
<div key={element.ID}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about whether giving it the same key as its child element might cause rendering issues... I don't know enough about how this works in React though

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case I think we can remove the key from the child component. I'm not 100% on this either but I'm pretty sure it's only used for the top level dom elements within a loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually can we just remove that div? It doesn't seem to serve any purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Adjacent JSX elements must be wrapped in an enclosing tag" 😉


const sectionKey = 'DNADesign\\Elemental\\Controllers\\ElementalAreaController';
const section = Config.getSection(sectionKey);
const formNameTemplate = section.form.elementForm.formNameTemplate;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use loadElementSchemaValue('formNameTemplate') for this (see client/src/state/editor/loadElementSchemaValue.js)


/**
* Update the active tab on tab actions menu button click event.
* @param event onChangeEvent from a input field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing prevProps declaration

@raissanorth raissanorth force-pushed the pulls/4.0/tabby-the-cat branch 2 times, most recently from 646328f to 88a491a Compare October 8, 2018 01:25
@raissanorth raissanorth changed the title WIP NEW Edit tab click changes tab state NEW Edit tab click changes tab state Oct 8, 2018
@raissanorth raissanorth force-pushed the pulls/4.0/tabby-the-cat branch 4 times, most recently from 6d68844 to 09b2f63 Compare October 8, 2018 04:07
Copy link
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

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

Looking really awesome. Been pretty nit-picky - I just want to know if we can avoid adding redux-form as a dependancy.

onClick={(event) => event.stopPropagation()
}
>
<ElementActionsComponent {...this.props} /></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this wrapping div doing? The </div> should be a on a new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It allows to ignore the button press on the divider tab item.

// {@see Tabs.getDefaultActiveKey}
const filterFieldsForTabs = (field) => field.component === 'Tabs';
const defaultValue = state.form.formSchemas[elementFormSchema].schema.fields
.filter(filterFieldsForTabs)[0].children[0].name;
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use find instead of filter here. Also, it'd probably be good to defensively program in for the possibility there's no tabs - although admittedly there's probably some work to do elsewhere for this...

@@ -48,7 +48,7 @@ class ElementList extends Component {
}

return blocks.map((element) => (
<div>
<div key={element.ID}>
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case I think we can remove the key from the child component. I'm not 100% on this either but I'm pretty sure it's only used for the top level dom elements within a loop.

@raissanorth raissanorth force-pushed the pulls/4.0/tabby-the-cat branch from 09b2f63 to 552e989 Compare October 9, 2018 22:04
@raissanorth raissanorth force-pushed the pulls/4.0/tabby-the-cat branch from 552e989 to 5632e26 Compare October 9, 2018 22:15
@raissanorth raissanorth force-pushed the pulls/4.0/tabby-the-cat branch from 5632e26 to b9898ef Compare October 9, 2018 23:22
@ScopeyNZ ScopeyNZ merged commit 600451b into silverstripe:master Oct 9, 2018
@NightJar NightJar deleted the pulls/4.0/tabby-the-cat branch October 10, 2018 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants