Skip to content

Commit

Permalink
Get all AWS Cloudformation stacks (raycast#1030)
Browse files Browse the repository at this point in the history
* fix: use id instead of name for list item key

* chore: fetch paginated list of stacks

Co-authored-by: Jonathan Wieben <jonathan.wieben@claimsforce.com>
  • Loading branch information
2 people authored and FezVrasta committed Mar 23, 2022
1 parent 5dc8276 commit d536f35
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions extensions/amazon-aws/src/cloudformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ export default function ListStacks() {

useEffect(() => {
if (!preferences.region) return;
async function fetch() {
cloudformation.listStacks({}, async (err, data) => {
if (err) {
setState({
hasError: true,
loaded: false,
stacks: [],
});
} else {
setState({
hasError: false,
loaded: true,
stacks: data.StackSummaries || [],
});
}
});
async function fetchStacks(token?: string, stacks?: StackSummary[]): Promise<StackSummary[]> {
const { NextToken, StackSummaries } = await cloudformation.listStacks({ NextToken: token }).promise();
const combinedStacks = [...(stacks || []), ...(StackSummaries || [])];

if (NextToken) {
return fetchStacks(NextToken, combinedStacks);
}

return combinedStacks.filter((stack) => stack.StackStatus !== "DELETE_COMPLETE");
}
fetch();

fetchStacks()
.then((stacks) => setState({ hasError: false, loaded: true, stacks }))
.catch(() => setState({ hasError: true, loaded: false, stacks: [] }));
}, []);

if (state.hasError) {
Expand All @@ -50,7 +46,7 @@ export default function ListStacks() {
return (
<List isLoading={!state.loaded} searchBarPlaceholder="Filter stacks by name...">
{state.stacks.map((s) => (
<CloudFormationStack key={s.StackName} stack={s} />
<CloudFormationStack key={s.StackId} stack={s} />
))}
</List>
);
Expand All @@ -62,7 +58,7 @@ function CloudFormationStack({ stack }: { stack: StackSummary }) {
return (
<List.Item
id={stack.StackName}
key={stack.StackName}
key={stack.StackId}
title={stack.StackName}
accessoryTitle={stack.LastUpdatedTime ? new Date(stack.LastUpdatedTime).toLocaleString() : undefined}
actions={
Expand Down

0 comments on commit d536f35

Please sign in to comment.