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

API Usage Chart Repair #85

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions components/ApiKeyUsageChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class ApiKeyUsageChart extends Component<Props, { value: GraphValue | null }> {
{this._renderKeyInfo()}
<XYPlot
height={300}
style={{ overflow: 'initial' }}
width={600} // Round up max y value to the nearest 10
xDomain={[
timestamp - 2 * ONE_DAY_MILLIS,
Expand Down
7 changes: 6 additions & 1 deletion components/RequestLogsDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { Sync } from '@styled-icons/fa-solid/Sync'
import { Button } from 'react-bootstrap'
import useSWR, { mutate } from 'swr'

import { Plan } from '../types/graph'

import ApiKeyUsage from './ApiKeyUsage'
import FetchMessage from './FetchMessage'

const REQUEST_LOGS_URL = `${process.env.API_BASE_URL}/api/secure/logs`
const USAGE_ID = process.env.USAGE_ID || null

type Props = {
isAdmin?: boolean
Expand Down Expand Up @@ -56,7 +59,9 @@ function RequestLogsDashboard({
)}
<ApiKeyUsage
isAdmin={isAdmin}
logs={result.data?.data}
logs={result.data?.data?.filter(
(l: Plan) => USAGE_ID === null || l.result.usagePlanId === USAGE_ID
)}
logsError={result.error}
summaryView={summaryView}
/>
Expand Down
34 changes: 20 additions & 14 deletions components/WelcomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type Props = {
handleSignup: HandleSignup
}

const USAGE_ID = process.env.USAGE_ID || null

const WelcomeScreen = ({ handleSignup }: Props): JSX.Element => (
<>
<Jumbotron>
Expand All @@ -16,21 +18,25 @@ const WelcomeScreen = ({ handleSignup }: Props): JSX.Element => (
Here, you can view documentation for and gain access to the{' '}
{process.env.API_NAME}.
</p>
{isApiManagerEnabled() && (
<p>
<Button className="mr-3" onClick={handleSignup} variant="primary">
Sign up for API access
</Button>
{process.env.API_DOCUMENTATION_URL && (
<Button
href={process.env.API_DOCUMENTATION_URL}
variant="outline-primary"
>
View API documentation
{
/* If we're specifying a USAGE_ID then we definitely don't want to
be creating API keys in that AWS environment! */
isApiManagerEnabled() && USAGE_ID === null && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be enabling account creation when USAGE_ID is null? Shouldn't it be the opposite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If USAGE_ID is set, then we don't have full access to the AWS instance, so probably shouldn't be creating AWS users and keys! If it is UNset, then we are safe to do so

<p>
<Button className="mr-3" onClick={handleSignup} variant="primary">
Sign up for API access
</Button>
)}
</p>
)}
{process.env.API_DOCUMENTATION_URL && (
<Button
href={process.env.API_DOCUMENTATION_URL}
variant="outline-primary"
>
View API documentation
</Button>
)}
</p>
)
}
</Jumbotron>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = (phase, { defaultConfig }) => {
SITE_TITLE: process.env.SITE_TITLE,
STATUS_PAGE_URL: process.env.STATUS_PAGE_URL,
SUPPORT_EMAIL: process.env.SUPPORT_EMAIL,
TERMS_CONDITIONS_URL: process.env.TERMS_CONDITIONS_URL
TERMS_CONDITIONS_URL: process.env.TERMS_CONDITIONS_URL,
USAGE_ID: process.env.USAGE_ID
}
// Return config with environment variables and webpack configuration.
return {
Expand Down
6 changes: 5 additions & 1 deletion types/graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ApiUser } from './user'

export type ApiKey = { startDate: number; items: { [key: string]: Requests } }
export type ApiKey = {
items: { [key: string]: Requests }
startDate: number
usagePlanId: string
}
export type Plan = {
apiUsers?: { [key: string]: ApiUser }
result: ApiKey
Expand Down
Loading