-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[codemod] Rename
shouldDisableTime
prop (#7709)
- Loading branch information
1 parent
6171427
commit e7d92df
Showing
13 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
packages/x-codemod/src/v6.0.0/pickers/rename-should-disable-time/actual-props.spec.js
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,9 @@ | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
const shouldDisable = (timeValue, view) => view === 'hours' && timeValue < 12; | ||
|
||
<div> | ||
<DateTimePicker shouldDisableTime={(timeValue, view) => view === 'hours' && timeValue < 12} /> | ||
<TimePicker shouldDisableTime={shouldDisable} /> | ||
</div>; |
9 changes: 9 additions & 0 deletions
9
packages/x-codemod/src/v6.0.0/pickers/rename-should-disable-time/expected-props.spec.js
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,9 @@ | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
const shouldDisable = (timeValue, view) => view === 'hours' && timeValue < 12; | ||
|
||
<div> | ||
<DateTimePicker shouldDisableClock={(timeValue, view) => view === 'hours' && timeValue < 12} /> | ||
<TimePicker shouldDisableClock={shouldDisable} /> | ||
</div>; |
41 changes: 41 additions & 0 deletions
41
packages/x-codemod/src/v6.0.0/pickers/rename-should-disable-time/index.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,41 @@ | ||
/** | ||
* @param {import('jscodeshift').FileInfo} file | ||
* @param {import('jscodeshift').API} api | ||
*/ | ||
export default function transformer(file, api, options) { | ||
const j = api.jscodeshift; | ||
|
||
const printOptions = options.printOptions; | ||
|
||
const root = j(file.source); | ||
|
||
root | ||
.find(j.ImportDeclaration) | ||
.filter(({ node }) => { | ||
return node.source.value.startsWith('@mui/x-date-pickers'); | ||
}) | ||
|
||
.forEach((path) => { | ||
path.node.specifiers.forEach((node) => { | ||
// Process only date-pickers components | ||
root.findJSXElements(node.local.name).forEach((elementPath) => { | ||
if (elementPath.node.type !== 'JSXElement') { | ||
return; | ||
} | ||
|
||
elementPath.node.openingElement.attributes.forEach((elementNode) => { | ||
if (elementNode.type !== 'JSXAttribute') { | ||
return; | ||
} | ||
if (elementNode.name.name === 'shouldDisableTime') { | ||
elementNode.name.name = 'shouldDisableClock'; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
const transformed = root.findJSXElements(); | ||
|
||
return transformed.toSource(printOptions); | ||
} |
41 changes: 41 additions & 0 deletions
41
...-codemod/src/v6.0.0/pickers/rename-should-disable-time/rename-should-disable-time.test.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,41 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
import jscodeshift from 'jscodeshift'; | ||
import transform from './index'; | ||
import readFile from '../../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('v6.0.0/pickers', () => { | ||
describe('rename-should-disable-time', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform( | ||
{ | ||
source: read('./actual-props.spec.js'), | ||
path: require.resolve('./actual-props.spec.js'), | ||
}, | ||
{ jscodeshift }, | ||
{}, | ||
); | ||
|
||
const expected = read('./expected-props.spec.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent for expression', () => { | ||
const actual = transform( | ||
{ | ||
source: read('./expected-props.spec.js'), | ||
path: require.resolve('./expected-props.spec.js'), | ||
}, | ||
{ jscodeshift }, | ||
{}, | ||
); | ||
|
||
const expected = read('./expected-props.spec.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
}); |
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