Skip to content

Conversation

danrosenthal
Copy link

Addresses #785.

@BPScott BPScott temporarily deployed to polaris-react-pr-803 December 21, 2018 13:50 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 December 21, 2018 13:56 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 December 21, 2018 14:01 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 December 21, 2018 14:16 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 December 21, 2018 17:32 Inactive
Copy link
Author

@danrosenthal danrosenthal left a comment

Choose a reason for hiding this comment

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

I'm noticing an issue where TypeScript yells at me for polaris and context being missing from ContextualSaveBar props in tests. Possibly related, I have to pull polaris and context out of this.props in ContextualSaveBar lifecycle methods. Anyone understand what is going on here?

Copy link
Author

@danrosenthal danrosenthal left a comment

Choose a reason for hiding this comment

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

Also feeling a little weird about putting everything onto a context object in props. @AndrewMusgrave can you explain the thinking behind this a bit? Does this feel right to you to keep as a pattern?

@AndrewMusgrave AndrewMusgrave self-requested a review January 2, 2019 16:02
@dleroux
Copy link
Contributor

dleroux commented Jan 2, 2019

I believe the Toast tests will need to be updated with the Provider just like you did for the ContextualSavebar. Same with Loading. Looks like similar tests in ContextualSaveBar are passing because they've been updating with the right context.

@danrosenthal
Copy link
Author

Looks like the typing issue was to do with using the wrong version of TS in VSCode. So that problem is resolved. @dleroux this is still a WIP, so I haven't updated the other tests yet. Those tests failing was expected.

@AndrewMusgrave
Copy link
Member

Looks like the typing issue was to do with using the wrong version of TS in VSCode. So that problem is resolved. @dleroux this is still a WIP, so I haven't updated the other tests yet. Those tests failing was expected.

Seems there is an issue with compose returns the type with context in TS v.3.2.2. 🔥 C should fix it.

Also feeling a little weird about putting everything onto a context object in props. @AndrewMusgrave can you explain the thinking behind this a bit? Does this feel right to you to keep as a pattern?

I think this will be ok to keep as a pattern. Rather than directly using a render prop this'll allow us to keep our render logic cleaner and force similar implementations across context usage. If we decide to change something in the future we'll only have to change it in the HoC. And this'll allow us to use the same injector pattern we're familiar with (e.g. withAppProvider, withSticky).

I decided to call the prop context to keep it consistent with old react context (this.context). Although this can definitely be changed.

It's a very common pattern to pass context down as props, it's just not normally called context. You'll see it in most major libraries, for example redux, react-router, apollo, etc.

@danrosenthal
Copy link
Author

That rationale makes sense to me @AndrewMusgrave. Would you see us moving polaris context under the context object once we refactor AppProvider to use the new context API?

@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 15:54 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 16:05 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 17:12 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 17:47 Inactive
@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from bce98c3 to 186d479 Compare January 3, 2019 17:55
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 17:55 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 17:56 Inactive
@danrosenthal danrosenthal changed the title [WIP] Refactor legacy frame context [Frame] Refactor to use createContext API Jan 3, 2019
@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from d0a78a2 to db45545 Compare January 3, 2019 17:58
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 3, 2019 17:58 Inactive
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

I left a few comments, and we'll probably want to squash the commits but it's looking good!

Would you see us moving polaris context under the context object once we refactor AppProvider to use the new context API?

It definitely could live there but it seems we currently use it for more app level utilities and configuration. We originally moved properties inside polaris, like easdk for example to namespace it. So we would be losing that.

};
contextualSaveBar.setProps({...newProps});
expect(frame.setContextualSaveBar).toHaveBeenCalledWith({
frame.setProps({
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why do we need to setProps on frame now?

Copy link
Author

Choose a reason for hiding this comment

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

This is an alternative to mounting and unmounting the child component, since we no longer have direct access to the child component. Calling setProps on Frame with children that have new props triggers the componentDidUpdate lifecycle method for those children.

@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from db45545 to 876a8f2 Compare January 7, 2019 17:25
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 7, 2019 17:26 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 7, 2019 20:49 Inactive
@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from 7da2a27 to c43b6e1 Compare January 7, 2019 20:50
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 7, 2019 20:50 Inactive
@BPScott
Copy link
Member

BPScott commented Jan 7, 2019

Seems there is an issue with compose returns the type with context in TS v.3.2.2. 🔥 C should fix it.

Would you be able to fire up a PR for this? Telling people to stick with TS 3.1.x is a bit rubbish

@lemonmade
Copy link
Member

I took a little stab at improving the typing of decorators, I think having the following types should allow you to grab just the static types on the decorated component:

type StaticFields<Object> = {
  [Key in keyof Object]: Key extends 'prototype' ? never : Key
}[keyof Object];
type Statics<Object> = Pick<Object, StaticFields<Object>>;

// Example
class MyComponent extends React.Component {
  static foo = 'bar';
  static Baz(qux: string) {
    return <div>{qux}</div>;
  }

  render() {
    return null;
  }
}

type StaticMembers = Statics<typeof MyComponent>; // {foo: string; Baz: () => JSX.Element}

@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from c43b6e1 to 28a8bbe Compare January 11, 2019 15:52
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 11, 2019 15:53 Inactive
@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from 28a8bbe to e135bdf Compare January 11, 2019 15:55
@BPScott BPScott temporarily deployed to polaris-react-pr-803 January 11, 2019 15:55 Inactive
@danrosenthal
Copy link
Author

@dleroux, @AndrewMusgrave, @tmlayton this is ready for another look

Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

LGTM 👍

onDismiss(): void;
}

export interface ToastID {
Copy link
Member

Choose a reason for hiding this comment

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

We use the {id: string} interface a lot. Maybe it would be worth it to bring this out to the main type file and name it ID?

@danrosenthal
Copy link
Author

@lemonmade is the Apollo issue preventing Provider/Consumer components at the Frame level no longer blocking this PR merging?

@lemonmade
Copy link
Member

Yes, we've shipped and reverted the Apollo upgrade several times so we are getting close, but it is currently blocking.

@tmlayton
Copy link
Contributor

Want to create a 4.0 branch and target it with this PR?

@danrosenthal danrosenthal changed the base branch from master to version-4.0.0 January 18, 2019 16:02
@danrosenthal danrosenthal force-pushed the refactor-legacy-frame-context branch from e135bdf to 6409c60 Compare January 18, 2019 16:18
@danrosenthal danrosenthal added the 🤖Skip Changelog Causes CI to ignore changelog update check. label Jan 18, 2019
@danrosenthal danrosenthal merged commit 81a69e9 into version-4.0.0 Jan 18, 2019
@danrosenthal danrosenthal deleted the refactor-legacy-frame-context branch January 18, 2019 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖Skip Changelog Causes CI to ignore changelog update check.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants