ResourceExhaustionWarningBanner.utils.ts19 lines · main
| 1 | import { RESOURCE_WARNING_MESSAGES } from './ResourceExhaustionWarningBanner.constants' |
| 2 | import type { ResourceWarning } from '@/data/usage/resource-warnings-query' |
| 3 | |
| 4 | export const getWarningContent = ( |
| 5 | resourceWarnings: ResourceWarning, |
| 6 | metric: string, |
| 7 | contentType: 'cardContent' | 'bannerContent' |
| 8 | ) => { |
| 9 | if (metric === 'is_readonly_mode_enabled') { |
| 10 | return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.cardContent.warning |
| 11 | } |
| 12 | |
| 13 | const severity = resourceWarnings[metric as keyof typeof resourceWarnings] |
| 14 | if (typeof severity !== 'string') return undefined |
| 15 | |
| 16 | return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES]?.[ |
| 17 | contentType |
| 18 | ]?.[severity as 'warning' | 'critical'] |
| 19 | } |