({ proxyContextValue })
| 26 | } |
| 27 | |
| 28 | export const ProxyMenu: FC<ProxyMenuProps> = ({ proxyContextValue }) => { |
| 29 | const [open, setOpen] = useState(false); |
| 30 | const [refetchDate, setRefetchDate] = useState<Date>(); |
| 31 | const selectedProxy = proxyContextValue.proxy.proxy; |
| 32 | const refreshLatencies = proxyContextValue.refetchProxyLatencies; |
| 33 | const closeMenu = () => setOpen(false); |
| 34 | const latencies = proxyContextValue.proxyLatencies; |
| 35 | const isLoadingLatencies = Object.keys(latencies).length === 0; |
| 36 | const isLoading = proxyContextValue.isLoading || isLoadingLatencies; |
| 37 | const { permissions } = useAuthenticated(); |
| 38 | |
| 39 | const proxyLatencyLoading = (proxy: TypesGen.Region): boolean => { |
| 40 | if (!refetchDate) { |
| 41 | // Only show loading if the user manually requested a refetch |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | // Only show a loading spinner if: |
| 46 | // - A latency exists. This means the latency was fetched at some point, so |
| 47 | // the loader *should* be resolved. |
| 48 | // - The proxy is healthy. If it is not, the loader might never resolve. |
| 49 | // - The latency reported is older than the refetch date. This means the |
| 50 | // latency is stale and we should show a loading spinner until the new |
| 51 | // latency is fetched. |
| 52 | const latency = latencies[proxy.id]; |
| 53 | return proxy.healthy && latency !== undefined && latency.at < refetchDate; |
| 54 | }; |
| 55 | |
| 56 | // This endpoint returns a 404 when not using enterprise. |
| 57 | // If we don't return null, then it looks like this is |
| 58 | // loading forever! |
| 59 | if (proxyContextValue.error) { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | if (isLoading) { |
| 64 | return ( |
| 65 | <Skeleton |
| 66 | width="110px" |
| 67 | height={40} |
| 68 | className="rounded-[6px] transform-none" |
| 69 | /> |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | return ( |
| 74 | <DropdownMenu open={open} onOpenChange={setOpen}> |
| 75 | <DropdownMenuTrigger asChild> |
| 76 | <Button variant="outline" size="lg"> |
| 77 | <span className="sr-only"> |
| 78 | Latency for {selectedProxy?.display_name ?? "your region"} |
| 79 | </span> |
| 80 | |
| 81 | {selectedProxy ? ( |
| 82 | <> |
| 83 | <ExternalImage |
| 84 | // Empty alt text used because we don't want to double up on |
| 85 | // screen reader announcements from visually-hidden span |
nothing calls this directly
no test coverage detected