Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
99a57fd
adds a hideMoreFiltersButton prop to the Filters component
rickitan Mar 18, 2020
c9b59f1
removes the hideMoreFiltersButton prop
rickitan Mar 18, 2020
f47a8e4
address Tim Layton comments
rickitan Mar 27, 2020
6da3f15
address border-radius problem
rickitan Mar 31, 2020
65e6346
adds tests and formats
rickitan Apr 8, 2020
26a002a
adds UNRELEASED.md
rickitan Apr 8, 2020
8680216
solve conflicts
rickitan Apr 8, 2020
e184e91
fix linting
rickitan Apr 8, 2020
bd58192
add two more tests
Apr 8, 2020
87eb592
refactor to remove branch which never executed
Apr 8, 2020
c953360
adds a hideMoreFiltersButton prop to the Filters component
rickitan Mar 18, 2020
0ffdfbe
removes the hideMoreFiltersButton prop
rickitan Mar 18, 2020
eef8cb9
address Tim Layton comments
rickitan Mar 27, 2020
71c7b49
address border-radius problem
rickitan Mar 31, 2020
a9aa508
adds tests and formats
rickitan Apr 8, 2020
c1908e0
adds UNRELEASED.md
rickitan Apr 8, 2020
ed93329
solve conflicts
rickitan Apr 8, 2020
39f8597
fix linting
rickitan Apr 8, 2020
993aed7
add two more tests
Apr 8, 2020
c28ad56
refactor to remove branch which never executed
Apr 8, 2020
06945aa
update UNRELEASED.md and revert Select.scss change
rickitan Apr 8, 2020
3244751
Merge branch 'hide_more_filters_button_prop' of https://github.com/Sh…
Apr 8, 2020
bfa40a0
markdown format
Apr 8, 2020
8b595f2
revert again Select.scss change
rickitan Apr 9, 2020
e92a551
Merge branch 'master' into hide_more_filters_button_prop
tmlayton Apr 9, 2020
aa990c4
replace bug fixes header
Apr 9, 2020
afb500a
one snuck by
Apr 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Enhancements

