@planningcenter/tapestry-migration-cli 2.2.1-qa-362.0 → 2.3.0-rc.2
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 +2 -2
- package/src/components/button/index.ts +6 -0
- package/src/components/button/transforms/iconLeftToPrefix.test.ts +432 -0
- package/src/components/button/transforms/iconLeftToPrefix.ts +33 -0
- package/src/components/button/transforms/iconRightToSuffix.test.ts +407 -0
- package/src/components/button/transforms/iconRightToSuffix.ts +33 -0
- package/src/components/button/transforms/tooltipToWrapper.test.ts +392 -0
- package/src/components/button/transforms/tooltipToWrapper.ts +35 -0
- package/src/components/shared/actions/convertAttributeFromObjectToJSXElement.test.ts +139 -0
- package/src/components/shared/actions/convertAttributeFromObjectToJSXElement.ts +81 -0
- package/src/components/shared/actions/createWrapper.test.ts +642 -0
- package/src/components/shared/actions/createWrapper.ts +70 -0
- package/src/components/shared/actions/getAttribute.ts +18 -0
- package/src/components/shared/actions/getAttributeValueAsProps.ts +57 -0
- package/src/components/shared/transformFactories/helpers/addImport.test.ts +278 -0
- package/src/components/shared/transformFactories/helpers/manageImports.ts +53 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-migration-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-rc.2",
|
|
4
4
|
"description": "CLI tool for Tapestry migrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ce455299271696ffb0a1f81c429341829b464498"
|
|
51
51
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Transform } from "jscodeshift"
|
|
2
2
|
|
|
3
|
+
import iconLeftToPrefix from "./transforms/iconLeftToPrefix"
|
|
4
|
+
import iconRightToSuffix from "./transforms/iconRightToSuffix"
|
|
3
5
|
import linkToButton from "./transforms/linkToButton"
|
|
4
6
|
import moveButtonImport from "./transforms/moveButtonImport"
|
|
5
7
|
import removeToTransform from "./transforms/removeTo"
|
|
6
8
|
import titleToLabel from "./transforms/titleToLabel"
|
|
9
|
+
import tooltipToWrapper from "./transforms/tooltipToWrapper"
|
|
7
10
|
|
|
8
11
|
const transform: Transform = (fileInfo, api, options) => {
|
|
9
12
|
let currentSource = fileInfo.source
|
|
@@ -12,6 +15,9 @@ const transform: Transform = (fileInfo, api, options) => {
|
|
|
12
15
|
const transforms: Transform[] = [
|
|
13
16
|
linkToButton,
|
|
14
17
|
titleToLabel,
|
|
18
|
+
tooltipToWrapper,
|
|
19
|
+
iconRightToSuffix,
|
|
20
|
+
iconLeftToPrefix,
|
|
15
21
|
removeToTransform,
|
|
16
22
|
moveButtonImport,
|
|
17
23
|
]
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./iconLeftToPrefix"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string | null {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
return transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("iconLeftToPrefix transform", () => {
|
|
18
|
+
describe("basic transformations", () => {
|
|
19
|
+
it("should convert iconLeft to prefix with Icon component", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
export default function Test() {
|
|
24
|
+
return <Button iconLeft={{name: "check"}}>Save</Button>
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const result = applyTransform(input)
|
|
29
|
+
|
|
30
|
+
expect(result).toContain(
|
|
31
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
32
|
+
)
|
|
33
|
+
expect(result).toContain('prefix={<Icon {...{name: "check"}} />}')
|
|
34
|
+
expect(result).toContain("<Button")
|
|
35
|
+
expect(result).toContain("Save</Button>")
|
|
36
|
+
expect(result).not.toContain("iconLeft=")
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("should handle complex icon props", () => {
|
|
40
|
+
const input = `
|
|
41
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
42
|
+
|
|
43
|
+
export default function Test() {
|
|
44
|
+
return <Button iconLeft={{name: "save", size: "sm", color: "blue"}}>Save</Button>
|
|
45
|
+
}
|
|
46
|
+
`.trim()
|
|
47
|
+
|
|
48
|
+
const result = applyTransform(input)
|
|
49
|
+
|
|
50
|
+
expect(result).toContain(
|
|
51
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
52
|
+
)
|
|
53
|
+
expect(result).toContain(
|
|
54
|
+
'prefix={<Icon {...{name: "save", size: "sm", color: "blue"}} />}'
|
|
55
|
+
)
|
|
56
|
+
expect(result).not.toContain("iconLeft=")
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("should preserve other Button attributes", () => {
|
|
60
|
+
const input = `
|
|
61
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
62
|
+
|
|
63
|
+
export default function Test() {
|
|
64
|
+
return <Button iconLeft={{name: "check"}} variant="primary" onClick={handleClick} disabled>Save</Button>
|
|
65
|
+
}
|
|
66
|
+
`.trim()
|
|
67
|
+
|
|
68
|
+
const result = applyTransform(input)
|
|
69
|
+
|
|
70
|
+
expect(result).toContain('prefix={<Icon {...{name: "check"}} />}')
|
|
71
|
+
expect(result).toContain(
|
|
72
|
+
'variant="primary" onClick={handleClick} disabled'
|
|
73
|
+
)
|
|
74
|
+
expect(result).not.toContain("iconLeft=")
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it("should handle self-closing Button with iconLeft", () => {
|
|
78
|
+
const input = `
|
|
79
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
80
|
+
|
|
81
|
+
export default function Test() {
|
|
82
|
+
return <Button iconLeft={{name: "check"}} />
|
|
83
|
+
}
|
|
84
|
+
`.trim()
|
|
85
|
+
|
|
86
|
+
const result = applyTransform(input)
|
|
87
|
+
|
|
88
|
+
expect(result).toContain(
|
|
89
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
90
|
+
)
|
|
91
|
+
expect(result).toContain('prefix={<Icon {...{name: "check"}} />}')
|
|
92
|
+
expect(result).not.toContain("iconLeft=")
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it("should handle variable expressions", () => {
|
|
96
|
+
const input = `
|
|
97
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
98
|
+
|
|
99
|
+
export default function Test() {
|
|
100
|
+
return <Button iconLeft={iconProps}>Save</Button>
|
|
101
|
+
}
|
|
102
|
+
`.trim()
|
|
103
|
+
|
|
104
|
+
const result = applyTransform(input)
|
|
105
|
+
|
|
106
|
+
expect(result).toContain(
|
|
107
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
108
|
+
)
|
|
109
|
+
expect(result).toContain("prefix={<Icon {...iconProps} />}")
|
|
110
|
+
expect(result).not.toContain("iconLeft=")
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe("import conflict handling", () => {
|
|
115
|
+
it("should use TRIcon alias when Icon already imported from another package", () => {
|
|
116
|
+
const input = `
|
|
117
|
+
import { Icon } from "react-feather"
|
|
118
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
119
|
+
|
|
120
|
+
export default function Test() {
|
|
121
|
+
return <Button iconLeft={{name: "check"}}>Save</Button>
|
|
122
|
+
}
|
|
123
|
+
`.trim()
|
|
124
|
+
|
|
125
|
+
const result = applyTransform(input)
|
|
126
|
+
|
|
127
|
+
expect(result).toContain('import { Icon } from "react-feather"')
|
|
128
|
+
expect(result).toContain(
|
|
129
|
+
'import { Button, Icon as TRIcon } from "@planningcenter/tapestry-react"'
|
|
130
|
+
)
|
|
131
|
+
expect(result).toContain('prefix={<TRIcon {...{name: "check"}} />}')
|
|
132
|
+
expect(result).not.toContain("iconLeft=")
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it("should use TRIcon alias when Icon is default import from another package", () => {
|
|
136
|
+
const input = `
|
|
137
|
+
import Icon from "heroicons"
|
|
138
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
139
|
+
|
|
140
|
+
export default function Test() {
|
|
141
|
+
return <Button iconLeft={{name: "save"}}>Save</Button>
|
|
142
|
+
}
|
|
143
|
+
`.trim()
|
|
144
|
+
|
|
145
|
+
const result = applyTransform(input)
|
|
146
|
+
|
|
147
|
+
expect(result).toContain('import Icon from "heroicons"')
|
|
148
|
+
expect(result).toContain(
|
|
149
|
+
'import { Button, Icon as TRIcon } from "@planningcenter/tapestry-react"'
|
|
150
|
+
)
|
|
151
|
+
expect(result).toContain('prefix={<TRIcon {...{name: "save"}} />}')
|
|
152
|
+
expect(result).not.toContain("iconLeft=")
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it("should not conflict with existing tapestry-react Icon import", () => {
|
|
156
|
+
const input = `
|
|
157
|
+
import { Button, Icon } from "@planningcenter/tapestry-react"
|
|
158
|
+
|
|
159
|
+
export default function Test() {
|
|
160
|
+
return <Button iconLeft={{name: "check"}}>Save</Button>
|
|
161
|
+
}
|
|
162
|
+
`.trim()
|
|
163
|
+
|
|
164
|
+
const result = applyTransform(input)
|
|
165
|
+
|
|
166
|
+
expect(result).toContain(
|
|
167
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
168
|
+
)
|
|
169
|
+
expect(result).toContain('prefix={<Icon {...{name: "check"}} />}')
|
|
170
|
+
expect(result).not.toContain("TRIcon")
|
|
171
|
+
expect(result).not.toContain("iconLeft=")
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it("should handle existing tapestry-react import without Icon", () => {
|
|
175
|
+
const input = `
|
|
176
|
+
import { Button, Link } from "@planningcenter/tapestry-react"
|
|
177
|
+
|
|
178
|
+
export default function Test() {
|
|
179
|
+
return <Button iconLeft={{name: "settings"}}>Settings</Button>
|
|
180
|
+
}
|
|
181
|
+
`.trim()
|
|
182
|
+
|
|
183
|
+
const result = applyTransform(input)
|
|
184
|
+
|
|
185
|
+
expect(result).toContain(
|
|
186
|
+
'import { Button, Link, Icon } from "@planningcenter/tapestry-react"'
|
|
187
|
+
)
|
|
188
|
+
expect(result).toContain('prefix={<Icon {...{name: "settings"}} />}')
|
|
189
|
+
expect(result).not.toContain("iconLeft=")
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it("should create new tapestry-react import when none exists", () => {
|
|
193
|
+
const input = `
|
|
194
|
+
import React from "react"
|
|
195
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
196
|
+
|
|
197
|
+
export default function Test() {
|
|
198
|
+
return <Button iconLeft={{name: "home"}}>Home</Button>
|
|
199
|
+
}
|
|
200
|
+
`.trim()
|
|
201
|
+
|
|
202
|
+
const result = applyTransform(input)
|
|
203
|
+
|
|
204
|
+
expect(result).toContain(
|
|
205
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
206
|
+
)
|
|
207
|
+
expect(result).toContain('prefix={<Icon {...{name: "home"}} />}')
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
describe("multiple elements", () => {
|
|
212
|
+
it("should handle multiple Buttons with iconLeft", () => {
|
|
213
|
+
const input = `
|
|
214
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
215
|
+
|
|
216
|
+
export default function Test() {
|
|
217
|
+
return (
|
|
218
|
+
<div>
|
|
219
|
+
<Button iconLeft={{name: "save"}}>Save</Button>
|
|
220
|
+
<Button iconLeft={{name: "cancel"}}>Cancel</Button>
|
|
221
|
+
</div>
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
`.trim()
|
|
225
|
+
|
|
226
|
+
const result = applyTransform(input)
|
|
227
|
+
|
|
228
|
+
expect(result).toContain(
|
|
229
|
+
'import { Button, Icon } from "@planningcenter/tapestry-react"'
|
|
230
|
+
)
|
|
231
|
+
expect(result).toContain('prefix={<Icon {...{name: "save"}} />}')
|
|
232
|
+
expect(result).toContain('prefix={<Icon {...{name: "cancel"}} />}')
|
|
233
|
+
expect(result).not.toContain("iconLeft=")
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it("should only transform Buttons with iconLeft attribute", () => {
|
|
237
|
+
const input = `
|
|
238
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
239
|
+
|
|
240
|
+
export default function Test() {
|
|
241
|
+
return (
|
|
242
|
+
<div>
|
|
243
|
+
<Button iconLeft={{name: "check"}}>With Icon</Button>
|
|
244
|
+
<Button>Without Icon</Button>
|
|
245
|
+
</div>
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
`.trim()
|
|
249
|
+
|
|
250
|
+
const result = applyTransform(input)
|
|
251
|
+
|
|
252
|
+
expect(result).toContain('prefix={<Icon {...{name: "check"}} />}')
|
|
253
|
+
expect(result).toContain("<Button>Without Icon</Button>")
|
|
254
|
+
// Only one prefix should be created
|
|
255
|
+
const prefixCount = (result?.match(/prefix=/g) || []).length
|
|
256
|
+
expect(prefixCount).toBe(1)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
it("should handle mixed import conflicts", () => {
|
|
260
|
+
const input = `
|
|
261
|
+
import { Icon } from "lucide-react"
|
|
262
|
+
import { Button, Link } from "@planningcenter/tapestry-react"
|
|
263
|
+
|
|
264
|
+
export default function Test() {
|
|
265
|
+
return (
|
|
266
|
+
<div>
|
|
267
|
+
<Button iconLeft={{name: "save"}}>Save</Button>
|
|
268
|
+
<Button iconLeft={{name: "delete", color: "red"}}>Delete</Button>
|
|
269
|
+
<Link>Cancel</Link>
|
|
270
|
+
</div>
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
`.trim()
|
|
274
|
+
|
|
275
|
+
const result = applyTransform(input)
|
|
276
|
+
|
|
277
|
+
expect(result).toContain('import { Icon } from "lucide-react"')
|
|
278
|
+
expect(result).toContain(
|
|
279
|
+
'import { Button, Link, Icon as TRIcon } from "@planningcenter/tapestry-react"'
|
|
280
|
+
)
|
|
281
|
+
expect(result).toContain('prefix={<TRIcon {...{name: "save"}} />}')
|
|
282
|
+
expect(result).toContain(
|
|
283
|
+
'prefix={<TRIcon {...{name: "delete", color: "red"}} />}'
|
|
284
|
+
)
|
|
285
|
+
expect(result).toContain("<Link>Cancel</Link>")
|
|
286
|
+
expect(result).not.toContain("iconLeft=")
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
describe("edge cases", () => {
|
|
291
|
+
it("should return null when Button is not imported from tapestry-react", () => {
|
|
292
|
+
const input = `
|
|
293
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
294
|
+
import { Button } from "other-library"
|
|
295
|
+
|
|
296
|
+
export default function Test() {
|
|
297
|
+
return <Button iconLeft={{name: "check"}}>Save</Button>
|
|
298
|
+
}
|
|
299
|
+
`.trim()
|
|
300
|
+
|
|
301
|
+
const result = applyTransform(input)
|
|
302
|
+
expect(result).toBe(null)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
it("should return null when no Button is imported", () => {
|
|
306
|
+
const input = `
|
|
307
|
+
import React from "react"
|
|
308
|
+
|
|
309
|
+
export default function Test() {
|
|
310
|
+
return <div>No buttons here</div>
|
|
311
|
+
}
|
|
312
|
+
`.trim()
|
|
313
|
+
|
|
314
|
+
const result = applyTransform(input)
|
|
315
|
+
expect(result).toBe(null)
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it("should return null when no iconLeft attributes are present", () => {
|
|
319
|
+
const input = `
|
|
320
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
321
|
+
|
|
322
|
+
export default function Test() {
|
|
323
|
+
return <Button variant="primary">Save</Button>
|
|
324
|
+
}
|
|
325
|
+
`.trim()
|
|
326
|
+
|
|
327
|
+
const result = applyTransform(input)
|
|
328
|
+
expect(result).toBe(null)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
it("should handle aliased Button import", () => {
|
|
332
|
+
const input = `
|
|
333
|
+
import { Button as TapestryButton } from "@planningcenter/tapestry-react"
|
|
334
|
+
|
|
335
|
+
export default function Test() {
|
|
336
|
+
return <TapestryButton iconLeft={{name: "settings"}}>Settings</TapestryButton>
|
|
337
|
+
}
|
|
338
|
+
`.trim()
|
|
339
|
+
|
|
340
|
+
const result = applyTransform(input)
|
|
341
|
+
|
|
342
|
+
expect(result).toContain(
|
|
343
|
+
'import { Button as TapestryButton, Icon } from "@planningcenter/tapestry-react"'
|
|
344
|
+
)
|
|
345
|
+
expect(result).toContain('prefix={<Icon {...{name: "settings"}} />}')
|
|
346
|
+
expect(result).toContain("<TapestryButton")
|
|
347
|
+
expect(result).not.toContain("iconLeft=")
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it("should handle empty iconLeft attribute", () => {
|
|
351
|
+
const input = `
|
|
352
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
353
|
+
|
|
354
|
+
export default function Test() {
|
|
355
|
+
return <Button iconLeft>Save</Button>
|
|
356
|
+
}
|
|
357
|
+
`.trim()
|
|
358
|
+
|
|
359
|
+
const result = applyTransform(input)
|
|
360
|
+
// Should not transform empty iconLeft attribute
|
|
361
|
+
expect(result).toBe(null)
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
describe("complex scenarios", () => {
|
|
366
|
+
it("should handle nested JSX and multiple import conflicts", () => {
|
|
367
|
+
const input = `
|
|
368
|
+
import React from "react"
|
|
369
|
+
import { Icon as FeatherIcon } from "react-feather"
|
|
370
|
+
import Icon from "heroicons"
|
|
371
|
+
import { Button, Link } from "@planningcenter/tapestry-react"
|
|
372
|
+
|
|
373
|
+
export default function Test() {
|
|
374
|
+
return (
|
|
375
|
+
<div>
|
|
376
|
+
<Button iconLeft={{name: "save", size: "lg"}} variant="primary">
|
|
377
|
+
Save Document
|
|
378
|
+
</Button>
|
|
379
|
+
<Button iconLeft={{name: "trash", color: "danger"}} variant="outline">
|
|
380
|
+
Delete
|
|
381
|
+
</Button>
|
|
382
|
+
<Link href="/cancel">Cancel</Link>
|
|
383
|
+
</div>
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
`.trim()
|
|
387
|
+
|
|
388
|
+
const result = applyTransform(input)
|
|
389
|
+
|
|
390
|
+
expect(result).toContain(
|
|
391
|
+
'import { Icon as FeatherIcon } from "react-feather"'
|
|
392
|
+
)
|
|
393
|
+
expect(result).toContain('import Icon from "heroicons"')
|
|
394
|
+
expect(result).toContain(
|
|
395
|
+
'import { Button, Link, Icon as TRIcon } from "@planningcenter/tapestry-react"'
|
|
396
|
+
)
|
|
397
|
+
expect(result).toContain(
|
|
398
|
+
'prefix={<TRIcon {...{name: "save", size: "lg"}} />}'
|
|
399
|
+
)
|
|
400
|
+
expect(result).toContain(
|
|
401
|
+
'prefix={<TRIcon {...{name: "trash", color: "danger"}} />}'
|
|
402
|
+
)
|
|
403
|
+
expect(result).toContain('<Link href="/cancel">Cancel</Link>')
|
|
404
|
+
expect(result).not.toContain("iconLeft=")
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('converts string values to {{ name: "value" }}', () => {
|
|
409
|
+
const input = `
|
|
410
|
+
import React from "react"
|
|
411
|
+
import { Button} from "@planningcenter/tapestry-react"
|
|
412
|
+
|
|
413
|
+
export default function Test() {
|
|
414
|
+
return (
|
|
415
|
+
<div>
|
|
416
|
+
<Button iconLeft="save" variant="primary">
|
|
417
|
+
Save Document
|
|
418
|
+
</Button>
|
|
419
|
+
</div>
|
|
420
|
+
)
|
|
421
|
+
}`.trim()
|
|
422
|
+
|
|
423
|
+
const result = applyTransform(input)
|
|
424
|
+
|
|
425
|
+
expect(result).not.toBeNull()
|
|
426
|
+
expect(result).toContain(`prefix={<Icon
|
|
427
|
+
{...{
|
|
428
|
+
name: "save"
|
|
429
|
+
}} />}`)
|
|
430
|
+
expect(result).not.toContain("iconLeft=")
|
|
431
|
+
})
|
|
432
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { convertAttributeFromObjectToJSXElement } from "../../shared/actions/convertAttributeFromObjectToJSXElement"
|
|
2
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
3
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
4
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
5
|
+
import { addImport } from "../../shared/transformFactories/helpers/manageImports"
|
|
6
|
+
|
|
7
|
+
const transform = attributeTransformFactory({
|
|
8
|
+
condition: hasAttribute("iconLeft"),
|
|
9
|
+
targetComponent: "Button",
|
|
10
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
11
|
+
transform: (element, { j, source }) => {
|
|
12
|
+
const name = addImport({
|
|
13
|
+
component: "Icon",
|
|
14
|
+
conflictAlias: "TRIcon",
|
|
15
|
+
j,
|
|
16
|
+
pkg: "@planningcenter/tapestry-react",
|
|
17
|
+
source,
|
|
18
|
+
})
|
|
19
|
+
const updatedElement = convertAttributeFromObjectToJSXElement({
|
|
20
|
+
attributeName: "iconLeft",
|
|
21
|
+
element,
|
|
22
|
+
elementName: name,
|
|
23
|
+
j,
|
|
24
|
+
stringValueKey: "name",
|
|
25
|
+
})
|
|
26
|
+
if (!updatedElement) return false
|
|
27
|
+
|
|
28
|
+
transformAttributeName("iconLeft", "prefix", { element })
|
|
29
|
+
return true
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export default transform
|