Skip to content

Commit cec18c7

Browse files
author
katiegoines
committed
fix extra toc
2 parents 29cbbe4 + d1f94e8 commit cec18c7

File tree

79 files changed

+5376106
-564
lines changed

Some content is hidden

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

79 files changed

+5376106
-564
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Receive repository dispatch event
2+
3+
on:
4+
# Listen to a repository dispatch event by the name of `dispatch-event`
5+
repository_dispatch:
6+
types: [update-references]
7+
workflow_dispatch:
8+
env:
9+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10+
11+
jobs:
12+
create-pull-request:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
17+
18+
- name: Setup Node.js 20
19+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
20+
with:
21+
node-version: 20.x
22+
23+
- name: Set github commit user
24+
env:
25+
GITHUB_EMAIL: ${{ vars.GH_EMAIL }}
26+
GITHUB_USER: ${{ vars.GH_USER }}
27+
run: |
28+
git config --global user.email $GITHUB_EMAIL
29+
git config --global user.name $GITHUB_USER
30+
31+
# Set branch name to be used as environment variable
32+
- name: Set Branch Name
33+
run: echo "BRANCH_NAME=$(echo update-ref-$(date +%s))" >> $GITHUB_ENV
34+
35+
# Create new branch, download, and commit changes to the new branch
36+
- name: Create new branch
37+
run: |
38+
git checkout -b ${{ env.BRANCH_NAME }}
39+
curl -L -o ${{ vars.REF_LOC }} ${{ vars.REMOTE_REF }}
40+
node tasks/clean-references.mjs
41+
git add ${{ vars.REF_LOC }} ${{ vars.CLEAN_LOC }}
42+
git commit -m "updating references"
43+
git push -u origin ${{ env.BRANCH_NAME }}
44+
45+
# Open pull request
46+
- name: Create Pull Request
47+
run: gh pr create -B main -H ${{ env.BRANCH_NAME }} --title 'Merge ${{ env.BRANCH_NAME }} into main' --body 'Created by Github action'

mdx-components.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { InternalLinkButton } from './src/components/InternalLinkButton';
2222
import { Grid, View } from '@aws-amplify/ui-react';
2323
import { Columns } from './src/components/Columns';
2424
import { Video } from './src/components/Video';
25+
import { ReferencePage } from './src/components/ApiDocs';
2526

2627
const ResponsiveImage = (props) => (
2728
<ExportedImage style={{ height: 'auto' }} {...props} />
@@ -71,6 +72,7 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
7172
Columns,
7273
Video,
7374
View,
75+
ReferencePage,
7476
...components
7577
};
7678
}
Loading
Loading
Loading
Loading
Loading
Loading

redirects.json

