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

[Remove SitesList] Add isSiteCustomizable selector #13160

Merged
merged 10 commits into from
Apr 21, 2017

Conversation

Tug
Copy link
Contributor

@Tug Tug commented Apr 17, 2017

This PR creates the isSiteCustomizable() selector and update the getSite selector to use it instead of using getComputedAttribute. It also updates usages of isCustomizable() in components so we can remove Sites#isCustomizable() as well as the computed attribute site.is_customizable.

Testing Instructions

  • Checkout the branch locally
  • Run the tests (make test)
  • Run the app and check that you don't have access to Themes in the left sidebar when you don't have the permissions.

@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label Apr 17, 2017
@Tug Tug self-assigned this Apr 17, 2017
@Tug Tug force-pushed the update/site-is-customizable branch from b3b731f to 1bac497 Compare April 17, 2017 23:16
@Tug Tug added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Apr 17, 2017
@Tug Tug requested review from gwwar and dmsnell April 17, 2017 23:29
@@ -14,7 +14,7 @@ import {
some,
split,
includes,
startsWith,
startsWith
Copy link
Member

Choose a reason for hiding this comment

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

is this unintentional? seems like an unnecessary change…

let defaultPostFormat = getSiteOption( state, siteId, 'default_post_format' );
if ( ! defaultPostFormat || defaultPostFormat === '0' ) {
defaultPostFormat = 'standard';
}
Copy link
Member

Choose a reason for hiding this comment

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

tests like this are good reasons for normalizing data form the API on entry into Calypso. instead of scattering around the checks and converting everywhere the data is used it would be helpful if it never came into the system in the odd formats. that's a side-comment 😉

default_post_format: defaultPostFormat
};
}

Copy link
Member

Choose a reason for hiding this comment

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

I see that the other new selector is in the state/selectors directory but this one is being added to the existing file. do we need to move it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about that. isSiteCustomizable() can live on its own now, it's not a computed attribute, whereas options still is. We might want to change it later but I think it makes sense to have it alongside getSite for now

Copy link
Member

Choose a reason for hiding this comment

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

well we have been adding all new selectors to the selector directory. I should probably rephrase the question: is there a good reason why we aren't adding it to the selector directory instead?

Copy link
Contributor Author

@Tug Tug Apr 18, 2017

Choose a reason for hiding this comment

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

First, I don't feel strongly on this so if you really think this is a blocker I can simply move it to state/selectors.

My logic is that all the selectors used to assemble the site in the getSite selector currently lives in that file and I'm not sure we plan to even use this selector at all or if we will always just access options through the property of the site.
Whether we keep it as a computed property or not is probably a subject for another PR since I haven't started to update usage of site.options anywhere (and I'm not sure we should).

In the case of is_customizable, I was able to update all usage to use the new selector instead and removed it from the site computed properties, so it's definitely a valid/useful selector and this is why it was moved to state/selectors.

Copy link
Member

Choose a reason for hiding this comment

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

let's see if @aduth has an opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Having authored the yet-unmerged #10234, I tend to sway more on the extreme of forbidding new selectors outside state/selectors directory, regardless of any inconsistencies it might introduce (an expected and necessary pain of adopting a new recommendation).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's put everything new on state/selectors.

@Tug Tug force-pushed the update/site-is-customizable branch from 1bac497 to 08da6a7 Compare April 18, 2017 07:43
};
},
( state ) => state.sites.items
);

