Skip to content

Commit eee3c24

Browse files
authored
Merge branch 'next-release/main' into renbran/setup-data-gen-2-android-swift
2 parents 8645909 + dabd267 commit eee3c24

File tree

56 files changed

+2070
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2070
-371
lines changed

cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@
10191019
"posts.graphql",
10201020
"PostsTable",
10211021
"posttitle",
1022+
"powertools",
10221023
"pre-annotated",
10231024
"pre-built",
10241025
"pre-created",
@@ -1047,6 +1048,7 @@
10471048
"pubsub",
10481049
"Pubsub",
10491050
"PubSub",
1051+
"Powertools",
10501052
"PUSHINFOPROVIDER",
10511053
"PushListenerService",
10521054
"pushnotification",

src/components/Layout/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export const Layout = ({
103103
const currentPlatform = platform
104104
? platform
105105
: PLATFORMS.includes(asPathPlatform)
106-
? asPathPlatform
107-
: DEFAULT_PLATFORM;
106+
? asPathPlatform
107+
: DEFAULT_PLATFORM;
108108

109109
const title = [
110110
pageTitle,

src/components/MDXComponents/MDXCode.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ const addVersions = (code: string) => {
3030
return code;
3131
};
3232

33+
const hasHighlights = (code: string): boolean => {
34+
const highlightableStrings = [
35+
'// highlight-start',
36+
'// highlight-end',
37+
'// highlight-next-line'
38+
];
39+
if (highlightableStrings.some((highlight) => code.includes(highlight))) {
40+
return true;
41+
}
42+
return false;
43+
};
44+
3345
export const MDXCode = ({
3446
codeString,
3547
language = 'js',
@@ -39,7 +51,7 @@ export const MDXCode = ({
3951
title
4052
}: MDXCodeProps) => {
4153
const [code, setCode] = useState(codeString);
42-
const shouldShowCopy = language !== 'console';
54+
const shouldShowCopy = language !== 'console' && !hasHighlights(codeString);
4355
const shouldShowHeader = shouldShowCopy || title;
4456
const titleId = `${useId()}-titleID`;
4557
const codeId = `${useId()}-codeID`;

src/components/MDXComponents/MDXCopyCodeButton.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,7 @@ import { useState } from 'react';
22
import { CopyToClipboard } from 'react-copy-to-clipboard';
33
import { Button, VisuallyHidden } from '@aws-amplify/ui-react';
44
import { trackCopyClicks } from '@/utils/track';
5-
6-
export const prepareCopyText = (codeString: string): string => {
7-
// We need to strip out markdown comments from the code string
8-
// so they don't show up in our copied text
9-
const highlightStartText = /\/\/\s?highlight-start/g;
10-
const highlightEndText = /\/\/\s?highlight-end/g;
11-
const highlightNextLine = /\/\/\s?highlight-next-line/g;
12-
13-
return codeString
14-
.replace(highlightStartText, '')
15-
.replace(highlightEndText, '')
16-
.replace(highlightNextLine, '');
17-
};
5+
import { prepareCopyText } from './utils/copy-code';
186

197
interface MDXCopyCodeButtonProps {
208
codeId: string;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useState } from 'react';
2+
import { CopyToClipboard } from 'react-copy-to-clipboard';
3+
import { VisuallyHidden } from '@aws-amplify/ui-react';
4+
import { trackCopyClicks } from '@/utils/track';
5+
import { prepareCopyText } from './utils/copy-code';
6+
7+
interface MDXCopyCodeButtonProps {
8+
codeId: string;
9+
codeString: string;
10+
testId?: string;
11+
title?: string;
12+
children?: React.ReactNode;
13+
}
14+
15+
export const MDXHighlightedCopyCodeButton = ({
16+
codeString,
17+
title,
18+
codeId,
19+
children
20+
}: MDXCopyCodeButtonProps) => {
21+
const [copied, setCopied] = useState(false);
22+
23+
const copyText = prepareCopyText(codeString);
24+
25+
const copy = () => {
26+
trackCopyClicks(copyText);
27+
setCopied(true);
28+
setTimeout(() => {
29+
setCopied(false);
30+
}, 2000);
31+
};
32+
return (
33+
<CopyToClipboard text={copyText} onCopy={copy}>
34+
<button className="highlight-copy-block" key={codeId}>
35+
{children}
36+
<span className="highlight-copy-block-hint">
37+
{copied ? 'Copied' : 'Copy'}
38+
</span>
39+
<VisuallyHidden>
40+
{` `}
41+
{title} highlighted code example
42+
</VisuallyHidden>
43+
</button>
44+
</CopyToClipboard>
45+
);
46+
};

src/components/MDXComponents/TokenList.tsx

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import type { Token } from 'prism-react-renderer';
22
import type { TokenListProps } from './types';
3+
import { MDXHighlightedCopyCodeButton } from './MDXHighlightedCopyCodeButton';
4+
5+
type ProcessedToken = {
6+
line: Token[];
7+
showLine: boolean;
8+
lineNumber: number;
9+
};
10+
11+
type TokenGroup =
12+
| (ProcessedToken & {
13+
type: 'regular';
14+
})
15+
| {
16+
tokens: ProcessedToken[];
17+
type: 'highlighted';
18+
};
319

420
export const TokenList = ({
521
tokens,
@@ -11,7 +27,9 @@ export const TokenList = ({
1127
let shouldHighlight = false;
1228
let highlightNextIndex: number | undefined;
1329

14-
return tokens.map((line: Token[], i: number) => {
30+
const tokenGroups: TokenGroup[] = [];
31+
32+
tokens.forEach((line: Token[], i: number) => {
1533
let showLine = true;
1634
lineNumber++;
1735

@@ -32,7 +50,7 @@ export const TokenList = ({
3250
// Test if the line contains code comment for highlight-next-line
3351
const isHighlightNext = textLine === '//highlight-next-line';
3452

35-
// If hilightNextIndex was set previously in the loop,
53+
// If highlightNextIndex was set previously in the loop,
3654
// then turn on highlight for this line
3755
if (highlightNextIndex && i === highlightNextIndex) {
3856
shouldHighlight = true;
@@ -53,6 +71,11 @@ export const TokenList = ({
5371
showLine = false;
5472
shouldHighlight = true;
5573
lineNumber--;
74+
75+
tokenGroups.push({
76+
tokens: [],
77+
type: 'highlighted'
78+
});
5679
}
5780

5881
// If this line is highlight-end, don't show this line,
@@ -73,17 +96,84 @@ export const TokenList = ({
7396
lineNumber--;
7497
}
7598

76-
return showLine ? (
99+
if (!shouldHighlight) {
100+
tokenGroups.push({
101+
type: 'regular',
102+
line,
103+
showLine,
104+
lineNumber
105+
});
106+
} else {
107+
const lastGroup = tokenGroups[tokenGroups.length - 1];
108+
let existingTokens: ProcessedToken[] = [];
109+
if (lastGroup?.type === 'highlighted') {
110+
existingTokens = lastGroup.tokens;
111+
}
112+
tokenGroups[tokenGroups.length - 1] = {
113+
tokens: [
114+
...existingTokens,
115+
{
116+
lineNumber,
117+
line,
118+
showLine
119+
}
120+
],
121+
type: 'highlighted'
122+
};
123+
}
124+
});
125+
126+
function renderProcessedToken(
127+
token: ProcessedToken,
128+
key: string,
129+
shouldHighlight: boolean,
130+
showLineNumbers: boolean = true
131+
) {
132+
return token.showLine ? (
77133
<div
78-
key={i}
79-
{...getLineProps({ line })}
134+
key={key}
135+
{...getLineProps({ line: token.line })}
80136
className={`token-line${shouldHighlight ? ' line-highlight' : ''}`}
81137
>
82-
{showLineNumbers && <span className="line-number">{lineNumber}</span>}
83-
{line.map((token, key) => (
138+
{showLineNumbers && (
139+
<span className="line-number">{token.lineNumber}</span>
140+
)}
141+
{token.line.map((token, key) => (
84142
<span key={key} {...getTokenProps({ token })} />
85143
))}
86144
</div>
87145
) : null;
146+
}
147+
148+
return tokenGroups.map((processedToken, i) => {
149+
if (processedToken.type === 'regular') {
150+
return renderProcessedToken(
151+
processedToken,
152+
`regular:${i}`,
153+
false,
154+
showLineNumbers
155+
);
156+
} else {
157+
const highlightedCodeString = processedToken.tokens
158+
.map((token) => token.line.map((line) => line.content).join(''))
159+
.join('\n');
160+
161+
return (
162+
<MDXHighlightedCopyCodeButton
163+
codeId={`highlighted:${i}`}
164+
key={`highlighted:${i}`}
165+
codeString={highlightedCodeString}
166+
>
167+
{processedToken.tokens.map((token, j) => {
168+
return renderProcessedToken(
169+
token,
170+
`highlighted:${i}:${j}`,
171+
true,
172+
showLineNumbers
173+
);
174+
})}
175+
</MDXHighlightedCopyCodeButton>
176+
);
177+
}
88178
});
89179
};

src/components/MDXComponents/__tests__/MDXCopyCodeButton.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
22
import { render, screen, waitFor } from '@testing-library/react';
3-
import { MDXCopyCodeButton, prepareCopyText } from '../MDXCopyCodeButton';
3+
import { MDXCopyCodeButton } from '../MDXCopyCodeButton';
44
import userEvent from '@testing-library/user-event';
55
import * as trackModule from '../../../utils/track';
6+
import { prepareCopyText } from '../utils/copy-code';
67

78
const codeString = `
89
import * as sns from 'aws-cdk-lib/aws-sns';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const prepareCopyText = (codeString: string): string => {
2+
// We need to strip out markdown comments from the code string
3+
// so they don't show up in our copied text
4+
const highlightStartText = /\/\/\s?highlight-start/g;
5+
const highlightEndText = /\/\/\s?highlight-end/g;
6+
const highlightNextLine = /\/\/\s?highlight-next-line/g;
7+
8+
return codeString
9+
.replace(highlightStartText, '')
10+
.replace(highlightEndText, '')
11+
.replace(highlightNextLine, '');
12+
};

src/directory/directory.mjs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ export const directory = {
255255
{
256256
path: 'src/pages/[platform]/build-a-backend/functions/examples/google-recaptcha-challenge/index.mdx'
257257
},
258+
{
259+
path: 'src/pages/[platform]/build-a-backend/functions/examples/kinesis-stream/index.mdx'
260+
},
261+
{
262+
path: 'src/pages/[platform]/build-a-backend/functions/examples/dynamo-db-stream/index.mdx'
263+
},
258264
{
259265
path: 'src/pages/[platform]/build-a-backend/functions/examples/bedrock-response/index.mdx'
260266
}
@@ -271,18 +277,6 @@ export const directory = {
271277
{
272278
path: 'src/pages/[platform]/build-a-backend/add-aws-services/index.mdx',
273279
children: [
274-
{
275-
path: 'src/pages/[platform]/build-a-backend/add-aws-services/custom-resources/index.mdx'
276-
},
277-
{
278-
path: 'src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx'
279-
},
280-
{
281-
path: 'src/pages/[platform]/build-a-backend/add-aws-services/rest-api/index.mdx'
282-
},
283-
{
284-
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/index.mdx'
285-
},
286280
{
287281
path: 'src/pages/[platform]/build-a-backend/add-aws-services/analytics/index.mdx',
288282
children: [
@@ -327,6 +321,41 @@ export const directory = {
327321
{
328322
path: 'src/pages/[platform]/build-a-backend/add-aws-services/geo/index.mdx'
329323
},
324+
{
325+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/index.mdx',
326+
children: [
327+
{
328+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/set-up-in-app-messaging/index.mdx'
329+
},
330+
{
331+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/integrate-application/index.mdx'
332+
},
333+
{
334+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/sync-messages/index.mdx'
335+
},
336+
{
337+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/display-messages/index.mdx'
338+
},
339+
{
340+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/clear-messages/index.mdx'
341+
},
342+
{
343+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/identify-user/index.mdx'
344+
},
345+
{
346+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/respond-interaction-events/index.mdx'
347+
},
348+
{
349+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/resolve-conflicts/index.mdx'
350+
},
351+
{
352+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/in-app-messaging/create-campaign/index.mdx'
353+
}
354+
]
355+
},
356+
{
357+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/rest-api/index.mdx'
358+
},
330359
{
331360
path: 'src/pages/[platform]/build-a-backend/add-aws-services/predictions/index.mdx',
332361
children: [
@@ -355,6 +384,12 @@ export const directory = {
355384
path: 'src/pages/[platform]/build-a-backend/add-aws-services/predictions/interpret-sentiment/index.mdx'
356385
}
357386
]
387+
},
388+
{
389+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/custom-resources/index.mdx'
390+
},
391+
{
392+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx'
358393
}
359394
]
360395
}
@@ -1564,6 +1599,9 @@ export const directory = {
15641599
},
15651600
{
15661601
path: 'src/pages/gen1/[platform]/tools/cli/migration/identity-claim-changes/index.mdx'
1602+
},
1603+
{
1604+
path: 'src/pages/gen1/[platform]/tools/cli/migration/iam-auth-updates-for-cdk-construct/index.mdx'
15671605
}
15681606
]
15691607
},

0 commit comments

Comments
 (0)