Skip to content

Commit

Permalink
Merge branch 'main' into docs/email-mfa
Browse files Browse the repository at this point in the history
  • Loading branch information
jjarvisp authored Oct 30, 2024
2 parents 86704dc + aaca1ad commit e7e61f7
Show file tree
Hide file tree
Showing 148 changed files with 5,376,903 additions and 929 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/update_references.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Receive repository dispatch event

on:
# Listen to a repository dispatch event by the name of `dispatch-event`
repository_dispatch:
types: [update-references]
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Setup Node.js 20
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20.x

- name: Set github commit user
env:
GITHUB_EMAIL: ${{ vars.GH_EMAIL }}
GITHUB_USER: ${{ vars.GH_USER }}
run: |
git config --global user.email $GITHUB_EMAIL
git config --global user.name $GITHUB_USER
# Set branch name to be used as environment variable
- name: Set Branch Name
run: echo "BRANCH_NAME=$(echo update-ref-$(date +%s))" >> $GITHUB_ENV

# Create new branch, download, and commit changes to the new branch
- name: Create new branch
run: |
git checkout -b ${{ env.BRANCH_NAME }}
curl -L -o ${{ vars.REF_LOC }} ${{ vars.REMOTE_REF }}
node tasks/clean-references.mjs
git add ${{ vars.REF_LOC }} ${{ vars.CLEAN_LOC }}
git commit -m "updating references"
git push -u origin ${{ env.BRANCH_NAME }}
# Open pull request
- name: Create Pull Request
run: gh pr create -B main -H ${{ env.BRANCH_NAME }} --title 'Merge ${{ env.BRANCH_NAME }} into main' --body 'Created by Github action'
2 changes: 2 additions & 0 deletions mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { InternalLinkButton } from './src/components/InternalLinkButton';
import { Grid, View } from '@aws-amplify/ui-react';
import { Columns } from './src/components/Columns';
import { Video } from './src/components/Video';
import { ReferencePage } from './src/components/ApiDocs';

const ResponsiveImage = (props) => (
<ExportedImage style={{ height: 'auto' }} {...props} />
Expand Down Expand Up @@ -71,6 +72,7 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
Columns,
Video,
View,
ReferencePage,
...components
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -7719,16 +7719,6 @@
"target": "https://ui.docs.amplify.aws/",
"status": "301"
},
{
"source": "/flutter/build-ui/<*>",
"target": "/flutter/build-ui/",
"status": "301"
},
{
"source": "/flutter/deploy-and-host/<*>",
"target": "/flutter/deploy-and-host",
"status": "301"
},
{
"source": "/flutter/sdk/",
"target": "/flutter/build-a-backend/",
Expand Down
38 changes: 38 additions & 0 deletions src/components/ApiDocs/ApiComment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Fragment } from 'react';
import { View } from '@aws-amplify/ui-react';
import { parseMarkdownLinks, parseMarkdown } from '@/utils/parseMdxLinks';

interface ApiCommentProps {
apiComment?: any[];
codeBlock?: boolean | undefined;
}

export const ApiComment = ({ apiComment, codeBlock }: ApiCommentProps) => {
if (!apiComment) return null;
const firstItem = apiComment[0];
if (!firstItem?.text?.replaceAll('-', '')?.trim()) {
apiComment.shift();
}
const commentList = apiComment.map((snippet, idx) => {
if (snippet.kind === 'code') {
return <code key={idx}>{snippet.text.replaceAll('`', '')}</code>;
} else {
const text = snippet.text;
if (idx === 0 && codeBlock) {
const words = text.split(' ');
return (
<Fragment key={`snippet-${idx}`}>
<code>{words[0]}</code>
{words.slice(1).join(' ')}
</Fragment>
);
} else {
return parseMarkdownLinks(text);
}
}
});

const parsedComments = parseMarkdown(commentList as (string | JSX.Element)[]);

return <View>{parsedComments}</View>;
};
56 changes: 56 additions & 0 deletions src/components/ApiDocs/ApiModalProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useState, createContext } from 'react';
import { LinkDataType } from './display/TypeLink';
import { ApiModal } from './display/ApiModal';

export const TypeContext = createContext({
setModalData: (data) => data,
modalOpen: () => {},
addBreadCrumb: (data) => data,
setBC: (data) => data
});

export const ApiModalProvider = ({ children }) => {
const [modalData, setModalData] = useState({});
const [showModal, setShowModal] = useState(false);
const [breadCrumbs, setBreadCrumbs] = useState<LinkDataType[]>([]);

const modalOpen = () => {
setShowModal(true);
};
const closeModal = () => {
setShowModal(false);
};

const addBreadCrumb = (bc) => {
breadCrumbs.push(bc);
setBreadCrumbs(breadCrumbs);
};

const setBC = (bc) => {
setBreadCrumbs(bc);
};

const clearBC = () => {
setBreadCrumbs([]);
};

const value = {
setModalData,
modalOpen,
addBreadCrumb,
setBC
};

return (
<TypeContext.Provider value={value}>
<ApiModal
data={modalData}
showModal={showModal}
close={closeModal}
breadCrumbs={breadCrumbs}
clearBC={clearBC}
/>
{children}
</TypeContext.Provider>
);
};
12 changes: 12 additions & 0 deletions src/components/ApiDocs/FunctionReference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { View } from '@aws-amplify/ui-react';
import { FunctionSignature } from './FunctionSignature';

