32 lines
2.0 KiB
TypeScript
32 lines
2.0 KiB
TypeScript
import {ScrollText, Zap} from 'lucide-react'
|
|
import type {CloudResource} from '@/types/resource'
|
|
|
|
type LambdaTrigger = {trigger: string; label: string; functionArn: string; functionName: string; version: string | null}
|
|
|
|
export function CognitoTriggersSection({pool}: {pool?: CloudResource}) {
|
|
const triggers = triggersOf(pool)
|
|
return <>
|
|
<div className="input-row resource-table-bar">
|
|
<div><p className="eyebrow">Lambda triggers</p><span className="muted">Functions Cognito runs during sign-up, sign-in and token issue</span></div>
|
|
</div>
|
|
{pool && triggers.length === 0 && <p className="muted padded">This pool runs no Lambda triggers.</p>}
|
|
{triggers.length > 0 && <div className="cognito-table"><table className="table"><thead><tr><th>Trigger</th><th>Function</th><th>Version</th><th/></tr></thead><tbody>{triggers.map((trigger) => (
|
|
<tr key={trigger.trigger}>
|
|
<td>{trigger.label}</td>
|
|
<td><code title={trigger.functionArn}>{trigger.functionName}</code></td>
|
|
<td>{trigger.version ? <code>{trigger.version}</code> : '—'}</td>
|
|
<td className="cognito-row-actions">
|
|
<a className="button" href={`/cloud-explorer/aws/serverless?resource=${encodeURIComponent(trigger.functionName)}`} aria-label={`Open function ${trigger.functionName}`}><Zap size={13}/> Function</a>
|
|
<a className="button" href={`/cloud-explorer/aws/logs?resource=${encodeURIComponent(`/aws/lambda/${trigger.functionName}`)}`} aria-label={`Open logs for ${trigger.functionName}`}><ScrollText size={13}/> Logs</a>
|
|
</td>
|
|
</tr>
|
|
))}</tbody></table></div>}
|
|
</>
|
|
}
|
|
|
|
function triggersOf(pool?: CloudResource): LambdaTrigger[] {
|
|
const triggers = pool?.metadata.lambdaTriggers
|
|
if (!Array.isArray(triggers)) return []
|
|
return triggers.filter((trigger): trigger is LambdaTrigger => typeof trigger?.functionName === 'string' && typeof trigger?.label === 'string')
|
|
}
|