Skip to content

Commit 458ec62

Browse files
committed
Filters consolidate se23 logic
1 parent 3f622e0 commit 458ec62

File tree

5 files changed

+26
-131
lines changed

5 files changed

+26
-131
lines changed

polaris-react/src/components/Filters/Filters.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {Text} from '../Text';
1010
import {UnstyledButton} from '../UnstyledButton';
1111
import {classNames} from '../../utilities/css';
1212
import {useBreakpoints} from '../../utilities/breakpoints';
13-
import {useFeatures} from '../../utilities/features';
1413
import type {
1514
ActionListItemDescriptor,
1615
AppliedFilterInterface,
@@ -139,7 +138,6 @@ export function Filters({
139138
}: FiltersProps) {
140139
const i18n = useI18n();
141140
const {mdDown} = useBreakpoints();
142-
const {polarisSummerEditions2023: se23} = useFeatures();
143141
const [popoverActive, setPopoverActive] = useState(false);
144142
const [localPinnedFilters, setLocalPinnedFilters] = useState<string[]>([]);
145143
const hasMounted = useRef(false);
@@ -231,8 +229,7 @@ export function Filters({
231229

232230
const hasOneOrMorePinnedFilters = pinnedFilters.length >= 1;
233231

234-
const se23LabelVariant = mdDown && se23 ? 'bodyLg' : 'bodySm';
235-
const labelVariant = mdDown ? 'bodyMd' : 'bodySm';
232+
const labelVariant = mdDown ? 'bodyLg' : 'bodySm';
236233

237234
const addFilterActivator = (
238235
<div>
@@ -247,7 +244,7 @@ export function Filters({
247244
disableFilters
248245
}
249246
>
250-
<Text variant={se23 ? se23LabelVariant : labelVariant} as="span">
247+
<Text variant={labelVariant} as="span">
251248
{i18n.translate('Polaris.Filters.addFilter')}{' '}
252249
</Text>
253250
<PlusMinor />
@@ -273,35 +270,17 @@ export function Filters({
273270
);
274271
}, [loading, children]);
275272

276-
const containerSpacing:
277-
| {
278-
paddingBlockStart: BoxProps['paddingBlockStart'];
279-
paddingBlockEnd: BoxProps['paddingBlockEnd'];
280-
paddingInlineStart: BoxProps['paddingInlineStart'];
281-
paddingInlineEnd: BoxProps['paddingInlineEnd'];
282-
}
283-
| {padding: BoxProps['padding']} = se23
284-
? {
285-
paddingInlineStart: '2',
286-
paddingInlineEnd: '2',
287-
paddingBlockStart: '1_5-experimental',
288-
paddingBlockEnd: '1_5-experimental',
289-
}
290-
: {
291-
paddingBlockStart: {
292-
xs: '3',
293-
md: '2',
294-
},
295-
paddingBlockEnd: {
296-
xs: '3',
297-
md: '2',
298-
},
299-
paddingInlineStart: '2',
300-
paddingInlineEnd: {
301-
xs: '4',
302-
md: '3',
303-
},
304-
};
273+
const containerSpacing: {
274+
paddingBlockStart: BoxProps['paddingBlockStart'];
275+
paddingBlockEnd: BoxProps['paddingBlockEnd'];
276+
paddingInlineStart: BoxProps['paddingInlineStart'];
277+
paddingInlineEnd: BoxProps['paddingInlineEnd'];
278+
} = {
279+
paddingInlineStart: '2',
280+
paddingInlineEnd: '2',
281+
paddingBlockStart: '1_5-experimental',
282+
paddingBlockEnd: '1_5-experimental',
283+
};
305284

306285
const queryFieldMarkup = hideQueryField ? null : (
307286
<div className={styles.Container}>

polaris-react/src/components/Filters/components/FilterPill/FilterPill.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import React, {useState, useEffect, useRef} from 'react';
2-
import {
3-
CancelSmallMinor,
4-
CaretDownMinor,
5-
ChevronDownMinor,
6-
} from '@shopify/polaris-icons';
2+
import {CancelSmallMinor, ChevronDownMinor} from '@shopify/polaris-icons';
73

84
import {useI18n} from '../../../../utilities/i18n';
95
import {useToggle} from '../../../../utilities/use-toggle';
@@ -15,7 +11,6 @@ import {Text} from '../../../Text';
1511
import {InlineStack} from '../../../InlineStack';
1612
import {UnstyledButton} from '../../../UnstyledButton';
1713
import {useBreakpoints} from '../../../../utilities/breakpoints';
18-
import {useFeatures} from '../../../../utilities/features';
1914
import {classNames} from '../../../../utilities/css';
2015
import type {FilterInterface} from '../../../../types';
2116

@@ -52,7 +47,6 @@ export function FilterPill({
5247
}: FilterPillProps) {
5348
const i18n = useI18n();
5449
const {mdDown} = useBreakpoints();
55-
const {polarisSummerEditions2023} = useFeatures();
5650

5751
const elementRef = useRef<HTMLDivElement>(null);
5852
const {
@@ -113,16 +107,11 @@ export function FilterPill({
113107
styles.ToggleButton,
114108
);
115109

116-
const se23LabelVariant =
117-
mdDown && polarisSummerEditions2023 ? 'bodyLg' : 'bodySm';
118-
const labelVariant = mdDown ? 'bodyMd' : 'bodySm';
110+
const labelVariant = mdDown ? 'bodyLg' : 'bodySm';
119111

120112
const wrappedLabel = (
121113
<div className={styles.Label}>
122-
<Text
123-
variant={polarisSummerEditions2023 ? se23LabelVariant : labelVariant}
124-
as="span"
125-
>
114+
<Text variant={labelVariant} as="span">
126115
{label}
127116
</Text>
128117
</div>
@@ -146,14 +135,7 @@ export function FilterPill({
146135
<>
147136
{wrappedLabel}
148137
<div className={styles.IconWrapper}>
149-
<Icon
150-
source={
151-
polarisSummerEditions2023
152-
? ChevronDownMinor
153-
: CaretDownMinor
154-
}
155-
color="base"
156-
/>
138+
<Icon source={ChevronDownMinor} color="base" />
157139
</div>
158140
</>
159141
)}

polaris-react/src/components/Filters/components/FilterPill/tests/FilterPill.test.tsx

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ describe('<Filters />', () => {
5353

5454
it('renders with bodyLg variant when on a small screen', () => {
5555
mockUseBreakpoints(true);
56-
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {
57-
features: {polarisSummerEditions2023: true},
58-
});
56+
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {});
5957
expect(wrapper).toContainReactComponent(Text, {
6058
variant: 'bodyLg',
6159
children: defaultProps.label,
@@ -85,18 +83,17 @@ describe('<Filters />', () => {
8583
});
8684

8785
it('when not selected, renders a chevron icon', () => {
88-
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {
89-
features: {polarisSummerEditions2023: true},
90-
});
86+
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {});
9187
expect(wrapper.findAll(UnstyledButton)[0]).toContainReactComponent(Icon, {
9288
source: ChevronDownMinor,
9389
});
9490
});
9591

9692
it('when selected, does not render a chevron icon', () => {
97-
const wrapper = mountWithApp(<FilterPill {...defaultProps} selected />, {
98-
features: {polarisSummerEditions2023: true},
99-
});
93+
const wrapper = mountWithApp(
94+
<FilterPill {...defaultProps} selected />,
95+
{},
96+
);
10097
expect(wrapper.findAll(UnstyledButton)[0]).not.toContainReactComponent(
10198
Icon,
10299
{
@@ -200,42 +197,6 @@ describe('<Filters />', () => {
200197
});
201198
});
202199
});
203-
204-
// se23 - small screen bodyMd text replaced with bodyLg
205-
// CaretDownMinor replaced with ChevronDownMinor
206-
describe('polarisSummerEditions2023 false', () => {
207-
it('renders with bodyMd variant when on a small screen', () => {
208-
mockUseBreakpoints(true);
209-
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {
210-
features: {polarisSummerEditions2023: false},
211-
});
212-
expect(wrapper).toContainReactComponent(Text, {
213-
variant: 'bodyMd',
214-
children: defaultProps.label,
215-
});
216-
});
217-
218-
it('when not selected, renders a caret icon', () => {
219-
const wrapper = mountWithApp(<FilterPill {...defaultProps} />, {
220-
features: {polarisSummerEditions2023: false},
221-
});
222-
expect(wrapper.findAll(UnstyledButton)[0]).toContainReactComponent(Icon, {
223-
source: CaretDownMinor,
224-
});
225-
});
226-
227-
it('when selected, does not render a caret icon', () => {
228-
const wrapper = mountWithApp(<FilterPill {...defaultProps} selected />, {
229-
features: {polarisSummerEditions2023: false},
230-
});
231-
expect(wrapper.findAll(UnstyledButton)[0]).not.toContainReactComponent(
232-
Icon,
233-
{
234-
source: CaretDownMinor,
235-
},
236-
);
237-
});
238-
});
239200
});
240201

241202
function mockUseBreakpoints(mdDown: boolean) {

polaris-react/src/components/Filters/components/SearchField/SearchField.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import {CircleCancelMinor} from '@shopify/polaris-icons';
33

44
import {Text} from '../../../Text';
55
import {classNames} from '../../../../utilities/css';
6-
import {useFeatures} from '../../../../utilities/features';
76
import {Icon} from '../../../Icon';
87
import {useI18n} from '../../../../utilities/i18n';
98
import {UnstyledButton} from '../../../UnstyledButton';
10-
import {TextField} from '../../../TextField';
119

1210
import styles from './SearchField.scss';
1311

@@ -36,7 +34,6 @@ export function SearchField({
3634
}: SearchFieldProps) {
3735
const i18n = useI18n();
3836
const id = useId();
39-
const {polarisSummerEditions2023} = useFeatures();
4037
const inputRef = useRef<HTMLInputElement>(null);
4138
function handleChange(value: string) {
4239
onChange(value);
@@ -54,7 +51,7 @@ export function SearchField({
5451
}
5552
}
5653

57-
return polarisSummerEditions2023 ? (
54+
return (
5855
<div className={styles.SearchField}>
5956
<label className={styles.Label} htmlFor={id}>
6057
{placeholder}
@@ -91,21 +88,5 @@ export function SearchField({
9188
</UnstyledButton>
9289
)}
9390
</div>
94-
) : (
95-
<TextField
96-
value={value}
97-
onChange={handleChange}
98-
onFocus={onFocus}
99-
onBlur={onBlur}
100-
label={placeholder}
101-
labelHidden
102-
autoComplete="off"
103-
focused={focused}
104-
placeholder={placeholder}
105-
clearButton
106-
onClearButtonClick={handleClear}
107-
disabled={disabled}
108-
variant={borderlessQueryField ? 'borderless' : undefined}
109-
/>
11091
);
11192
}

polaris-react/src/components/Filters/components/SearchField/tests/SearchField.test.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ describe('SearchField', () => {
1919
it('will call onChange when changed', () => {
2020
const props = {...defaultProps};
2121
const spy = jest.fn();
22-
const wrapper = mountWithApp(<SearchField {...props} onChange={spy} />, {
23-
features: {
24-
polarisSummerEditions2023: true,
25-
},
26-
});
22+
const wrapper = mountWithApp(<SearchField {...props} onChange={spy} />, {});
2723

2824
wrapper.act(() => {
2925
wrapper.find('input')!.trigger('onChange');
@@ -34,11 +30,7 @@ describe('SearchField', () => {
3430

3531
it('will call onChange correctly when clear button clicked', () => {
3632
const props = {...defaultProps};
37-
const wrapper = mountWithApp(<SearchField {...props} />, {
38-
features: {
39-
polarisSummerEditions2023: true,
40-
},
41-
});
33+
const wrapper = mountWithApp(<SearchField {...props} />, {});
4234

4335
wrapper.act(() => {
4436
wrapper.findAll(UnstyledButton)[0]?.trigger('onClick');

0 commit comments

Comments
 (0)