Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement codemod ibm-products-update-http-errors #17960

Merged
merged 8 commits into from
Dec 4, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import {
HTTPError403,
HTTPError404,
HTTPErrorOther,
} from '@carbon/ibm-products';
import './_example.scss';

export const Example = () => (
<>
<HTTPError403
description="You are not authorized to access this resource."
errorCodeLabel="Error 403"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Forbidden"
/>
<HTTPError404
description="The page you are looking for was not found."
errorCodeLabel="Error 404"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Page not found"
/>
<HTTPErrorOther
description="Received an invalid response."
errorCodeLabel="Error 502"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Bad gateway"
/>
<MyComponent
errorCodeLabel="error"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
/>
</>
);
31 changes: 31 additions & 0 deletions packages/upgrade/src/upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,37 @@
});
},
},
{
name: 'ibm-products-update-http-errors',
description:
'Rewrites HttpError403, HttpError404, HttpErrorOther to FullPageError',
migrate: async (options) => {
const transform = path.join(

Check warning on line 367 in packages/upgrade/src/upgrades.js

View check run for this annotation

Codecov / codecov/patch

packages/upgrade/src/upgrades.js#L366-L367

Added lines #L366 - L367 were not covered by tests
TRANSFORM_DIR,
'ibm-products-update-http-errors.js'
);
const paths =
Array.isArray(options.paths) && options.paths.length > 0
? options.paths
: await glob(['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], {

Check warning on line 374 in packages/upgrade/src/upgrades.js

View check run for this annotation

Codecov / codecov/patch

packages/upgrade/src/upgrades.js#L373-L374

Added lines #L373 - L374 were not covered by tests
cwd: options.workspaceDir,
ignore: [
'**/es/**',
'**/lib/**',
'**/umd/**',
'**/node_modules/**',
'**/storybook-static/**',
],
});

await run({

Check warning on line 385 in packages/upgrade/src/upgrades.js

View check run for this annotation

Codecov / codecov/patch

packages/upgrade/src/upgrades.js#L385

Added line #L385 was not covered by tests
dry: !options.write,
transform,
paths,
verbose: options.verbose,
});
},
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import {
HTTPError403,
HTTPError404,
HTTPErrorOther,
} from '@carbon/ibm-products';
import './_example.scss';

export const Example = () => (
<>
<HTTPError403
description="You are not authorized to access this resource."
errorCodeLabel="Error 403"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Forbidden"
/>
<HTTPError404
description="The page you are looking for was not found."
errorCodeLabel="Error 404"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Page not found"
/>
<HTTPErrorOther
description="Received an invalid response."
errorCodeLabel="Error 502"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
title="Bad gateway"
/>
<MyComponent
errorCodeLabel="error"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
/>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Link } from "@carbon/react";
import React from 'react';
import { FullPageError } from '@carbon/ibm-products';
import './_example.scss';

export const Example = () => (
<>
<FullPageError
description="You are not authorized to access this resource."
label="Error 403"
children={<><Link href={"https://www.carbondesignsystem.com"}>Carbon Design System</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link></>}
title="Forbidden"
kind="403" />
<FullPageError
description="The page you are looking for was not found."
label="Error 404"
children={<><Link href={"https://www.carbondesignsystem.com"}>Carbon Design System</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link></>}
title="Page not found"
kind="404" />
<FullPageError
description="Received an invalid response."
label="Error 502"
children={<><Link href={"https://www.carbondesignsystem.com"}>Carbon Design System</Link><br /><Link href={"https://github.com/carbon-design-system/ibm-products"}>Carbon for IBM Products component library</Link></>}
title="Bad gateway"
kind="custom" />
<MyComponent
errorCodeLabel="error"
links={[
{
href: 'https://www.carbondesignsystem.com',
text: 'Carbon Design System',
},
{
href: 'https://github.com/carbon-design-system/ibm-products',
text: 'Carbon for IBM Products component library',
},
]}
/>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright IBM Corp. 2021, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { defineTest } = require('jscodeshift/dist/testUtils');

defineTest(__dirname, 'ibm-products-update-http-errors');
Loading
Loading