Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codemod: remove Section and Items imports if not used elsewhere in file #6908

Merged
merged 9 commits into from
Aug 22, 2024

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented Aug 19, 2024

Previously we weren't removing Section or Item imports, because they may still be used by other components. Now we check if the import is still used, and removed it if not.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Aug 19, 2024

@rspbot
Copy link

rspbot commented Aug 19, 2024

snowystinger
snowystinger previously approved these changes Aug 20, 2024
@rspbot
Copy link

rspbot commented Aug 20, 2024

snowystinger
snowystinger previously approved these changes Aug 20, 2024
@rspbot
Copy link

rspbot commented Aug 21, 2024

@@ -68,7 +67,6 @@ const items = [

exports[`Dynamic - Renames key to id 1`] = `
"import { MenuItem, Menu, MenuTrigger, SubmenuTrigger, Button } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
Copy link
Member

Choose a reason for hiding this comment

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

This is a lot of cases where we're removing the Item or Section from tests. This seems like a great change.
I found the two following tests where we aren't able to determine the "item" and leave the imports. Isn't there a third "leave the import" case where someone does one section that is static and a second section that is dynamic? Like the following.

<MenuTrigger>
    <Button>Edit</Button>
    <Menu>
      <Section key={section.key} title="Static Menu Items">
        <Item key="cut">Cut</Item>
        <Item key="copy">Copy</Item>
      </Section> 
      <Section key={section.key} title="Social Media Sites">
        {items}
      </Section

    </Menu>
  </MenuTrigger>

Copy link
Member Author

Choose a reason for hiding this comment

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

Just tried this locally, and it kept the Item import. Are you seeing something different?

Before:

import {Menu, Section, Item, MenuTrigger, Button} from '@adobe/react-spectrum';

let items = [
  {key: 'facebook', name: 'Facebook'},
  {key: 'twitter', name: 'Twitter'},
  {key: 'instagram', name: 'Instagram'},
].map(item => <Item key={item.key}>{item.name}</Item>);

<div>
  <MenuTrigger>
      <Button>Edit</Button>
      <Menu>
        <Section key={section.key} title="Static Menu Items">
          <Item key="cut">Cut</Item>
          <Item key="copy">Copy</Item>
        </Section> 
        <Section key={section.key} title="Social Media Sites">
          {items}
        </Section>
      </Menu>
    </MenuTrigger>
</div>

After:

import { MenuSection, MenuItem, Menu, MenuTrigger, Button } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';

let items = [
  {key: 'facebook', name: 'Facebook'},
  {key: 'twitter', name: 'Twitter'},
  {key: 'instagram', name: 'Instagram'},
].map(item => // TODO(S2-upgrade): Couldn't automatically detect what type of collection component this is rendered in. You'll need to update this manually.
<Item key={item.key}>{item.name}</Item>);

<div>
  <MenuTrigger>
      <Button>Edit</Button>
      <Menu>
        <MenuSection id={section.key}><Header>Static Menu Items</Header>
          <MenuItem id="cut">Cut</MenuItem>
          <MenuItem id="copy">Copy</MenuItem>
        </MenuSection> 
        <MenuSection id={section.key}><Header>Social Media Sites</Header>
          {items}
        </MenuSection>
      </Menu>
    </MenuTrigger>
</div>

Copy link
Member

Choose a reason for hiding this comment

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

I just wanted that in a test. :)

@rspbot
Copy link

rspbot commented Aug 22, 2024

@rspbot
Copy link

rspbot commented Aug 22, 2024

@reidbarber reidbarber merged commit dcf312b into main Aug 22, 2024
29 checks passed
@reidbarber reidbarber deleted the codemod-remove-items-sections-imports branch August 22, 2024 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants