-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: codemod to enable v12 tile default icons (#18453)
* feat: codemod to enable v12 tile default icons * fix: test cases * fix: formatting issues * fix: formatting issues * fix: formatting issues * fix: formatting issues * fix: formatting issues
- Loading branch information
1 parent
fa1abc1
commit 2f99a47
Showing
7 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
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
70 changes: 70 additions & 0 deletions
70
packages/upgrade/transforms/__testfixtures__/enable-v12-tile-default-icons.input.js
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,70 @@ | ||
import React from 'react'; | ||
import { TileGroup, Tile, Stack } from '@carbon/react'; | ||
import { FeatureFlags } from '@carbon/feature-flags'; | ||
|
||
function TestComponent() { | ||
return ( | ||
<div> | ||
{/* Case 1: Unwrapped TileGroup */} | ||
<TileGroup legend="TestGroup" name="test"> | ||
<Tile>Option 1</Tile> | ||
<Tile>Option 2</Tile> | ||
</TileGroup> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags> | ||
<TileGroup legend="Missing Attribute" name="wrapped"> | ||
<Tile>Already Wrapped Option 1</Tile> | ||
<Tile>Already Wrapped Option 2</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 3: Already wrapped with other attributes */} | ||
<FeatureFlags enable-v12-tile-radio-icons> | ||
<TileGroup legend="Other Attribute" name="other-wrapped"> | ||
<Tile>Other Flag Option 1</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 4: Already wrapped with correct attribute */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Correct Wrapped" name="correct"> | ||
<Tile>Correctly Wrapped Option</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 5: Standalone Tiles with different scenarios */} | ||
<Stack> | ||
{/* Unwrapped standalone */} | ||
<Tile>Standalone Tile</Tile> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags> | ||
<Tile>Wrapped Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Wrapped standalone with other flag */} | ||
<FeatureFlags enable-v12-tile-radio-icons> | ||
<Tile>Other Flag Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Correctly wrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile>Correct Standalone</Tile> | ||
</FeatureFlags> | ||
</Stack> | ||
|
||
{/* Case 6: Nested structures */} | ||
<div className="nested"> | ||
<TileGroup legend="Nested Group" name="nested"> | ||
<div className="wrapper"> | ||
<Tile>Nested Option 1</Tile> | ||
</div> | ||
<Tile>Nested Option 2</Tile> | ||
</TileGroup> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default TestComponent; |
72 changes: 72 additions & 0 deletions
72
packages/upgrade/transforms/__testfixtures__/enable-v12-tile-default-icons.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,72 @@ | ||
import React from 'react'; | ||
import { TileGroup, Tile, Stack } from '@carbon/react'; | ||
import { FeatureFlags } from '@carbon/feature-flags'; | ||
|
||
const TestComponent: React.FC = () => { | ||
return ( | ||
//prettier-ignore | ||
<div> | ||
{/* Case 1: Unwrapped TileGroup */} | ||
<TileGroup legend="TestGroup" name="test"> | ||
<Tile id="test-1">Option 1</Tile> | ||
<Tile id="test-2">Option 2</Tile> | ||
</TileGroup> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags> | ||
<TileGroup legend="Missing Attribute" name="wrapped"> | ||
<Tile id="wrapped-1">Already Wrapped Option 1</Tile> | ||
<Tile id="wrapped-2">Already Wrapped Option 2</Tile> | ||
<Tile id="wrapped-3">Already Wrapped Option 3</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 3: Already wrapped with other flags */} | ||
<FeatureFlags enable-v12-tile-radio-icons> | ||
<TileGroup legend="Other Attribute" name="other-wrapped"> | ||
<Tile id="other-1">Other Flag Option 1</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 4: Already wrapped with correct flag */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Correct Wrapped" name="correct"> | ||
<Tile id="correct-1">Correctly Wrapped Option</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
|
||
{/* Case 5: Standalone Tiles with different scenarios */} | ||
<Stack> | ||
{/* Unwrapped standalone */} | ||
<Tile id="standalone">Standalone Tile</Tile> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags> | ||
<Tile id="wrapped-standalone">Wrapped Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Wrapped standalone with other flag */} | ||
<FeatureFlags enable-v12-tile-radio-icons> | ||
<Tile id="other-standalone">Other Flag Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Correctly wrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile id="correct-standalone">Correct Standalone</Tile> | ||
</FeatureFlags> | ||
</Stack> | ||
|
||
{/* Case 6: Nested structures */} | ||
<div className="nested"> | ||
<TileGroup legend="Nested Group" name="nested"> | ||
<div className="wrapper"> | ||
<Tile id="nested-1">Nested Option 1</Tile> | ||
</div> | ||
<Tile id="nested-2">Nested Option 2</Tile> | ||
</TileGroup> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TestComponent; |
89 changes: 89 additions & 0 deletions
89
packages/upgrade/transforms/__testfixtures__/enable-v12-tile-default-icons.output.js
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,89 @@ | ||
import React from 'react'; | ||
import { TileGroup, Tile, Stack } from '@carbon/react'; | ||
import { FeatureFlags } from '@carbon/feature-flags'; | ||
|
||
function TestComponent() { | ||
return ( | ||
(<div> | ||
{/* Case 1: Unwrapped TileGroup */} | ||
<FeatureFlags enableV12TileDefaultIcons><TileGroup legend="TestGroup" name="test"> | ||
<Tile> | ||
Option 1 | ||
</Tile> | ||
<Tile> | ||
Option 2 | ||
</Tile> | ||
</TileGroup></FeatureFlags> | ||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Missing Attribute" name="wrapped"> | ||
<Tile> | ||
Already Wrapped Option 1 | ||
</Tile> | ||
<Tile> | ||
Already Wrapped Option 2 | ||
</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 3: Already wrapped with other attributes */} | ||
<FeatureFlags enable-v12-tile-radio-icons enableV12TileDefaultIcons> | ||
<TileGroup legend="Other Attribute" name="other-wrapped"> | ||
<Tile> | ||
Other Flag Option 1 | ||
</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 4: Already wrapped with correct attribute */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Correct Wrapped" name="correct"> | ||
<Tile> | ||
Correctly Wrapped Option | ||
</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 5: Standalone Tiles with different scenarios */} | ||
<Stack> | ||
{/* Unwrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons><Tile> | ||
Standalone Tile | ||
</Tile></FeatureFlags> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile> | ||
Wrapped Standalone | ||
</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Wrapped standalone with other flag */} | ||
<FeatureFlags enable-v12-tile-radio-icons enableV12TileDefaultIcons> | ||
<Tile> | ||
Other Flag Standalone | ||
</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Correctly wrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile> | ||
Correct Standalone | ||
</Tile> | ||
</FeatureFlags> | ||
</Stack> | ||
{/* Case 6: Nested structures */} | ||
<div className="nested"> | ||
<FeatureFlags enableV12TileDefaultIcons><TileGroup legend="Nested Group" name="nested"> | ||
<div className="wrapper"> | ||
<Tile> | ||
Nested Option 1 | ||
</Tile> | ||
</div> | ||
<Tile> | ||
Nested Option 2 | ||
</Tile> | ||
</TileGroup></FeatureFlags> | ||
</div> | ||
</div>) | ||
); | ||
} | ||
|
||
export default TestComponent; |
67 changes: 67 additions & 0 deletions
67
packages/upgrade/transforms/__testfixtures__/enable-v12-tile-default-icons.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,67 @@ | ||
import React from 'react'; | ||
import { TileGroup, Tile, Stack } from '@carbon/react'; | ||
import { FeatureFlags } from '@carbon/feature-flags'; | ||
|
||
const TestComponent: React.FC = () => { | ||
return ( | ||
//prettier-ignore | ||
(<div> | ||
{/* Case 1: Unwrapped TileGroup */} | ||
<FeatureFlags enableV12TileDefaultIcons><TileGroup legend="TestGroup" name="test"> | ||
<Tile id="test-1">Option 1</Tile> | ||
<Tile id="test-2">Option 2</Tile> | ||
</TileGroup></FeatureFlags> | ||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Missing Attribute" name="wrapped"> | ||
<Tile id="wrapped-1">Already Wrapped Option 1</Tile> | ||
<Tile id="wrapped-2">Already Wrapped Option 2</Tile> | ||
<Tile id="wrapped-3">Already Wrapped Option 3</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 3: Already wrapped with other flags */} | ||
<FeatureFlags enable-v12-tile-radio-icons enableV12TileDefaultIcons> | ||
<TileGroup legend="Other Attribute" name="other-wrapped"> | ||
<Tile id="other-1">Other Flag Option 1</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 4: Already wrapped with correct flag */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<TileGroup legend="Correct Wrapped" name="correct"> | ||
<Tile id="correct-1">Correctly Wrapped Option</Tile> | ||
</TileGroup> | ||
</FeatureFlags> | ||
{/* Case 5: Standalone Tiles with different scenarios */} | ||
<Stack> | ||
{/* Unwrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons><Tile id="standalone">Standalone Tile</Tile></FeatureFlags> | ||
|
||
{/* Wrapped standalone missing flag prop */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile id="wrapped-standalone">Wrapped Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Wrapped standalone with other flag */} | ||
<FeatureFlags enable-v12-tile-radio-icons enableV12TileDefaultIcons> | ||
<Tile id="other-standalone">Other Flag Standalone</Tile> | ||
</FeatureFlags> | ||
|
||
{/* Correctly wrapped standalone */} | ||
<FeatureFlags enableV12TileDefaultIcons> | ||
<Tile id="correct-standalone">Correct Standalone</Tile> | ||
</FeatureFlags> | ||
</Stack> | ||
{/* Case 6: Nested structures */} | ||
<div className="nested"> | ||
<FeatureFlags enableV12TileDefaultIcons><TileGroup legend="Nested Group" name="nested"> | ||
<div className="wrapper"> | ||
<Tile id="nested-1">Nested Option 1</Tile> | ||
</div> | ||
<Tile id="nested-2">Nested Option 2</Tile> | ||
</TileGroup></FeatureFlags> | ||
</div> | ||
</div>) | ||
); | ||
}; | ||
|
||
export default TestComponent; |
12 changes: 12 additions & 0 deletions
12
packages/upgrade/transforms/__tests__/enable-v12-tile-default-icons-test.js
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,12 @@ | ||
/** | ||
* Copyright IBM Corp. 2025 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { defineTest } = require('jscodeshift/dist/testUtils'); | ||
|
||
defineTest(__dirname, 'enable-v12-tile-default-icons'); |
Oops, something went wrong.