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

BREAKING CHANGE(web-react): TooltipModern modern to Tooltip #1394

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions docs/migrations/web-react/MIGRATION-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Introducing version 2 of the _spirit-web-react_ package
- [TextField: `label` prop](#textfield-label-prop)
- [Tooltip: `off` Placement](#tooltip-off-placement)
- [Tooltip: Refactored](#tooltip-refactored)
- [TooltipModern](#tooltipmodern)

## General Changes

Expand Down Expand Up @@ -328,6 +329,22 @@ Use:
</Tooltip>
```

### TooltipModern

The `TooltipModern` component was renamed to `Tooltip`.

#### Migration Guide

Use codemod to automatically update your codebase.

```sh
npx @lmc-eu/spirit-codemods -p <path> -t v2/web-react/tooltipmodern-component-name
```

See [Codemods documentation][readme-codemods] for more details.

Or manually rename `TooltipModern` to the `Tooltip`.

---

Please refer back to these instructions or reach out to our team if you encounter any issues during migration.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures.
import { TooltipModern } from '@lmc-eu/spirit-web-react';

export const MyComponent = () => (
<>
<TooltipModern>Tooltip</TooltipModern>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures.
import { Tooltip } from '@lmc-eu/spirit-web-react';

export const MyComponent = () => (
<>
<Tooltip>Tooltip</Tooltip>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { testTransform } from '../../../../../tests/testUtils';

testTransform(__dirname, 'tooltipmodern-component-name');
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { API, FileInfo, JSXIdentifier, JSXOpeningElement, JSXClosingElement } from 'jscodeshift';

const transform = (fileInfo: FileInfo, api: API) => {
const j = api.jscodeshift;
const root = j(fileInfo.source);

// Find import statements for the specific module and TooltipModern specifier
const importStatements = root.find(j.ImportDeclaration, {
source: {
value: (value: string) => /^@lmc-eu\/spirit-web-react(\/.*)?$/.test(value),
},
});

// Check if the module is imported
if (importStatements.length > 0) {
const componentSpecifier = importStatements.find(j.ImportSpecifier, {
imported: {
type: 'Identifier',
name: 'TooltipModern',
},
});

// Check if TooltipModern specifier is present
if (componentSpecifier.length > 0) {
// Find opening tags for TooltipModern components
root
.find<JSXOpeningElement>(j.JSXOpeningElement, {
name: {
type: 'JSXIdentifier',
name: 'TooltipModern',
},
})
.forEach((openingTagPath) => {
// Change component name to 'Tooltip'
if (openingTagPath.node.name.type === 'JSXIdentifier') {
(openingTagPath.node.name as JSXIdentifier).name = 'Tooltip';
}
});

// Find closing tags for TooltipModern components
root
.find<JSXClosingElement>(j.JSXClosingElement, {
name: {
type: 'JSXIdentifier',
name: 'TooltipModern',
},
})
.forEach((closingTagPath) => {
// Change closing tag name to 'Tooltip'
if (closingTagPath.node.name.type === 'JSXIdentifier') {
(closingTagPath.node.name as JSXIdentifier).name = 'Tooltip';
}
});

// Change 'TooltipModern' to 'Tooltip' in import statement
componentSpecifier.forEach((path) => {
j(path).replaceWith(j.importSpecifier(j.identifier('Tooltip'), j.identifier('Tooltip')));
});
}
}

return root.toSource();
};

export default transform;
Loading
Loading