|
1 | 1 | import { YamlViewButtonProps } from './YamlViewButtonWithLoader.tsx'; |
2 | | -import { FC } from 'react'; |
| 2 | +import { FC, useMemo } from 'react'; |
3 | 3 |
|
4 | 4 | import { stringify } from 'yaml'; |
5 | 5 |
|
@@ -29,15 +29,24 @@ export const YamlLoader: FC<YamlLoaderProps> = ({ |
29 | 29 | true, |
30 | 30 | ); |
31 | 31 | const { t } = useTranslation(); |
| 32 | + const yamlString = useMemo(() => { |
| 33 | + if (isLoading || error) return ''; |
| 34 | + return stringify(removeManagedFieldsProperty(data as Resource, showOnlyImportantData)); |
| 35 | + }, [data, error, isLoading, showOnlyImportantData]); |
| 36 | + |
| 37 | + const yamlStringToCopy = useMemo(() => { |
| 38 | + if (isLoading || error) return ''; |
| 39 | + return stringify(removeManagedFieldsProperty(data as Resource, false)); |
| 40 | + }, [data, error, isLoading]); |
32 | 41 | if (isLoading) return <Loading />; |
33 | 42 | if (error) { |
34 | 43 | return <IllustratedError details={t('common.cannotLoadData')} />; |
35 | 44 | } |
36 | 45 |
|
37 | 46 | return ( |
38 | 47 | <YamlViewer |
39 | | - yamlString={stringify(removeManagedFieldsProperty(data as Resource, showOnlyImportantData))} |
40 | | - yamlStringToCopy={stringify(removeManagedFieldsProperty(data as Resource, false))} |
| 48 | + yamlString={yamlString} |
| 49 | + yamlStringToCopy={yamlStringToCopy} |
41 | 50 | filename={`${workspaceName ? `${workspaceName}_` : ''}${resourceType}_${resourceName}`} |
42 | 51 | setShowOnlyImportantData={setShowOnlyImportantData} |
43 | 52 | showOnlyImportantData={showOnlyImportantData} |
|
0 commit comments