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

Feature/api docs #7990

Merged
merged 55 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
67310a1
initial template implementation
Aug 20, 2024
a71b22f
additional template functionality
Aug 22, 2024
a02f857
update modal
Aug 22, 2024
7e9db00
add api references json
Aug 29, 2024
b0237d6
add api categories
Aug 29, 2024
1967eda
update to template and display
Sep 5, 2024
607b121
revert changes to dev script
Sep 5, 2024
822306a
pass references to components
Sep 5, 2024
7f43348
remove build cache
Sep 5, 2024
c8ec4fb
remove pass through references
Sep 5, 2024
24f630b
clean references
Sep 5, 2024
8cabe59
add categories into clean references
Sep 5, 2024
0b96f5d
update references
Sep 5, 2024
8a1fb1b
update references with correct categories
Sep 5, 2024
fa57868
update references
Sep 6, 2024
b6c9c68
cleaned references
Sep 6, 2024
8106d66
update to clean references
Sep 6, 2024
bc8e502
update header and Toc
Sep 6, 2024
2231a12
update directories
Sep 6, 2024
5fd3b40
update generate directory
Sep 6, 2024
c1877af
add sub categories
Sep 6, 2024
5917c24
move references and rename to raw-references
Sep 6, 2024
a0eee84
update api docs template
Sep 9, 2024
0f1c394
undo unwanted changes
Sep 9, 2024
ea1739d
remove colons, some type updates, add keys (#7952)
hbuchel Sep 9, 2024
d571025
update TypeLink to output a button (#7953)
hbuchel Sep 9, 2024
4ec76ba
chore(api-docs-template): Update ApiModal styling/markup. Move breadc…
hbuchel Sep 10, 2024
75c2941
update to generateDirectory to add api reference pages (#7950)
jacoblogan Sep 11, 2024
df7efc1
add getApiStaticPath util function (#7949)
jacoblogan Sep 12, 2024
8cbc2f7
parse out markdown links in comments
Sep 16, 2024
01da321
update link to display literal type
Sep 16, 2024
aaf93da
Feature/api docs workflow (#7948)
jacoblogan Sep 17, 2024
98efe01
merge template changes
Sep 17, 2024
bccb11f
add dark mode to modal description text
Sep 17, 2024
1c8a870
update api function returns to use typeParameters
Sep 17, 2024
0c47b2f
remove space in promise display
Sep 17, 2024
b803bbc
close modal when click outside modal (#7969)
katiegoines Sep 17, 2024
1976e36
focus modal on open (#7970)
katiegoines Sep 17, 2024
eeef8e8
fix typo;
Sep 17, 2024
1494bc8
fix error in modal close
Sep 17, 2024
a439970
format "Returns" as code (#7971)
katiegoines Sep 17, 2024
44cd92c
add api link legend
Sep 17, 2024
6385358
update breadcrumbs separator, render nested typeArgs, render nested a…
Sep 19, 2024
62ac034
add function type display
Sep 19, 2024
6eb27d7
add error type
Sep 20, 2024
77150a6
update api legend and link colors
Sep 23, 2024
755e211
update cleaned references location
Sep 23, 2024
be3bfe4
update base references files
Sep 23, 2024
b0a2e9d
update scroll behavior
Sep 24, 2024
5115cf4
reverting uneeded changes to base.scss
Sep 24, 2024
dc13ada
update formatting
Sep 24, 2024
ac7bbea
add spacing to breadcrumbs
Sep 24, 2024
5cf25ff
remove extra space and add legend header
Sep 25, 2024
2a8c4ff
add formatting to api comments (#8000)
jacoblogan Sep 26, 2024
7dc4aac
update list parsing
Sep 26, 2024
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
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
};
}
36 changes: 36 additions & 0 deletions src/components/ApiDocs/ApiComment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Fragment } from 'react';
import { View } from '@aws-amplify/ui-react';
import { parseMarkdownLinks } 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);
}
}
});

return <View>{commentList}</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>
);
};
37 changes: 37 additions & 0 deletions src/components/ApiDocs/ReferencePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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';

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>
))}
<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