-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HorizontalCellShowMore): remove compensateLastCellIndent prop
- Loading branch information
1 parent
6a1e0ba
commit 1688838
Showing
8 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ges/codemods/src/transforms/v7/__testfixtures__/horizontal-cell-show-more/basic.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,22 @@ | ||
import { HorizontalCellShowMore, HorizontalScroll } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
import '@vkontakte/vkui/dist/vkui.css'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<HorizontalScroll inline> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} compensateLastCellIndent size="m" height={88} /> | ||
</HorizontalScroll> | ||
<HorizontalScroll inline> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} compensateLastCellIndent={true} size="m" height={88} /> | ||
</HorizontalScroll> | ||
</React.Fragment> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
...ages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell-show-more.ts.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`horizontal-cell-show-more transforms correctly 1`] = ` | ||
"import { HorizontalCell, HorizontalCellShowMore, HorizontalScroll } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
import '@vkontakte/vkui/dist/vkui.css'; | ||
const App = () => { | ||
return ( | ||
(<React.Fragment> | ||
<HorizontalScroll inline> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} size="m" height={88} /> | ||
</HorizontalScroll> | ||
<HorizontalScroll inline> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} size="m" height={88} /> | ||
</HorizontalScroll> | ||
</React.Fragment>) | ||
); | ||
};" | ||
`; |
12 changes: 12 additions & 0 deletions
12
packages/codemods/src/transforms/v7/__tests__/horizontal-cell-show-more.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,12 @@ | ||
jest.autoMockOff(); | ||
|
||
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper'; | ||
|
||
const name = 'horizontal-cell-show-more'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
47 changes: 47 additions & 0 deletions
47
packages/codemods/src/transforms/v7/horizontal-cell-show-more.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,47 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { report } from '../../report'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
const componentName = 'HorizontalCellShowMore'; | ||
export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { | ||
const { alias } = options; | ||
const j = api.jscodeshift; | ||
const source = j(file.source); | ||
const { localName } = getImportInfo(j, file, componentName, alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
source | ||
.find(j.JSXOpeningElement) | ||
.filter( | ||
(path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName, | ||
) | ||
.find(j.JSXAttribute) | ||
.filter((attribute) => attribute.node.name.name === 'compensateLastCellIndent') | ||
.forEach((attribute) => { | ||
const node = attribute.node; | ||
|
||
if (!node.value) { | ||
j(attribute).remove(); | ||
} else if ( | ||
node.value.type === 'JSXExpressionContainer' && | ||
node.value.expression.type === 'BooleanLiteral' | ||
) { | ||
if (node.value.expression.value) { | ||
j(attribute).remove(); | ||
} else { | ||
report( | ||
api, | ||
`Manual changes required for ${componentName}'s "compensateLastCellIndent" prop. You might not need it anymore.`, | ||
); | ||
} | ||
} | ||
}); | ||
|
||
return source.toSource(); | ||
} |
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
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