- Updated `Filters` to only show the "More filters" button if necessary ([#2856](https://github.com/Shopify/polaris-react/pull/2856)).

### Bug fixes

### Documentation
Expand Down
13 changes: 8 additions & 5 deletions src/components/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,15 @@ class FiltersInner extends React.Component<ComposedProps, State> {
plural: intl.translate('Polaris.ResourceList.defaultItemPlural'),
};

const transformedFilters = this.transformFilters(filters);

const filtersControlMarkup = (
<ConnectedFilterControl
rightPopoverableActions={this.transformFilters(filters)}
rightPopoverableActions={transformedFilters}
rightAction={rightActionMarkup}
auxiliary={children}
disabled={disabled}
forceShowMorefiltersButton={filters.length > transformedFilters.length}
>
<TextField
placeholder={
Expand Down Expand Up @@ -513,10 +516,10 @@ class FiltersInner extends React.Component<ComposedProps, State> {
}
}

private transformFilters(
filters: FilterInterface[],
): ConnectedFilterControlProps['rightPopoverableActions'] | null {
const transformedActions: ConnectedFilterControlProps['rightPopoverableActions'] = [];
private transformFilters(filters: FilterInterface[]) {
const transformedActions: Required<
ConnectedFilterControlProps['rightPopoverableActions']
> = [];

getShortcutFilters(filters).forEach((filter) => {
const {key, label, disabled} = filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ $stacking-order: (
}
}

.RightContainerWithoutMoreFilters {
.Item:last-child > * > * {
border-top-right-radius: var(
--p-border-radius-base,
border-radius()
) !important;
border-bottom-right-radius: var(
--p-border-radius-base,
border-radius()
) !important;
}
}

.newDesignLanguage .RightContainer {
.Item:first-of-type > * > * {
border-top-left-radius: var(--p-border-radius-base) !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ConnectedFilterControlProps {
rightAction?: React.ReactNode;
auxiliary?: React.ReactNode;
disabled?: boolean;
forceShowMorefiltersButton?: boolean;
}

interface ComputedProperty {
Expand Down Expand Up @@ -74,6 +75,7 @@ export class ConnectedFilterControl extends React.Component<
rightPopoverableActions,
rightAction,
auxiliary,
forceShowMorefiltersButton = true,
} = this.props;

const actionsToRender =
Expand All @@ -87,11 +89,25 @@ export class ConnectedFilterControl extends React.Component<
newDesignLanguage && styles.newDesignLanguage,
);

const rightMarkup = rightPopoverableActions ? (
<div className={styles.RightContainer} testID="FilterShortcutContainer">
{this.popoverFrom(actionsToRender)}
</div>
) : null;
const shouldRenderMoreFiltersButton =
forceShowMorefiltersButton ||
(rightPopoverableActions &&
rightPopoverableActions.length !== actionsToRender.length);

const RightContainerClassName = classNames(
styles.RightContainer,
!shouldRenderMoreFiltersButton && styles.RightContainerWithoutMoreFilters,
);

const rightMarkup =
actionsToRender.length > 0 ? (
<div
className={RightContainerClassName}
testID="FilterShortcutContainer"
>
{this.popoverFrom(actionsToRender)}
</div>
) : null;

const moreFiltersButtonContainerClassname = classNames(
styles.MoreFiltersButtonContainer,
Expand All @@ -105,7 +121,7 @@ export class ConnectedFilterControl extends React.Component<
ref={this.moreFiltersButtonContainer}
className={moreFiltersButtonContainerClassname}
>
<Item>{rightAction}</Item>
{shouldRenderMoreFiltersButton && <Item>{rightAction}</Item>}
</div>
) : null;

Expand Down Expand Up @@ -197,6 +213,10 @@ export class ConnectedFilterControl extends React.Component<
if (actionWidth <= remainingWidth) {
actionsToReturn.push(action);
remainingWidth -= actionWidth;
} else {
// When we can't fit an action, we break the loop.
// The ones that didn't fit will be accessible through the "More filters" button
break;
}
}
return actionsToReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,46 @@ describe('<ConnectedFilterControl />', () => {
expect(connectedFilterControl.find(Popover).exists()).toBe(false);
});

it('does render a button with a right action', () => {
it('always render a RightAction if forceShowMorefiltersButton is true', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl rightAction={mockRightAction}>
<ConnectedFilterControl
rightAction={mockRightAction}
forceShowMorefiltersButton
>
<MockChild />
</ConnectedFilterControl>,
);

expect(connectedFilterControl.find(Button).exists()).toBe(true);
});

it('renders a RightAction if forceShowMorefiltersButton is false and rightPopoverableActions do not fit on the "right action" container', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl
rightAction={mockRightAction}
rightPopoverableActions={[mockRightOpenPopoverableAction]}
forceShowMorefiltersButton={false}
>
<MockChild />
</ConnectedFilterControl>,
);

expect(connectedFilterControl.find(Button).exists()).toBe(true);
});

it('does not render a RightAction there are no actions hidden', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl
rightAction={mockRightAction}
forceShowMorefiltersButton={false}
>
<MockChild />
</ConnectedFilterControl>,
);

expect(connectedFilterControl.find(Button).exists()).toBe(false);
});

it('does render a button with a popoverable action', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl
Expand Down Expand Up @@ -104,6 +134,24 @@ describe('<ConnectedFilterControl />', () => {
expect(connectedFilterControl.find(Button)).toHaveLength(3);
});

it('hides an action if it does not fit', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl
rightPopoverableActions={[
mockRightOpenPopoverableAction,
mockRightClosedPopoverableAction,
]}
rightAction={mockRightAction}
>
<MockChild />
</ConnectedFilterControl>,
);

connectedFilterControl.setState({availableWidth: 100});

expect(findActions(connectedFilterControl)).toHaveLength(2);
});

it('renders auxiliary content', () => {
const connectedFilterControl = mountWithAppProvider(
<ConnectedFilterControl auxiliary={<MockAux />}>
Expand Down Expand Up @@ -171,3 +219,8 @@ function noop() {}
function findById(wrapper: ReactWrapper, id: string) {
return wrapper.find(`#${id}`).first();
}

function findActions(wrapper: ReactWrapper) {
// this omits the invisible proxy actions used for measuring width
return wrapper.find('.Wrapper Button');
}
40 changes: 40 additions & 0 deletions src/components/Filters/tests/Filters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,46 @@ describe('<Filters />', () => {
).toHaveLength(2);
});

it('forces showing the "More Filters" button if there are filters without shortcuts', () => {
const resourceFilters = mountWithAppProvider(
<Filters {...mockPropsWithShortcuts} />,
);

expect(
resourceFilters.find(ConnectedFilterControl).props()
.forceShowMorefiltersButton,
).toBe(true);
});

it('does not force showing the "More Filters" button if all the filters have shorcuts', () => {
const mockPropsWithShortcuts: FiltersProps = {
onQueryChange: noop,
onQueryClear: noop,
onClearAll: noop,
filters: [
{
key: 'filterOne',
label: 'Filter One',
filter: <MockFilter id="filterOne" />,
shortcut: true,
},
{
key: 'filterTwo',
label: 'Filter Two',
filter: <MockFilter id="filterTwo" />,
shortcut: true,
},
],
};
const resourceFilters = mountWithAppProvider(
<Filters {...mockPropsWithShortcuts} />,
);
expect(
resourceFilters.find(ConnectedFilterControl).props()
.forceShowMorefiltersButton,
).toBe(false);
});

it('receives shortcut filters with popoverOpen set to false on mount', () => {
const resourceFilters = mountWithAppProvider(
<Filters {...mockPropsWithShortcuts} />,
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaCard/MediaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {HorizontalDotsMinor} from '@shopify/polaris-icons';
import {useToggle} from '../../utilities/use-toggle';
import {classNames} from '../../utilities/css';
import {useI18n} from '../../utilities/i18n';
import {Action, ActionListItemDescriptor} from '../../types';
import type {Action, ActionListItemDescriptor} from '../../types';
import {Card} from '../Card';
import {Button, buttonFrom} from '../Button';
import {Heading} from '../Heading';
Expand Down