-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(codemods): Add codemods for Modal deprecations #DS-1184 #DS-1201…
… #DS-1181
- Loading branch information
Showing
9 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...demods/src/transforms/v2/web-react/__testfixtures__/modal-isdockedonmobile-prop.input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ModalDialog } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ModalDialog /> | ||
<ModalDialog isDockedOnMobile /> | ||
<ModalDialog isDockedOnMobile={false} /> | ||
</> | ||
); |
11 changes: 11 additions & 0 deletions
11
...emods/src/transforms/v2/web-react/__testfixtures__/modal-isdockedonmobile-prop.output.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ModalDialog } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ModalDialog isDockedOnMobile /> | ||
<ModalDialog isDockedOnMobile /> | ||
<ModalDialog isDockedOnMobile={false} /> | ||
</> | ||
); |
11 changes: 11 additions & 0 deletions
11
...s/codemods/src/transforms/v2/web-react/__testfixtures__/modal-isscrollable-prop.input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ModalDialog } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ModalDialog /> | ||
<ModalDialog isScrollable /> | ||
<ModalDialog isScrollable={false} /> | ||
</> | ||
); |
11 changes: 11 additions & 0 deletions
11
.../codemods/src/transforms/v2/web-react/__testfixtures__/modal-isscrollable-prop.output.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ModalDialog } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ModalDialog isScrollable /> | ||
<ModalDialog isScrollable /> | ||
<ModalDialog isScrollable={false} /> | ||
</> | ||
); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v2/web-react/__tests__/modal-isdockedonmobile-prop.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { testTransform } from '../../../../../tests/testUtils'; | ||
|
||
testTransform(__dirname, 'modal-isdockedonmobile-prop'); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v2/web-react/__tests__/modal-isscrollable-prop.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { testTransform } from '../../../../../tests/testUtils'; | ||
|
||
testTransform(__dirname, 'modal-isscrollable-prop'); |
52 changes: 52 additions & 0 deletions
52
packages/codemods/src/transforms/v2/web-react/modal-isdockedonmobile-prop.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { API, FileInfo } 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 ModalDialog 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 modalDialogSpecifier = importStatements.find(j.ImportSpecifier, { | ||
imported: { | ||
type: 'Identifier', | ||
name: 'ModalDialog', | ||
}, | ||
}); | ||
|
||
// Check if ModalDialog specifier is present | ||
if (modalDialogSpecifier.length > 0) { | ||
// Find ModalDialog components in the module | ||
const modalDialogComponents = root.find(j.JSXOpeningElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'ModalDialog', | ||
}, | ||
}); | ||
|
||
modalDialogComponents.forEach((path) => { | ||
if (path.node && path.node.attributes) { | ||
// Check if the component already has the isDockedOnMobile attribute | ||
const hasIsDockedOnMobileAttribute = path.node.attributes.some( | ||
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'isDockedOnMobile', | ||
); | ||
|
||
// If not, add isDockedOnMobile attribute | ||
if (!hasIsDockedOnMobileAttribute) { | ||
path.node.attributes.push(j.jsxAttribute(j.jsxIdentifier('isDockedOnMobile'), null)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |
52 changes: 52 additions & 0 deletions
52
packages/codemods/src/transforms/v2/web-react/modal-isscrollable-prop.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { API, FileInfo } 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 ModalDialog 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 modalDialogSpecifier = importStatements.find(j.ImportSpecifier, { | ||
imported: { | ||
type: 'Identifier', | ||
name: 'ModalDialog', | ||
}, | ||
}); | ||
|
||
// Check if ModalDialog specifier is present | ||
if (modalDialogSpecifier.length > 0) { | ||
// Find ModalDialog components in the module | ||
const modalDialogComponents = root.find(j.JSXOpeningElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'ModalDialog', | ||
}, | ||
}); | ||
|
||
modalDialogComponents.forEach((path) => { | ||
if (path.node && path.node.attributes) { | ||
// Check if the component already has the isScrollable attribute | ||
const hasIsScrollableAttribute = path.node.attributes.some( | ||
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'isScrollable', | ||
); | ||
|
||
// If not, add isScrollable attribute | ||
if (!hasIsScrollableAttribute) { | ||
path.node.attributes.push(j.jsxAttribute(j.jsxIdentifier('isScrollable'), null)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters