-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingestion) Implement secrets in new managed ingestion form (#5574)
- Loading branch information
1 parent
cfcc1cf
commit 6749171
Showing
6 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...hub-web-react/src/app/ingest/source/builder/RecipeForm/SecretField/CreateSecretButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
42 changes: 42 additions & 0 deletions
42
datahub-web-react/src/app/ingest/source/builder/RecipeForm/SecretField/SecretField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}`}> | ||
{secret.name} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
</Form.Item> | ||
); | ||
} | ||
|
||
export default SecretField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters