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

Editor: Use TermTokenField to edit non-hierarchical CPT taxonomies #6348

Merged
merged 2 commits into from
Jun 30, 2016

Conversation

nylen
Copy link
Contributor

@nylen nylen commented Jun 27, 2016

This PR adds support for fetching and editing non-hierarchical terms using a TokenField. Adds a new TermTokenField component which is modeled after post-editor/editor-tags/index.jsx.

Planned future steps:

  • After Editor: Manage post title edits using global Redux state #5445 lands connecting the edited post to Redux state, get rid of the postTerms property in favor of getEditedPostValue( ..., 'terms' )
  • Use reduxified TermTreeSelector and TermTokenField in EditorCategoriesTagsAccordion to edit categories and tags, respectively. (This is why I renamed EditorTaxonomiesAccordion to EditorCategoriesTagsAccordion - I expect the logic there will still be used, but to render only categories and tags rather than all taxonomies.)
  • Use EditorDrawerTaxonomies to render all taxonomies, including tags and categories if present
  • Get rid of old code to edit categories and tags, including TagListData and CategoryListData components

To test

Edit a post of a custom type that has one or more non-hierarchical taxonomies. Ensure that existing taxonomies are loaded correctly in the TokenField:

  • values (terms assigned to the saved post)
  • suggestions (all terms from the site)

Ensure that terms can be updated and saved as expected.

Test live: https://calypso.live/?branch=update/editor/cpt-term-token-field

@nylen nylen added [Feature] Post/Page Editor The editor for editing posts and pages. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Custom Post Types (CPT) labels Jun 27, 2016
@nylen nylen self-assigned this Jun 27, 2016
</span>
<QueryTerms
siteId={ this.props.siteId }
taxonomy={ this.props.taxonomyName }
Copy link
Contributor

Choose a reason for hiding this comment

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

QueryTerms uses the default number of 100 per page for a query. I think in the old <TokenField/> looks like we are fetching 1,000 tags in the first request. Do we want to make a larger request here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does paging for these query components usally work? Will it initiate another page on its own, or is there an easy way to do that?

If not, then I agree we should go ahead and fetch 1,000 tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking through the code some more, it doesn't look like it. Pushed 0532210 to address this. I'm having trouble fully testing the fix due to /me/sites timing out but will try again tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

How does paging for these query components usally work?

Sorry missed this question earlier. Pagination so far has been implemented using react-virtualized/VirtualScroll seen here in conjunction with the 🔮 of QueryManager.

Currently we don't do any pagination in the TokenField correct? So I do think grabbing the large number of tags up-front is the way to go.

@timmyc
Copy link
Contributor

timmyc commented Jun 28, 2016

Confirmed that 100 tags are being loaded, I have up to "Tag100" and a few other random ones and not all of the Tag9x are showing up:

edit_project_ testingtimmy2_wordpress_com _wordpress_com

Guessing we want to do 1,000 just like post-tags, but not sure. Couple of other minor items above but looking great!

Use reduxified TermTreeSelector

I have that working locally and would be happy to add to this branch or wait for a follow-up PR.

@timmyc timmyc added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 28, 2016
@nylen nylen added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jun 28, 2016
@nylen
Copy link
Contributor Author

nylen commented Jun 28, 2016

Fine with me if you wanna push stuff up here too, it's one less link in the chain of PRs we have to wait on.

render() {
const termNames = ( this.props.terms || [] ).map( term => term.name );

const query = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this query is static, what do you think about putting it in TermsConstants in-lieu of a new const on each render?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, this also allowed me to use the query in the existing EditorTags component. Done in rebased 53a571b.

@timmyc
Copy link
Contributor

timmyc commented Jun 28, 2016

I'll follow up with another PR after this one lands. This is looking good to me. Left a few small comments above, but fine to merge as-is, or you can make changes if you please.

@timmyc timmyc added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 28, 2016
nylen added 2 commits June 28, 2016 16:08
This component will be used to render categories and/or tags, if
supported by the current post type.  The more generic
EditorDrawerTaxonomies will render all taxonomies.
@nylen nylen force-pushed the update/editor/cpt-term-token-field branch from 0532210 to 53a571b Compare June 28, 2016 21:08
number: module.exports.MAX_TAGS,
order_by: 'count',
order: 'DESC'
};
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 considered bringing this file up to date with ES6 but didn't want to also change the existing imports and usage in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't matter much here since I suspect this is a file we'll seek to eliminate altogether, but in general I don't think it's a big deal to mix import / export syntaxes. If anything, the eyesore will hasten follow-up 😄

@nylen nylen merged commit d98ba96 into master Jun 30, 2016
@nylen nylen deleted the update/editor/cpt-term-token-field branch June 30, 2016 17:45
}

render() {
const termNames = ( this.props.terms || [] ).map( term => term.name );
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm a bit Lodash obsessed, but the Lodash map implementation could simplify this a bit, removing the need for fallback array and callback function:

const termNames = map( this.props.terms, 'name' );

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'll incorporate this into #6548.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Custom Post Types (CPT) [Feature] Post/Page Editor The editor for editing posts and pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants