-
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.
fix(CustomSelect): refactor logic of empty value (#7822)
* fix(CustomSelect): refactor logic of reset value * fix(CustomSelect): fix types * feat(Select, CustomSelect, NativeSelect): remove event from onChange callback * fix(Select, CustomSelect, NativeSelect): add codemods * fix: fix error Co-authored-by: Andrey Medvedev <[email protected]> --------- Co-authored-by: Andrey Medvedev <[email protected]>
- Loading branch information
1 parent
50960ea
commit ebb46a5
Showing
30 changed files
with
350 additions
and
191 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/codemods/src/transforms/v7/common/warnSelectOnChange.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,16 @@ | ||
import { API, Collection } from 'jscodeshift'; | ||
import { report } from '../../../report'; | ||
|
||
export const warnSelectOnChange = (api: API, source: Collection, componentName: string) => { | ||
const j = api.jscodeshift; | ||
source | ||
.find(j.JSXOpeningElement, { name: { name: componentName } }) | ||
.find(j.JSXAttribute) | ||
.filter((attr) => attr.node.name.name === 'onChange') | ||
.forEach(() => { | ||
report( | ||
api, | ||
`Manual changes required for ${componentName}'s "onChange" prop: need to change event argument to select value`, | ||
); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
import { warnSelectOnChange } from './common/warnSelectOnChange'; | ||
|
||
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, 'NativeSelect', alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
warnSelectOnChange(api, 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
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
Oops, something went wrong.