-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ingestion) Implement secrets in new managed ingestion form #5574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, message } from 'antd'; | ||
import { PlusOutlined } from '@ant-design/icons'; | ||
import { blue } from '@ant-design/colors'; | ||
import styled from 'styled-components/macro'; | ||
import { SecretBuilderModal } from '../../../../secret/SecretBuilderModal'; | ||
import { useCreateSecretMutation } from '../../../../../../graphql/ingestion.generated'; | ||
import { SecretBuilderState } from '../../../../secret/types'; | ||
|
||
const CreateButton = styled(Button)` | ||
align-items: center; | ||
display: flex; | ||
justify-content: center; | ||
margin: 8px 12px 4px 12px; | ||
width: calc(100% - 24px); | ||
|
||
&:hover { | ||
color: ${blue[5]}; | ||
} | ||
|
||
.anticon-plus { | ||
margin-right: 5px; | ||
} | ||
`; | ||
|
||
interface Props { | ||
refetchSecrets: () => void; | ||
} | ||
|
||
function CreateSecretButton({ refetchSecrets }: Props) { | ||
const [isCreateModalVisible, setIsCreateModalVisible] = useState(false); | ||
const [createSecretMutation] = useCreateSecretMutation(); | ||
|
||
const createSecret = (state: SecretBuilderState, resetBuilderState: () => void) => { | ||
createSecretMutation({ | ||
variables: { | ||
input: { | ||
name: state.name as string, | ||
value: state.value as string, | ||
description: state.description as string, | ||
}, | ||
}, | ||
}) | ||
.then(() => { | ||
setIsCreateModalVisible(false); | ||
resetBuilderState(); | ||
setTimeout(() => refetchSecrets(), 3000); | ||
message.loading({ content: `Loading...`, duration: 3 }).then(() => { | ||
message.success({ content: `Successfully created Secret!` }); | ||
}); | ||
}) | ||
.catch((e) => { | ||
message.destroy(); | ||
message.error({ content: `Failed to create secret: \n ${e.message || ''}` }); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<CreateButton onClick={() => setIsCreateModalVisible(true)} type="text"> | ||
<PlusOutlined /> Create Secret | ||
</CreateButton> | ||
{isCreateModalVisible && ( | ||
<SecretBuilderModal | ||
visible={isCreateModalVisible} | ||
onCancel={() => setIsCreateModalVisible(false)} | ||
onSubmit={createSecret} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default CreateSecretButton; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { Divider, Form, Select } from 'antd'; | ||
import styled from 'styled-components/macro'; | ||
import { RecipeField } from '../utils'; | ||
import { Secret } from '../../../../../../types.generated'; | ||
import CreateSecretButton from './CreateSecretButton'; | ||
|
||
const StyledDivider = styled(Divider)` | ||
margin: 0; | ||
`; | ||
|
||
interface SecretFieldProps { | ||
field: RecipeField; | ||
secrets: Secret[]; | ||
refetchSecrets: () => void; | ||
} | ||
|
||
function SecretField({ field, secrets, refetchSecrets }: SecretFieldProps) { | ||
return ( | ||
<Form.Item name={field.name} label={field.label} tooltip={field.tooltip}> | ||
<Select | ||
showSearch | ||
filterOption={(input, option) => !!option?.children.toLowerCase().includes(input.toLowerCase())} | ||
dropdownRender={(menu) => ( | ||
<> | ||
{menu} | ||
<StyledDivider /> | ||
<CreateSecretButton refetchSecrets={refetchSecrets} /> | ||
</> | ||
)} | ||
> | ||
{secrets.map((secret) => ( | ||
<Select.Option key={secret.urn} value={`\${${secret.name}}`}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotta escape the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahhhh |
||
{secret.name} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
</Form.Item> | ||
); | ||
} | ||
|
||
export default SecretField; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we store these as constant and constant+1 so if one is changed this modal doesn't disappear for (seemingly) no reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh i wanted to do that, but it's Ant designs constant of 1050 so we don't actually have access to that in our code base :( so this is risky if they change that number for some reason. we could just plop this at some ridiculously high number as well if we really wanted to