export const FunctionReference = ({ func }) => {
return (
<View>
{func.signatures.map((sig, index) => (
<FunctionSignature sig={sig} key={`signature-${index}`} />
))}
</View>
);
};
35 changes: 35 additions & 0 deletions src/components/ApiDocs/FunctionReturn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { View } from '@aws-amplify/ui-react';
import { MDXHeading } from '../MDXComponents';
import { Promise } from './display/Promise';
import { ApiComment } from './ApiComment';
import references from '@/directory/apiReferences.json';
import { ParameterType } from './display';

export const FunctionReturn = ({ functionReturn, sigName }) => {
const name = functionReturn.name;
let display, description;
if (name === 'Promise') {
const returnType = references[functionReturn.typeArguments[0].target];
display = <Promise typeObject={functionReturn} />;
if (returnType?.comment?.summary) {
description = <ApiComment apiComment={returnType.comment.summary} />;
}
} else {
const returnType = references[functionReturn.target];
display = <ParameterType typeData={functionReturn} />;
if (returnType?.comment?.summary) {
description = <ApiComment apiComment={returnType.comment.summary} />;
}
}
return (
<View>
<MDXHeading level={3} id={`${sigName}-Returns`}>
Returns
</MDXHeading>

<code>{display}</code>

{description}
</View>
);
};
44 changes: 44 additions & 0 deletions src/components/ApiDocs/FunctionSignature.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { View } from '@aws-amplify/ui-react';
import { MDXHeading } from '../MDXComponents';
import { ApiComment } from './ApiComment';
import { Parameters } from './Parameters';
import { Throws } from './Throws';
import { FunctionReturn } from './FunctionReturn';
import references from '@/directory/apiReferences.json';

export const FunctionSignature = ({ sig }) => {
const sigObject = references[sig];
const description = sigObject?.comment?.summary;
const parameters = sigObject?.parameters;
const throws = sigObject?.comment?.blockTags?.filter(
(tagObject) => tagObject['tag'] === '@throws'
);
const returns = sigObject?.type;
return (
<View>
<MDXHeading level={2} id={`${sigObject.name}-${sigObject.id}`}>
{sigObject.name}
</MDXHeading>

{description && <ApiComment apiComment={description} />}

{parameters && (
<Parameters
parameters={parameters}
sigName={`${sigObject.name}-${sigObject.id}`}
/>
)}

{throws && throws.length > 0 && (
<Throws throws={throws} sigName={`${sigObject.name}-${sigObject.id}`} />
)}

{returns && (
<FunctionReturn
functionReturn={returns}
sigName={`${sigObject.name}-${sigObject.id}`}
/>
)}
</View>
);
};
46 changes: 46 additions & 0 deletions src/components/ApiDocs/Parameters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { View } from '@aws-amplify/ui-react';
import { MDXHeading, MDXTable } from '../MDXComponents';
import { ApiComment } from './ApiComment';
import { ParameterType } from './display';
import references from '@/directory/apiReferences.json';

export const Parameters = ({ parameters, sigName }) => {
const paramObjects = parameters.map((id) => references[id]);
return (
<View>
<MDXHeading level={3} id={`${sigName}-Parameters`}>
Parameters
</MDXHeading>
<MDXTable>
<thead>
<tr>
<th>Option</th>
<th>Required</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{paramObjects.map((option) => {
return (
<tr key={option.id}>
<td>
<code>{option.name}</code>
</td>
<td>{option?.flags?.isOptional ? 'false' : 'true'}</td>
<td>
<ParameterType typeData={option.type} />
</td>
<td>
{option?.comment?.summary && (
<ApiComment apiComment={option.comment.summary} />
)}
</td>
</tr>
);
})}
</tbody>
</MDXTable>
</View>
);
};
40 changes: 40 additions & 0 deletions src/components/ApiDocs/ReferencePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Fragment } from 'react';

import { FunctionReference } from './FunctionReference';
import { Divider, View, Flex } from '@aws-amplify/ui-react';
import { API_CATEGORIES, API_SUB_CATEGORIES } from '@/data/api-categories.mjs';
import references from '@/directory/apiReferences.json';
import { MDXHeading } from '../MDXComponents';

export const ReferencePage = ({ category }) => {
category = API_CATEGORIES[category] || API_SUB_CATEGORIES[category];
const cat = references['categories'].find(
(catObject) => catObject.name === category
);
return (
<View className={'reference-page'}>
{cat?.children?.map((child, idx) => (
<Fragment key={`reference-${idx}`}>
{idx !== 0 && <Divider marginTop={'medium'} />}
<FunctionReference func={child} />
</Fragment>
))}
<Divider marginTop={'large'} marginBottom={'large'} />
<MDXHeading level={4}>Link Color Legend</MDXHeading>
<Flex className="api-legend-container">
<Flex>
<View as="span" className="api-legend interface" />
Interface
</Flex>
<Flex>
<View as="span" className="api-legend reference" />
Reference
</Flex>
<Flex>
<View as="span" className="api-legend union" />
Other
</Flex>
</Flex>
</View>
);
};
21 changes: 21 additions & 0 deletions src/components/ApiDocs/Throws.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { View } from '@aws-amplify/ui-react';
import { MDXHeading } from '../MDXComponents';
import { ApiComment } from './ApiComment';

export const Throws = ({ throws, sigName }) => {
return (
<View>
<MDXHeading level={3} id={`${sigName}-Throws`}>
Throws
</MDXHeading>

<ul>
{throws.map((error, i) => (
<li key={i}>
<ApiComment apiComment={error.content} codeBlock={true} />{' '}
</li>
))}
</ul>
</View>
);
};
Loading

0 comments on commit e7e61f7

Please sign in to comment.