-
Notifications
You must be signed in to change notification settings - Fork 3k
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) Build out UI form for Snowflake Managed Ingestion #5391
Merged
anshbansal
merged 16 commits into
datahub-project:master
from
chriscollins3456:cc--managed-ingestion-form
Jul 15, 2022
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
13fa797
have it sloppily working with all types
d215340
clean up the code a good amount
1886276
make overall styling improvements
948e059
do some file refactoring
cbbc4f1
add two sections and style some stuff
10c522c
add most of the fields
1d5b8f4
refactor constants file to get more reuse going
3f75131
most of finishing touches except filter sections
8d324b6
add filters sections and help tooltips next to filter fields
ffbb728
fix some edge case bugs and update default yaml for snowflake
b09ba10
final cleanup and add tests
7847534
remove cruft
c342b5a
make recipe setter extensible with arbitrary field path
def52fc
final PR edits
ee94aa1
fix test titles
680956a
add override fields
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
103 changes: 103 additions & 0 deletions
103
datahub-web-react/src/app/ingest/source/builder/RecipeBuilder.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,103 @@ | ||
import { Button, message } from 'antd'; | ||
import React, { useState } from 'react'; | ||
import YAML from 'yamljs'; | ||
import { CodeOutlined, FormOutlined } from '@ant-design/icons'; | ||
import styled from 'styled-components/macro'; | ||
import { ANTD_GRAY } from '../../../entity/shared/constants'; | ||
import { YamlEditor } from './YamlEditor'; | ||
import RecipeForm from './RecipeForm/RecipeForm'; | ||
|
||
export const ControlsContainer = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
margin-top: 8px; | ||
`; | ||
|
||
const BorderedSection = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
padding-bottom: 16px; | ||
border: solid ${ANTD_GRAY[4]} 0.5px; | ||
`; | ||
|
||
const StyledButton = styled(Button)<{ isSelected: boolean }>` | ||
${(props) => | ||
props.isSelected && | ||
` | ||
color: #1890ff; | ||
&:focus { | ||
color: #1890ff; | ||
} | ||
`} | ||
`; | ||
|
||
const ButtonsWrapper = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
margin-bottom: 10px; | ||
`; | ||
|
||
interface Props { | ||
type: string; | ||
isEditing: boolean; | ||
displayRecipe: string; | ||
setStagedRecipe: (recipe: string) => void; | ||
onClickNext: () => void; | ||
goToPrevious?: () => void; | ||
} | ||
|
||
function RecipeBuilder(props: Props) { | ||
const { type, isEditing, displayRecipe, setStagedRecipe, onClickNext, goToPrevious } = props; | ||
|
||
const [isViewingForm, setIsViewingForm] = useState(true); | ||
|
||
function switchViews(isFormView: boolean) { | ||
try { | ||
YAML.parse(displayRecipe); | ||
setIsViewingForm(isFormView); | ||
} catch (e) { | ||
const messageText = (e as any).parsedLine | ||
? `Fix line ${(e as any).parsedLine} in your recipe` | ||
: 'Please fix your recipe'; | ||
message.warn(`Found invalid YAML. ${messageText} in order to switch views.`); | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<ButtonsWrapper> | ||
<StyledButton type="text" isSelected={isViewingForm} onClick={() => switchViews(true)}> | ||
<FormOutlined /> Form | ||
</StyledButton> | ||
<StyledButton type="text" isSelected={!isViewingForm} onClick={() => switchViews(false)}> | ||
<CodeOutlined /> YAML | ||
</StyledButton> | ||
</ButtonsWrapper> | ||
{isViewingForm && ( | ||
<RecipeForm | ||
type={type} | ||
isEditing={isEditing} | ||
displayRecipe={displayRecipe} | ||
setStagedRecipe={setStagedRecipe} | ||
onClickNext={onClickNext} | ||
goToPrevious={goToPrevious} | ||
/> | ||
)} | ||
{!isViewingForm && ( | ||
<> | ||
<BorderedSection> | ||
<YamlEditor initialText={displayRecipe} onChange={setStagedRecipe} /> | ||
</BorderedSection> | ||
<ControlsContainer> | ||
<Button disabled={isEditing} onClick={goToPrevious}> | ||
Previous | ||
</Button> | ||
<Button onClick={onClickNext}>Next</Button> | ||
</ControlsContainer> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default RecipeBuilder; |
115 changes: 115 additions & 0 deletions
115
datahub-web-react/src/app/ingest/source/builder/RecipeForm/FormField.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,115 @@ | ||
import { Button, Checkbox, Form, Input, Tooltip } from 'antd'; | ||
import React from 'react'; | ||
import styled from 'styled-components/macro'; | ||
import { MinusCircleOutlined, PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons'; | ||
import { FieldType, RecipeField } from './utils'; | ||
import { ANTD_GRAY } from '../../../../entity/shared/constants'; | ||
|
||
const Label = styled.div` | ||
font-weight: bold; | ||
padding-bottom: 8px; | ||
`; | ||
|
||
const StyledButton = styled(Button)` | ||
color: ${ANTD_GRAY[7]}; | ||
width: 80%; | ||
`; | ||
|
||
const StyledQuestion = styled(QuestionCircleOutlined)` | ||
color: rgba(0, 0, 0, 0.45); | ||
margin-left: 4px; | ||
`; | ||
|
||
const StyledRemoveIcon = styled(MinusCircleOutlined)` | ||
font-size: 14px; | ||
margin-left: 10px; | ||
`; | ||
|
||
const StyledFormItem = styled(Form.Item)<{ alignLeft: boolean; removeMargin: boolean }>` | ||
margin-bottom: ${(props) => (props.removeMargin ? '0' : '16px')}; | ||
|
||
${(props) => | ||
props.alignLeft && | ||
` | ||
.ant-form-item { | ||
flex-direction: row; | ||
|
||
} | ||
|
||
.ant-form-item-label { | ||
padding: 0; | ||
margin-right: 10px; | ||
} | ||
`} | ||
`; | ||
|
||
const ListWrapper = styled.div<{ removeMargin: boolean }>` | ||
margin-bottom: ${(props) => (props.removeMargin ? '0' : '16px')}; | ||
`; | ||
|
||
interface ListFieldProps { | ||
field: RecipeField; | ||
removeMargin?: boolean; | ||
} | ||
|
||
function ListField({ field, removeMargin }: ListFieldProps) { | ||
return ( | ||
<Form.List name={field.name}> | ||
{(fields, { add, remove }) => ( | ||
<ListWrapper removeMargin={!!removeMargin}> | ||
<Label> | ||
{field.label} | ||
<Tooltip overlay={field.tooltip}> | ||
<StyledQuestion /> | ||
</Tooltip> | ||
</Label> | ||
{fields.map((item) => ( | ||
<Form.Item key={item.fieldKey} style={{ marginBottom: '10px' }}> | ||
<Form.Item {...item} noStyle> | ||
<Input style={{ width: '80%' }} /> | ||
</Form.Item> | ||
<StyledRemoveIcon onClick={() => remove(item.name)} /> | ||
</Form.Item> | ||
))} | ||
<StyledButton type="dashed" onClick={() => add()} style={{ width: '80%' }} icon={<PlusOutlined />}> | ||
Add pattern | ||
</StyledButton> | ||
</ListWrapper> | ||
)} | ||
</Form.List> | ||
); | ||
} | ||
|
||
interface Props { | ||
field: RecipeField; | ||
removeMargin?: boolean; | ||
} | ||
|
||
function FormField(props: Props) { | ||
const { field, removeMargin } = props; | ||
|
||
if (field.type === FieldType.LIST) return <ListField field={field} removeMargin={removeMargin} />; | ||
|
||
const isBoolean = field.type === FieldType.BOOLEAN; | ||
const input = isBoolean ? <Checkbox /> : <Input />; | ||
const valuePropName = isBoolean ? 'checked' : 'value'; | ||
const getValueFromEvent = isBoolean ? undefined : (e) => (e.target.value === '' ? null : e.target.value); | ||
|
||
return ( | ||
<StyledFormItem | ||
style={isBoolean ? { flexDirection: 'row', alignItems: 'center' } : {}} | ||
label={field.label} | ||
name={field.name} | ||
tooltip={field.tooltip} | ||
rules={field.rules || undefined} | ||
valuePropName={valuePropName} | ||
getValueFromEvent={getValueFromEvent} | ||
alignLeft={isBoolean} | ||
removeMargin={!!removeMargin} | ||
> | ||
{input} | ||
</StyledFormItem> | ||
); | ||
} | ||
|
||
export default FormField; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice!