-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,882 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
83 changes: 83 additions & 0 deletions
83
...rsion/components/forms/components/transformer/components/table_inputs/EncoderInputCard.js
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,83 @@ | ||
import React from "react"; | ||
import { | ||
EuiFieldText, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiFormRow | ||
} from "@elastic/eui"; | ||
import { FormLabelWithToolTip, useOnChangeHandler } from "@gojek/mlp-ui"; | ||
import { DraggableHeader } from "../../../DraggableHeader"; | ||
import { SelectEncoder } from "./SelectEncoder"; | ||
import { OrdinalEncoderInputGroup } from "./OrdinalEncoderInputGroup"; | ||
|
||
export const EncoderInputCard = ({ | ||
index = 0, | ||
encoder, | ||
onChangeHandler, | ||
onDelete, | ||
errors = {}, | ||
...props | ||
}) => { | ||
const { onChange } = useOnChangeHandler(onChangeHandler); | ||
|
||
return ( | ||
<EuiPanel> | ||
<DraggableHeader | ||
onDelete={onDelete} | ||
dragHandleProps={props.dragHandleProps} | ||
/> | ||
|
||
<EuiSpacer size="s" /> | ||
|
||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem> | ||
<EuiFlexGroup direction="row"> | ||
<EuiFlexItem> | ||
<EuiFormRow | ||
label={ | ||
<FormLabelWithToolTip | ||
label="Encoder Name *" | ||
content="The name of encoder that will be passed in the table transformation step." | ||
/> | ||
} | ||
isInvalid={!!errors.name} | ||
error={errors.name} | ||
display="columnCompressed" | ||
fullWidth> | ||
<EuiFieldText | ||
placeholder="Encoder name" | ||
value={encoder.name || ""} | ||
onChange={e => onChange("name")(e.target.value)} | ||
isInvalid={!!errors.name} | ||
name={`name-${index}`} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem> | ||
<SelectEncoder | ||
encoderConfig={encoder} | ||
onChangeHandler={onChangeHandler} | ||
errors={errors} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
||
<EuiSpacer size="s" /> | ||
|
||
{encoder["ordinalEncoderConfig"] !== undefined && ( | ||
<OrdinalEncoderInputGroup | ||
index={index} | ||
ordinalEncoderConfig={encoder.ordinalEncoderConfig} | ||
onChangeHandler={onChangeHandler} | ||
errors={errors} | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}; |
108 changes: 108 additions & 0 deletions
108
...ion/components/forms/components/transformer/components/table_inputs/EncodersInputGroup.js
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,108 @@ | ||
import React from "react"; | ||
import { | ||
EuiDragDropContext, | ||
euiDragDropReorder, | ||
EuiDraggable, | ||
EuiDroppable, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPanel, | ||
EuiSpacer | ||
} from "@elastic/eui"; | ||
import { get, useOnChangeHandler } from "@gojek/mlp-ui"; | ||
import { DraggableHeader } from "../../../DraggableHeader"; | ||
import { AddButton } from "../../../transformer/components/AddButton"; | ||
import { EncoderInputCard } from "./EncoderInputCard"; | ||
|
||
export const EncodersInputGroup = ({ | ||
groupIndex, | ||
encoders, | ||
onChangeHandler, | ||
onDelete, | ||
errors = {}, | ||
...props | ||
}) => { | ||
const { onChange } = useOnChangeHandler(onChangeHandler); | ||
|
||
const onAddEncoder = () => { | ||
onChange(`${groupIndex}.encoders`)([...encoders, { name: "" }]); | ||
}; | ||
|
||
const onDeleteEncoder = idx => () => { | ||
encoders.splice(idx, 1); | ||
onChange(`${groupIndex}.encoders`)([...encoders]); | ||
}; | ||
|
||
const onDragEnd = ({ source, destination }) => { | ||
if (source && destination) { | ||
const items = euiDragDropReorder( | ||
encoders, | ||
source.index, | ||
destination.index | ||
); | ||
onChange(`${groupIndex}.encoders`)([...items]); | ||
} | ||
}; | ||
|
||
return ( | ||
<EuiPanel> | ||
<DraggableHeader | ||
onDelete={onDelete} | ||
dragHandleProps={props.dragHandleProps} | ||
/> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiDragDropContext onDragEnd={onDragEnd}> | ||
<EuiDroppable | ||
droppableId="ENCODERS_INPUT_DROPPABLE_AREA" | ||
spacing="m"> | ||
{encoders.map((encoder, encoderIdx) => ( | ||
<EuiDraggable | ||
key={`${encoderIdx}`} | ||
index={encoderIdx} | ||
draggableId={`${encoderIdx}`} | ||
customDragHandle={true} | ||
disableInteractiveElementBlocking> | ||
{provided => ( | ||
<EuiFlexItem key={`${encoderIdx}`}> | ||
<EncoderInputCard | ||
index={encoderIdx} | ||
encoder={encoder} | ||
onChangeHandler={onChange( | ||
`${groupIndex}.encoders.${encoderIdx}` | ||
)} | ||
onDelete={ | ||
encoders.length > 1 | ||
? onDeleteEncoder(encoderIdx) | ||
: undefined | ||
} | ||
dragHandleProps={provided.dragHandleProps} | ||
errors={get( | ||
errors, | ||
`${groupIndex}.encoders.${encoderIdx}` | ||
)} | ||
/> | ||
<EuiSpacer size="s" /> | ||
</EuiFlexItem> | ||
)} | ||
</EuiDraggable> | ||
))} | ||
</EuiDroppable> | ||
</EuiDragDropContext> | ||
</EuiFlexGroup> | ||
|
||
<EuiFlexItem> | ||
<AddButton | ||
title="+ Add Another Encoder" | ||
description="Declare a new encoder function that can be used on table transformation step." | ||
titleSize="xs" | ||
onClick={() => onAddEncoder()} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}; |
87 changes: 87 additions & 0 deletions
87
...mponents/forms/components/transformer/components/table_inputs/OrdinalEncoderInputGroup.js
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,87 @@ | ||
import React from "react"; | ||
import { | ||
EuiFormRow, | ||
EuiFieldNumber, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiText, | ||
EuiSpacer | ||
} from "@elastic/eui"; | ||
import { FormLabelWithToolTip, useOnChangeHandler } from "@gojek/mlp-ui"; | ||
import { SelectOrdinalValueType } from "./SelectOrdinalValueType"; | ||
import { OrdinalEncoderMapper } from "./OrdinalEncoderMapper"; | ||
|
||
export const OrdinalEncoderInputGroup = ({ | ||
index, | ||
ordinalEncoderConfig, | ||
onChangeHandler, | ||
errors = {} | ||
}) => { | ||
const { onChange } = useOnChangeHandler(onChangeHandler); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem> | ||
<EuiFlexGroup direction="row"> | ||
<EuiFlexItem> | ||
<EuiFormRow | ||
label={ | ||
<FormLabelWithToolTip | ||
label="Default Value *" | ||
content="Default value to map to if mapping undefined" | ||
/> | ||
} | ||
isInvalid={!!errors.defaultValue} | ||
error={errors.defaultValue} | ||
display="columnCompressed" | ||
fullWidth> | ||
<EuiFieldNumber | ||
placeholder="Default value" | ||
value={ordinalEncoderConfig.defaultValue || ""} | ||
onChange={e => | ||
onChange("ordinalEncoderConfig.defaultValue")(e.target.value) | ||
} | ||
isInvalid={!!errors.defaultValue} | ||
name={`defaultValue-${index}`} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<SelectOrdinalValueType | ||
defaultValue={ordinalEncoderConfig.defaultValue} | ||
valueType={ordinalEncoderConfig.targetValueType} | ||
mapping={ordinalEncoderConfig.mapping} | ||
onChangeHandler={onChange("ordinalEncoderConfig")} | ||
errors={errors} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
|
||
<EuiSpacer size="s" /> | ||
|
||
{ordinalEncoderConfig.targetValueType && ( | ||
<EuiFlexItem> | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem> | ||
<EuiText size="xs"> | ||
<h4>Mapping *</h4> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiFlexGroup direction="row"> | ||
<EuiFlexItem> | ||
<OrdinalEncoderMapper | ||
mappings={ordinalEncoderConfig.mapping} | ||
onChangeHandler={onChange("ordinalEncoderConfig")} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; |
Oops, something went wrong.