forked from newrelic/docs-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentConfig.js
More file actions
112 lines (106 loc) · 2.95 KB
/
Copy pathAgentConfig.js
File metadata and controls
112 lines (106 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { useState } from 'react';
import { css } from '@emotion/react';
import PropTypes from 'prop-types';
import {
CustomTextInput,
InteractiveOutput,
} from '@newrelic/gatsby-theme-newrelic';
import MDXContainer from './MDXContainer';
const AgentConfig = ({ inputOptions, config, tipMdx, onChange, fileName }) => {
const [state, setState] = useState([...inputOptions]);
const { body } = tipMdx;
const handleChange = (value, idx, name) => {
setState([
...state.slice(0, idx),
{ ...state[idx], value },
...state.slice(idx + 1),
]);
onChange({ name, value });
};
return (
<div
css={css`
display: flex;
justify-content: space-between;
width: 100%;
position: relative;
@media screen and (max-width: 1000px) {
flex-direction: column;
}
`}
>
<div
css={css`
width: 49%;
@media screen and (max-width: 1000px) {
width: 100%;
}
`}
>
{inputOptions.map(
({ name, label, codeLine, defaultValue, toolTip, url }, idx) => (
<CustomTextInput
name={name}
key={name}
label={label}
codeLine={parseInt(codeLine)}
defaultValue={defaultValue}
placeholder={defaultValue}
value={state[idx].value}
url={url}
onChange={(e) => handleChange(e.target.value, idx, name)}
toolTip={toolTip}
css={css`
margin-bottom: 1.5rem;
`}
containerId="agent-config-codeblock"
/>
)
)}
{body && <MDXContainer body={body} />}
</div>
<InteractiveOutput
inputs={state}
config={config}
fileName={fileName}
containerId="agent-config-codeblock"
css={css`
margin-top: 1rem;
width: 49%;
@media screen and (max-width: 1000px) {
width: 100%;
}
#agent-config-codeblock {
// removing the height of the buttons at the top or it overflows
max-height: calc(100% - 50px);
}
> div {
height: calc(100% - 16px);
position: absolute;
width: inherit;
@media screen and (max-width: 1000px) {
position: relative;
height: 400px;
}
}
`}
/>
</div>
);
};
AgentConfig.propTypes = {
inputOptions: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
defaultValue: PropTypes.string.isRequired,
codeLine: PropTypes.string.isRequired,
label: PropTypes.string,
toolTip: PropTypes.string,
url: PropTypes.shape({ title: PropTypes.string, href: PropTypes.string }),
})
),
config: PropTypes.string,
tipMdx: PropTypes.node,
onChange: PropTypes.func,
};
export default AgentConfig;