/****************************************************************************** * Copyright (c) 2026 Contributors to the Eclipse Foundation. * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 *****************************************************************************/ import { FunctionComponent, useEffect, useState, useContext, useRef } from 'react'; import { Box, Typography, Divider, List, ListItem, ListItemText, IconButton, Paper, Button, type PaperProps } from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; import AddIcon from '@mui/icons-material/Add'; import { MainContext } from '../../../context'; import { Customer, isError, RateLimitToken } from '../../../extension-registry-types'; import { GenerateTokenDialog } from '../../../components/generate-token-dialog'; import { Timestamp } from "../../../components/timestamp"; const sectionPaperProps: PaperProps = { elevation: 1, sx: { p: 3, mb: 3 } }; export const CustomerTokenList: FunctionComponent = props => { const { service, handleError } = useContext(MainContext); const [tokens, setTokens] = useState([]); const [dialogOpen, setDialogOpen] = useState(false); const abortController = useRef(new AbortController()); useEffect(() => { fetchTokens(); }, [props.customer]); useEffect(() => { return () => { abortController.current.abort(); }; }, []); const fetchTokens = async () => { try { const result = await service.admin.getCustomerRateLimitTokens(abortController.current, props.customer.name); setTokens([...result]); } catch (err) { handleError(err); } }; const handleGenerate = async (description: string): Promise => { const token = await service.admin.createCustomerRateLimitToken(abortController.current, props.customer.name, description); await fetchTokens(); return token.value ?? ''; }; const handleDelete = async (tokenId: number) => { try { const result = await service.admin.deleteCustomerRateLimitToken(abortController.current, props.customer.name, tokenId); if (isError(result)) { throw result; } await fetchTokens(); } catch (err) { handleError(err); } }; return Tokens {tokens.length === 0 ? ( No rate limiting tokens for this customer. ) : ( {tokens.map(token => ( handleDelete(token.id)} title='Delete token'> } > {token.description || 'N/A'} } secondary={ Created: } /> ))} )} setDialogOpen(false)} onGenerate={handleGenerate} onError={handleError} title='Generate token' /> ; }; export interface CustomerTokenListProps { customer: Customer; }