-
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.
Merge pull request #7666 from VKCOM/e.muhamethanov/7665/users-stack-d…
…irection-to-avatarsPosition feat(UsersStack): replace direction prop to avatarsPosition
- Loading branch information
Showing
23 changed files
with
208 additions
and
45 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/codemods/src/transforms/v7/__testfixtures__/users-stack/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,43 @@ | ||
import { UsersStack } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
{/* direction="row" -> avatarsPosition="start" */} | ||
<UsersStack | ||
photos={[]} | ||
direction="row" | ||
size="s" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
|
||
{/* direction="row-reverse" -> avatarsPosition="end" */} | ||
<UsersStack | ||
photos={[]} | ||
direction={"row-reverse"} | ||
size="m" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
|
||
{/* direction="column" -> avatarsPosition="top" */} | ||
<UsersStack | ||
photos={[]} | ||
direction="column" | ||
size="l" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
|
||
{/* do nothing */} | ||
<UsersStack | ||
photos={[]} | ||
size="s" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
</React.Fragment> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/codemods/src/transforms/v7/__tests__/__snapshots__/users-stack.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,44 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`users-stack transforms correctly 1`] = ` | ||
"import { UsersStack } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
const App = () => { | ||
return ( | ||
(<React.Fragment> | ||
{/* direction="row" -> avatarsPosition="start" */} | ||
<UsersStack | ||
photos={[]} | ||
avatarsPosition="inline-start" | ||
size="s" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
{/* direction="row-reverse" -> avatarsPosition="end" */} | ||
<UsersStack | ||
photos={[]} | ||
avatarsPosition="inline-end" | ||
size="m" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
{/* direction="column" -> avatarsPosition="top" */} | ||
<UsersStack | ||
photos={[]} | ||
avatarsPosition="block-start" | ||
size="l" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
{/* do nothing */} | ||
<UsersStack | ||
photos={[]} | ||
size="s" | ||
> | ||
Иван и ещё 2 ваших друга подписаны | ||
</UsersStack> | ||
</React.Fragment>) | ||
); | ||
};" | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/codemods/src/transforms/v7/__tests__/users-stack.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 = 'users-stack'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
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,57 @@ | ||
import { API, FileInfo, JSXAttribute } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { report } from '../../report'; | ||
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, 'UsersStack', alias); | ||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
const attributeToReplace = 'direction'; | ||
const newAttributeName = 'avatarsPosition'; | ||
|
||
const directionToAvatarsPosition: Record<string, string> = { | ||
'row': 'inline-start', | ||
'row-reverse': 'inline-end', | ||
'column': 'block-start', | ||
}; | ||
|
||
const getValueFromAttribute = (attribute: JSXAttribute): string | null => { | ||
if (attribute.value?.type === 'StringLiteral') { | ||
return attribute.value.value; | ||
} | ||
if (attribute.value?.type === 'JSXExpressionContainer') { | ||
const expression = attribute.value.expression; | ||
if (expression.type === 'StringLiteral') { | ||
return expression.value; | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
source | ||
.find(j.JSXElement, { openingElement: { name: { name: localName } } }) | ||
.find(j.JSXAttribute, { name: { name: attributeToReplace } }) | ||
.forEach((path) => { | ||
const avatar = path.node; | ||
avatar.name.name = newAttributeName; | ||
const value = getValueFromAttribute(avatar); | ||
if (!value || !directionToAvatarsPosition[value]) { | ||
report( | ||
api, | ||
`: ${localName} has been changed. Manual changes required: need to change direction prop to avatarsPosition`, | ||
); | ||
return; | ||
} | ||
avatar.value = j.stringLiteral(directionToAvatarsPosition[value]); | ||
}); | ||
|
||
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
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
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
...ents/UsersStack/__image_snapshots__/usersstack-android-chromium-dark-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
...nts/UsersStack/__image_snapshots__/usersstack-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/UsersStack/__image_snapshots__/usersstack-ios-webkit-dark-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/UsersStack/__image_snapshots__/usersstack-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
...onents/UsersStack/__image_snapshots__/usersstack-vkcom-chromium-dark-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
...nents/UsersStack/__image_snapshots__/usersstack-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
...ponents/UsersStack/__image_snapshots__/usersstack-vkcom-firefox-dark-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
...onents/UsersStack/__image_snapshots__/usersstack-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
...mponents/UsersStack/__image_snapshots__/usersstack-vkcom-webkit-dark-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/UsersStack/__image_snapshots__/usersstack-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.