Skip to content

Commit 86eb91f

Browse files
authored
Codemod: don't affect Items in unimplemented collection components (#6903)
1 parent cfd890e commit 86eb91f

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/multi-collection.test.ts.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Does not affect unimplemented collections 1`] = `
4+
"import {Accordion, Item, ActionBarContainer, ActionBar, ListView, ListBox} from '@adobe/react-spectrum';
5+
import {SearchAutocomplete} from '@react-spectrum/autocomplete';
6+
import {StepList} from '@react-spectrum/steplist';
7+
8+
<div>
9+
<SearchAutocomplete>
10+
<Item key="one">One</Item>
11+
<Item key="two">Two</Item>
12+
<Item key="three">Three</Item>
13+
</SearchAutocomplete>
14+
<Accordion>
15+
<Item title="One" key="one">One</Item>
16+
<Item title="Two" key="two">Two</Item>
17+
<Item title="Three" key="three">Three</Item>
18+
</Accordion>
19+
<ActionBarContainer height={300} maxWidth="size-6000">
20+
<ListView>
21+
<Item key="photoshop">Adobe Photoshop</Item>
22+
<Item key="illustrator">Adobe Illustrator</Item>
23+
<Item key="xd">Adobe XD</Item>
24+
</ListView>
25+
<ActionBar>
26+
<Item key="one">One</Item>
27+
<Item key="two">Two</Item>
28+
<Item key="three">Three</Item>
29+
</ActionBar>
30+
</ActionBarContainer>
31+
<StepList>
32+
<Item key="one">One</Item>
33+
<Item key="two">Two</Item>
34+
<Item key="three">Three</Item>
35+
</StepList>
36+
<ListBox>
37+
<Item key="one">One</Item>
38+
<Item key="two">Two</Item>
39+
<Item key="three">Three</Item>
40+
</ListBox>
41+
</div>"
42+
`;
43+
344
exports[`Static - Renames Item to Breadcrumb and adds import 1`] = `
445
"import {
546
Breadcrumb,

packages/dev/codemods/src/s1-to-s2/__tests__/multi-collection.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,43 @@ import {Breadcrumbs, Item, Menu, MenuTrigger, SubmenuTrigger, Button, Section, H
3939
</div>
4040
`);
4141

42+
test('Does not affect unimplemented collections', `
43+
import {Accordion, Item, ActionBarContainer, ActionBar, ListView, ListBox} from '@adobe/react-spectrum';
44+
import {SearchAutocomplete} from '@react-spectrum/autocomplete';
45+
import {StepList} from '@react-spectrum/steplist';
46+
47+
<div>
48+
<SearchAutocomplete>
49+
<Item key="one">One</Item>
50+
<Item key="two">Two</Item>
51+
<Item key="three">Three</Item>
52+
</SearchAutocomplete>
53+
<Accordion>
54+
<Item title="One" key="one">One</Item>
55+
<Item title="Two" key="two">Two</Item>
56+
<Item title="Three" key="three">Three</Item>
57+
</Accordion>
58+
<ActionBarContainer height={300} maxWidth="size-6000">
59+
<ListView>
60+
<Item key="photoshop">Adobe Photoshop</Item>
61+
<Item key="illustrator">Adobe Illustrator</Item>
62+
<Item key="xd">Adobe XD</Item>
63+
</ListView>
64+
<ActionBar>
65+
<Item key="one">One</Item>
66+
<Item key="two">Two</Item>
67+
<Item key="three">Three</Item>
68+
</ActionBar>
69+
</ActionBarContainer>
70+
<StepList>
71+
<Item key="one">One</Item>
72+
<Item key="two">Two</Item>
73+
<Item key="three">Three</Item>
74+
</StepList>
75+
<ListBox>
76+
<Item key="one">One</Item>
77+
<Item key="two">Two</Item>
78+
<Item key="three">Three</Item>
79+
</ListBox>
80+
</div>
81+
`);

packages/dev/codemods/src/s1-to-s2/src/codemods/transforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function updateComponentWithinCollection(
509509
function commentIfParentCollectionNotDetected(
510510
path: NodePath<t.JSXElement>
511511
) {
512-
const collectionItemParents = new Set(['Menu', 'ActionMenu', 'TagGroup', 'Breadcrumbs', 'Picker', 'ComboBox', 'ListBox', 'TabList', 'TabPanels', 'ActionGroup', 'ListBox', 'ListView', 'Collection']);
512+
const collectionItemParents = new Set(['Menu', 'ActionMenu', 'TagGroup', 'Breadcrumbs', 'Picker', 'ComboBox', 'ListBox', 'TabList', 'TabPanels', 'ActionGroup', 'ListBox', 'ListView', 'Collection', 'SearchAutocomplete', 'Accordion', 'ActionBar', 'StepList']);
513513
if (
514514
t.isJSXElement(path.node)
515515
) {

0 commit comments

Comments
 (0)