Skip to content

Commit 3dda068

Browse files
authored
fix(orchestrator): fix CSS bugs for variables dialog and input schema dialog (#990)
Signed-off-by: Lior Soffer <liorsoffer1@gmail.com>
1 parent 7d55c63 commit 3dda068

6 files changed

Lines changed: 124 additions & 79 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator': patch
3+
---
4+
5+
fix CSS bugs for variables dialog and input schema dialog

workspaces/orchestrator/plugins/orchestrator/src/components/InfoDialog.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ const useStyles = makeStyles()(theme => ({
4747
paddingLeft: theme.spacing(3),
4848
paddingBottom: theme.spacing(2),
4949
},
50+
dialogContent: {
51+
'& > div': {
52+
backgroundColor: 'transparent',
53+
},
54+
},
5055
titleContainer: {
5156
display: 'flex',
5257
},
@@ -100,14 +105,13 @@ export const RefForwardingInfoDialog: ForwardRefRenderFunction<
100105
</IconButton>
101106
</Box>
102107
</DialogTitle>
103-
<DialogContent>
104-
<Box>{children}</Box>
108+
<DialogContent className={classes.dialogContent}>
109+
{children}
105110
</DialogContent>
106111
<DialogActions className={classes.dialogActions}>
107112
{dialogActions}
108113
</DialogActions>
109114
</Dialog>
110115
);
111116
};
112-
113117
export const InfoDialog = forwardRef(RefForwardingInfoDialog);

workspaces/orchestrator/plugins/orchestrator/src/components/OrchestratorPage/InputSchemaDialog.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
import React from 'react';
1818
import { useAsync } from 'react-use';
1919

20-
import {
21-
CodeSnippet,
22-
Progress,
23-
ResponseErrorPanel,
24-
} from '@backstage/core-components';
20+
import { Progress, ResponseErrorPanel } from '@backstage/core-components';
2521
import { useApi } from '@backstage/core-plugin-api';
2622

2723
import Box from '@mui/material/Box';
2824
import Button from '@mui/material/Button';
25+
import Typography from '@mui/material/Typography';
2926

3027
import { InputSchemaResponseDTO } from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
3128

3229
import { orchestratorApiRef } from '../../api/api';
3330
import { FormattedWorkflowOverview } from '../../dataFormatters/WorkflowOverviewFormatter';
31+
import { useIsDarkMode } from '../../utils/isDarkMode';
3432
import { InfoDialog } from '../InfoDialog';
33+
import { JsonCodeBlock } from '../ui/JsonCodeBlock';
3534

3635
const InputSchemaDialogContent = ({
3736
inputSchema,
@@ -42,6 +41,8 @@ const InputSchemaDialogContent = ({
4241
loading: boolean;
4342
error: Error | undefined;
4443
}) => {
44+
const isDarkMode = useIsDarkMode();
45+
4546
if (loading) return <Progress />;
4647
if (error)
4748
return (
@@ -53,16 +54,11 @@ const InputSchemaDialogContent = ({
5354
return (
5455
<Box>
5556
{inputSchema?.inputSchema === undefined ? (
56-
'No input schema is defined for this workflow'
57+
<Typography>No input schema is defined for this workflow.</Typography>
5758
) : (
58-
<CodeSnippet
59-
text={JSON.stringify(inputSchema, null, 2)}
60-
language="json"
61-
showLineNumbers
62-
showCopyCodeButton
63-
customStyle={{
64-
padding: '25px 0',
65-
}}
59+
<JsonCodeBlock
60+
isDarkMode={isDarkMode}
61+
value={inputSchema?.inputSchema}
6662
/>
6763
)}
6864
</Box>

workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowInstancePage/VariablesDialog.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import React from 'react';
1716

18-
import { CodeSnippet } from '@backstage/core-components';
17+
import React from 'react';
1918

2019
import Box from '@mui/material/Box';
2120
import Button from '@mui/material/Button';
@@ -26,7 +25,9 @@ import {
2625
WorkflowDataDTO,
2726
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
2827

28+
import { useIsDarkMode } from '../../utils/isDarkMode';
2929
import { InfoDialog } from '../InfoDialog';
30+
import { JsonCodeBlock } from '../ui/JsonCodeBlock';
3031

3132
export const VariablesDialog = ({
3233
open,
@@ -37,6 +38,9 @@ export const VariablesDialog = ({
3738
onClose: () => void;
3839
instanceVariables: WorkflowDataDTO;
3940
}) => {
41+
const isDarkMode = useIsDarkMode();
42+
const hasVariables = Object.keys(instanceVariables).length > 0;
43+
4044
return (
4145
<InfoDialog
4246
title="Run Variables"
@@ -49,24 +53,18 @@ export const VariablesDialog = ({
4953
}
5054
wideDialog
5155
>
52-
<Box>
53-
{Object.entries(instanceVariables).map(([key, value]) => (
54-
<div key={key} style={{ marginBottom: '16px' }}>
55-
<Typography variant="h6" style={{ marginBottom: '8px' }}>
56+
{hasVariables ? (
57+
Object.entries(instanceVariables).map(([key, value]) => (
58+
<Box key={key} m={2}>
59+
<Typography variant="h6" mb={1}>
5660
{capitalize(key)}
5761
</Typography>
58-
<CodeSnippet
59-
text={JSON.stringify(value, null, 2)}
60-
language="json"
61-
showLineNumbers
62-
showCopyCodeButton
63-
customStyle={{
64-
padding: '25px 0',
65-
}}
66-
/>
67-
</div>
68-
))}
69-
</Box>
62+
<JsonCodeBlock isDarkMode={isDarkMode} value={value} />
63+
</Box>
64+
))
65+
) : (
66+
<Typography>No variables found for this run.</Typography>
67+
)}
7068
</InfoDialog>
7169
);
7270
};

workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowVariablesViewer.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
19+
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
20+
import Box from '@mui/material/Box';
21+
import IconButton from '@mui/material/IconButton';
22+
import Paper from '@mui/material/Paper';
23+
import Tooltip from '@mui/material/Tooltip';
24+
import { makeStyles } from 'tss-react/mui';
25+
26+
const useStyles = makeStyles<{ isDarkMode: boolean }>()(
27+
(theme, { isDarkMode }) => ({
28+
root: {
29+
position: 'relative',
30+
paddingTop: theme.spacing(2),
31+
paddingBottom: theme.spacing(2),
32+
backgroundColor: isDarkMode ? '#151515' : '#F0F0F0',
33+
maxWidth: 600,
34+
marginTop: '0.6rem',
35+
},
36+
iconButton: {
37+
position: 'absolute',
38+
top: 8,
39+
right: 8,
40+
},
41+
copyIcon: {
42+
color: isDarkMode ? '#B0B0B0' : '#4D4D4D',
43+
},
44+
pre: {
45+
margin: theme.spacing(1),
46+
fontFamily: 'Monospace',
47+
fontSize: '0.875rem',
48+
whiteSpace: 'pre-wrap',
49+
wordBreak: 'break-word',
50+
color: isDarkMode ? '#B0B0B0' : '#4D4D4D',
51+
},
52+
}),
53+
);
54+
55+
export const JsonCodeBlock = ({
56+
value,
57+
isDarkMode,
58+
}: {
59+
value: object;
60+
isDarkMode: boolean;
61+
}) => {
62+
const jsonString = JSON.stringify(value, null, 2);
63+
const [copied, setCopied] = React.useState(false);
64+
const { classes } = useStyles({ isDarkMode });
65+
66+
const handleCopy = async () => {
67+
await window.navigator.clipboard.writeText(jsonString);
68+
setCopied(true);
69+
setTimeout(() => setCopied(false), 2000);
70+
};
71+
72+
return (
73+
<Paper elevation={1} className={classes.root}>
74+
<Box className={classes.iconButton}>
75+
<Tooltip title={copied ? 'Copied!' : 'Copy'}>
76+
<IconButton size="large" onClick={handleCopy}>
77+
<ContentCopyIcon fontSize="small" className={classes.copyIcon} />
78+
</IconButton>
79+
</Tooltip>
80+
</Box>
81+
<Box component="pre" className={classes.pre}>
82+
{jsonString}
83+
</Box>
84+
</Paper>
85+
);
86+
};

0 commit comments

Comments
 (0)