-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🎨 Satt opp codemod boilerplate for chat deprecation * 🐛 v5 -> v6 i codemod * 🧪 Tester for alias-import av chat * 🧪 idempotent codemod-test * 🔥 Fjernet deprecated props fra Chat * 📝 Changeset * 📝 Bedre advarsel i chat-codemod * 📝 v6-migration update * 🧪 Tester vanlig import av Chat * 📝 Oppdatert tekster i codemod * 🔥 Fjernet return fra removeProps * Update @navikt/aksel/src/codemod/migrations.ts
- Loading branch information
Showing
14 changed files
with
214 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@navikt/ds-react": major | ||
"@navikt/aksel": major | ||
--- | ||
|
||
Chat: Fjernet deprecated props `backgroundColor` og `avatarBgColor`. Bruk prop `variant` som erstatning. |
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,75 @@ | ||
import { getLineTerminator } from "../../../utils/lineterminator"; | ||
|
||
/** | ||
* @param {import('jscodeshift').FileInfo} file | ||
* @param {import('jscodeshift').API} api | ||
*/ | ||
export default function transformer(file, api) { | ||
const j = api.jscodeshift; | ||
let localName = "Chat"; | ||
|
||
const root = j(file.source); | ||
|
||
/* Finds used name for Chat component */ | ||
root | ||
.find(j.ImportDeclaration) | ||
.filter((path) => path.node.source.value === "@navikt/ds-react") | ||
.forEach((imp) => { | ||
imp.value.specifiers.forEach((x) => { | ||
if (x.imported.name === "Chat" && x.local.name !== x.imported.name) { | ||
localName = x.local.name; | ||
} | ||
}); | ||
}); | ||
|
||
root | ||
.find(j.JSXElement, { | ||
openingElement: { | ||
name: { | ||
name: localName, | ||
}, | ||
}, | ||
}) | ||
.forEach((path) => { | ||
j(path) | ||
.find(j.JSXAttribute, { | ||
name: { | ||
name: "backgroundColor", | ||
}, | ||
}) | ||
.remove(); | ||
j(path) | ||
.find(j.JSXAttribute, { | ||
name: { | ||
name: "avatarBgColor", | ||
}, | ||
}) | ||
.remove(); | ||
}); | ||
|
||
root | ||
.find(j.JSXElement, { | ||
openingElement: { | ||
name: { | ||
type: "JSXMemberExpression", | ||
object: { | ||
name: localName, | ||
}, | ||
property: { | ||
name: "Bubble", | ||
}, | ||
}, | ||
}, | ||
}) | ||
.forEach((path) => { | ||
j(path) | ||
.find(j.JSXAttribute, { | ||
name: { | ||
name: "backgroundColor", | ||
}, | ||
}) | ||
.remove(); | ||
}); | ||
|
||
return root.toSource(getLineTerminator(file.source)); | ||
} |
12 changes: 12 additions & 0 deletions
12
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/chat.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,12 @@ | ||
import { check } from "../../../../utils/check"; | ||
|
||
const migration = "chat"; | ||
const fixtures = ["import-alias", "idempotent"]; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture, | ||
migration, | ||
extension: "js", | ||
}); | ||
} |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/idempotent.input.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,17 @@ | ||
import { | ||
Chat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00"> | ||
<Chat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</Chat.Bubble> | ||
<Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble> | ||
<Chat.Bubble> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</Chat.Bubble> | ||
</Chat> | ||
); |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/idempotent.output.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,17 @@ | ||
import { | ||
Chat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00"> | ||
<Chat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</Chat.Bubble> | ||
<Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble> | ||
<Chat.Bubble> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</Chat.Bubble> | ||
</Chat> | ||
); |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/import-alias.input.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,17 @@ | ||
import { | ||
Chat as DsChat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<DsChat avatar="ON" name="Ola Normann" backgroundColor="#321" timestamp="01.01.21 14:00" avatarBgColor="#123" > | ||
<DsChat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</DsChat.Bubble> | ||
<DsChat.Bubble backgroundColor="#fff">Tempor fugiat amet eu sint in in ullamco.</DsChat.Bubble> | ||
<DsChat.Bubble backgroundColor="#111"> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</DsChat.Bubble> | ||
</DsChat> | ||
); |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/import-alias.output.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,17 @@ | ||
import { | ||
Chat as DsChat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<DsChat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00"> | ||
<DsChat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</DsChat.Bubble> | ||
<DsChat.Bubble>Tempor fugiat amet eu sint in in ullamco.</DsChat.Bubble> | ||
<DsChat.Bubble> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</DsChat.Bubble> | ||
</DsChat> | ||
); |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/import.input.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,17 @@ | ||
import { | ||
Chat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<Chat avatar="ON" name="Ola Normann" backgroundColor="#321" timestamp="01.01.21 14:00" avatarBgColor="#123" > | ||
<Chat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</Chat.Bubble> | ||
<Chat.Bubble backgroundColor="#fff">Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble> | ||
<Chat.Bubble backgroundColor="#111"> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</Chat.Bubble> | ||
</Chat> | ||
); |
17 changes: 17 additions & 0 deletions
17
@navikt/aksel/src/codemod/transforms/v6.0.0/chat/tests/import.output.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,17 @@ | ||
import { | ||
Chat, | ||
Button, | ||
} from "@navikt/ds-react"; | ||
|
||
export const Demo = () => ( | ||
<Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00"> | ||
<Chat.Bubble> | ||
Aute minim nisi sunt mollit duis sunt nulla minim non proident. | ||
</Chat.Bubble> | ||
<Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble> | ||
<Chat.Bubble> | ||
Adipisicing laborum est eu laborum est sit in commodo enim sint laboris | ||
labore nisi ut. | ||
</Chat.Bubble> | ||
</Chat> | ||
); |
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