-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathOwnerSecuredVariables.tsx
102 lines (90 loc) · 3.09 KB
/
OwnerSecuredVariables.tsx
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
import React, { useState } from 'react';
import { useMutation, useFragment } from 'react-relay';
import { graphql } from 'babel-plugin-relay/macro';
import Button from '@mui/material/Button';
import Card from '@mui/material/Card';
import CardActions from '@mui/material/CardActions';
import CardContent from '@mui/material/CardContent';
import CardHeader from '@mui/material/CardHeader';
import FormControl from '@mui/material/FormControl';
import TextField from '@mui/material/TextField';
import CopyPasteField from 'components/common/CopyPasteField';
import {
OwnerSecuredVariablesMutation,
OwnerSecuredVariablesMutation$data,
OwnerSecuredVariablesMutation$variables,
} from './__generated__/OwnerSecuredVariablesMutation.graphql';
import { OwnerSecuredVariables_info$key } from './__generated__/OwnerSecuredVariables_info.graphql';
interface Props {
info: OwnerSecuredVariables_info$key;
}
export default function OwnerSecuredVariables(props: Props) {
let info = useFragment(
graphql`
fragment OwnerSecuredVariables_info on OwnerInfo {
platform
uid
name
}
`,
props.info,
);
let [securedVariableName, setSecuredVariableName] = useState<string | undefined>(undefined);
let [inputValue, setInputValue] = useState('');
let securedComponent: null | JSX.Element = null;
if (securedVariableName) {
let valueForYAMLFile = `ENCRYPTED[${securedVariableName}]`;
securedComponent = <CopyPasteField name="securedVariable" fullWidth={true} value={valueForYAMLFile} />;
}
const [commitSecuredVariableMutation] = useMutation<OwnerSecuredVariablesMutation>(graphql`
mutation OwnerSecuredVariablesMutation($input: OwnerSecuredVariableInput!) {
securedOwnerVariable(input: $input) {
variableName
}
}
`);
function encryptCurrentValue() {
const variables: OwnerSecuredVariablesMutation$variables = {
input: {
clientMutationId: info.name,
platform: info.platform,
ownerUid: info.uid,
valueToSecure: inputValue,
},
};
commitSecuredVariableMutation({
variables: variables,
onCompleted: (response: OwnerSecuredVariablesMutation$data, errors) => {
if (errors) {
console.log(errors);
return;
}
setSecuredVariableName(response.securedOwnerVariable.variableName);
},
onError: err => console.error(err),
});
}
return (
<Card elevation={24}>
<CardHeader title="Owner-Level Secured Variables" />
<CardContent>
<FormControl style={{ width: '100%' }}>
<TextField
name="securedVariableValue"
placeholder="Value to create a secure variable for"
value={inputValue}
onChange={event => setInputValue(event.target.value)}
multiline={true}
fullWidth={true}
/>
{securedComponent}
</FormControl>
</CardContent>
<CardActions>
<Button variant="contained" disabled={inputValue === ''} onClick={() => encryptCurrentValue()}>
Encrypt
</Button>
</CardActions>
</Card>
);
}