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

Themes: Remove ThemesHelpers.getSlugFromName #1628

Merged
merged 2 commits into from
Dec 15, 2015

Conversation

sirbrillig
Copy link
Member

It is not possible to reliably determine the theme slug from its name, particularly around the usage of spaces and hyphens (eg: big-brother, twentythirteen). It is much more reliable to include the theme slug with the data provided to theme selection components.

Testing

Make sure the signup flows work: http://calypso.localhost:3000/start, http://calypso.localhost:3000/start/dss

That is, there are no JS errors, the site is correctly created, and the site has the chosen theme.

It is not possible to reliably determine the theme slug from its name,
particularly around the usage of spaces and hyphens. It is much more reliable to
use include the theme slug with the data provided to theme selection components.
@sirbrillig sirbrillig added [Feature Group] Appearance & Themes Features related to the appearance of sites. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 15, 2015
@sirbrillig sirbrillig self-assigned this Dec 15, 2015
{ name: 'Twenty Fifteen', slug: 'twentyfifteen' },
{ name: 'Sequential', slug: 'sequential' },
{ name: 'Colinear', slug: 'colinear' },
{ name: 'Edin', slug: 'edin' },
Copy link
Contributor

Choose a reason for hiding this comment

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

These are different from the old ones -- any reason for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ones we were using were actually being passed in as props, but they were static, so I see no reason not to just put them here instead of in steps.js

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, scrolled over steps.js too quickly :-p

@sirbrillig
Copy link
Member Author

Also worth noting that even though I updated it here, ThemeThumbnail is not used in the codebase anywhere anymore.

@ockham
Copy link
Contributor

ockham commented Dec 15, 2015

Also worth noting that even though I updated it here, ThemeThumbnail is not used in the codebase anywhere anymore.

Yeah, would be cool if the Theme component was used here. (Or ThemesList, if possible.)

@ockham
Copy link
Contributor

ockham commented Dec 15, 2015

CC'ing @kwight since I think this affects code written by you :-)

@sirbrillig
Copy link
Member Author

Yeah, would be cool if the Theme component was used here. (Or ThemesList, if possible.)

There's a trial working on that at the moment, so we've postponed it until he's done (at least for now or until DSS is activated permanently).

@ockham
Copy link
Contributor

ockham commented Dec 15, 2015

LGTM

propTypes: {
themeName: React.PropTypes.string.isRequired,
themeSlug: React.PropTypes.string.isRequired,
},
Copy link
Member

Choose a reason for hiding this comment

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

Why not just pass theme as the only prop? It'd make it more consistent with the changes in other files, and we could replace the above with

propTypes: {
  theme: React.PropTypes.Shape( {
    name: React.PropTypes.string.isRequired,
    slug: React.PropTypes.string.isRequired
  } ).isRequired
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooooh. I didn't know about PropType.Shape. I figured it's good to split them up so it's explicit what is required by this component, but Shape might change that. I'll look into it.

@kwight
Copy link
Contributor

kwight commented Dec 15, 2015

This just feels like a lateral move; we remove a function, but now require two pieces of data (and more complex data structure) to get the same result. It just makes me think again that what we really want is an endpoint that can take a name, eg. GET /v1.1/themes/?name=Twenty+Fifteen.

It all works well though, so I'm good with it for now 👍

@kwight
Copy link
Contributor

kwight commented Dec 15, 2015

Or, I guess the simpler inverse is using GET /v1.1/themes/<slug> to get the name.

@kwight kwight 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 Dec 15, 2015
@sirbrillig
Copy link
Member Author

@kwight it is certainly possible to use the API even now to get the theme name, but I think a better approach (since that data could be useful elsewhere and because 1 API request is probably faster than 9) would be to pull a list of all available themes from the API and keep it in a Store as soon as Calypso loads. Then we would have the ability to query that store to get the theme slug for a theme name or vice versa. We'd also be able to validate themes, get screenshot URLs without having to build them, etc.

That said, I think adding all that infrastructure is maybe beyond the scope here, and there's already a ThemesStore available. From what I was able to tell, though, that Store isn't populated by the time the signup flow loads, and I haven't dug into it enough to determine A) what action is required to populate it, and B) how to delay the signup process until it finished loading.

It seems to me that if all we're trying to do with the API here is get the theme slug for the theme name, and we're entering the theme names manually anyway, why not enter the theme slugs too? However, I don't want to increase complexity needlessly, only if there's a problem that needs fixing, and I think that getSlugFromName doesn't do what it's supposed to do.

my thought was: "getSlugFromName is being used all over the place as if it's 100% accurate. It's not, so let's remove it until we can make it work right (and even then it won't be a helper, it will be using Actions and a Store and will have to be async, meaning the code has to be quite different)"

sirbrillig added a commit that referenced this pull request Dec 15, 2015
Signup: Themes: Remove ThemesHelpers.getSlugFromName
@sirbrillig sirbrillig merged commit b30c0b3 into master Dec 15, 2015
@sirbrillig sirbrillig deleted the remove/themes-helper-get-slug branch December 15, 2015 22:54
@ockham
Copy link
Contributor

ockham commented Dec 15, 2015

and there's already a ThemesStore available

Quick follow-up, don't use any themes related Flux stores, we're in the middle of migrating to Redux altogether, so they're going away soon (#840 #1363).

@oskosk oskosk mentioned this pull request Dec 15, 2015
10 tasks
@kwight
Copy link
Contributor

kwight commented Dec 15, 2015

@ockham Thanks; I'm sure those will be taken care of before we're at a point of needing to move on store stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Appearance & Themes Features related to the appearance of sites.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants