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

Framework: add schema for posts #3487

Merged
merged 1 commit into from
Mar 1, 2016
Merged

Framework: add schema for posts #3487

merged 1 commit into from
Mar 1, 2016

Conversation

gwwar
Copy link
Contributor

@gwwar gwwar commented Feb 23, 2016

This PR adds a schema for posts/items so we can avoid data shape changes as described in #3101.
posts/siteRequests and posts/queriesLastPage are not persisted, since this is mostly transient data.

Testing Instructions

  • Start Calypso with:
    ENABLE_FEATURES=persist-redux make run
  • In the console set localStorage.debug to calypso:state
  • Make sure that your blog has some pages
  • Navigate to the editor to add a new page
  • Click on Page Options to make sure we can see parent page options
    screen shot 2016-02-22 at 6 01 09 pm
  • Refresh the page.
  • The app behaves normally and loads the persisted state/posts/items from IndexedDB storage

To Validate that we can't get into an inconsistent state:

  • Add a non-existent required property to itemsSchema, like foo:
export const itemsSchema = {
    type: 'object',
    patternProperties: {
        '^[0-9a-z]+$': {
            type: 'object',
            required: [ 'ID', 'site_ID', 'global_ID', 'foo' ], //add a non-existent prop to test invalidations
            properties: {
                ID: { type: 'integer' },
                site_ID: { type: 'integer' },
                //...
            }
        }
    },
    additionalProperties: false
};
  • Navigate to the Editor
  • Refresh the page
  • You should see a console warning that validation failed
  • The Editor should load, and we should be able to see parent page options.

cc @aduth @rralian @artpi @retrofox @mtias

@gwwar gwwar added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 23, 2016
@gwwar gwwar self-assigned this Feb 23, 2016
@gwwar gwwar added this to the Calypso Core: Offline 5 milestone Feb 23, 2016
@@ -114,7 +147,7 @@ describe( 'reducer', () => {
}
} );
} );
it( 'never persists state because this is not implemented', () => {
it( 'never persists state', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we not persist this? Or at the very least, we could repopulate the mapping from the set of loaded posts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can persist this provided that the selectors can handle items and sitePosts potentially not being in sync. This is the same data consistency issue we saw in #3357, though this doesn't happen to trigger an error.

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'm going to take a bit of time to play with memoized selectors: http://redux.js.org/docs/recipes/ComputingDerivedData.html

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 created #3522 to address this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

posts.sitePosts were removed in #3602

@aduth aduth 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 Feb 23, 2016
@gwwar
Copy link
Contributor Author

gwwar commented Feb 27, 2016

@aduth I think posts.queries is also worth persisting but I'll spin up another PR to move fetching state to another subtree before I do so.

@gwwar gwwar 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 Feb 27, 2016
@@ -205,7 +238,7 @@ describe( 'reducer', () => {
} );
} );

it( 'never persists state because this is not implemented', () => {
it( 'never persists state', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Were these purposeful changes or did they just come in from your last PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, probably bad copy pasta. I'll clean this up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, or is it that these are things that should not be persisted (rather than just haven't been implemented yet), so the previous language wasn't quite accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to persist queries in the future, but not the other temporary fetch state, so posts/siteRequests and posts/queriesLastPage should not be persisted, while posts/queries will be in the future.

@rralian
Copy link
Contributor

rralian commented Feb 29, 2016

This looks good to me... had one question about changes to the description, and I'm also not sure about the schema being so restrictive as to disallow additionalProperties. I think that's probably a bigger discussion though and should not hold this up. 👍

@rralian rralian 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 Feb 29, 2016
@aduth
Copy link
Contributor

aduth commented Feb 29, 2016

@aduth I think posts.queries is also worth persisting but I'll spin up another PR to move fetching state to another subtree before I do so.

See #3671

@gwwar
Copy link
Contributor Author

gwwar commented Mar 1, 2016

Thanks for the reviews! I'll merge this in tomorrow morning.

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