-
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(Flex, SimpleGrid): swap gap prop elements (#7550)
h2. Описание Сейчас у свойства `gap` в компонентах `Flex` и `SimpleGrid` последовательность отступов такая: `[column, row]`. Нужно поменять местами и сделать `[row, column]`. Нужно не забыть добавить кодмоды, чтобы поменять местами row и column h2. Изменения - Поменял последовательность отступов в `Flex` и `SimpleGrid` в свойстве `gap` на `[row, column]` - Написал кодмоды для изменения последовательности в коде - Обновил скриншотные тесты - Поправил тесты h2. Release notes h2. BREAKING CHANGE - Flex: изменена последовательность отступов в свойстве `gap` на `[row, column]` ```diff <Flex direction="column" - gap={[20, 10]} + gap={[10, 20]} align="center" > <div/> <div/> </Flex> ``` - SimpleGrid: изменена последовательность отступов в свойстве `gap` на `[row, column]` ```diff <SimpleGrid columns={2} - gap={[20, 10]} + gap={[10, 20]} align="center" > <div/> <div/> </SimpleGrid> ```
- Loading branch information
1 parent
4902ab8
commit f676e88
Showing
27 changed files
with
239 additions
and
36 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/codemods/src/transforms/v7/__testfixtures__/flex/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,27 @@ | ||
import { Flex } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<Flex | ||
direction="column" | ||
gap={[20, 10]} | ||
align="center" | ||
> | ||
<div/> | ||
<div/> | ||
</Flex> | ||
<Flex | ||
direction="column" | ||
gap={[15, 20]} | ||
align="center" | ||
/> | ||
<Flex | ||
direction="column" | ||
gap={20} | ||
align="center" | ||
/> | ||
</React.Fragment> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/codemods/src/transforms/v7/__testfixtures__/simple-grid/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,25 @@ | ||
import { SimpleGrid } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<SimpleGrid | ||
columns={2} | ||
gap={[20, 10]} | ||
align="center" | ||
> | ||
<div/> | ||
<div/> | ||
</SimpleGrid> | ||
<SimpleGrid | ||
gap={[15, 20]} | ||
align="center" | ||
/> | ||
<SimpleGrid | ||
gap={20} | ||
align="center" | ||
/> | ||
</React.Fragment> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/codemods/src/transforms/v7/__tests__/__snapshots__/flex.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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`flex transforms correctly 1`] = ` | ||
"import { Flex } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
const App = () => { | ||
return ( | ||
(<React.Fragment> | ||
<Flex | ||
direction="column" | ||
gap={[10, 20]} | ||
align="center" | ||
> | ||
<div/> | ||
<div/> | ||
</Flex> | ||
<Flex | ||
direction="column" | ||
gap={[20, 15]} | ||
align="center" | ||
/> | ||
<Flex | ||
direction="column" | ||
gap={20} | ||
align="center" | ||
/> | ||
</React.Fragment>) | ||
); | ||
};" | ||
`; |
29 changes: 29 additions & 0 deletions
29
packages/codemods/src/transforms/v7/__tests__/__snapshots__/simple-grid.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,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`simple-grid transforms correctly 1`] = ` | ||
"import { SimpleGrid } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
const App = () => { | ||
return ( | ||
(<React.Fragment> | ||
<SimpleGrid | ||
columns={2} | ||
gap={[10, 20]} | ||
align="center" | ||
> | ||
<div/> | ||
<div/> | ||
</SimpleGrid> | ||
<SimpleGrid | ||
gap={[20, 15]} | ||
align="center" | ||
/> | ||
<SimpleGrid | ||
gap={20} | ||
align="center" | ||
/> | ||
</React.Fragment>) | ||
); | ||
};" | ||
`; |
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,11 @@ | ||
jest.autoMockOff(); | ||
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper'; | ||
|
||
const name = 'flex'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/codemods/src/transforms/v7/__tests__/simple-grid.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,11 @@ | ||
jest.autoMockOff(); | ||
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper'; | ||
|
||
const name = 'simple-grid'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/codemods/src/transforms/v7/common/swapGapPropElements.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,31 @@ | ||
import { Collection, JSCodeshift, JSXAttribute } from 'jscodeshift'; | ||
|
||
export const swapGapPropElements = (j: JSCodeshift, source: Collection, componentName: string) => { | ||
source | ||
.find(j.JSXOpeningElement) | ||
.filter( | ||
(path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === componentName, | ||
) | ||
.forEach((path) => { | ||
const attributes = path.node.attributes; | ||
const gapAttribute = attributes?.find( | ||
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'gap', | ||
) as JSXAttribute; | ||
|
||
if ( | ||
gapAttribute && | ||
gapAttribute.value && | ||
gapAttribute.value.type === 'JSXExpressionContainer' | ||
) { | ||
const expression = gapAttribute.value.expression; | ||
|
||
if (expression.type === 'ArrayExpression' && expression.elements.length === 2) { | ||
// Меняем местами элементы массива | ||
const [first, second] = expression.elements; | ||
if (first && second) { | ||
expression.elements = [second, first]; | ||
} | ||
} | ||
} | ||
}); | ||
}; |
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,21 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { swapGapPropElements } from './common/swapGapPropElements'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
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, 'Flex', alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
swapGapPropElements(j, source, localName); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { swapGapPropElements } from './common/swapGapPropElements'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
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, 'SimpleGrid', alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
swapGapPropElements(j, source, localName); | ||
|
||
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
4 changes: 2 additions & 2 deletions
4
...nents/Flex/__image_snapshots__/flex-rendering-android-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
.../components/Flex/__image_snapshots__/flex-rendering-ios-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...ponents/Flex/__image_snapshots__/flex-rendering-vkcom-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...mponents/Flex/__image_snapshots__/flex-rendering-vkcom-firefox-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...omponents/Flex/__image_snapshots__/flex-rendering-vkcom-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
4 changes: 2 additions & 2 deletions
4
...Grid/__image_snapshots__/simplegrid-rendering-android-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...SimpleGrid/__image_snapshots__/simplegrid-rendering-ios-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...leGrid/__image_snapshots__/simplegrid-rendering-vkcom-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...pleGrid/__image_snapshots__/simplegrid-rendering-vkcom-firefox-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...mpleGrid/__image_snapshots__/simplegrid-rendering-vkcom-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.