Merge pull request #1503 from Shopify/rli-dep-hoc

[v4][ResourceList.Item] Remove withContext
This commit is contained in:
Andrew Musgrave
2019-05-28 14:23:59 -04:00
committed by GitHub
2 changed files with 11 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Upgraded the `Autocomplete` component from legacy context API to use createContext ([#1403](https://github.com/Shopify/polaris-react/pull/1403))
- Removed testID warning in tests ([#1447](https://github.com/Shopify/polaris-react/pull/1447))
- Updated `ThemeProvider` to use the new context api ([#1396](https://github.com/Shopify/polaris-react/pull/1396))
- Removed `withContext` from `ResourceList.Item` ([#1503](https://github.com/Shopify/polaris-react/pull/1503))
- Updated `AppProvider` to no longer use `componentWillReceiveProps`([#1255](https://github.com/Shopify/polaris-react/pull/1255))
- Removed `withContext` from `Scrollable.ScrollTo` and added a test to boost coverage ([#1499](https://github.com/Shopify/polaris-react/pull/1499))
- Removed `withContext` from `ResourceList.FilterControl` ([#1500](https://github.com/Shopify/polaris-react/pull/1500))

View File

@@ -2,7 +2,6 @@ import React from 'react';
import {HorizontalDotsMinor} from '@shopify/polaris-icons';
import {classNames} from '@shopify/css-utilities';
import {createUniqueIDFactory} from '@shopify/javascript-utilities/other';
import compose from '@shopify/react-compose';
import isEqual from 'lodash/isEqual';
import {DisableableAction, WithContextTypes} from '../../../../types';
import ActionList from '../../../ActionList';
@@ -16,7 +15,6 @@ import Button, {buttonsFrom} from '../../../Button';
import {withAppProvider, WithAppProviderProps} from '../../../AppProvider';
import {SELECT_ALL_ITEMS, SelectedItems} from '../../types';
import withContext from '../../../WithContext';
import ResourceListContext, {ResourceListContextType} from '../../context';
import styles from './Item.scss';
@@ -69,7 +67,7 @@ export type CombinedProps =
const getUniqueCheckboxID = createUniqueIDFactory('ResourceListItemCheckbox');
const getUniqueOverlayID = createUniqueIDFactory('ResourceListItemOverlay');
export class Item extends React.Component<CombinedProps, State> {
export class BaseItem extends React.Component<CombinedProps, State> {
static getDerivedStateFromProps(nextProps: CombinedProps, prevState: State) {
const selected = isSelected(nextProps.id, nextProps.context.selectedItems);
@@ -411,9 +409,12 @@ function isSelected(id: string, selectedItems?: SelectedItems) {
);
}
export default compose<Props>(
withContext<Props, WithAppProviderProps, ResourceListContextType>(
ResourceListContext.Consumer,
),
withAppProvider<Props>(),
)(Item);
function Item(props: CombinedProps) {
return (
<ResourceListContext.Consumer>
{(context) => <BaseItem {...props} context={context} />}
</ResourceListContext.Consumer>
);
}
export default withAppProvider<Props>()(Item);