-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(Popover): deprecate variant and customIcon props * fix(Popover): fix RTL styles * feat(codemods): add codemod to remove Popover props variant and customIcon * refactor(codemods): update readme and remove alias references
- Loading branch information
1 parent
9961e87
commit df16927
Showing
25 changed files
with
252 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kaizen/components": patch | ||
--- | ||
|
||
Deprecate `Popover` `variant` and `customIcon` props, and fix RTL styles. |
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
2 changes: 1 addition & 1 deletion
2
.../components/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.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
2 changes: 1 addition & 1 deletion
2
packages/components/codemods/migrateCardVariantToColor/transformCardVariantToColor.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
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
81 changes: 25 additions & 56 deletions
81
...demods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.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 |
---|---|---|
@@ -1,59 +1,28 @@ | ||
import ts from "typescript" | ||
import { getPropValueText } from "../utils/getPropValueText" | ||
import type { ConfirmationModalProps } from "../../src/Modal" | ||
import { migrateStringProp } from "../utils" | ||
|
||
/** Recurses through AST to find and update any jsx element that matched the tagName */ | ||
export const transformConfirmationModalMoodsToVariant = | ||
(context: ts.TransformationContext, tagName: string) => | ||
(rootNode: ts.Node): ts.Node => { | ||
function visit(node: ts.Node): ts.Node { | ||
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) { | ||
if (node.tagName.getText() === tagName) { | ||
const newAttributes = node.attributes.properties.map(attr => { | ||
if (ts.isJsxAttribute(attr) && attr.name.getText() === "mood") { | ||
const valueName = | ||
attr.initializer && getPropValueText(attr.initializer) | ||
const OLD_PROP_NAME = "mood" | ||
const NEW_PROP_NAME = "variant" | ||
|
||
if (valueName) { | ||
let variantValue: string = "" | ||
switch (valueName) { | ||
case "positive": | ||
variantValue = "success" | ||
break | ||
case "negative": | ||
variantValue = "warning" | ||
break | ||
case "assertive": | ||
variantValue = "cautionary" | ||
break | ||
} | ||
return ts.factory.createJsxAttribute( | ||
ts.factory.createIdentifier("variant"), | ||
ts.factory.createStringLiteral(variantValue) | ||
) | ||
} | ||
} | ||
|
||
return attr | ||
}) | ||
|
||
if (ts.isJsxOpeningElement(node)) { | ||
return ts.factory.updateJsxOpeningElement( | ||
node, | ||
node.tagName, | ||
node.typeArguments, | ||
ts.factory.createJsxAttributes(newAttributes) | ||
) | ||
} else if (ts.isJsxSelfClosingElement(node)) { | ||
return ts.factory.updateJsxSelfClosingElement( | ||
node, | ||
node.tagName, | ||
node.typeArguments, | ||
ts.factory.createJsxAttributes(newAttributes) | ||
) | ||
} | ||
} | ||
} | ||
return ts.visitEachChild(node, visit, context) | ||
} | ||
return ts.visitNode(rootNode, visit) | ||
const getNewVariantValue = ( | ||
oldValue: Exclude<ConfirmationModalProps[typeof OLD_PROP_NAME], undefined> | ||
): Exclude<ConfirmationModalProps[typeof NEW_PROP_NAME], undefined> => { | ||
switch (oldValue) { | ||
case "positive": | ||
return "success" | ||
case "informative": | ||
return "informative" | ||
case "negative": | ||
return "warning" | ||
case "cautionary": | ||
return "cautionary" | ||
case "assertive": | ||
return "cautionary" | ||
} | ||
} | ||
|
||
export const transformConfirmationModalMoodsToVariant = migrateStringProp( | ||
OLD_PROP_NAME, | ||
NEW_PROP_NAME, | ||
getNewVariantValue | ||
) |
2 changes: 1 addition & 1 deletion
2
...igrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.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
2 changes: 1 addition & 1 deletion
2
...nts/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.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
2 changes: 1 addition & 1 deletion
2
...nts/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.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
2 changes: 1 addition & 1 deletion
2
.../components/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.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
2 changes: 1 addition & 1 deletion
2
...ages/components/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.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
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
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
41 changes: 2 additions & 39 deletions
41
packages/components/codemods/removeInputEditModalMood/removeInputEditModalMood.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 |
---|---|---|
@@ -1,40 +1,3 @@ | ||
import ts from "typescript" | ||
import { removeProps } from "../utils/removeProps" | ||
|
||
/** Recurses through AST to find and update any jsx element that matched the tagName */ | ||
export const removeInputEditModalMood = | ||
(context: ts.TransformationContext, tagName: string) => | ||
(rootNode: ts.Node): ts.Node => { | ||
function visit(node: ts.Node): ts.Node { | ||
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) { | ||
if (node.tagName.getText() === tagName) { | ||
const newAttributes = node.attributes.properties.reduce< | ||
ts.JsxAttributeLike[] | ||
>((acc, attr) => { | ||
if (ts.isJsxAttribute(attr) && attr.name.getText() === "mood") { | ||
return acc | ||
} | ||
|
||
return [...acc, attr] | ||
}, []) | ||
|
||
if (ts.isJsxOpeningElement(node)) { | ||
return ts.factory.updateJsxOpeningElement( | ||
node, | ||
node.tagName, | ||
node.typeArguments, | ||
ts.factory.createJsxAttributes(newAttributes) | ||
) | ||
} else if (ts.isJsxSelfClosingElement(node)) { | ||
return ts.factory.updateJsxSelfClosingElement( | ||
node, | ||
node.tagName, | ||
node.typeArguments, | ||
ts.factory.createJsxAttributes(newAttributes) | ||
) | ||
} | ||
} | ||
} | ||
return ts.visitEachChild(node, visit, context) | ||
} | ||
return ts.visitNode(rootNode, visit) | ||
} | ||
export const removeInputEditModalMood = removeProps(["mood"]) |
15 changes: 15 additions & 0 deletions
15
packages/components/codemods/removePopoverVariant/index.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,15 @@ | ||
import { transformComponentsInDir } from "../utils" | ||
import { removePopoverVariant } from "./removePopoverVariant" | ||
|
||
const run = (): void => { | ||
// eslint-disable-next-line no-console | ||
console.log(" ~(-_- ~) Running Popover transformer (~ -_-)~") | ||
const targetDir = process.argv[2] | ||
if (!targetDir) { | ||
process.exit(1) | ||
} | ||
|
||
transformComponentsInDir(targetDir, removePopoverVariant, "Popover") | ||
} | ||
|
||
run() |
65 changes: 65 additions & 0 deletions
65
packages/components/codemods/removePopoverVariant/removePopoverVariant.spec.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,65 @@ | ||
import { parseJsx } from "../__tests__/utils" | ||
import { transformSource, printAst } from "../utils" | ||
import { removePopoverVariant } from "./removePopoverVariant" | ||
|
||
describe("removePopoverVariant()", () => { | ||
it("removes variant", () => { | ||
const inputAst = parseJsx(` | ||
export const TestComponent = () => <Popover variant="positive" /> | ||
`) | ||
const outputAst = parseJsx(` | ||
export const TestComponent = () => <Popover /> | ||
`) | ||
const transformed = transformSource({ | ||
sourceFile: inputAst, | ||
astTransformer: removePopoverVariant, | ||
tagName: "Popover", | ||
}) | ||
expect(transformed).toEqual(printAst(outputAst)) | ||
}) | ||
|
||
it("removes customIcon", () => { | ||
const inputAst = parseJsx(` | ||
export const TestComponent = () => <Popover variant="positive" customIcon={<Icon />} /> | ||
`) | ||
const outputAst = parseJsx(` | ||
export const TestComponent = () => <Popover /> | ||
`) | ||
const transformed = transformSource({ | ||
sourceFile: inputAst, | ||
astTransformer: removePopoverVariant, | ||
tagName: "Popover", | ||
}) | ||
expect(transformed).toEqual(printAst(outputAst)) | ||
}) | ||
|
||
it("handles multiple attributes and remove only variant", () => { | ||
const inputAst = parseJsx(` | ||
export const TestComponent = () => <Popover variant="negative" id="123"/> | ||
`) | ||
const outputAst = parseJsx(` | ||
export const TestComponent = () => <Popover id="123"/> | ||
`) | ||
const transformed = transformSource({ | ||
sourceFile: inputAst, | ||
astTransformer: removePopoverVariant, | ||
tagName: "Popover", | ||
}) | ||
expect(transformed).toBe(printAst(outputAst)) | ||
}) | ||
|
||
it("transforms multiple Popovers", () => { | ||
const inputAst = parseJsx(` | ||
export const TestComponent = () => <div><Popover variant="positive"/><Popover variant="negative" customIcon={<Icon />}/></div> | ||
`) | ||
const outputAst = parseJsx(` | ||
export const TestComponent = () => <div><Popover /><Popover /></div> | ||
`) | ||
const transformed = transformSource({ | ||
sourceFile: inputAst, | ||
astTransformer: removePopoverVariant, | ||
tagName: "Popover", | ||
}) | ||
expect(transformed).toBe(printAst(outputAst)) | ||
}) | ||
}) |
3 changes: 3 additions & 0 deletions
3
packages/components/codemods/removePopoverVariant/removePopoverVariant.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 { removeProps } from "../utils/removeProps" | ||
|
||
export const removePopoverVariant = removeProps(["variant", "customIcon"]) |
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
Oops, something went wrong.