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

[WIP] docs: provide TS version of code snippets #2638

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ddf137
chore: setup multi code examples in docs
kark Jun 8, 2022
5e35dd9
docs: data fetching code examples
kark Jun 9, 2022
7f7a980
docs: ui components code examples
kark Jun 9, 2022
8029bd3
docs: help needed code sample
kark Jun 13, 2022
8f6342e
docs(website): updated code snippets for development_permissions
CarlosCortizasCT Jun 13, 2022
f65c48d
docs(website): updated code snippets for api-reference_application-shell
CarlosCortizasCT Jun 13, 2022
213a271
docs(website): fixed code snippets for development_permissions
CarlosCortizasCT Jun 13, 2022
c94726f
docs(website): fixed link in docs for api-reference_application-shell
CarlosCortizasCT Jun 13, 2022
eb508ed
docs: integrate own api, application config
kark Jun 14, 2022
e248b11
docs(website): added code snippets for api-reference_application-comp…
CarlosCortizasCT Jun 14, 2022
58424e0
docs(website): update snippets mdx snippets
CarlosCortizasCT Jun 14, 2022
f99caef
docs: migrating from project-level custom apps, api reference - permi…
kark Jun 14, 2022
88a4af9
docs: application shell connectors
kark Jun 14, 2022
686a9b0
docs: testing
Rhotimee Jun 16, 2022
9e232e8
docs: translations
Rhotimee Jun 16, 2022
8a02a7a
docs: remove language props and use .jsx
Rhotimee Jun 17, 2022
badad37
chore(website): update docs-kit dependencies
CarlosCortizasCT Jun 17, 2022
71e3e96
docs(website): update application-shell docs examples
CarlosCortizasCT Jun 17, 2022
0a84e68
docs(website): update application-components docs examples
CarlosCortizasCT Jun 17, 2022
f320dc1
docs(website): update permissions docs examples
CarlosCortizasCT Jun 17, 2022
636c411
docs(kk): update snippets to use jsx
kark Jun 17, 2022
4faa86b
docs(kk): add missing snippet for sdk actions use with forwardTo
kark Jun 17, 2022
9c08bb5
docs: fix highlight lines
kark Jun 17, 2022
3b008cf
docs: fix issue with urls not found
kark Jun 17, 2022
4e41536
docs(website): update code snippets for deve
ddouglasz Jun 20, 2022
4065d04
refactor(docs): action-global
Rhotimee Jun 20, 2022
85d17eb
docs: align with changes in TS starter template
kark Jun 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions jest.eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module.exports = {
'.yarn',
'.cache',
'build/',
'code-examples/',
'compiled-data/',
'generated/',
'dist/',
'public/',
'generated',
'compiled-data',
],
testMatch: ['<rootDir>/**/*.js', '<rootDir>/**/*.ts', '<rootDir>/**/*.tsx'],
watchPlugins: [
Expand Down
7 changes: 3 additions & 4 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const micromatch = require('micromatch');

module.exports = {
'*.md': ['prettier --write --parser markdown'],
'*.yaml': ['prettier --write --parser yaml'],
Expand All @@ -9,7 +7,7 @@ module.exports = {
'*.ctp.graphql': () => 'yarn generate-types:ctp',
'*.settings.graphql': () => 'yarn generate-types:settings',
'*.proxy.graphql': () => 'yarn generate-types:proxy',
'*.js': [
'!(website)/**/*.js': [
'prettier --write',
// NOTE: apparently if you pass some argument that is not a flag AFTER the `reporters`
// flag, jest does not seem correctly parse the arguments.
Expand All @@ -21,7 +19,7 @@ module.exports = {
// For that reason, we move the `--onlyChanged` flag next to it.
'yarn lint:js --reporters=jest-silent-reporter --onlyChanged',
],
'!(cypress)/**/*.{ts,tsx}': [
'!(cypress|website)/**/*.{ts,tsx}': [
'prettier --write',
// NOTE: apparently if you pass some argument that is not a flag AFTER the `reporters`
// flag, jest does not seem correctly parse the arguments.
Expand All @@ -48,6 +46,7 @@ module.exports = {
'yarn lint:js --reporters=jest-silent-reporter --onlyChanged',
() => 'yarn typecheck:cypress',
],
'website/**/*.{js,ts,tsx}': ['prettier --write'],
'*.css': [
'prettier --write --parser css',
// NOTE: apparently if you pass some argument that is not a flag AFTER the `reporters`
Expand Down
31 changes: 16 additions & 15 deletions website/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const colorPresets = require('@commercetools-docs/gatsby-theme-docs/color-presets');
const {
configureThemeWithAddOns,
} = require('@commercetools-docs/gatsby-theme-docs/configure-theme');

module.exports = {
// https://www.gatsbyjs.com/docs/reference/release-notes/v2.28/#feature-flags-in-gatsby-configjs
Expand All @@ -19,21 +22,19 @@ module.exports = {
},
plugins: [
// Docs theme
{
resolve: '@commercetools-docs/gatsby-theme-docs',
options: {
websiteKey: 'custom-applications',
colorPreset: colorPresets.merchantCenterDeveloperDocs.key,
beta: false,
excludeFromSearchIndex: false,
gaTrackingId: 'UA-38285631-3',
globalNotification: {
notificationType: 'info',
content:
'This is the new documentation of Custom Applications. You can still visit the [legacy documentation](https://docs.commercetools.com/custom-applications/legacy) during the [migration](/migrating-from-project-level-custom-applications) from Project-level Custom Applications.',
},
overrideDefaultConfigurationData: ['**/top-*'],
...configureThemeWithAddOns({
websiteKey: 'custom-applications',
colorPreset: colorPresets.merchantCenterDeveloperDocs.key,
beta: false,
excludeFromSearchIndex: false,
gaTrackingId: 'UA-38285631-3',
globalNotification: {
notificationType: 'info',
content:
'This is the new documentation of Custom Applications. You can still visit the [legacy documentation](https://docs.commercetools.com/custom-applications/legacy) during the [migration](/migrating-from-project-level-custom-applications) from Project-level Custom Applications.',
},
},
overrideDefaultConfigurationData: ['**/top-*'],
addOns: ['@commercetools-docs/gatsby-theme-code-examples'],
}),
],
};
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"generate-icons": "svgr -d src/icons/generated -- src/icons/svg && prettier --write '**/generated/*.js'"
},
"dependencies": {
"@commercetools-docs/gatsby-theme-docs": "18.6.0",
"@commercetools-docs/gatsby-theme-code-examples": "19.2.0",
"@commercetools-docs/gatsby-theme-docs": "19.1.0",
"@commercetools-docs/ui-kit": "18.6.0",
"@commercetools-uikit/card": "^15.0.0",
"@commercetools-uikit/spacings-inline": "^15.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addon-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable prettier/prettier */
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
/* THIS IS AN AUTOGENERATED FILE, DO NOT EDIT DIRECTLY */
import * as components0 from '@commercetools-docs/gatsby-theme-code-examples/shortcodes';

export default {
...components0,
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BetaFlag } from '@commercetools-docs/gatsby-theme-docs';
import Playground from '../../../components/playground';
import addonComponents from './addon-components';

const markdownComponents = {
Playground,
BetaFlag,
...addonComponents,
};

export default markdownComponents;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';

const MyComponent = () => {
const applicationName = useApplicationContext(
(context) => context.environment.applicationName
);
return <div>{`Welcome to the application ${applicationName}!`}</div>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';

const MyComponent = () => {
const applicationName = useApplicationContext(
(context) => context.environment.applicationName
);
return <div>{`Welcome to the application ${applicationName}!`}</div>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const EntryPoint = () => (
<ApplicationShell
environment={window.app}
// other props
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ApplicationWindow } from '@commercetools-frontend/constants';

declare let window: ApplicationWindow;

const EntryPoint = () => (
<ApplicationShell
environment={window.app}
// other props
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}
const error = new CustomError('error');
dispatch(handleActionError(error)); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CustomError extends Error {
constructor(message: string) {
super(message);
this.name = 'CustomError';
}
}
const error = new CustomError('error');
dispatch(handleActionError(error)); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { STATUS_CODES } from '@commercetools-frontend/constants';
const error = {
statusCode: STATUS_CODES.FORBIDDEN, // statusCode: 403
body: {
message: 'This is an error',
errors: [
{
message: 'This is an error', // this message will be displayed as notification text
code: 'Invalid',
},
],
},
};
// ...
dispatch(handleActionError(error)); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { STATUS_CODES } from '@commercetools-frontend/constants';

type TStatusCode = typeof STATUS_CODES[keyof typeof STATUS_CODES];

type TAppNotificationApiError<ExtraFields extends {} = {}> = {
message: string;
/** @deprecated Use `extensions.code` */
code?: string;
extensions?: {
code?: string;
};
} & ExtraFields;

type TActionError = {
statusCode: TStatusCode;
body: {
message: string;
errors?: TAppNotificationApiError | TAppNotificationApiError[];
};
};

const error: TActionError = {
statusCode: STATUS_CODES.FORBIDDEN, // statusCode: 403
body: {
message: 'This is an error',
errors: [
{
message: 'This is an error', // this message will be displayed as notification text
code: 'Invalid',
},
],
},
};
// ...
dispatch(handleActionError(error)); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const error = {
// ...
body: {
// ...
errors: [
{
message:
"This is the first error", // displayed as the notification text
code: "Invalid",
},
{
message:
"This is the second error", // also displayed as the notification text
code: "Invalid",
},
],
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { STATUS_CODES } from '@commercetools-frontend/constants';

type TStatusCode = typeof STATUS_CODES[keyof typeof STATUS_CODES];

type TAppNotificationApiError<ExtraFields extends {} = {}> = {
message: string;
/** @deprecated Use `extensions.code` */
code?: string;
extensions?: {
code?: string;
};
} & ExtraFields;

type TActionError = {
statusCode: TStatusCode;
body: {
message: string;
errors?: TAppNotificationApiError | TAppNotificationApiError[];
};
};

const error: TActionError = {
// ...
body: {
// ...
errors: [
{
message: 'This is the first error', // displayed as the notification text
code: 'Invalid',
},
{
message: 'This is the second error', // also displayed as the notification text
code: 'Invalid',
},
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const errors = [
{
message: "A duplicate value '\"Test channel\"' exists for field 'key'.",
code: 'DuplicateField',
extensions: {
code: 'DuplicateField',
},
},
];
// ...
dispatch(showApiErrorNotification({ errors })); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type TAppNotificationApiError<ExtraFields extends {} = {}> = {
message: string;
/** @deprecated Use `extensions.code` */
code?: string;
extensions?: {
code?: string;
};
} & ExtraFields;

const errors: TAppNotificationApiError[] = [
{
message: "A duplicate value '\"Test channel\"' exists for field 'key'.",
code: 'DuplicateField',
extensions: {
code: 'DuplicateField',
},
},
];
// ...
// dispatch(showApiErrorNotification({ errors })); // dispatch method from Redux store
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {
DOMAINS,
NOTIFICATION_KINDS_SIDE,
} from '@commercetools-frontend/constants';

const kind = NOTIFICATION_KINDS_SIDE.success;
const domain = DOMAINS.SIDE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {
DOMAINS,
NOTIFICATION_KINDS_SIDE,
} from '@commercetools-frontend/constants';

const kind = NOTIFICATION_KINDS_SIDE.success;
const domain = DOMAINS.SIDE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { useHideAllPageNotifications } from '@commercetools-frontend/actions-global';

const hideAllPageNotifications = useHideAllPageNotifications();
hideAllPageNotifications();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { useHideAllPageNotifications } from '@commercetools-frontend/actions-global';

const hideAllPageNotifications = useHideAllPageNotifications();
hideAllPageNotifications();
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { STATUS_CODES } from '@commercetools-frontend/constants';
import { useOnActionError } from '@commercetools-frontend/actions-global';

const error = {
statusCode: STATUS_CODES.FORBIDDEN, // statusCode: 403
body: {
message: "This is an error",
errors: [
{
message:
"This is an error",
code: "Invalid",
},
],
},
}
const onActionError = useOnActionError();
onActionError(error)
Loading