@planningcenter/tapestry-migration-cli 3.2.3-rc.4 → 3.2.3-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/button/transforms/unsupportedProps.ts +3 -31
- package/src/components/checkbox/transforms/unsupportedProps.ts +3 -28
- package/src/components/date-picker/index.ts +56 -0
- package/src/components/date-picker/transforms/auditSpreadProps.test.ts +97 -0
- package/src/components/date-picker/transforms/auditSpreadProps.ts +10 -0
- package/src/components/date-picker/transforms/convertStyleProps.test.ts +58 -0
- package/src/components/date-picker/transforms/convertStyleProps.ts +10 -0
- package/src/components/date-picker/transforms/maxDateToMax.test.ts +87 -0
- package/src/components/date-picker/transforms/maxDateToMax.ts +16 -0
- package/src/components/date-picker/transforms/mergeFieldIntoDateField.test.ts +240 -0
- package/src/components/date-picker/transforms/mergeFieldIntoDateField.ts +5 -0
- package/src/components/date-picker/transforms/minDateToMin.test.ts +87 -0
- package/src/components/date-picker/transforms/minDateToMin.ts +16 -0
- package/src/components/date-picker/transforms/momentToDateString.test.ts +240 -0
- package/src/components/date-picker/transforms/momentToDateString.ts +87 -0
- package/src/components/date-picker/transforms/moveDatePickerImport.test.ts +157 -0
- package/src/components/date-picker/transforms/moveDatePickerImport.ts +14 -0
- package/src/components/date-picker/transforms/nativeDateToString.test.ts +220 -0
- package/src/components/date-picker/transforms/nativeDateToString.ts +59 -0
- package/src/components/date-picker/transforms/removeDuplicateKeys.test.ts +120 -0
- package/src/components/date-picker/transforms/removeDuplicateKeys.ts +8 -0
- package/src/components/date-picker/transforms/removeFormatValue.test.ts +119 -0
- package/src/components/date-picker/transforms/removeFormatValue.ts +22 -0
- package/src/components/date-picker/transforms/removePlaceholder.test.ts +117 -0
- package/src/components/date-picker/transforms/removePlaceholder.ts +22 -0
- package/src/components/date-picker/transforms/sizeMapping.test.ts +173 -0
- package/src/components/date-picker/transforms/sizeMapping.ts +15 -0
- package/src/components/date-picker/transforms/stateToInvalid.test.ts +109 -0
- package/src/components/date-picker/transforms/stateToInvalid.ts +57 -0
- package/src/components/date-picker/transforms/stateToInvalidTernary.test.ts +72 -0
- package/src/components/date-picker/transforms/stateToInvalidTernary.ts +11 -0
- package/src/components/date-picker/transforms/unsupportedProps.test.ts +170 -0
- package/src/components/date-picker/transforms/unsupportedProps.ts +10 -0
- package/src/components/input/transforms/unsupportedProps.ts +2 -2
- package/src/components/link/transforms/unsupportedProps.test.ts +3 -1
- package/src/components/link/transforms/unsupportedProps.ts +9 -37
- package/src/components/radio/transforms/unsupportedProps.ts +3 -28
- package/src/components/select/transforms/unsupportedProps.ts +9 -35
- package/src/components/shared/helpers/unsupportedPropsHelpers.ts +22 -0
- package/src/components/shared/transformFactories/unsupportedPropsFactory.test.ts +162 -0
- package/src/components/shared/transformFactories/unsupportedPropsFactory.ts +60 -0
- package/src/components/text-area/transforms/unsupportedProps.ts +3 -28
- package/src/components/time-field/transforms/unsupportedProps.ts +3 -30
- package/src/components/toggle-switch/transforms/unsupportedProps.ts +3 -28
- package/src/index.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-migration-cli",
|
|
3
|
-
"version": "3.2.3-rc.
|
|
3
|
+
"version": "3.2.3-rc.6",
|
|
4
4
|
"description": "CLI tool for Tapestry migrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@emotion/react": "^11.14.0",
|
|
35
|
-
"@planningcenter/tapestry": "^3.2.3-rc.
|
|
35
|
+
"@planningcenter/tapestry": "^3.2.3-rc.6",
|
|
36
36
|
"@planningcenter/tapestry-react": "^4.11.5",
|
|
37
37
|
"@types/jscodeshift": "^17.3.0",
|
|
38
38
|
"@types/node": "^20.0.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "66ef71c22b569382d2047f8cce603051322a451d"
|
|
56
56
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { JSXAttribute, Transform } from "jscodeshift"
|
|
2
|
-
|
|
3
|
-
import { addCommentToUnsupportedProps } from "../../shared/actions/addCommentToUnsupportedProps"
|
|
4
1
|
import { BUTTON_LINK_SUPPORTED_PROPS } from "../../shared/helpers/unsupportedPropsHelpers"
|
|
5
|
-
import {
|
|
2
|
+
import { unsupportedPropsFactory } from "../../shared/transformFactories/unsupportedPropsFactory"
|
|
6
3
|
|
|
7
4
|
const BUTTON_SPECIFIC_PROPS = [
|
|
8
5
|
"disabled",
|
|
@@ -19,35 +16,10 @@ const SUPPORTED_PROPS = [
|
|
|
19
16
|
...BUTTON_SPECIFIC_PROPS,
|
|
20
17
|
]
|
|
21
18
|
|
|
22
|
-
const transform
|
|
19
|
+
const transform = unsupportedPropsFactory({
|
|
20
|
+
supportedProps: SUPPORTED_PROPS,
|
|
23
21
|
targetComponent: "Button",
|
|
24
22
|
targetPackage: "@planningcenter/tapestry-react",
|
|
25
|
-
transform: (element, { j }) => {
|
|
26
|
-
const UNSUPPORTED_PROPS = (element.openingElement.attributes || [])
|
|
27
|
-
.filter(
|
|
28
|
-
(attr) =>
|
|
29
|
-
attr.type === "JSXAttribute" &&
|
|
30
|
-
!SUPPORTED_PROPS.includes(attr.name.name as string) &&
|
|
31
|
-
!(attr.name.name as string).startsWith("aria-") &&
|
|
32
|
-
!(attr.name.name as string).startsWith("data-")
|
|
33
|
-
)
|
|
34
|
-
.map((attr) => (attr as JSXAttribute).name.name as string)
|
|
35
|
-
|
|
36
|
-
return addCommentToUnsupportedProps({
|
|
37
|
-
element,
|
|
38
|
-
j,
|
|
39
|
-
messageSuffix: (prop) => {
|
|
40
|
-
if (prop === "mediaQueries") {
|
|
41
|
-
return "\n * It is recommended to use CSS media queries in a class that you apply to the component.\n"
|
|
42
|
-
}
|
|
43
|
-
if (prop === "hover" || prop === "focus" || prop === "active") {
|
|
44
|
-
return "\n * State-based styles (hover, focus, active) should be handled with CSS class selectors.\n"
|
|
45
|
-
}
|
|
46
|
-
return ""
|
|
47
|
-
},
|
|
48
|
-
props: UNSUPPORTED_PROPS,
|
|
49
|
-
})
|
|
50
|
-
},
|
|
51
23
|
})
|
|
52
24
|
|
|
53
25
|
export default transform
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { JSXAttribute, Transform } from "jscodeshift"
|
|
2
|
-
|
|
3
|
-
import { addCommentToUnsupportedProps } from "../../shared/actions/addCommentToUnsupportedProps"
|
|
4
1
|
import { CHECKBOX_RADIO_SUPPORTED_PROPS } from "../../shared/helpers/unsupportedPropsHelpers"
|
|
5
|
-
import {
|
|
2
|
+
import { unsupportedPropsFactory } from "../../shared/transformFactories/unsupportedPropsFactory"
|
|
6
3
|
|
|
7
4
|
const CHECKBOX_SPECIFIC_PROPS = ["indeterminate"]
|
|
8
5
|
|
|
@@ -11,32 +8,10 @@ const SUPPORTED_PROPS = [
|
|
|
11
8
|
...CHECKBOX_SPECIFIC_PROPS,
|
|
12
9
|
]
|
|
13
10
|
|
|
14
|
-
const transform
|
|
11
|
+
const transform = unsupportedPropsFactory({
|
|
12
|
+
supportedProps: SUPPORTED_PROPS,
|
|
15
13
|
targetComponent: "Checkbox",
|
|
16
14
|
targetPackage: "@planningcenter/tapestry-react",
|
|
17
|
-
transform: (element, { j }) => {
|
|
18
|
-
const UNSUPPORTED_PROPS = (element.openingElement.attributes || [])
|
|
19
|
-
.filter(
|
|
20
|
-
(attr) =>
|
|
21
|
-
attr.type === "JSXAttribute" &&
|
|
22
|
-
!SUPPORTED_PROPS.includes(attr.name.name as string) &&
|
|
23
|
-
!(attr.name.name as string).startsWith("aria-") &&
|
|
24
|
-
!(attr.name.name as string).startsWith("data-")
|
|
25
|
-
)
|
|
26
|
-
.map((attr) => (attr as JSXAttribute).name.name as string)
|
|
27
|
-
|
|
28
|
-
return addCommentToUnsupportedProps({
|
|
29
|
-
element,
|
|
30
|
-
j,
|
|
31
|
-
messageSuffix: (prop) => {
|
|
32
|
-
if (prop === "css") {
|
|
33
|
-
return "\n * CSS prop is not supported. Use className or style prop instead.\n"
|
|
34
|
-
}
|
|
35
|
-
return ""
|
|
36
|
-
},
|
|
37
|
-
props: UNSUPPORTED_PROPS,
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
15
|
})
|
|
41
16
|
|
|
42
17
|
export default transform
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import auditSpreadProps from "./transforms/auditSpreadProps"
|
|
4
|
+
import convertStyleProps from "./transforms/convertStyleProps"
|
|
5
|
+
import maxDateToMax from "./transforms/maxDateToMax"
|
|
6
|
+
import mergeFieldIntoDateField from "./transforms/mergeFieldIntoDateField"
|
|
7
|
+
import minDateToMin from "./transforms/minDateToMin"
|
|
8
|
+
import momentToDateString from "./transforms/momentToDateString"
|
|
9
|
+
import moveDatePickerImport from "./transforms/moveDatePickerImport"
|
|
10
|
+
import nativeDateToString from "./transforms/nativeDateToString"
|
|
11
|
+
import removeDuplicateKeys from "./transforms/removeDuplicateKeys"
|
|
12
|
+
import removeFormatValue from "./transforms/removeFormatValue"
|
|
13
|
+
import removePlaceholder from "./transforms/removePlaceholder"
|
|
14
|
+
import sizeMapping from "./transforms/sizeMapping"
|
|
15
|
+
import stateToInvalid from "./transforms/stateToInvalid"
|
|
16
|
+
import stateToInvalidTernary from "./transforms/stateToInvalidTernary"
|
|
17
|
+
import unsupportedProps from "./transforms/unsupportedProps"
|
|
18
|
+
|
|
19
|
+
const transform: Transform = (fileInfo, api, options) => {
|
|
20
|
+
let currentSource = fileInfo.source
|
|
21
|
+
let hasAnyChanges = false
|
|
22
|
+
|
|
23
|
+
const transforms = [
|
|
24
|
+
mergeFieldIntoDateField,
|
|
25
|
+
auditSpreadProps,
|
|
26
|
+
sizeMapping,
|
|
27
|
+
stateToInvalidTernary,
|
|
28
|
+
stateToInvalid,
|
|
29
|
+
momentToDateString,
|
|
30
|
+
nativeDateToString,
|
|
31
|
+
minDateToMin,
|
|
32
|
+
maxDateToMax,
|
|
33
|
+
convertStyleProps,
|
|
34
|
+
removeFormatValue,
|
|
35
|
+
removePlaceholder,
|
|
36
|
+
removeDuplicateKeys,
|
|
37
|
+
unsupportedProps,
|
|
38
|
+
moveDatePickerImport,
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
for (const individualTransform of transforms) {
|
|
42
|
+
const result = individualTransform(
|
|
43
|
+
{ ...fileInfo, source: currentSource },
|
|
44
|
+
api,
|
|
45
|
+
options
|
|
46
|
+
)
|
|
47
|
+
if (result && result !== currentSource) {
|
|
48
|
+
currentSource = result as string
|
|
49
|
+
hasAnyChanges = true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return hasAnyChanges ? currentSource : null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default transform
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./auditSpreadProps"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
const AUDIT_COMMENT =
|
|
9
|
+
"TODO: tapestry-migration (spreadAttribute): Spread props can contain unsupported props, please explore usages and migrate as needed."
|
|
10
|
+
|
|
11
|
+
function applyTransform(source: string) {
|
|
12
|
+
const fileInfo = { path: "test.tsx", source }
|
|
13
|
+
return transform(
|
|
14
|
+
fileInfo,
|
|
15
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
16
|
+
{}
|
|
17
|
+
) as string | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("auditSpreadProps transform", () => {
|
|
21
|
+
describe("basic transformations", () => {
|
|
22
|
+
it("should add comment to DateField with spread props", () => {
|
|
23
|
+
const input = `
|
|
24
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
25
|
+
|
|
26
|
+
export default function Test() {
|
|
27
|
+
const props = { onChange: handleChange }
|
|
28
|
+
return <DateField {...props} value={date} onChange={setDate} />
|
|
29
|
+
}
|
|
30
|
+
`.trim()
|
|
31
|
+
|
|
32
|
+
const result = applyTransform(input)
|
|
33
|
+
expect(result).toContain(AUDIT_COMMENT)
|
|
34
|
+
expect(result).toContain("{...props}")
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("should add comment to DateField with multiple spread props", () => {
|
|
38
|
+
const input = `
|
|
39
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
40
|
+
|
|
41
|
+
export default function Test() {
|
|
42
|
+
const baseProps = { onChange: handleChange }
|
|
43
|
+
const extraProps = { disabled: true }
|
|
44
|
+
return <DateField {...baseProps} {...extraProps} value={date} onChange={setDate} />
|
|
45
|
+
}
|
|
46
|
+
`.trim()
|
|
47
|
+
|
|
48
|
+
const result = applyTransform(input)
|
|
49
|
+
expect(result).toContain(AUDIT_COMMENT)
|
|
50
|
+
expect(result).toContain("{...baseProps}")
|
|
51
|
+
expect(result).toContain("{...extraProps}")
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe("edge cases", () => {
|
|
56
|
+
it("should not transform DateField without spread props", () => {
|
|
57
|
+
const input = `
|
|
58
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
59
|
+
|
|
60
|
+
export default function Test() {
|
|
61
|
+
return <DateField value={date} onChange={setDate} />
|
|
62
|
+
}
|
|
63
|
+
`.trim()
|
|
64
|
+
|
|
65
|
+
const result = applyTransform(input)
|
|
66
|
+
expect(result).toBe(null)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it("should not transform if DateField is not imported from @planningcenter/tapestry-react", () => {
|
|
70
|
+
const input = `
|
|
71
|
+
import { DateField } from "other-library"
|
|
72
|
+
|
|
73
|
+
export default function Test() {
|
|
74
|
+
const props = { onChange: handleChange }
|
|
75
|
+
return <DateField {...props} value={date} />
|
|
76
|
+
}
|
|
77
|
+
`.trim()
|
|
78
|
+
|
|
79
|
+
const result = applyTransform(input)
|
|
80
|
+
expect(result).toBe(null)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("should return null when no DateField imports exist", () => {
|
|
84
|
+
const input = `
|
|
85
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
86
|
+
|
|
87
|
+
export default function Test() {
|
|
88
|
+
const props = { onClick: handleClick }
|
|
89
|
+
return <Button {...props}>Save</Button>
|
|
90
|
+
}
|
|
91
|
+
`.trim()
|
|
92
|
+
|
|
93
|
+
const result = applyTransform(input)
|
|
94
|
+
expect(result).toBe(null)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import { commentOnSpreadPropsFactory } from "../../shared/transformFactories/commentOnSpreadPropsFactory"
|
|
4
|
+
|
|
5
|
+
const transform: Transform = commentOnSpreadPropsFactory({
|
|
6
|
+
targetComponent: "DateField",
|
|
7
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export default transform
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./convertStyleProps"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
const result = transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
return result || source
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("convertStyleProps transform", () => {
|
|
19
|
+
it("should convert marginTop style prop to inline style", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
function Test() {
|
|
24
|
+
return <DateField marginTop="16px" value={date} onChange={setDate} />
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const result = applyTransform(input)
|
|
29
|
+
expect(result).toContain("style=")
|
|
30
|
+
expect(result).not.toContain('marginTop="16px"')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("should not transform DateField without style props", () => {
|
|
34
|
+
const input = `
|
|
35
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
36
|
+
|
|
37
|
+
function Test() {
|
|
38
|
+
return <DateField value={date} onChange={setDate} />
|
|
39
|
+
}
|
|
40
|
+
`.trim()
|
|
41
|
+
|
|
42
|
+
const result = applyTransform(input)
|
|
43
|
+
expect(result).toBe(input)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("should not affect other components", () => {
|
|
47
|
+
const input = `
|
|
48
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
49
|
+
|
|
50
|
+
function Test() {
|
|
51
|
+
return <Button marginTop="16px">Click</Button>
|
|
52
|
+
}
|
|
53
|
+
`.trim()
|
|
54
|
+
|
|
55
|
+
const result = applyTransform(input)
|
|
56
|
+
expect(result).toBe(input)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { stackViewPlugin } from "../../../stubs/stackViewPlugin"
|
|
2
|
+
import { stylePropTransformFactory } from "../../shared/transformFactories/stylePropTransformFactory"
|
|
3
|
+
|
|
4
|
+
export default stylePropTransformFactory({
|
|
5
|
+
plugin: stackViewPlugin,
|
|
6
|
+
stylesToKeep: ["visible"],
|
|
7
|
+
stylesToRemove: [],
|
|
8
|
+
targetComponent: "DateField",
|
|
9
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
10
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./maxDateToMax"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
const result = transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
return result || source
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("maxDateToMax transform", () => {
|
|
19
|
+
it("should rename maxDate to max", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
function Test() {
|
|
24
|
+
return <DateField maxDate={endDate} value={date} onChange={setDate} />
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const result = applyTransform(input)
|
|
29
|
+
expect(result).toContain("max={endDate}")
|
|
30
|
+
expect(result).not.toContain("maxDate")
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("should rename maxDate with inline Date value", () => {
|
|
34
|
+
const input = `
|
|
35
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
36
|
+
|
|
37
|
+
function Test() {
|
|
38
|
+
return <DateField maxDate={new Date("2024-12-31")} value={date} onChange={setDate} />
|
|
39
|
+
}
|
|
40
|
+
`.trim()
|
|
41
|
+
|
|
42
|
+
const result = applyTransform(input)
|
|
43
|
+
expect(result).toContain("max={")
|
|
44
|
+
expect(result).not.toContain("maxDate=")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("should not transform DateField without maxDate prop", () => {
|
|
48
|
+
const input = `
|
|
49
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
50
|
+
|
|
51
|
+
function Test() {
|
|
52
|
+
return <DateField value={date} onChange={setDate} />
|
|
53
|
+
}
|
|
54
|
+
`.trim()
|
|
55
|
+
|
|
56
|
+
const result = applyTransform(input)
|
|
57
|
+
expect(result).toBe(input)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it("should not affect other components", () => {
|
|
61
|
+
const input = `
|
|
62
|
+
import { Input } from "@planningcenter/tapestry-react"
|
|
63
|
+
|
|
64
|
+
function Test() {
|
|
65
|
+
return <Input maxDate={endDate} label="Name" />
|
|
66
|
+
}
|
|
67
|
+
`.trim()
|
|
68
|
+
|
|
69
|
+
const result = applyTransform(input)
|
|
70
|
+
expect(result).toBe(input)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("should preserve other props", () => {
|
|
74
|
+
const input = `
|
|
75
|
+
import { DateField } from "@planningcenter/tapestry-react"
|
|
76
|
+
|
|
77
|
+
function Test() {
|
|
78
|
+
return <DateField minDate={startDate} maxDate={endDate} value={date} onChange={setDate} />
|
|
79
|
+
}
|
|
80
|
+
`.trim()
|
|
81
|
+
|
|
82
|
+
const result = applyTransform(input)
|
|
83
|
+
expect(result).toContain("max={endDate}")
|
|
84
|
+
expect(result).toContain("minDate={startDate}")
|
|
85
|
+
expect(result).toContain("value={date}")
|
|
86
|
+
})
|
|
87
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
4
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
5
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
6
|
+
|
|
7
|
+
const transform: Transform = attributeTransformFactory({
|
|
8
|
+
condition: hasAttribute("maxDate"),
|
|
9
|
+
targetComponent: "DateField",
|
|
10
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
11
|
+
transform: (element, { j, options }) => {
|
|
12
|
+
return transformAttributeName("maxDate", "max", { element, j, options })
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export default transform
|