Skip to content

Commit

Permalink
Respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Oct 11, 2022
1 parent 642a5fe commit bd3d381
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Container, Grid } from "@cloudscape-design/components";
import { useCallback } from "react";
import { Readme } from "./ItemTrackerReadmeComponent";
import { useItemTrackerAction } from "./ItemTrackerStore";
import { AddWorkItem } from "./work-item/AddWorkItemComponent";
import { WorkItemControls, WorkItems } from "./work-item/WorkItemListComponent";
import { workItemService as service } from "./work-item/WorkItemService";

const Component = () => {
const { setError } = useItemTrackerAction();
const sendReport = useCallback(
async (email: string) => {
try {
service.mailItem(email);
} catch (e) {
setError((e as Error).message);
}
},
[setError]
);

return (
<>
<Readme />
<Container>
<h2>Work Items</h2>
<Grid gridDefinition={[{ colspan: 9 }, { colspan: 3 }]}>
<WorkItems />
<WorkItemControls sendReport={sendReport} />
<WorkItemControls />
<AddWorkItem />
</Grid>
</Container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Box, Header, Link, SpaceBetween } from "@cloudscape-design/components";
export function Readme() {
return (
Expand Down Expand Up @@ -28,15 +31,15 @@ export function Readme() {
<li>
<Link
external
href="https://github.com/awsdocs/aws-doc-sdk-examples/tree/2142ca5b294e06b719b6e22a38339e86050d8fde/javav2/usecases/Creating_Spring_RDS_%20Rest"
href="https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/Creating_Spring_RDS_%20Rest"
>
Java Spring
</Link>
</li>
<li>
<Link
external
href="https://github.com/awsdocs/aws-doc-sdk-examples/tree/84ea245588ffe9043ed162f211cbfdc91f952640/kotlin/usecases/serverless_rds"
href="https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/usecases/serverless_rds"
>
Kotlin
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import create from "zustand";
import {
WorkItem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mapObjIndexed, reduceWhile } from "ramda";
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export type RestParams<T> = Partial<Record<keyof T, string>>;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"BASE_URL": "http://localhost:8080/api"
}
16 changes: 10 additions & 6 deletions resources/clients/react/elwing/src/plugins/item-tracker/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { SideNavigationProps } from "@cloudscape-design/components";
import { lazy } from "react";
Expand All @@ -14,8 +12,14 @@ const ItemTracker = {
items: [
{
type: "link",
text: "Example external link",
href: "https://cloudscape.design/",
text: "Creating Spring RDS REST (Java)",
href: "https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/Creating_Spring_RDS_%20Rest",
external: true,
},
{
type: "link",
text: "Creating Spring RDS REST ()",
href: "https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/usecases/serverless_rds",
external: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import {
Button,
Form,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/**
* An element that displays a list of work items that are retrieved from a REST service.
*
* - Select Active or Archived to display work items with the specified state.
* - Select the wastebasket icon to archive an active item.
* - Select 'Add item' to add a new item.
* - Enter a recipient email and select 'Send report' to send a report of work items.
*/
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { WorkItem, WorkItemStatus } from "./WorkItemService";
import { workItemService as service } from "./WorkItemService";
import {
Expand All @@ -28,14 +22,21 @@ const STATUS_OPTIONS: OptionDefinition[] = [
{ value: "", label: "All" },
];

export const WorkItemControls = ({
sendReport,
}: {
sendReport: (email: string) => Promise<void>;
}) => {
export const WorkItemControls = () => {
const [email, setEmail] = useState("");
const [status, setStatus] = useState(STATUS_OPTIONS[0]);
const { setStatus: handleStatusChange } = useItemTrackerAction();
const { setStatus: handleStatusChange, setError } = useItemTrackerAction();

const sendReport = useCallback(
async (email: string) => {
try {
service.mailItem(email);
} catch (e) {
setError((e as Error).message);
}
},
[setError]
);

useEffect(() => {
handleStatusChange((status.value as WorkItemStatus) ?? "");
Expand All @@ -52,7 +53,7 @@ export const WorkItemControls = ({
</FormField>
<FormField
label="Email Report"
description="You must first register the recipient's email with Amazon SES."
description="Register the recipient's email with Amazon SES."
>
<Input
value={email}
Expand All @@ -70,13 +71,11 @@ export const WorkItemControls = ({
export const WorkItems = () => {
const [selected, setSelected] = useState<WorkItem[]>([]);
const { loadItems, setError } = useItemTrackerAction();
// const status = useItemTrackerState(({ status }) => status);
const items = useItemTrackerState(({ items }) => items);
// const loading = useItemTrackerState(({ loading }) => loading);

useEffect(() => {
loadItems();
}, []);
}, [loadItems]);

const archiveItem = async (itemId: string) => {
try {
Expand Down Expand Up @@ -141,39 +140,4 @@ export const WorkItems = () => {
items={items}
/>
);
// return (
// <>
// {!loading && items.length === 0 ? (
// <Alert>No work items found.</Alert>
// ) : (
// <table>
// <thead>
// <tr>
// <th>Item Id</th>
// <th>User</th>
// <th>Guide</th>
// <th>Description</th>
// <th>Status</th>
// <th />
// </tr>
// </thead>
// {loading ? (
// <tbody>
// <WorkItemsLoading />
// </tbody>
// ) : (
// <tbody>
// {items.map((item) => (
// <WorkItem
// item={item}
// status={status}
// archiveItem={archiveItem}
// />
// ))}
// </tbody>
// )}
// </table>
// )}
// </>
// );
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { RestService } from "../RestService";
import { BASE_URL } from "../config.json";

/**
* Sends REST requests to get work items, add new work items, modify work items,
Expand Down Expand Up @@ -36,12 +37,11 @@ export class WorkItemService extends RestService<WorkItem> {
/**
* Sends a POST request to email a report of work items.
*/
mailItem = async (email: string) => {
async mailItem(email: string) {
return await fetch(`${this.url()}:report`, {
body: JSON.stringify({ email }),
});
};
}
}

export const BASE_URL = "http://localhost:8080/api";
export const workItemService = new WorkItemService();

0 comments on commit bd3d381

Please sign in to comment.