export function getSiteOptions( state, siteId ) {
Copy link
Member

Choose a reason for hiding this comment

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

Mmm, I actually don't think we should make this an exportable selector. It should only be used in getSite. Also probably the name of the function should be changed to reflect we are computing values and not just returning site.options.

@gwwar
Copy link
Contributor

gwwar commented Apr 18, 2017

Changes here look pretty reasonable 👍 Looks like this needs a rebase, ping me when it's ready and I can help smoke test.

@matticbot
Copy link
Contributor

@Tug This PR needs a rebase

@Tug Tug force-pushed the update/site-is-customizable branch from dc57fe6 to 158c8f0 Compare April 21, 2017 10:25
@Tug Tug changed the title [Remove SitesList] Add isSiteCustomizable and getSiteOptions selectors [Remove SitesList] Add isSiteCustomizable selector Apr 21, 2017
@Tug
Copy link
Contributor Author

Tug commented Apr 21, 2017

Rebased and renamed getSiteOptions() into computeSiteOptions().

@gziolo gziolo added [Status] Needs Author Reply [Status] Ready to Merge and removed [Status] Needs Rebase [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] Needs Author Reply labels Apr 21, 2017
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I haven't tested it, because I'm not sure when I shouldn't have access to themes.

@Tug
Copy link
Contributor Author

Tug commented Apr 21, 2017

I think you don't have access when you have any other role than "Administrator" on a site.

@Tug Tug merged commit d180acc into master Apr 21, 2017
@Tug Tug deleted the update/site-is-customizable branch April 21, 2017 11:39
mcsf added a commit that referenced this pull request Apr 26, 2017
…omizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.
mcsf added a commit that referenced this pull request May 2, 2017
…omizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.
mcsf added a commit that referenced this pull request May 8, 2017
…omizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.
mcsf added a commit that referenced this pull request May 9, 2017
…omizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.
mcsf added a commit that referenced this pull request May 9, 2017
)

* WIP Add QuerySites in Layout and shift from sitesFactory to Redux sites

* WIP more seek & destroy sites-list (Navigation, Picker, Sidebar)

* Tackle SitesList in my-sites/controller

* Use post-rebase selector areAllSitesSingleUser

* Selectors: getSite: support non-ID-based retrieval

In the process of removing SitesList, some instances are found of:

  sites.getSite( siteFragment )

where `siteFragment` is of mixed format. See lib/route/test.

* my-sites: controller: SITES_ONCE_CHANGED; no more sites.once

* Post-rebase fix

* Update CurrentSite and AllSites to use getSites.

* ES6ify SiteSelector

* AllSites: Use ES6-style defaultProps

* getSite: don't return false

* CurrentSite: Use ES6-style state initializer

* SiteSelector: Fix passing of `this` to `map`

Lodash's `map` doesn't support passing of `this` (anymore?).
Fixes TypeError.

* Appease linter

* Selectors: canManageSelectedOrAnySite, getSelectedOrAllSites

* Use getSelectedOrAllSites selector in current site block.

* Fix exports.

* Fix switch sites.

* Add isRequestingMissingSites selector.

* Resetting attributes creates a circular call with getRawSite

That means we end up passing a slug to getRawSite, which
fails, meaning computted attributes are not set.

* getSites: wrap with createSelector

* Add siteSearch HoC to replace sites.search in SiteSelector

* Remove sites-list from sites dropdown.

* Use getPrimarySiteId() selector

* CurrentSite: connect to redux; bind selector :(

* siteSelection: ensure siteID is numeric before firing setting actions

Adds `getSiteId` selector.

* Sites: use connect to provide selected site

* [DELETE AFTER 13121] PostsNavigation: connect to Redux

* rm selector canManageSelectedOrAnySite

* Revert "Merge pull request #13160 from Automattic/update/site-is-customizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.

* getSite: re-remove cyclical selector calls

* Stats: Controllers: Don't depend on sites-list

* Import was kept, as `sites` is passed as props in one controller. To
  be fixed in a separate PR.

* SitesDropdown: "fix" tests

* Avoid duplicate selector call, use `get`

* state/lib/middleware: better naming, comments

* siteSelection: fix redirs, wait for selected site's data

* Keep SitesList's `selected` in sync with Redux

- :-(

- Aims to fix regressions found, notably around flows in `/domains`

* siteSelect: immediately redirectToPrimary if data ready

This mimics the behavior that used to be in place with
`sites.initialized`. Without it, render jumps may happen as we default
to a site-less view then correct to a site-specific one.

* NavItem: fix propTypes (`count`)

Component logic expects non-number `count`, e.g. when no site is
selected. This eliminates React type warnings.

* Signup: fetchSitesAndUser: wait & load new site into Redux store

One of the async jobs of fetchSitesAndUser is to trigger a `fetch` on
`lib/sites-list`, wait for changes to that structure, check for the
local availability of data for the new site, then either continue or
retrigger a fetch.

This commit ports that behavior to our Redux data layer.

* Invites: Pull sites from server upon accepting

Before #13094, this behavior was ensured by the `acceptInvite` action
creator, which dispatches old Flux actions that `lib/sites-list` listens
to in order to call a `sync` on itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework [Size] XL Probably needs to be broken down into multiple smaller issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants