Skip to content

Commit 3a6def1

Browse files
committed
refactor
1 parent 58f524b commit 3a6def1

File tree

3 files changed

+57
-43
lines changed

3 files changed

+57
-43
lines changed

src/components/Yaml/YamlViewButton.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bar, Button, Dialog } from '@ui5/webcomponents-react';
1+
import { Button } from '@ui5/webcomponents-react';
22
import { FC, useState } from 'react';
33
import styles from './YamlViewer.module.css';
44
import { useTranslation } from 'react-i18next';
@@ -9,6 +9,7 @@ import {
99
Resource,
1010
} from '../../utils/removeManagedFieldsProperty.ts';
1111
import { YamlIcon } from './YamlIcon.tsx';
12+
import { YamlViewDialog } from './YamlViewDialog.tsx';
1213

1314
export type YamlViewButtonProps = {
1415
resourceObject: unknown;
@@ -20,31 +21,17 @@ export const YamlViewButton: FC<YamlViewButtonProps> = ({ resourceObject }) => {
2021
const resource = resourceObject as Resource;
2122
return (
2223
<span>
23-
<Dialog
24-
open={isOpen}
25-
stretch
26-
onClick={(e) => e.stopPropagation()}
27-
footer={
28-
<Bar
29-
design="Footer"
30-
endContent={
31-
<Button design="Emphasized" onClick={() => setIsOpen(false)}>
32-
{t('common.close')}
33-
</Button>
34-
}
35-
/>
36-
}
37-
onClose={() => {
38-
setIsOpen(false);
39-
}}
40-
>
41-
{isOpen && (
24+
<YamlViewDialog
25+
isOpen={isOpen}
26+
setIsOpen={setIsOpen}
27+
dialogContent={
4228
<YamlViewer
4329
yamlString={stringify(removeManagedFieldsProperty(resource))}
4430
filename={`${resource.kind ?? ''}${resource.metadata.name ? '_' : ''}${resource.metadata.name ?? ''}`}
4531
/>
46-
)}
47-
</Dialog>
32+
}
33+
/>
34+
4835
<Button
4936
className={styles.button}
5037
design={'Transparent'}

src/components/Yaml/YamlViewButtonWithLoader.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { YamlLoader } from './YamlLoader.tsx';
44
import { useTranslation } from 'react-i18next';
55
import styles from './YamlViewer.module.css';
66
import { YamlIcon } from './YamlIcon.tsx';
7+
import { YamlViewDialog } from './YamlViewDialog.tsx';
78

89
export type YamlViewButtonProps = {
910
workspaceName?: string;
@@ -20,32 +21,18 @@ export const YamlViewButtonWithLoader: FC<YamlViewButtonProps> = ({
2021
const { t } = useTranslation();
2122
return (
2223
<span>
23-
<Dialog
24-
open={isOpen}
25-
stretch
26-
onClick={(e) => e.stopPropagation()}
27-
footer={
28-
<Bar
29-
design="Footer"
30-
endContent={
31-
<Button design="Emphasized" onClick={() => setIsOpen(false)}>
32-
{t('common.close')}
33-
</Button>
34-
}
35-
/>
36-
}
37-
onClose={() => {
38-
setIsOpen(false);
39-
}}
40-
>
41-
{isOpen && (
24+
<YamlViewDialog
25+
isOpen={isOpen}
26+
setIsOpen={setIsOpen}
27+
dialogContent={
4228
<YamlLoader
4329
workspaceName={workspaceName}
4430
resourceName={resourceName}
4531
resourceType={resourceType}
4632
/>
47-
)}
48-
</Dialog>
33+
}
34+
/>
35+
4936
<Button
5037
className={styles.button}
5138
design={'Transparent'}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Bar, Button, Dialog } from '@ui5/webcomponents-react';
2+
3+
import { FC, ReactNode } from 'react';
4+
import { useTranslation } from 'react-i18next';
5+
6+
export type YamlViewDialogProps = {
7+
isOpen: boolean;
8+
setIsOpen: (isOpen: boolean) => void;
9+
dialogContent: ReactNode;
10+
};
11+
12+
export const YamlViewDialog: FC<YamlViewDialogProps> = ({
13+
isOpen,
14+
setIsOpen,
15+
dialogContent,
16+
}) => {
17+
const { t } = useTranslation();
18+
return (
19+
<Dialog
20+
open={isOpen}
21+
stretch
22+
onClick={(e) => e.stopPropagation()}
23+
footer={
24+
<Bar
25+
design="Footer"
26+
endContent={
27+
<Button design="Emphasized" onClick={() => setIsOpen(false)}>
28+
{t('common.close')}
29+
</Button>
30+
}
31+
/>
32+
}
33+
onClose={() => {
34+
setIsOpen(false);
35+
}}
36+
>
37+
{isOpen && dialogContent}
38+
</Dialog>
39+
);
40+
};

0 commit comments

Comments
 (0)