11import { YamlViewButtonProps } from './YamlViewButtonWithLoader.tsx' ;
2- import { FC } from 'react' ;
2+ import { FC , useMemo } from 'react' ;
33
44import { stringify } from 'yaml' ;
55
@@ -9,24 +9,47 @@ import Loading from '../Shared/Loading.tsx';
99import IllustratedError from '../Shared/IllustratedError.tsx' ;
1010import YamlViewer from './YamlViewer.tsx' ;
1111import { useApiResource } from '../../lib/api/useApiResource' ;
12- import { removeManagedFieldsProperty , Resource } from '../../utils/removeManagedFieldsProperty .ts' ;
12+ import { removeManagedFieldsAndFilterData , Resource } from '../../utils/removeManagedFieldsAndFilterData .ts' ;
1313
14- export const YamlLoader : FC < YamlViewButtonProps > = ( { workspaceName, resourceType, resourceName } ) => {
14+ interface YamlLoaderProps extends YamlViewButtonProps {
15+ showOnlyImportantData ?: boolean ;
16+ setShowOnlyImportantData ?: ( showOnlyImportantData : boolean ) => void ;
17+ }
18+
19+ export const YamlLoader : FC < YamlLoaderProps > = ( {
20+ workspaceName,
21+ resourceType,
22+ resourceName,
23+ showOnlyImportantData = false ,
24+ setShowOnlyImportantData,
25+ } ) => {
1526 const { isLoading, data, error } = useApiResource (
1627 ResourceObject ( workspaceName ?? '' , resourceType , resourceName ) ,
1728 undefined ,
1829 true ,
1930 ) ;
2031 const { t } = useTranslation ( ) ;
32+ const yamlString = useMemo ( ( ) => {
33+ if ( isLoading || error ) return '' ;
34+ return stringify ( removeManagedFieldsAndFilterData ( data as Resource , showOnlyImportantData ) ) ;
35+ } , [ data , error , isLoading , showOnlyImportantData ] ) ;
36+
37+ const yamlStringToCopy = useMemo ( ( ) => {
38+ if ( isLoading || error ) return '' ;
39+ return stringify ( removeManagedFieldsAndFilterData ( data as Resource , false ) ) ;
40+ } , [ data , error , isLoading ] ) ;
2141 if ( isLoading ) return < Loading /> ;
2242 if ( error ) {
2343 return < IllustratedError details = { t ( 'common.cannotLoadData' ) } /> ;
2444 }
2545
2646 return (
2747 < YamlViewer
28- yamlString = { stringify ( removeManagedFieldsProperty ( data as Resource ) ) }
48+ yamlString = { yamlString }
49+ yamlStringToCopy = { yamlStringToCopy }
2950 filename = { `${ workspaceName ? `${ workspaceName } _` : '' } ${ resourceType } _${ resourceName } ` }
51+ setShowOnlyImportantData = { setShowOnlyImportantData }
52+ showOnlyImportantData = { showOnlyImportantData }
3053 />
3154 ) ;
3255} ;
0 commit comments