Skip to content

Commit b069877

Browse files
mannycarrera4manuel.carrera
and
manuel.carrera
authored
chore: Set up v13 files (#3100)
Set up initial files for v13. [category:Documentation] Co-authored-by: manuel.carrera <[email protected]>
1 parent 813b845 commit b069877

File tree

5 files changed

+256
-52
lines changed

5 files changed

+256
-52
lines changed

modules/codemod/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ const {
8181
describe: chalk.gray('The path to execute the transform in (recursively).'),
8282
});
8383
})
84+
.command('v13 [path]', chalk.gray('Canvas Kit v12 > v13 upgrade transform'), yargs => {
85+
yargs.positional('path', {
86+
type: 'string',
87+
default: '.',
88+
describe: chalk.gray('The path to execute the transform in (recursively).'),
89+
});
90+
})
8491
.demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
8592
.strictCommands()
8693
.fail((msg, err, yargs) => {

modules/codemod/lib/v13/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Transform} from 'jscodeshift';
2+
3+
const transform: Transform = (file, api, options) => {
4+
// These will run in order. If your transform depends on others, place yours after dependent transforms
5+
// const fixes = [
6+
// // add codemods here
7+
// ];
8+
// return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source);
9+
};
10+
11+
export default transform;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {Collection, JSCodeshift, CallExpression} from 'jscodeshift';
2+
3+
export function getImportRenameMap(
4+
j: JSCodeshift,
5+
root: Collection<any>,
6+
mainPackage = '@workday/canvas-kit-react',
7+
packageName = ''
8+
) {
9+
let containsCanvasImports = false;
10+
11+
// build import name remapping - in case someone renamed imports...
12+
// i.e. `import { IconButton as StyledIconButton } ...`
13+
const importMap: Record<string, string> = {};
14+
const styledMap: Record<string, string> = {};
15+
root.find(j.ImportDeclaration, node => {
16+
// imports our module
17+
const value = node.source.value;
18+
if (
19+
typeof value === 'string' &&
20+
(value === mainPackage || value.startsWith(mainPackage) || value === packageName)
21+
) {
22+
containsCanvasImports = true;
23+
(node.specifiers || []).forEach(specifier => {
24+
if (specifier.type === 'ImportSpecifier') {
25+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
26+
importMap[specifier.imported.name] = specifier.imported.name;
27+
} else {
28+
importMap[specifier.imported.name] = specifier.local.name;
29+
}
30+
}
31+
});
32+
}
33+
return false;
34+
});
35+
36+
root
37+
.find(j.CallExpression, (node: CallExpression) => {
38+
if (
39+
node.callee.type === 'Identifier' &&
40+
node.callee.name === 'styled' &&
41+
node.arguments[0].type === 'Identifier'
42+
) {
43+
return true;
44+
}
45+
return false;
46+
})
47+
.forEach(nodePath => {
48+
if (
49+
(nodePath.parent.value.type === 'CallExpression' ||
50+
nodePath.parent.value.type === 'TaggedTemplateExpression') &&
51+
nodePath.parent.parent.value.type === 'VariableDeclarator' &&
52+
nodePath.parent.parent.value.id.type === 'Identifier'
53+
) {
54+
const styledName = nodePath.parent.parent.value.id.name;
55+
56+
if (nodePath.value.arguments[0].type === 'Identifier') {
57+
styledMap[nodePath.value.arguments[0].name] = styledName;
58+
}
59+
}
60+
});
61+
62+
return {containsCanvasImports, importMap, styledMap};
63+
}
+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { Meta } from '@storybook/addon-docs';
2+
import { Table } from '@workday/canvas-kit-react/table';
3+
import { base, brand, system } from '@workday/canvas-tokens-web';
4+
import { StatusIndicator } from '@workday/canvas-kit-preview-react/status-indicator';
5+
import { cssVar } from '@workday/canvas-kit-styling';
6+
import { Box } from '@workday/canvas-kit-react/layout';
7+
8+
<Meta title="Guides/Upgrade Guides/v13.0" />
9+
10+
# Canvas Kit 13.0 Upgrade Guide
11+
12+
This guide contains an overview of the changes in Canvas Kit v13. Please
13+
[reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have
14+
any questions.
15+
16+
17+
## Table of contents
18+
19+
- [Codemod](#codemod)
20+
- [Instructions](#instructions)
21+
- [Troubleshooting](#troubleshooting)
22+
- [Glossary](#glossary)
23+
- [Main](#main)
24+
- [Preview](#preview)
25+
- [Labs](#labs)
26+
27+
## Codemod
28+
29+
We've provided a [codemod](https://github.com/Workday/canvas-kit/tree/master/modules/codemod) to
30+
automatically update your code to work with most of the breaking changes in v13. **Breaking changes
31+
handled by the codemod are marked with 🤖 in the Upgrade Guide.**
32+
33+
A codemod is a script that makes programmatic transformations on your codebase by traversing the
34+
[AST](https://www.codeshiftcommunity.com/docs/understanding-asts), identifying patterns, and making
35+
prescribed changes. This greatly decreases opportunities for error and reduces the number of manual
36+
updates, which allows you to focus on changes that need your attention. **We highly recommend you
37+
use the codemod for these reasons.**
38+
39+
If you're new to running codemods or if it's been a minute since you've used one, there are a few
40+
things you'll want to keep in mind.
41+
42+
- Our codemods are meant to be run sequentially. For example, if you're using v8 of Canvas Kit,
43+
you'll need to run the v9 codemod before you run v10 and so on.
44+
- The codemod will update your code to be compatible with the specified version, but it will **not**
45+
remove outdated dependencies or upgrade dependencies to the latest version. You'll need to upgrade
46+
dependencies on your own.
47+
- We recommend upgrading dependencies before running the codemod.
48+
- Always review your `package.json` files to make sure your dependency versions look correct.
49+
- The codemod will not handle every breaking change in v13. You will likely need to make some manual
50+
changes to be compatible. Use our Upgrade Guide as a checklist.
51+
- Codemods are not bulletproof.
52+
- Conduct a thorough PR and QA review of all changes to ensure no regressions were introduced.
53+
- As a safety precaution, we recommend committing the changes from the codemod as a single
54+
isolated commit (separate from other changes) so you can roll back more easily if necessary.
55+
56+
We're here to help! Automatic changes to your codebase can feel scary. You can always reach out to
57+
our team. We'd be very happy to walk you through the process to set you up for success.
58+
59+
### Instructions
60+
61+
The easiest way to run our codemod is to use `npx` in your terminal.
62+
63+
```sh
64+
npx @workday/canvas-kit-codemod v13 [path]
65+
```
66+
67+
Be sure to provide specific directories that need to be updated via the `[path]` argument. This
68+
decreases the amount of AST the codemod needs to traverse and reduces the chances of the script
69+
having an error. For example, if your source code lives in `src/`, use `src/` as your `[path]`. Or,
70+
if you have a monorepo with three packages using Canvas Kit, provide those specific packages as your
71+
`[path]`.
72+
73+
Alternatively, if you're unable to run the codemod successfully using `npx`, you can install the
74+
codemod package as a dev dependency, run it with `yarn`, and then remove the package after you're
75+
finished.
76+
77+
```sh
78+
yarn add @workday/canvas-kit-codemod --dev
79+
yarn canvas-kit-codemod v13 [path]
80+
yarn remove @workday/canvas-kit-codemod
81+
```
82+
83+
> **Note**: The codemod only works on `.js`, `.jsx`, `.ts`, and `.tsx` files. You'll need to
84+
> manually edit other file types (`.json`, `.mdx`, `.md`, etc.). You may need to run your linter
85+
> after executing the codemod, as its resulting formatting (spacing, quotes, etc.) may not match
86+
> your project conventions.
87+
88+
89+
## Troubleshooting
90+
91+
## Glossary
92+
93+
### Main
94+
95+
Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has
96+
undergone a full design and a11y review and is approved for use in product.
97+
98+
Breaking changes to code in Main will only occur during major version updates and will always be
99+
communicated in advance and accompanied by migration strategies.
100+
101+
---
102+
103+
### Preview
104+
105+
Our Preview package of Canvas Kit tokens, components, and utilities at
106+
`@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for
107+
use in product, but may not be up to the high code standards upheld in the [Main](#main) package.
108+
Preview is analagous to code in beta.
109+
110+
Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without
111+
triggering a major version update, though such changes will be communicated in advance and
112+
accompanied by migration strategies.
113+
114+
Generally speaking, our goal is to eventually promote code from Preview to [Main](#main).
115+
Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for
116+
example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and
117+
[Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)).
118+
In these cases, Preview serves as a staging ground for an improved version of the component with a
119+
different API. The component in [Main](#main) will eventually be replaced with the one in Preview.
120+
121+
---
122+
123+
### Labs
124+
125+
Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react`
126+
has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and
127+
experimental code and is analagous to code in alpha.
128+
129+
Breaking changes can be deployed to Labs at any time without triggering a major version update and
130+
may not be subject to the same rigor in communcation and migration strategies reserved for breaking
131+
changes in [Preview](#preview) and [Main](#main).
132+
`import { opacity } from "@workday/canvas-tokens-web/dist/es6/system"`

modules/docs/mdx/versionsTable.tsx

+43-52
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,6 @@ import {StatusIndicator, StatusIndicatorVariant} from '@workday/canvas-kit-previ
44
// @ts-ignore: Cannot find module error
55
import {version} from '../../../lerna.json';
66

7-
// When we release a new version, add the support version before the first item.
8-
const allVersions = [
9-
{
10-
versionNumber: version, // This will always be the current major version
11-
documentation: 'https://github.com/Workday/canvas-kit',
12-
},
13-
{
14-
versionNumber: 11, // This is support, update this when we release v13
15-
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v11/?path=/docs/welcome--page',
16-
},
17-
{
18-
versionNumber: 10,
19-
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v10/?path=/docs/welcome--page',
20-
},
21-
{
22-
versionNumber: 9,
23-
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v9/?path=/docs/welcome--page',
24-
},
25-
{
26-
versionNumber: 8,
27-
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/welcome--page',
28-
},
29-
{
30-
versionNumber: 7,
31-
documentation:
32-
'https://d2krrudi3mmzzw.cloudfront.net/v7/?path=/story/welcome-getting-started--page',
33-
},
34-
{
35-
versionNumber: 6,
36-
documentation:
37-
'https://d2krrudi3mmzzw.cloudfront.net/v7/?path=/story/welcome-getting-started--page',
38-
},
39-
];
40-
417
const statusIndicators = {
428
stable: {
439
variant: 'blue',
@@ -52,6 +18,12 @@ const statusIndicators = {
5218
label: 'No Longer Supported',
5319
},
5420
};
21+
22+
type VersionType = {
23+
versionNumber: number;
24+
versionUrl: string;
25+
};
26+
5527
function getVersionStatusIndicator(versionNumber: number | string) {
5628
// version from lerna is a string, so we need to do modify into a number
5729
const currentMajorVersion = Number(version.split('.')[0]);
@@ -69,6 +41,22 @@ function getVersionStatusIndicator(versionNumber: number | string) {
6941
}
7042

7143
export const VersionTable = () => {
44+
const [versions, setVersions] = React.useState<VersionType[]>([]);
45+
const minVersion = 6;
46+
const currentMajorVersion = Number(version?.split('.')[0]);
47+
React.useEffect(() => {
48+
let arr: VersionType[] = [];
49+
for (let i = minVersion; i <= currentMajorVersion; i++) {
50+
arr.push({
51+
versionNumber: i,
52+
versionUrl:
53+
i === currentMajorVersion
54+
? 'https://canvas.workday.com/'
55+
: `https://canvas.workday.com/v${i}/`,
56+
});
57+
}
58+
setVersions(arr);
59+
}, []);
7260
return (
7361
<Table>
7462
<Table.Head>
@@ -79,24 +67,27 @@ export const VersionTable = () => {
7967
</Table.Row>
8068
</Table.Head>
8169
<Table.Body>
82-
{allVersions.map(item => {
83-
const {label, variant} = getVersionStatusIndicator(item.versionNumber);
84-
return (
85-
<Table.Row>
86-
<Table.Cell>v{item.versionNumber}</Table.Cell>
87-
<Table.Cell>
88-
<a href={item.documentation} target="_blank" rel="noreferrer">
89-
Documentation
90-
</a>
91-
</Table.Cell>
92-
<Table.Cell>
93-
<StatusIndicator variant={variant as StatusIndicatorVariant}>
94-
<StatusIndicator.Label>{label}</StatusIndicator.Label>
95-
</StatusIndicator>
96-
</Table.Cell>
97-
</Table.Row>
98-
);
99-
})}
70+
{versions
71+
.slice()
72+
.reverse()
73+
.map(item => {
74+
const {label, variant} = getVersionStatusIndicator(item.versionNumber);
75+
return (
76+
<Table.Row>
77+
<Table.Cell>v{item.versionNumber}</Table.Cell>
78+
<Table.Cell>
79+
<a href={item.versionUrl} target="_blank" rel="noreferrer">
80+
Documentation
81+
</a>
82+
</Table.Cell>
83+
<Table.Cell>
84+
<StatusIndicator variant={variant as StatusIndicatorVariant}>
85+
<StatusIndicator.Label>{label}</StatusIndicator.Label>
86+
</StatusIndicator>
87+
</Table.Cell>
88+
</Table.Row>
89+
);
90+
})}
10091
</Table.Body>
10192
</Table>
10293
);

0 commit comments

Comments
 (0)