Skip to content

Commit

Permalink
BREAKING CHANGE(web-react): Rename TooltipModern to Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed May 13, 2024
1 parent 6bafe41 commit 354dfde
Show file tree
Hide file tree
Showing 51 changed files with 540 additions and 1,468 deletions.
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 @@ -22,6 +22,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 @@ -310,6 +311,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

0 comments on commit 354dfde

Please sign in to comment.