1- import { FC , useMemo } from 'react' ;
1+ import { FC , useMemo , useEffect , useRef } from 'react' ;
22
33import { YamlViewer , YamlViewerProps } from './YamlViewer.tsx' ;
44import { useApiResource } from '../../lib/api/useApiResource.ts' ;
@@ -8,6 +8,7 @@ import openapiSchemaToJsonSchema from '@openapi-contrib/openapi-schema-to-json-s
88
99import { ApiConfig } from '../../lib/api/types/apiConfig.ts' ;
1010import { getCustomResourceDefinitionPluralName } from '../../utils/getPluralName.ts' ;
11+ import { useToast } from '../../context/ToastContext.tsx' ;
1112
1213interface YamlViewerSchemaLoaderProps extends YamlViewerProps {
1314 apiVersion : string ;
@@ -27,7 +28,14 @@ export const YamlViewerSchemaLoader: FC<YamlViewerSchemaLoaderProps> = ({
2728 kind,
2829} ) => {
2930 const customResourceDefinitionName = getCustomResourceDefinitionPluralName ( kind ) ;
30- const { data : crdData , isLoading } = useApiResource < CustomResourceDefinition > (
31+ const { show } = useToast ( ) ;
32+ const hasShownErrorRef = useRef ( false ) ;
33+
34+ const {
35+ data : crdData ,
36+ isLoading,
37+ error,
38+ } = useApiResource < CustomResourceDefinition > (
3139 {
3240 path : `/apis/apiextensions.k8s.io/v1/customresourcedefinitions/${ customResourceDefinitionName } .${ apiGroupName } ` ,
3341 } ,
@@ -36,6 +44,14 @@ export const YamlViewerSchemaLoader: FC<YamlViewerSchemaLoaderProps> = ({
3644 ! customResourceDefinitionName ,
3745 ) ;
3846
47+ useEffect ( ( ) => {
48+ if ( ! hasShownErrorRef . current && error ) {
49+ const message = ( error as { message ?: string } ) . message || 'Failed to load schema' ;
50+ show ( message ) ;
51+ hasShownErrorRef . current = true ;
52+ }
53+ } , [ error , show ] ) ;
54+
3955 const schema =
4056 crdData ?. spec . versions ?. find ( ( { name } ) => name === apiVersion ) ?. schema . openAPIV3Schema ??
4157 crdData ?. spec . versions ?. [ 0 ] . schema . openAPIV3Schema ;
0 commit comments