Skip to content

Commit 75a2142

Browse files
authored
Merge pull request #19 from smartcontractkit/dynamic-config
2 parents c034d17 + 19eedda commit 75a2142

File tree

3 files changed

+68
-27
lines changed

3 files changed

+68
-27
lines changed

src/screens/Configuration/ConfigurationCard/ConfigurationCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react'
33
import { gql, useQuery } from '@apollo/client'
44

55
import { KeyValueListCard } from 'src/components/Cards/KeyValueListCard'
6+
import {isNil} from "lodash";
67

78
export const CONFIG__ITEMS_FIELDS = gql`
89
fragment Config_ItemsFields on ConfigItem {
@@ -44,11 +45,11 @@ export const ConfigurationCard = () => {
4445

4546
return (
4647
<KeyValueListCard
47-
title="ENV Configuration (legacy)"
48+
title="ENV Configuration"
4849
error={error?.message}
4950
loading={loading}
5051
entries={entries}
51-
showHead
52+
showHead={isNil(error?.message)}
5253
/>
5354
)
5455
}

src/screens/Configuration/ConfigurationV2Card/ConfigurationV2Card.tsx

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import CardHeader from '@material-ui/core/CardHeader'
77
import TableCell from '@material-ui/core/TableCell'
88
import TableRow from '@material-ui/core/TableRow'
99
import Grid from '@material-ui/core/Grid'
10+
import ExpansionPanel from '@material-ui/core/ExpansionPanel'
11+
import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'
12+
import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'
13+
14+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
15+
import { prism } from 'react-syntax-highlighter/dist/esm/styles/prism'
16+
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'
17+
import Typography from '@material-ui/core/Typography'
1018

1119
export const CONFIG_V2_QUERY = gql`
1220
query FetchConfigV2 {
@@ -24,25 +32,46 @@ export const ConfigurationV2Card = () => {
2432
fetchPolicy: 'cache-and-network',
2533
})
2634

35+
if (data?.configv2.effective == 'N/A') {
36+
return (
37+
<>
38+
<Grid item xs={12}>
39+
<Card>
40+
<CardHeader title="TOML Configuration" />
41+
<TOMLPanel
42+
title="V2 config dump:"
43+
error={error?.message}
44+
loading={loading}
45+
toml={data?.configv2.user}
46+
showHead
47+
/>
48+
</Card>
49+
</Grid>
50+
</>
51+
)
52+
}
53+
2754
return (
2855
<>
2956
<Grid item xs={12}>
30-
<TOMLCard
31-
title="TOML Configuration (user-specified)"
32-
error={error?.message}
33-
loading={loading}
34-
toml={data?.configv2.user}
35-
showHead
36-
/>
37-
</Grid>
38-
<Grid item xs={12}>
39-
<TOMLCard
40-
title="TOML Configuration (effective)"
41-
error={error?.message}
42-
loading={loading}
43-
toml={data?.configv2.effective}
44-
showHead
45-
/>
57+
<Card>
58+
<CardHeader title="TOML Configuration" />
59+
<TOMLPanel
60+
title="User specified:"
61+
error={error?.message}
62+
loading={loading}
63+
toml={data?.configv2.user}
64+
showHead
65+
expanded={true}
66+
/>
67+
<TOMLPanel
68+
title="Effective (with defaults):"
69+
error={error?.message}
70+
loading={loading}
71+
toml={data?.configv2.effective}
72+
showHead
73+
/>
74+
</Card>
4675
</Grid>
4776
</>
4877
)
@@ -54,6 +83,7 @@ interface Props {
5483
showHead?: boolean
5584
title?: string
5685
error?: string
86+
expanded?: boolean
5787
}
5888

5989
const SpanRow: React.FC = ({ children }) => (
@@ -68,7 +98,7 @@ const FetchingRow = () => <SpanRow>...</SpanRow>
6898

6999
const ErrorRow: React.FC = ({ children }) => <SpanRow>{children}</SpanRow>
70100

71-
const TOMLCard = ({ loading, toml, error = '', title }: Props) => {
101+
const TOMLPanel = ({ loading, toml, error = '', title, expanded }: Props) => {
72102
if (error) {
73103
return <ErrorRow>{error}</ErrorRow>
74104
}
@@ -77,14 +107,24 @@ const TOMLCard = ({ loading, toml, error = '', title }: Props) => {
77107
return <FetchingRow />
78108
}
79109

80-
let styles = {marginLeft: '1em'};
110+
if (!title) {
111+
title = 'TOML'
112+
}
113+
114+
const styles = { display: 'block' }
81115

82116
return (
83-
<Card>
84-
{title && <CardHeader title={title} />}
85-
<pre style={styles}>
86-
<code>{toml}</code>
87-
</pre>
88-
</Card>
117+
<Typography>
118+
<ExpansionPanel defaultExpanded={expanded}>
119+
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
120+
{title}
121+
</ExpansionPanelSummary>
122+
<ExpansionPanelDetails style={styles}>
123+
<SyntaxHighlighter language="toml" style={prism}>
124+
{toml}
125+
</SyntaxHighlighter>
126+
</ExpansionPanelDetails>
127+
</ExpansionPanel>
128+
</Typography>
89129
)
90130
}

src/screens/Configuration/ConfigurationView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('ConfigurationView', () => {
1818
</BuildInfoProvider>,
1919
)
2020

21-
expect(await findByText('ENV Configuration (legacy)')).toBeInTheDocument()
21+
expect(await findByText('ENV Configuration')).toBeInTheDocument()
2222
expect(await findByText('Node')).toBeInTheDocument()
2323
expect(await findByText('Job Runs')).toBeInTheDocument()
2424
expect(await findByText('Logging')).toBeInTheDocument()

0 commit comments

Comments
 (0)