Skip to content

Commit 20ac8b3

Browse files
committed
Add option to show only important YAML data
Introduces a 'showOnlyImportantData' prop to YAML viewer components, allowing users to toggle the display of only essential YAML fields. Updates related components and dialog to support this feature and propagate state.
1 parent 3c34a39 commit 20ac8b3

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

src/components/Yaml/YamlLoader.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ import YamlViewer from './YamlViewer.tsx';
1111
import { useApiResource } from '../../lib/api/useApiResource';
1212
import { removeManagedFieldsProperty, Resource } from '../../utils/removeManagedFieldsProperty.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,
@@ -25,8 +36,10 @@ export const YamlLoader: FC<YamlViewButtonProps> = ({ workspaceName, resourceTyp
2536

2637
return (
2738
<YamlViewer
28-
yamlString={stringify(removeManagedFieldsProperty(data as Resource, true))}
39+
yamlString={stringify(removeManagedFieldsProperty(data as Resource, showOnlyImportantData))}
2940
filename={`${workspaceName ? `${workspaceName}_` : ''}${resourceType}_${resourceName}`}
41+
setShowOnlyImportantData={setShowOnlyImportantData}
42+
showOnlyImportantData={showOnlyImportantData}
3043
/>
3144
);
3245
};

src/components/Yaml/YamlViewButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export type YamlViewButtonProps = {
1313
};
1414

1515
export const YamlViewButton: FC<YamlViewButtonProps> = ({ resourceObject }) => {
16+
const [showOnlyImportantData, setShowOnlyImportantData] = useState(true);
1617
const [isOpen, setIsOpen] = useState(false);
1718
const { t } = useTranslation();
1819
const resource = resourceObject as Resource;
1920

2021
const yamlString = useMemo(() => {
21-
return stringify(removeManagedFieldsProperty(resource));
22+
return stringify(removeManagedFieldsProperty(resource, showOnlyImportantData));
2223
}, [resource]);
2324
return (
2425
<span>
@@ -29,6 +30,8 @@ export const YamlViewButton: FC<YamlViewButtonProps> = ({ resourceObject }) => {
2930
<YamlViewer
3031
yamlString={yamlString}
3132
filename={`${resource?.kind ?? ''}${resource?.metadata?.name ? '_' : ''}${resource?.metadata?.name ?? ''}`}
33+
setShowOnlyImportantData={setShowOnlyImportantData}
34+
showOnlyImportantData={showOnlyImportantData}
3235
/>
3336
}
3437
/>

src/components/Yaml/YamlViewButtonWithLoader.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import styles from './YamlViewer.module.css';
66
import { YamlIcon } from './YamlIcon.tsx';
77
import { YamlViewDialog } from './YamlViewDialog.tsx';
88

9-
export type YamlViewButtonProps = {
9+
export interface YamlViewButtonProps {
1010
workspaceName?: string;
1111
resourceType: 'projects' | 'workspaces' | 'managedcontrolplanes';
1212
resourceName: string;
13-
};
13+
}
1414

1515
export const YamlViewButtonWithLoader: FC<YamlViewButtonProps> = ({ workspaceName, resourceType, resourceName }) => {
16+
const [showOnlyImportantData, setShowOnlyImportantData] = useState(true);
1617
const [isOpen, setIsOpen] = useState(false);
1718
const { t } = useTranslation();
1819
return (
@@ -21,8 +22,16 @@ export const YamlViewButtonWithLoader: FC<YamlViewButtonProps> = ({ workspaceNam
2122
isOpen={isOpen}
2223
setIsOpen={setIsOpen}
2324
dialogContent={
24-
<YamlLoader workspaceName={workspaceName} resourceName={resourceName} resourceType={resourceType} />
25+
<YamlLoader
26+
workspaceName={workspaceName}
27+
resourceName={resourceName}
28+
resourceType={resourceType}
29+
showOnlyImportantData={showOnlyImportantData}
30+
setShowOnlyImportantData={setShowOnlyImportantData}
31+
/>
2532
}
33+
setShowOnlyImportantData={setShowOnlyImportantData}
34+
showOnlyImportantData={showOnlyImportantData}
2635
/>
2736

2837
<Button

src/components/Yaml/YamlViewDialog.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bar, Button, Dialog } from '@ui5/webcomponents-react';
1+
import { Bar, Button, CheckBox, Dialog } from '@ui5/webcomponents-react';
22

33
import { FC, ReactNode } from 'react';
44
import { useTranslation } from 'react-i18next';
@@ -7,16 +7,36 @@ export type YamlViewDialogProps = {
77
isOpen: boolean;
88
setIsOpen: (isOpen: boolean) => void;
99
dialogContent: ReactNode;
10+
showOnlyImportantData?: boolean;
11+
setShowOnlyImportantData?: (showOnlyImportantData: boolean) => void;
1012
};
1113

12-
export const YamlViewDialog: FC<YamlViewDialogProps> = ({ isOpen, setIsOpen, dialogContent }) => {
14+
export const YamlViewDialog: FC<YamlViewDialogProps> = ({
15+
isOpen,
16+
setIsOpen,
17+
dialogContent,
18+
showOnlyImportantData,
19+
setShowOnlyImportantData,
20+
}) => {
1321
const { t } = useTranslation();
22+
const handleShowOnlyImportantData = () => {
23+
setShowOnlyImportantData?.(!showOnlyImportantData);
24+
};
1425
return (
1526
<Dialog
1627
open={isOpen}
1728
stretch
1829
footer={
1930
<Bar
31+
startContent={
32+
setShowOnlyImportantData && (
33+
<CheckBox
34+
text={t('yaml.showOnlyImportant')}
35+
checked={showOnlyImportantData}
36+
onChange={handleShowOnlyImportantData}
37+
/>
38+
)
39+
}
2040
design="Footer"
2141
endContent={
2242
<Button design="Emphasized" onClick={() => setIsOpen(false)}>

src/components/Yaml/YamlViewer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import styles from './YamlViewer.module.css';
77
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard.ts';
88
import { useTranslation } from 'react-i18next';
99
import { useTheme } from '../../hooks/useTheme.ts';
10-
type YamlViewerProps = { yamlString: string; filename: string };
10+
type YamlViewerProps = {
11+
yamlString: string;
12+
filename: string;
13+
showOnlyImportantData?: boolean;
14+
setShowOnlyImportantData?: (showOnlyImportantData: boolean) => void;
15+
};
1116
const YamlViewer: FC<YamlViewerProps> = ({ yamlString, filename }) => {
1217
const { t } = useTranslation();
1318
const { isDarkTheme } = useTheme();

0 commit comments

Comments
 (0)