Skip to content

Commit e1e224e

Browse files
authored
Merge pull request #7 from smartcontractkit/feature/sc-33623
Show TOML Config
2 parents b286a55 + bb608be commit e1e224e

File tree

6 files changed

+133
-3
lines changed

6 files changed

+133
-3
lines changed

.changeset/forty-chairs-play.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@smartcontractkit/operator-ui': minor
3+
---
4+
5+
Add ability to show TOML config
6+
7+
On the configuration screen, the user is now able to view their node's TOML config

schema/type/configv2.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type ConfigV2Payload {
2+
user: String!
3+
effective: String!
4+
}

src/screens/Configuration/ConfigurationCard/ConfigurationCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const ConfigurationCard = () => {
4444

4545
return (
4646
<KeyValueListCard
47-
title="Configuration"
47+
title="ENV Configuration (legacy)"
4848
error={error?.message}
4949
loading={loading}
5050
entries={entries}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import React from 'react'
2+
3+
import { gql, useQuery } from '@apollo/client'
4+
5+
import Card from '@material-ui/core/Card'
6+
import CardHeader from '@material-ui/core/CardHeader'
7+
import Table from '@material-ui/core/Table'
8+
import TableBody from '@material-ui/core/TableBody'
9+
import TableCell from '@material-ui/core/TableCell'
10+
import TableRow from '@material-ui/core/TableRow'
11+
import Grid from '@material-ui/core/Grid'
12+
13+
export const CONFIG_V2_QUERY = gql`
14+
query FetchConfigV2 {
15+
configv2 {
16+
user
17+
effective
18+
}
19+
}
20+
`
21+
export const ConfigurationV2Card = () => {
22+
const { data, loading, error } = useQuery<
23+
FetchConfigV2,
24+
FetchConfigV2Variables
25+
>(CONFIG_V2_QUERY, {
26+
fetchPolicy: 'cache-and-network',
27+
})
28+
29+
var user: string[] = []
30+
if (data != undefined) {
31+
user = data?.configv2.user.split(/\n/).map((l) => {
32+
return l
33+
})
34+
} else {
35+
user = []
36+
}
37+
var effective: string[] = []
38+
if (data != undefined) {
39+
effective = data?.configv2.effective.split(/\n/).map((l) => {
40+
return l
41+
})
42+
} else {
43+
effective = []
44+
}
45+
46+
return (
47+
<>
48+
<Grid item xs={12}>
49+
<TOMLCard
50+
title="TOML Configuration (user-specified)"
51+
error={error?.message}
52+
loading={loading}
53+
entries={user}
54+
showHead
55+
/>
56+
</Grid>
57+
<Grid item xs={12}>
58+
<TOMLCard
59+
title="TOML Configuration (effective)"
60+
error={error?.message}
61+
loading={loading}
62+
entries={effective}
63+
showHead
64+
/>
65+
</Grid>
66+
</>
67+
)
68+
}
69+
70+
interface Props {
71+
entries: Array<string>
72+
loading: boolean
73+
showHead?: boolean
74+
title?: string
75+
error?: string
76+
}
77+
78+
const SpanRow: React.FC = ({ children }) => (
79+
<TableRow>
80+
<TableCell component="th" scope="row" colSpan={3}>
81+
{children}
82+
</TableCell>
83+
</TableRow>
84+
)
85+
86+
const FetchingRow = () => <SpanRow>...</SpanRow>
87+
88+
const ErrorRow: React.FC = ({ children }) => <SpanRow>{children}</SpanRow>
89+
90+
const TOMLCard = ({ loading, entries, error = '', title }: Props) => {
91+
if (error) {
92+
return <ErrorRow>{error}</ErrorRow>
93+
}
94+
95+
if (loading) {
96+
return <FetchingRow />
97+
}
98+
99+
return (
100+
<Card>
101+
{title && <CardHeader title={title} />}
102+
<Table>
103+
<TableBody>
104+
{entries.map((k, i) => (
105+
<TableRow key={title + k + i}>
106+
<TableCell>{k}</TableCell>
107+
</TableRow>
108+
))}
109+
</TableBody>
110+
</Table>
111+
</Card>
112+
)
113+
}

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('Configuration')).toBeInTheDocument()
21+
expect(await findByText('ENV Configuration (legacy)')).toBeInTheDocument()
2222
expect(await findByText('Node')).toBeInTheDocument()
2323
expect(await findByText('Job Runs')).toBeInTheDocument()
2424
expect(await findByText('Logging')).toBeInTheDocument()

src/screens/Configuration/ConfigurationView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import { LoggingCard } from 'src/pages/Configuration/LoggingCard'
66
import { JobRuns } from 'src/pages/Configuration/JobRuns'
77

88
import { ConfigurationCard } from './ConfigurationCard/ConfigurationCard'
9+
import { ConfigurationV2Card } from './ConfigurationV2Card/ConfigurationV2Card'
910
import { NodeInfoCard } from './NodeInfoCard/NodeInfoCard'
1011

1112
export const ConfigurationView = () => {
1213
return (
1314
<Content>
1415
<Grid container>
1516
<Grid item sm={12} md={8}>
16-
<ConfigurationCard />
17+
<Grid container>
18+
<Grid item xs={12}>
19+
<ConfigurationCard />
20+
</Grid>
21+
<ConfigurationV2Card />
22+
</Grid>
1723
</Grid>
1824
<Grid item sm={12} md={4}>
1925
<Grid container>

0 commit comments

Comments
 (0)