-10
Original file line numberDiff line numberDiff line change
@@ -7719,16 +7719,6 @@
77197719
"target": "https://ui.docs.amplify.aws/",
77207720
"status": "301"
77217721
},
7722-
{
7723-
"source": "/flutter/build-ui/<*>",
7724-
"target": "/flutter/build-ui/",
7725-
"status": "301"
7726-
},
7727-
{
7728-
"source": "/flutter/deploy-and-host/<*>",
7729-
"target": "/flutter/deploy-and-host",
7730-
"status": "301"
7731-
},
77327722
{
77337723
"source": "/flutter/sdk/",
77347724
"target": "/flutter/build-a-backend/",

src/components/ApiDocs/ApiComment.tsx

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Fragment } from 'react';
2+
import { View } from '@aws-amplify/ui-react';
3+
import { parseMarkdownLinks, parseMarkdown } from '@/utils/parseMdxLinks';
4+
5+
interface ApiCommentProps {
6+
apiComment?: any[];
7+
codeBlock?: boolean | undefined;
8+
}
9+
10+
export const ApiComment = ({ apiComment, codeBlock }: ApiCommentProps) => {
11+
if (!apiComment) return null;
12+
const firstItem = apiComment[0];
13+
if (!firstItem?.text?.replaceAll('-', '')?.trim()) {
14+
apiComment.shift();
15+
}
16+
const commentList = apiComment.map((snippet, idx) => {
17+
if (snippet.kind === 'code') {
18+
return <code key={idx}>{snippet.text.replaceAll('`', '')}</code>;
19+
} else {
20+
const text = snippet.text;
21+
if (idx === 0 && codeBlock) {
22+
const words = text.split(' ');
23+
return (
24+
<Fragment key={`snippet-${idx}`}>
25+
<code>{words[0]}</code>
26+
{words.slice(1).join(' ')}
27+
</Fragment>
28+
);
29+
} else {
30+
return parseMarkdownLinks(text);
31+
}
32+
}
33+
});
34+
35+
const parsedComments = parseMarkdown(commentList as (string | JSX.Element)[]);
36+
37+
return <View>{parsedComments}</View>;
38+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { useState, createContext } from 'react';
2+
import { LinkDataType } from './display/TypeLink';
3+
import { ApiModal } from './display/ApiModal';
4+
5+
export const TypeContext = createContext({
6+
setModalData: (data) => data,
7+
modalOpen: () => {},
8+
addBreadCrumb: (data) => data,
9+
setBC: (data) => data
10+
});
11+
12+
export const ApiModalProvider = ({ children }) => {
13+
const [modalData, setModalData] = useState({});
14+
const [showModal, setShowModal] = useState(false);
15+
const [breadCrumbs, setBreadCrumbs] = useState<LinkDataType[]>([]);
16+
17+
const modalOpen = () => {
18+
setShowModal(true);
19+
};
20+
const closeModal = () => {
21+
setShowModal(false);
22+
};
23+
24+
const addBreadCrumb = (bc) => {
25+
breadCrumbs.push(bc);
26+
setBreadCrumbs(breadCrumbs);
27+
};
28+
29+
const setBC = (bc) => {
30+
setBreadCrumbs(bc);
31+
};
32+
33+
const clearBC = () => {
34+
setBreadCrumbs([]);
35+
};
36+
37+
const value = {
38+
setModalData,
39+
modalOpen,
40+
addBreadCrumb,
41+
setBC
42+
};
43+
44+
return (
45+
<TypeContext.Provider value={value}>
46+
<ApiModal
47+
data={modalData}
48+
showModal={showModal}
49+
close={closeModal}
50+
breadCrumbs={breadCrumbs}
51+
clearBC={clearBC}
52+
/>
53+
{children}
54+
</TypeContext.Provider>
55+
);
56+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { FunctionSignature } from './FunctionSignature';
3+
4+
export const FunctionReference = ({ func }) => {
5+
return (
6+
<View>
7+
{func.signatures.map((sig, index) => (
8+
<FunctionSignature sig={sig} key={`signature-${index}`} />
9+
))}
10+
</View>
11+
);
12+
};
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { Promise } from './display/Promise';
4+
import { ApiComment } from './ApiComment';
5+
import references from '@/directory/apiReferences.json';
6+
import { ParameterType } from './display';
7+
8+
export const FunctionReturn = ({ functionReturn, sigName }) => {
9+
const name = functionReturn.name;
10+
let display, description;
11+
if (name === 'Promise') {
12+
const returnType = references[functionReturn.typeArguments[0].target];
13+
display = <Promise typeObject={functionReturn} />;
14+
if (returnType?.comment?.summary) {
15+
description = <ApiComment apiComment={returnType.comment.summary} />;
16+
}
17+
} else {
18+
const returnType = references[functionReturn.target];
19+
display = <ParameterType typeData={functionReturn} />;
20+
if (returnType?.comment?.summary) {
21+
description = <ApiComment apiComment={returnType.comment.summary} />;
22+
}
23+
}
24+
return (
25+
<View>
26+
<MDXHeading level={3} id={`${sigName}-Returns`}>
27+
Returns
28+
</MDXHeading>
29+
30+
<code>{display}</code>
31+
32+
{description}
33+
</View>
34+
);
35+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
import { Parameters } from './Parameters';
5+
import { Throws } from './Throws';
6+
import { FunctionReturn } from './FunctionReturn';
7+
import references from '@/directory/apiReferences.json';
8+
9+
export const FunctionSignature = ({ sig }) => {
10+
const sigObject = references[sig];
11+
const description = sigObject?.comment?.summary;
12+
const parameters = sigObject?.parameters;
13+
const throws = sigObject?.comment?.blockTags?.filter(
14+
(tagObject) => tagObject['tag'] === '@throws'
15+
);
16+
const returns = sigObject?.type;
17+
return (
18+
<View>
19+
<MDXHeading level={2} id={`${sigObject.name}-${sigObject.id}`}>
20+
{sigObject.name}
21+
</MDXHeading>
22+
23+
{description && <ApiComment apiComment={description} />}
24+
25+
{parameters && (
26+
<Parameters
27+
parameters={parameters}
28+
sigName={`${sigObject.name}-${sigObject.id}`}
29+
/>
30+
)}
31+
32+
{throws && throws.length > 0 && (
33+
<Throws throws={throws} sigName={`${sigObject.name}-${sigObject.id}`} />
34+
)}
35+
36+
{returns && (
37+
<FunctionReturn
38+
functionReturn={returns}
39+
sigName={`${sigObject.name}-${sigObject.id}`}
40+
/>
41+
)}
42+
</View>
43+
);
44+
};

src/components/ApiDocs/Parameters.tsx

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading, MDXTable } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
import { ParameterType } from './display';
5+
import references from '@/directory/apiReferences.json';
6+
7+
export const Parameters = ({ parameters, sigName }) => {
8+
const paramObjects = parameters.map((id) => references[id]);
9+
return (
10+
<View>
11+
<MDXHeading level={3} id={`${sigName}-Parameters`}>
12+
Parameters
13+
</MDXHeading>
14+
<MDXTable>
15+
<thead>
16+
<tr>
17+
<th>Option</th>
18+
<th>Required</th>
19+
<th>Type</th>
20+
<th>Description</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
{paramObjects.map((option) => {
25+
return (
26+
<tr key={option.id}>
27+
<td>
28+
<code>{option.name}</code>
29+
</td>
30+
<td>{option?.flags?.isOptional ? 'false' : 'true'}</td>
31+
<td>
32+
<ParameterType typeData={option.type} />
33+
</td>
34+
<td>
35+
{option?.comment?.summary && (
36+
<ApiComment apiComment={option.comment.summary} />
37+
)}
38+
</td>
39+
</tr>
40+
);
41+
})}
42+
</tbody>
43+
</MDXTable>
44+
</View>
45+
);
46+
};
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Fragment } from 'react';
2+
3+
import { FunctionReference } from './FunctionReference';
4+
import { Divider, View, Flex } from '@aws-amplify/ui-react';
5+
import { API_CATEGORIES, API_SUB_CATEGORIES } from '@/data/api-categories.mjs';
6+
import references from '@/directory/apiReferences.json';
7+
import { MDXHeading } from '../MDXComponents';
8+
9+
export const ReferencePage = ({ category }) => {
10+
category = API_CATEGORIES[category] || API_SUB_CATEGORIES[category];
11+
const cat = references['categories'].find(
12+
(catObject) => catObject.name === category
13+
);
14+
return (
15+
<View className={'reference-page'}>
16+
{cat?.children?.map((child, idx) => (
17+
<Fragment key={`reference-${idx}`}>
18+
{idx !== 0 && <Divider marginTop={'medium'} />}
19+
<FunctionReference func={child} />
20+
</Fragment>
21+
))}
22+
<Divider marginTop={'large'} marginBottom={'large'} />
23+
<MDXHeading level={4}>Link Color Legend</MDXHeading>
24+
<Flex className="api-legend-container">
25+
<Flex>
26+
<View as="span" className="api-legend interface" />
27+
Interface
28+
</Flex>
29+
<Flex>
30+
<View as="span" className="api-legend reference" />
31+
Reference
32+
</Flex>
33+
<Flex>
34+
<View as="span" className="api-legend union" />
35+
Other
36+
</Flex>
37+
</Flex>
38+
</View>
39+
);
40+
};

src/components/ApiDocs/Throws.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
5+
export const Throws = ({ throws, sigName }) => {
6+
return (
7+
<View>
8+
<MDXHeading level={3} id={`${sigName}-Throws`}>
9+
Throws
10+
</MDXHeading>
11+
12+
<ul>
13+
{throws.map((error, i) => (
14+
<li key={i}>
15+
<ApiComment apiComment={error.content} codeBlock={true} />{' '}
16+
</li>
17+
))}
18+
</ul>
19+
</View>
20+
);
21+
};

0 commit comments

Comments
 (0)